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:
Mon May 25 11:40:15 2020 +0000
Revision:
8:5feb1913bc92
Parent:
7:94bc3e21d664
Child:
9:759b419fec3b
Bullets work with anti spam and all in the right direction

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MatisRequis 2:d59a92e65bd9 1 #include "TempestEngine.h"
MatisRequis 2:d59a92e65bd9 2
MatisRequis 2:d59a92e65bd9 3 TempestEngine::TempestEngine() {
MatisRequis 2:d59a92e65bd9 4
MatisRequis 2:d59a92e65bd9 5 }
MatisRequis 2:d59a92e65bd9 6
MatisRequis 2:d59a92e65bd9 7 TempestEngine::~TempestEngine() {
MatisRequis 2:d59a92e65bd9 8
MatisRequis 2:d59a92e65bd9 9 }
MatisRequis 2:d59a92e65bd9 10
MatisRequis 2:d59a92e65bd9 11
MatisRequis 4:8e3ba8d6d915 12 void TempestEngine::init() {
MatisRequis 4:8e3ba8d6d915 13 _hero.init(0);
MatisRequis 2:d59a92e65bd9 14 }
MatisRequis 2:d59a92e65bd9 15
MatisRequis 4:8e3ba8d6d915 16
MatisRequis 2:d59a92e65bd9 17 void TempestEngine::draw(N5110 &lcd) {
MatisRequis 3:54132cf073d7 18 _board.draw(lcd);
MatisRequis 4:8e3ba8d6d915 19
MatisRequis 4:8e3ba8d6d915 20 //draw hero ship
MatisRequis 4:8e3ba8d6d915 21 _hero.draw(lcd);
MatisRequis 2:d59a92e65bd9 22
MatisRequis 2:d59a92e65bd9 23 //draw bullets
MatisRequis 6:037dfa5064a1 24 draw_bullets(lcd);
MatisRequis 2:d59a92e65bd9 25
MatisRequis 4:8e3ba8d6d915 26 }
MatisRequis 4:8e3ba8d6d915 27 void TempestEngine::read_input(Gamepad &pad) {
MatisRequis 4:8e3ba8d6d915 28 _d = pad.get_angle();
MatisRequis 7:94bc3e21d664 29 _mag = pad.get_mag();
MatisRequis 7:94bc3e21d664 30 _a = pad.A_pressed();
MatisRequis 4:8e3ba8d6d915 31 }
MatisRequis 4:8e3ba8d6d915 32
MatisRequis 4:8e3ba8d6d915 33
MatisRequis 4:8e3ba8d6d915 34 void TempestEngine::update() {
MatisRequis 6:037dfa5064a1 35 _hero.update(_d, _mag);
MatisRequis 6:037dfa5064a1 36 create_bullets();
MatisRequis 6:037dfa5064a1 37 }
MatisRequis 6:037dfa5064a1 38
MatisRequis 6:037dfa5064a1 39 void TempestEngine::create_bullets() {
MatisRequis 8:5feb1913bc92 40 if (_bullet_timer <= 0) {
MatisRequis 7:94bc3e21d664 41 if (_a) {
MatisRequis 6:037dfa5064a1 42 Bullet new_bullet;
MatisRequis 6:037dfa5064a1 43
MatisRequis 6:037dfa5064a1 44 new_bullet.init(_hero.get_column());
MatisRequis 6:037dfa5064a1 45
MatisRequis 6:037dfa5064a1 46 bullet_vect.push_back(new_bullet);
MatisRequis 6:037dfa5064a1 47
MatisRequis 8:5feb1913bc92 48 _bullet_timer = 2;
MatisRequis 6:037dfa5064a1 49 }
MatisRequis 8:5feb1913bc92 50 }
MatisRequis 8:5feb1913bc92 51 _bullet_timer--;
MatisRequis 6:037dfa5064a1 52 }
MatisRequis 6:037dfa5064a1 53
MatisRequis 7:94bc3e21d664 54
MatisRequis 6:037dfa5064a1 55 //draws all the bullets
MatisRequis 6:037dfa5064a1 56 void TempestEngine::draw_bullets(N5110 &lcd) {
MatisRequis 6:037dfa5064a1 57 //iterates through the bullet objects
MatisRequis 6:037dfa5064a1 58 for (int i = 0; i< bullet_vect.size(); i++) {
MatisRequis 7:94bc3e21d664 59 bullet_vect[i].update();
MatisRequis 6:037dfa5064a1 60 //draws current bullet
MatisRequis 6:037dfa5064a1 61 bullet_vect[i].draw(lcd);
MatisRequis 6:037dfa5064a1 62
MatisRequis 6:037dfa5064a1 63 //checks if bullet needs to be deleted
MatisRequis 6:037dfa5064a1 64 if (bullet_vect[i].checkdelete()) {
MatisRequis 6:037dfa5064a1 65 bullet_vect.erase(bullet_vect.begin() + i);
MatisRequis 6:037dfa5064a1 66 }
MatisRequis 6:037dfa5064a1 67 }
MatisRequis 4:8e3ba8d6d915 68 }