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.
Hero/Hero.cpp
- Committer:
- MatisRequis
- Date:
- 2020-05-22
- Revision:
- 4:8e3ba8d6d915
- Parent:
- 2:d59a92e65bd9
- Child:
- 5:a3c9a5837a7c
File content as of revision 4:8e3ba8d6d915:
#include "Hero.h" Hero::Hero() { } Hero::~Hero() { } void Hero::init(int column) { _column = column; } 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; _y = xypos.y; 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); 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.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.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(float d, float mag, int a) { _d = d; _mag = mag; 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}; return p; } else if (_column == 1) { Vector2D p = {35, 1}; return p; } else if (_column == 2) { Vector2D p = {48, 1}; return p; } else if (_column == 3) { Vector2D p = {64, 3}; return p; } else if (_column == 4) { Vector2D p = {64, 17}; return p; } else if (_column == 5) { Vector2D p = {64, 30}; return p; } else if (_column == 6) { Vector2D p = {62, 46}; return p; } else if (_column == 7) { Vector2D p = {48, 46}; return p; } else if (_column == 8) { Vector2D p = {35, 46}; return p; } else if (_column == 9) { Vector2D p = {19, 44}; return p; } else if (_column == 10) { Vector2D p = {19, 30}; return p; } else if (_column == 11) { Vector2D p = {19, 17}; return p; } else { Vector2D p = {0,0}; return p; } }