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@12:1f1907ebebeb, 2020-05-27 (annotated)
- Committer:
- MatisRequis
- Date:
- Wed May 27 05:53:03 2020 +0000
- Revision:
- 12:1f1907ebebeb
- Parent:
- 10:2ae9d4145410
Final Submission. I have read and agreed with Statement of Academic Integrity
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 | 10:2ae9d4145410 | 11 | //initialises the alien with all the speed values and the path it uses |
MatisRequis | 9:759b419fec3b | 12 | void Alien::init(int column, int speed) { |
MatisRequis | 10:2ae9d4145410 | 13 | _currentpos = 13; |
MatisRequis | 10:2ae9d4145410 | 14 | //makes pseudo rando number generator have different seed every time based on the current time |
MatisRequis | 10:2ae9d4145410 | 15 | srand(time(NULL)); |
MatisRequis | 9:759b419fec3b | 16 | _column = column; |
MatisRequis | 9:759b419fec3b | 17 | _board.path(); |
MatisRequis | 9:759b419fec3b | 18 | _alienspeed = speed; |
MatisRequis | 10:2ae9d4145410 | 19 | _movcount = 10; |
MatisRequis | 9:759b419fec3b | 20 | |
MatisRequis | 9:759b419fec3b | 21 | } |
MatisRequis | 9:759b419fec3b | 22 | |
MatisRequis | 10:2ae9d4145410 | 23 | //draws the alien |
MatisRequis | 9:759b419fec3b | 24 | void Alien::draw(N5110 &lcd) { |
MatisRequis | 9:759b419fec3b | 25 | getxy(); |
MatisRequis | 10:2ae9d4145410 | 26 | |
MatisRequis | 10:2ae9d4145410 | 27 | //draws the alien in differnet orientation depending on the column |
MatisRequis | 9:759b419fec3b | 28 | if (_column < 3 && _column >= 0) { |
MatisRequis | 9:759b419fec3b | 29 | lcd.drawLine(_x-1, _y, _x+1, _y, 1); |
MatisRequis | 9:759b419fec3b | 30 | lcd.drawLine(_x-2, _y+1, _x+2, _y+1, 1); |
MatisRequis | 9:759b419fec3b | 31 | |
MatisRequis | 9:759b419fec3b | 32 | } else if (_column < 6 && _column > 2) { |
MatisRequis | 9:759b419fec3b | 33 | lcd.drawLine(_x, _y-1, _x, _y+1, 1); |
MatisRequis | 9:759b419fec3b | 34 | lcd.drawLine(_x-1, _y-2, _x-1, _y+2, 1); |
MatisRequis | 9:759b419fec3b | 35 | |
MatisRequis | 9:759b419fec3b | 36 | } else if (_column < 9 && _column > 5) { |
MatisRequis | 9:759b419fec3b | 37 | lcd.drawLine(_x-1, _y, _x+1, _y, 1); |
MatisRequis | 9:759b419fec3b | 38 | lcd.drawLine(_x-2, _y-1, _x+2, _y-1, 1); |
MatisRequis | 9:759b419fec3b | 39 | |
MatisRequis | 9:759b419fec3b | 40 | } else if (_column < 12 && _column > 8) { |
MatisRequis | 9:759b419fec3b | 41 | lcd.drawLine(_x, _y-1, _x, _y+1, 1); |
MatisRequis | 9:759b419fec3b | 42 | lcd.drawLine(_x+1, _y-2, _x+1, _y+2, 1); |
MatisRequis | 9:759b419fec3b | 43 | } |
MatisRequis | 9:759b419fec3b | 44 | } |
MatisRequis | 9:759b419fec3b | 45 | |
MatisRequis | 9:759b419fec3b | 46 | void Alien::update() { |
MatisRequis | 9:759b419fec3b | 47 | //advances the alien every x update |
MatisRequis | 9:759b419fec3b | 48 | if (_movcount <= 0) { |
MatisRequis | 9:759b419fec3b | 49 | |
MatisRequis | 9:759b419fec3b | 50 | //random movement can move the alien +1 column, -1 column or not move |
MatisRequis | 9:759b419fec3b | 51 | _rand = (rand() % 3)-1; |
MatisRequis | 9:759b419fec3b | 52 | _column += _rand; |
MatisRequis | 9:759b419fec3b | 53 | |
MatisRequis | 9:759b419fec3b | 54 | _currentpos--; |
MatisRequis | 10:2ae9d4145410 | 55 | //resets the speed limiter |
MatisRequis | 9:759b419fec3b | 56 | _movcount = _alienspeed; |
MatisRequis | 9:759b419fec3b | 57 | } else { |
MatisRequis | 9:759b419fec3b | 58 | _movcount--; |
MatisRequis | 9:759b419fec3b | 59 | } |
MatisRequis | 9:759b419fec3b | 60 | |
MatisRequis | 9:759b419fec3b | 61 | } |
MatisRequis | 9:759b419fec3b | 62 | |
MatisRequis | 10:2ae9d4145410 | 63 | //checks if the alien is at the end of the lane |
MatisRequis | 9:759b419fec3b | 64 | int Alien::checkdelete() { |
MatisRequis | 10:2ae9d4145410 | 65 | if (_currentpos < 1) { |
MatisRequis | 9:759b419fec3b | 66 | return 1; |
MatisRequis | 9:759b419fec3b | 67 | } else { |
MatisRequis | 9:759b419fec3b | 68 | return 0; |
MatisRequis | 9:759b419fec3b | 69 | } |
MatisRequis | 9:759b419fec3b | 70 | } |
MatisRequis | 9:759b419fec3b | 71 | |
MatisRequis | 10:2ae9d4145410 | 72 | //returns the current position of the alien |
MatisRequis | 9:759b419fec3b | 73 | Vector2D Alien::getxy() { |
MatisRequis | 9:759b419fec3b | 74 | _x = _board.drawcolumn[_column][_currentpos].x; |
MatisRequis | 9:759b419fec3b | 75 | _y = _board.drawcolumn[_column][_currentpos].y; |
MatisRequis | 10:2ae9d4145410 | 76 | |
MatisRequis | 10:2ae9d4145410 | 77 | Vector2D alienxy = {_board.drawcolumn[_column][_currentpos].x, _board.drawcolumn[_column][_currentpos].y}; |
MatisRequis | 10:2ae9d4145410 | 78 | return alienxy; |
MatisRequis | 10:2ae9d4145410 | 79 | } |
MatisRequis | 10:2ae9d4145410 | 80 | |
MatisRequis | 10:2ae9d4145410 | 81 | //returns the column and position in the lane of the alien |
MatisRequis | 10:2ae9d4145410 | 82 | Vector2D Alien::getcolumnpos() { |
MatisRequis | 10:2ae9d4145410 | 83 | Vector2D aliencolpos = {_column, _currentpos}; |
MatisRequis | 10:2ae9d4145410 | 84 | return aliencolpos; |
MatisRequis | 10:2ae9d4145410 | 85 | } |