deemo1

Dependencies:   mbed

Revision:
4:9fa0c5edd1a1
Parent:
3:1db91ad3ab84
Child:
5:32dbfaf578dd
--- a/StarcraftEngine/StarcraftEngine.cpp	Tue May 12 15:13:22 2020 +0000
+++ b/StarcraftEngine/StarcraftEngine.cpp	Tue May 12 15:54:51 2020 +0000
@@ -10,7 +10,7 @@
     
 }
 
-void StarcraftEngine::init(int Battleship_height, int Battleship_width, int Laser_height, int Laser_width, int Swarm_height, int Swarm_width,int Boss_height, int Boss_width, int speed)
+void StarcraftEngine::init(int Battleship_height, int Battleship_width, int Laser_height, int Laser_width, int Swarm_height, int Swarm_width,int Boss_height, int Boss_width, int Acid_height, int Acid_width, int speed)
 {
      // initialise the game parameters
      _Battleship_height = Battleship_height;
@@ -21,6 +21,8 @@
      _Swarm_width = Swarm_width;
      _Boss_height = Boss_height;
      _Boss_width = Boss_width;
+     _Acid_height = Acid_height;
+     _Acid_width = Acid_width;
      _speed = speed;
      
      // x position on screen - WIDTH is defined in N5110.h
@@ -31,6 +33,7 @@
      _Laser.init(_Laser_height, _Laser_width, _speed);
      _Swarm.init(_Swarm_height, _Swarm_width, _speed);
      _Boss.init(_Boss_height, _Boss_width, _speed);
+     _Acid.init(_Acid_height, _Acid_width, -speed);
      
 }
 
@@ -65,6 +68,8 @@
     _Boss.draw(lcd);
     // Laser
     _Laser.draw(lcd); 
+    // Acid
+    _Acid.draw(lcd);
     
 }
 
@@ -79,9 +84,11 @@
      _Swarm.update();
      _Boss.update();
      _Laser.update();
+     _Acid.update();
      
      check_Swarm_collisions(pad);
      check_Boss_collisions(pad);
+     check_Battleship_collisions(pad);
 }
 
 void StarcraftEngine::check_Swarm_collisions(Gamepad &pad)
@@ -180,6 +187,38 @@
       _Boss.set_pos(Boss_pos);  
 }              
        
+void StarcraftEngine::check_Battleship_collisions(Gamepad &pad)   
+{
+     Vector2D Boss_pos = _Boss.get_pos();
+     Vector2D Battleship_pos = _Battleship.get_pos();  
+     Vector2D Acid_pos = _Acid.get_pos();
+     
+     Vector2D Acid_velocity = _Acid.get_velocity();
+     Vector2D Boss_velocity = _Boss.get_velocity();
+     
+     // Player get score
+     if ((Acid_pos.x >= Battleship_pos.x)&&
+         (Acid_pos.x <= Battleship_pos.x + 6)&&
+         (Acid_pos.y + 3 >= Battleship_pos.y)&&
+         (Acid_pos.y <= Battleship_pos.y + 3))
+     {
+         _Battleship.minus_life();
+         pad.tone(800.0,0.1);  //  Audio feedback 
+     }
+     
+      
+     if ((Acid_pos.y > HEIGHT - 3)||(Acid_pos.y < 6))
+     {
+        Acid_pos.x = Boss_pos.x + 3;
+        Acid_pos.y = Boss_pos.y + 5; 
+     }
+     
+      _Acid.set_velocity(Acid_velocity);
+      _Boss.set_velocity(Boss_velocity);
+      _Acid.set_pos(Acid_pos);   
+      _Boss.set_pos(Boss_pos);  
+}                  
+       
 void StarcraftEngine::print_scores(N5110 &lcd)
 {
      // get scores from battleship