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 07:46:48 2020 +0000
Revision:
6:037dfa5064a1
Parent:
4:8e3ba8d6d915
Child:
7:94bc3e21d664
Added new bullet create and draw funtions

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 6:037dfa5064a1 22
MatisRequis 4:8e3ba8d6d915 23
MatisRequis 2:d59a92e65bd9 24
MatisRequis 2:d59a92e65bd9 25 //draw ennemies
MatisRequis 6:037dfa5064a1 26 // _ennemy.draw(lcd);
MatisRequis 2:d59a92e65bd9 27
MatisRequis 2:d59a92e65bd9 28 //draw bullets
MatisRequis 6:037dfa5064a1 29 draw_bullets(lcd);
MatisRequis 2:d59a92e65bd9 30
MatisRequis 4:8e3ba8d6d915 31 }
MatisRequis 4:8e3ba8d6d915 32 void TempestEngine::read_input(Gamepad &pad) {
MatisRequis 4:8e3ba8d6d915 33 _d = pad.get_angle();
MatisRequis 4:8e3ba8d6d915 34 _mag = pad.get_mag();
MatisRequis 4:8e3ba8d6d915 35 _a = pad.A_pressed();
MatisRequis 4:8e3ba8d6d915 36 }
MatisRequis 4:8e3ba8d6d915 37
MatisRequis 4:8e3ba8d6d915 38
MatisRequis 4:8e3ba8d6d915 39 void TempestEngine::update() {
MatisRequis 6:037dfa5064a1 40 _hero.update(_d, _mag);
MatisRequis 6:037dfa5064a1 41 create_bullets();
MatisRequis 6:037dfa5064a1 42 }
MatisRequis 6:037dfa5064a1 43
MatisRequis 6:037dfa5064a1 44 void TempestEngine::create_bullets() {
MatisRequis 6:037dfa5064a1 45 if (_bullet_timer <= 0) {
MatisRequis 6:037dfa5064a1 46 if (_a == 1) {
MatisRequis 6:037dfa5064a1 47 Bullet new_bullet;
MatisRequis 6:037dfa5064a1 48
MatisRequis 6:037dfa5064a1 49 new_bullet.init(_hero.get_column());
MatisRequis 6:037dfa5064a1 50
MatisRequis 6:037dfa5064a1 51 bullet_vect.push_back(new_bullet);
MatisRequis 6:037dfa5064a1 52
MatisRequis 6:037dfa5064a1 53 _bullet_timer = 5;
MatisRequis 6:037dfa5064a1 54 }
MatisRequis 6:037dfa5064a1 55 }
MatisRequis 6:037dfa5064a1 56 _bullet_timer--;
MatisRequis 6:037dfa5064a1 57 }
MatisRequis 6:037dfa5064a1 58
MatisRequis 6:037dfa5064a1 59 //draws all the bullets
MatisRequis 6:037dfa5064a1 60 void TempestEngine::draw_bullets(N5110 &lcd) {
MatisRequis 6:037dfa5064a1 61 //iterates through the bullet objects
MatisRequis 6:037dfa5064a1 62 for (int i = 0; i< bullet_vect.size(); i++) {
MatisRequis 6:037dfa5064a1 63 //draws current bullet
MatisRequis 6:037dfa5064a1 64 bullet_vect[i].draw(lcd);
MatisRequis 6:037dfa5064a1 65
MatisRequis 6:037dfa5064a1 66 //checks if bullet needs to be deleted
MatisRequis 6:037dfa5064a1 67 if (bullet_vect[i].checkdelete()) {
MatisRequis 6:037dfa5064a1 68 bullet_vect.erase(bullet_vect.begin() + i);
MatisRequis 6:037dfa5064a1 69 }
MatisRequis 6:037dfa5064a1 70 }
MatisRequis 4:8e3ba8d6d915 71 }