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.

Revision:
6:037dfa5064a1
Parent:
4:8e3ba8d6d915
Child:
7:94bc3e21d664
diff -r a3c9a5837a7c -r 037dfa5064a1 TempestEngine/TempestEngine.cpp
--- a/TempestEngine/TempestEngine.cpp	Fri May 22 10:37:26 2020 +0000
+++ b/TempestEngine/TempestEngine.cpp	Mon May 25 07:46:48 2020 +0000
@@ -19,18 +19,14 @@
     
     //draw hero ship
     _hero.draw(lcd);
-    
-    /*
-    //score
-    print_score(lcd);
-    
+
 
     
     //draw ennemies
-    _ennemy.draw(lcd);
+//    _ennemy.draw(lcd);
     
     //draw bullets
-    _bullet.draw(lcd); */
+    draw_bullets(lcd);
     
     }
 void TempestEngine::read_input(Gamepad &pad) {
@@ -41,5 +37,35 @@
 
 
 void TempestEngine::update() {
-    _hero.update(_d, _mag, _a);   
+    _hero.update(_d, _mag);
+    create_bullets();
+}
+
+void TempestEngine::create_bullets() {
+    if (_bullet_timer <= 0) {
+        if (_a == 1) {
+            Bullet new_bullet;
+            
+            new_bullet.init(_hero.get_column());
+            
+            bullet_vect.push_back(new_bullet);
+            
+            _bullet_timer = 5;  
+        }
+    }  
+    _bullet_timer--;
+}
+
+//draws all the bullets
+void TempestEngine::draw_bullets(N5110 &lcd) {
+    //iterates through the bullet objects
+    for (int i = 0; i< bullet_vect.size(); i++) {
+        //draws current bullet
+        bullet_vect[i].draw(lcd);
+        
+        //checks if bullet needs to be deleted
+        if (bullet_vect[i].checkdelete()) {
+            bullet_vect.erase(bullet_vect.begin() + i);
+        }
+    }
 }
\ No newline at end of file