Matis Requis 201241242
Dependencies: mbed
Tempest Game
Game Screen
The board is made of 12 columns. The Hero stays at the top of the column
Game Controls
To control the hero spaceship point the joystick to the column you want the hero to go to.
Press the A button to shoot a bullet in the column you are currently in.
Diff: Hero/Hero.cpp
- Revision:
- 4:8e3ba8d6d915
- Parent:
- 2:d59a92e65bd9
- Child:
- 5:a3c9a5837a7c
diff -r 54132cf073d7 -r 8e3ba8d6d915 Hero/Hero.cpp --- a/Hero/Hero.cpp Thu May 21 07:10:22 2020 +0000 +++ b/Hero/Hero.cpp Fri May 22 10:29:49 2020 +0000 @@ -13,6 +13,20 @@ } void Hero::draw(N5110 &lcd) { + + + char buffer[3]; + sprintf(buffer,"%2d", _column); + lcd.printString(buffer,0, 0); + + char ruffer[3]; + sprintf(ruffer,"%2d", _d); + lcd.printString(ruffer,70, 0); + + char tuffer[3]; + sprintf(tuffer,"%2d", _mag); + lcd.printString(tuffer,0, 24); + Vector2D xypos = getxy(); _x = xypos.x; @@ -20,90 +34,67 @@ if (_column < 3 && _column >= 0) { lcd.drawRect(_x+4, _y, 6, 2, FILL_BLACK); - lcd.drawLine(_x+2, _y+1, _x+12, _y+1, 1); - lcd.drawLine(_x+2, _y+3, _x+3, _y+5, 1); - lcd.drawLine(_x+12, _y+3, _x+11, _y+5, 1); + lcd.drawLine(_x+2, _y+1, _x+11, _y+1, 1); + lcd.drawLine(_x+2, _y+3, _x+3, _y+4, 1); + lcd.drawLine(_x+11, _y+3, _x+10, _y+4, 1); } else if (_column < 6 && _column > 2) { - lcd.drawRect(_x-2, _y+4, 2, 6, FILL_BLACK); + lcd.drawLine(_x, _y+4, _x, _y+9, 1); + lcd.drawLine(_x-1, _y+2,_x-1, _y+11, 1); + lcd.drawLine(_x-3, _y+2, _x-4, _y+3, 1); + lcd.drawLine(_x-3, _y+11, _x-4, _y+10, 1); } else if (_column < 9 && _column > 5) { - //lcd.drawRect(); - - } else { - //lcd.drawRect(); + lcd.drawLine(_x-4, _y, _x-9, _y, 1); + lcd.drawLine(_x-2, _y-1, _x-11, _y-1, 1); + lcd.drawLine(_x-2, _y-3, _x-3, _y-4, 1); + lcd.drawLine(_x-11, _y-3, _x-10, _y-4, 1); + + } else if (_column < 12 && _column > 8) { + lcd.drawLine(_x, _y-4, _x, _y-9, 1); + lcd.drawLine(_x+1, _y-2, _x+1, _y-11, 1); + lcd.drawLine(_x+3, _y-2, _x+4, _y-4, 1); + lcd.drawLine(_x+3, _y-11, _x+4, _y-10, 1); } } -void Hero::update(Direction d) { - if (_column < 3 && _column >= 0) { - - if (d == W) { - if (_column == 0) { - _column = 11; - } else { - _column--; - } - } else if (d == E) { - if (_column == 11) { - _column = 0; - } else { - _column++; - } - } - - - } else if (_column < 6 && _column > 2) { - if (d == N) { - if (_column == 0) { - _column = 11; - } else { - _column--; - } - } else if (d == S) { - if (_column == 11) { - _column = 0; - } else { - _column++; - } - } - - - } else if (_column < 9 && _column > 5) { - if (d == E) { - if (_column == 0) { - _column = 11; - } else { - _column--; - } - } else if (d == W) { - if (_column == 11) { - _column = 0; - } else { - _column++; - } - } - + +void Hero::update(float d, float mag, int a) { + + _d = d; + _mag = mag; - } else { - if (d == S) { - if (_column == 0) { - _column = 11; - } else { - _column--; - } - } else if (d == N) { - if (_column == 11) { - _column = 0; - } else { - _column++; - } - } - - + if (_d < 0) { + } else if (_d <= 15) { + _column = 1; + } else if (_d <= 45) { + _column = 2; + } else if (_d <= 75) { + _column = 3; + } else if (_d <= 105) { + _column = 4; + } else if (_d <= 135) { + _column = 5; + } else if (_d <= 165) { + _column = 6; + } else if (_d <= 195) { + _column = 7; + } else if (_d <= 225) { + _column = 8; + } else if (_d <= 255) { + _column = 9; + } else if (_d <= 285) { + _column = 10; + } else if (_d <= 315) { + _column = 11; + } else if (_d <= 345) { + _column = 0; + } else { + _column = 1; } } + Vector2D Hero::getxy() { if (_column == 0) { Vector2D p = {21, 1}; @@ -112,36 +103,37 @@ Vector2D p = {35, 1}; return p; } else if (_column == 2) { - Vector2D p = {49, 1}; + Vector2D p = {48, 1}; return p; } else if (_column == 3) { - Vector2D p = {65, 3}; + Vector2D p = {64, 3}; return p; } else if (_column == 4) { - Vector2D p = {65, 17}; + Vector2D p = {64, 17}; return p; } else if (_column == 5) { - Vector2D p = {65, 31}; + Vector2D p = {64, 30}; return p; } else if (_column == 6) { - Vector2D p = {63, 47}; + Vector2D p = {62, 46}; return p; } else if (_column == 7) { - Vector2D p = {49, 47}; + Vector2D p = {48, 46}; return p; } else if (_column == 8) { - Vector2D p = {35, 47}; + Vector2D p = {35, 46}; return p; } else if (_column == 9) { - Vector2D p = {19, 45}; + Vector2D p = {19, 44}; return p; } else if (_column == 10) { - Vector2D p = {19, 31}; + Vector2D p = {19, 30}; return p; } else if (_column == 11) { Vector2D p = {19, 17}; return p; - } - Vector2D p = {0,0}; - return p; + } else { + Vector2D p = {0,0}; + return p; + } } \ No newline at end of file