Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

https://os.mbed.com/media/uploads/evanso/84bc1a30759fd6a1e3f1fd1fae3e97c2.png

Hello, soldier, you have been specially selected as the defender of planet earth.

Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.

But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.

As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.

Revision:
25:70b55f5bfc87
Parent:
24:479da6ca0e7e
Child:
27:8bb2bd97c319
--- a/GameEngine/GameEngine.cpp	Tue May 12 15:08:56 2020 +0000
+++ b/GameEngine/GameEngine.cpp	Tue May 12 23:08:08 2020 +0000
@@ -31,6 +31,7 @@
     map.draw_map(lcd, d_);
     draw_aliens();
     draw_bullets();
+    draw_explosions(); 
 
     // refresh's screen
     lcd.refresh(); 
@@ -62,6 +63,16 @@
     alien_vector.push_back(new_alien);
 }
 
+void GameEngine::create_explosion(){
+    // explosion object
+    Explosion new_explosion;
+    
+    new_explosion.init();
+    
+    // Stores explosion object in vector 
+    explosion_vector.push_back(new_explosion);
+}
+
 void GameEngine::draw_bullets(){
     // interates over bullet vector and get each new_bullet object to draw its self and move
     for (int i = 0; i < bullet_vector.size(); i++){
@@ -82,8 +93,23 @@
         
         // Deletes bullet and alien if collision detected
         if (alien_vector[i].check_collision(bullet_vector[i])){
-            bullet_vector.erase(bullet_vector.begin()+ i);  
-            alien_vector.erase(alien_vector.begin()+ i);          
+            create_explosion();
+            explosion_vector[i].set_explosion_posistion(alien_vector[i].get_pos()); 
+            
+            bullet_vector.erase(bullet_vector.begin()+ i);    
+            alien_vector.erase(alien_vector.begin()+ i);  
+        }
+    }
+}
+
+void GameEngine::draw_explosions(){
+    // interates over expoltion vector and draws each explosion object then deleted object after set size
+    for (int i = 0; i < explosion_vector.size(); i++){
+        explosion_vector[i].draw_explosion(lcd);
+        
+        // delete explosion after reaches set size
+        if(explosion_vector[i].get_explosion_radius() == 8){
+             explosion_vector.erase(explosion_vector.begin()+ i);    
         }
     }
 }
\ No newline at end of file