![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
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:
- 10:2ae9d4145410
- Parent:
- 6:037dfa5064a1
- Child:
- 11:b6698572e551
--- a/Hero/Hero.cpp Tue May 26 07:26:13 2020 +0000 +++ b/Hero/Hero.cpp Tue May 26 16:31:22 2020 +0000 @@ -8,10 +8,12 @@ } +//initialises the hero's starting column void Hero::init(int column) { _column = column; } - + +//draws the hero void Hero::draw(N5110 &lcd) { Vector2D xypos = getxy(); @@ -19,6 +21,7 @@ _x = xypos.x; _y = xypos.y; + changes the orientation of the hero depending on the current column if (_column < 3 && _column >= 0) { lcd.drawRect(_x+4, _y, 6, 2, FILL_BLACK); lcd.drawLine(_x+2, _y+1, _x+11, _y+1, 1); @@ -45,36 +48,34 @@ } } - -void Hero::update(float d, float mag) { - - _d = d; - _mag = mag; +//sets the column depending on the joystick angle +void Hero::update(float d) { + - if (_d < 0) { - } else if (_d <= 15) { + if (d < 0) { + } else if (d <= 15) { _column = 1; - } else if (_d <= 45) { + } else if (d <= 45) { _column = 2; - } else if (_d <= 75) { + } else if (d <= 75) { _column = 3; - } else if (_d <= 105) { + } else if (d <= 105) { _column = 4; - } else if (_d <= 135) { + } else if (d <= 135) { _column = 5; - } else if (_d <= 165) { + } else if (d <= 165) { _column = 6; - } else if (_d <= 195) { + } else if (d <= 195) { _column = 7; - } else if (_d <= 225) { + } else if (d <= 225) { _column = 8; - } else if (_d <= 255) { + } else if (d <= 255) { _column = 9; - } else if (_d <= 285) { + } else if (d <= 285) { _column = 10; - } else if (_d <= 315) { + } else if (d <= 315) { _column = 11; - } else if (_d <= 345) { + } else if (d <= 345) { _column = 0; } else { _column = 1; @@ -83,50 +84,63 @@ } - +//returns the current hero position Vector2D Hero::getxy() { if (_column == 0) { - Vector2D p = {21, 1}; - return p; + Vector2D hero_pos = {21, 1}; + return hero_pos; + } else if (_column == 1) { - Vector2D p = {35, 1}; - return p; + Vector2D hero_pos = {35, 1}; + return hero_pos; + } else if (_column == 2) { - Vector2D p = {48, 1}; - return p; + Vector2D hero_pos = {48, 1}; + return hero_pos; + } else if (_column == 3) { - Vector2D p = {64, 3}; - return p; + Vector2D hero_pos = {64, 3}; + return hero_pos; + } else if (_column == 4) { - Vector2D p = {64, 17}; - return p; + Vector2D hero_pos = {64, 17}; + return hero_pos; + } else if (_column == 5) { - Vector2D p = {64, 30}; - return p; + Vector2D hero_pos = {64, 30}; + return hero_pos; + } else if (_column == 6) { - Vector2D p = {62, 46}; - return p; + Vector2D hero_pos = {62, 46}; + return hero_pos; + } else if (_column == 7) { - Vector2D p = {48, 46}; - return p; + Vector2D hero_pos = {48, 46}; + return hero_pos; + } else if (_column == 8) { - Vector2D p = {35, 46}; - return p; + Vector2D hero_pos = {35, 46}; + return hero_pos; + } else if (_column == 9) { - Vector2D p = {19, 44}; - return p; + Vector2D hero_pos = {19, 44}; + return hero_pos; + } else if (_column == 10) { - Vector2D p = {19, 30}; - return p; + Vector2D hero_pos = {19, 30}; + return hero_pos; + } else if (_column == 11) { - Vector2D p = {19, 17}; - return p; + Vector2D hero_pos = {19, 17}; + return hero_pos; + } else { - Vector2D p = {0,0}; - return p; + Vector2D hero_pos = {0,0}; + return hero_pos; } } +//returns the current column of the hero int Hero::get_column() { return _column; } \ No newline at end of file