![](/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.
Alien/Alien.cpp@9:759b419fec3b, 2020-05-26 (annotated)
- Committer:
- MatisRequis
- Date:
- Tue May 26 07:26:13 2020 +0000
- Revision:
- 9:759b419fec3b
- Child:
- 10:2ae9d4145410
Aliens working similar to bullets with random
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MatisRequis | 9:759b419fec3b | 1 | #include "Alien.h" |
MatisRequis | 9:759b419fec3b | 2 | |
MatisRequis | 9:759b419fec3b | 3 | Alien::Alien() { |
MatisRequis | 9:759b419fec3b | 4 | |
MatisRequis | 9:759b419fec3b | 5 | } |
MatisRequis | 9:759b419fec3b | 6 | |
MatisRequis | 9:759b419fec3b | 7 | Alien::~Alien() { |
MatisRequis | 9:759b419fec3b | 8 | |
MatisRequis | 9:759b419fec3b | 9 | } |
MatisRequis | 9:759b419fec3b | 10 | |
MatisRequis | 9:759b419fec3b | 11 | void Alien::init(int column, int speed) { |
MatisRequis | 9:759b419fec3b | 12 | _currentpos = 14; |
MatisRequis | 9:759b419fec3b | 13 | srand(time(NULL)); //makes pseudo rando number generator have different seed every time based on the current time |
MatisRequis | 9:759b419fec3b | 14 | _column = column; |
MatisRequis | 9:759b419fec3b | 15 | _board.path(); |
MatisRequis | 9:759b419fec3b | 16 | _alienspeed = speed; |
MatisRequis | 9:759b419fec3b | 17 | _movcount = 1; |
MatisRequis | 9:759b419fec3b | 18 | |
MatisRequis | 9:759b419fec3b | 19 | } |
MatisRequis | 9:759b419fec3b | 20 | |
MatisRequis | 9:759b419fec3b | 21 | void Alien::draw(N5110 &lcd) { |
MatisRequis | 9:759b419fec3b | 22 | getxy(); |
MatisRequis | 9:759b419fec3b | 23 | if (_column < 3 && _column >= 0) { |
MatisRequis | 9:759b419fec3b | 24 | lcd.drawLine(_x-1, _y, _x+1, _y, 1); |
MatisRequis | 9:759b419fec3b | 25 | lcd.drawLine(_x-2, _y+1, _x+2, _y+1, 1); |
MatisRequis | 9:759b419fec3b | 26 | |
MatisRequis | 9:759b419fec3b | 27 | } else if (_column < 6 && _column > 2) { |
MatisRequis | 9:759b419fec3b | 28 | lcd.drawLine(_x, _y-1, _x, _y+1, 1); |
MatisRequis | 9:759b419fec3b | 29 | lcd.drawLine(_x-1, _y-2, _x-1, _y+2, 1); |
MatisRequis | 9:759b419fec3b | 30 | |
MatisRequis | 9:759b419fec3b | 31 | } else if (_column < 9 && _column > 5) { |
MatisRequis | 9:759b419fec3b | 32 | lcd.drawLine(_x-1, _y, _x+1, _y, 1); |
MatisRequis | 9:759b419fec3b | 33 | lcd.drawLine(_x-2, _y-1, _x+2, _y-1, 1); |
MatisRequis | 9:759b419fec3b | 34 | |
MatisRequis | 9:759b419fec3b | 35 | } else if (_column < 12 && _column > 8) { |
MatisRequis | 9:759b419fec3b | 36 | lcd.drawLine(_x, _y-1, _x, _y+1, 1); |
MatisRequis | 9:759b419fec3b | 37 | lcd.drawLine(_x+1, _y-2, _x+1, _y+2, 1); |
MatisRequis | 9:759b419fec3b | 38 | } |
MatisRequis | 9:759b419fec3b | 39 | } |
MatisRequis | 9:759b419fec3b | 40 | |
MatisRequis | 9:759b419fec3b | 41 | void Alien::update() { |
MatisRequis | 9:759b419fec3b | 42 | //advances the alien every x update |
MatisRequis | 9:759b419fec3b | 43 | if (_movcount <= 0) { |
MatisRequis | 9:759b419fec3b | 44 | |
MatisRequis | 9:759b419fec3b | 45 | //random movement can move the alien +1 column, -1 column or not move |
MatisRequis | 9:759b419fec3b | 46 | _rand = (rand() % 3)-1; |
MatisRequis | 9:759b419fec3b | 47 | _column += _rand; |
MatisRequis | 9:759b419fec3b | 48 | |
MatisRequis | 9:759b419fec3b | 49 | _currentpos--; |
MatisRequis | 9:759b419fec3b | 50 | _movcount = _alienspeed; |
MatisRequis | 9:759b419fec3b | 51 | } else { |
MatisRequis | 9:759b419fec3b | 52 | _movcount--; |
MatisRequis | 9:759b419fec3b | 53 | } |
MatisRequis | 9:759b419fec3b | 54 | |
MatisRequis | 9:759b419fec3b | 55 | } |
MatisRequis | 9:759b419fec3b | 56 | |
MatisRequis | 9:759b419fec3b | 57 | int Alien::checkdelete() { |
MatisRequis | 9:759b419fec3b | 58 | if (_currentpos < 1) { |
MatisRequis | 9:759b419fec3b | 59 | _loss = 1; |
MatisRequis | 9:759b419fec3b | 60 | return 1; |
MatisRequis | 9:759b419fec3b | 61 | } else { |
MatisRequis | 9:759b419fec3b | 62 | return 0; |
MatisRequis | 9:759b419fec3b | 63 | } |
MatisRequis | 9:759b419fec3b | 64 | } |
MatisRequis | 9:759b419fec3b | 65 | |
MatisRequis | 9:759b419fec3b | 66 | int Alien::checkobjective() { |
MatisRequis | 9:759b419fec3b | 67 | if (_loss) { |
MatisRequis | 9:759b419fec3b | 68 | return 1; |
MatisRequis | 9:759b419fec3b | 69 | } else { |
MatisRequis | 9:759b419fec3b | 70 | return 0; |
MatisRequis | 9:759b419fec3b | 71 | } |
MatisRequis | 9:759b419fec3b | 72 | } |
MatisRequis | 9:759b419fec3b | 73 | |
MatisRequis | 9:759b419fec3b | 74 | Vector2D Alien::getxy() { |
MatisRequis | 9:759b419fec3b | 75 | _x = _board.drawcolumn[_column][_currentpos].x; |
MatisRequis | 9:759b419fec3b | 76 | _y = _board.drawcolumn[_column][_currentpos].y; |
MatisRequis | 9:759b419fec3b | 77 | |
MatisRequis | 9:759b419fec3b | 78 | Vector2D p = {_board.drawcolumn[_column][_currentpos].x, _board.drawcolumn[_column][_currentpos].y}; |
MatisRequis | 9:759b419fec3b | 79 | return p; |
MatisRequis | 9:759b419fec3b | 80 | } |