Matis Requis 201241242

Dependencies:   mbed

Tempest Game

Game Screen

https://os.mbed.com/media/uploads/MatisRequis/tempest_board_wiki.png The board is made of 12 columns. The Hero stays at the top of the column

Game Controls

https://os.mbed.com/media/uploads/MatisRequis/gamepad_buttons.png

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.

Committer:
MatisRequis
Date:
Tue May 26 16:31:22 2020 +0000
Revision:
10:2ae9d4145410
Parent:
9:759b419fec3b
Finished code with comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MatisRequis 2:d59a92e65bd9 1 #include "Bullet.h"
MatisRequis 2:d59a92e65bd9 2
MatisRequis 2:d59a92e65bd9 3 Bullet::Bullet() {
MatisRequis 2:d59a92e65bd9 4
MatisRequis 2:d59a92e65bd9 5 }
MatisRequis 2:d59a92e65bd9 6
MatisRequis 2:d59a92e65bd9 7 Bullet::~Bullet() {
MatisRequis 2:d59a92e65bd9 8
MatisRequis 2:d59a92e65bd9 9 }
MatisRequis 2:d59a92e65bd9 10
MatisRequis 10:2ae9d4145410 11 //initialises the current column and position in the column of the bullet and draws the path
MatisRequis 4:8e3ba8d6d915 12 void Bullet::init(int column) {
MatisRequis 3:54132cf073d7 13 _currentpos = 0;
MatisRequis 3:54132cf073d7 14 _column = column;
MatisRequis 3:54132cf073d7 15 _board.path();
MatisRequis 4:8e3ba8d6d915 16
MatisRequis 2:d59a92e65bd9 17 }
MatisRequis 2:d59a92e65bd9 18
MatisRequis 10:2ae9d4145410 19 //draws the bullet
MatisRequis 2:d59a92e65bd9 20 void Bullet::draw(N5110 &lcd) {
MatisRequis 10:2ae9d4145410 21 getxy();
MatisRequis 3:54132cf073d7 22 lcd.drawRect(_x, _y, 2, 2, FILL_BLACK);
MatisRequis 3:54132cf073d7 23 }
MatisRequis 3:54132cf073d7 24
MatisRequis 10:2ae9d4145410 25 //updates the bullet, moving it forward
MatisRequis 4:8e3ba8d6d915 26 void Bullet::update() {
MatisRequis 4:8e3ba8d6d915 27 _currentpos++;
MatisRequis 6:037dfa5064a1 28 }
MatisRequis 6:037dfa5064a1 29
MatisRequis 10:2ae9d4145410 30 //checks if the bullet has reached the end of the lane
MatisRequis 6:037dfa5064a1 31 int Bullet::checkdelete() {
MatisRequis 9:759b419fec3b 32 if (_currentpos > 13) {
MatisRequis 6:037dfa5064a1 33 return 1;
MatisRequis 6:037dfa5064a1 34 } else {
MatisRequis 6:037dfa5064a1 35 return 0;
MatisRequis 6:037dfa5064a1 36 }
MatisRequis 10:2ae9d4145410 37 }
MatisRequis 10:2ae9d4145410 38
MatisRequis 10:2ae9d4145410 39 //gets the coordinates of the bullet
MatisRequis 10:2ae9d4145410 40 Vector2D Bullet::getxy() {
MatisRequis 10:2ae9d4145410 41 _x = _board.drawcolumn[_column][_currentpos].x;
MatisRequis 10:2ae9d4145410 42 _y = _board.drawcolumn[_column][_currentpos].y;
MatisRequis 10:2ae9d4145410 43
MatisRequis 10:2ae9d4145410 44 Vector2D bulletxy = {_board.drawcolumn[_column][_currentpos].x, _board.drawcolumn[_column][_currentpos].y};
MatisRequis 10:2ae9d4145410 45 return bulletxy;
MatisRequis 10:2ae9d4145410 46 }
MatisRequis 10:2ae9d4145410 47
MatisRequis 10:2ae9d4145410 48 //gets the current column and position in the column
MatisRequis 10:2ae9d4145410 49 Vector2D Bullet::getcolumnpos() {
MatisRequis 10:2ae9d4145410 50 Vector2D p = {_column, _currentpos};
MatisRequis 10:2ae9d4145410 51 return p;
MatisRequis 4:8e3ba8d6d915 52 }