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.
Alien/Alien.cpp
- Committer:
- MatisRequis
- Date:
- 2020-05-26
- Revision:
- 9:759b419fec3b
- Child:
- 10:2ae9d4145410
File content as of revision 9:759b419fec3b:
#include "Alien.h" Alien::Alien() { } Alien::~Alien() { } void Alien::init(int column, int speed) { _currentpos = 14; srand(time(NULL)); //makes pseudo rando number generator have different seed every time based on the current time _column = column; _board.path(); _alienspeed = speed; _movcount = 1; } void Alien::draw(N5110 &lcd) { getxy(); if (_column < 3 && _column >= 0) { lcd.drawLine(_x-1, _y, _x+1, _y, 1); lcd.drawLine(_x-2, _y+1, _x+2, _y+1, 1); } else if (_column < 6 && _column > 2) { lcd.drawLine(_x, _y-1, _x, _y+1, 1); lcd.drawLine(_x-1, _y-2, _x-1, _y+2, 1); } else if (_column < 9 && _column > 5) { lcd.drawLine(_x-1, _y, _x+1, _y, 1); lcd.drawLine(_x-2, _y-1, _x+2, _y-1, 1); } else if (_column < 12 && _column > 8) { lcd.drawLine(_x, _y-1, _x, _y+1, 1); lcd.drawLine(_x+1, _y-2, _x+1, _y+2, 1); } } void Alien::update() { //advances the alien every x update if (_movcount <= 0) { //random movement can move the alien +1 column, -1 column or not move _rand = (rand() % 3)-1; _column += _rand; _currentpos--; _movcount = _alienspeed; } else { _movcount--; } } int Alien::checkdelete() { if (_currentpos < 1) { _loss = 1; return 1; } else { return 0; } } int Alien::checkobjective() { if (_loss) { return 1; } else { return 0; } } Vector2D Alien::getxy() { _x = _board.drawcolumn[_column][_currentpos].x; _y = _board.drawcolumn[_column][_currentpos].y; Vector2D p = {_board.drawcolumn[_column][_currentpos].x, _board.drawcolumn[_column][_currentpos].y}; return p; }