Haoyan Zhang / Mbed 2 deprecated demmo

Dependencies:   mbed

Revision:
5:32dbfaf578dd
Parent:
4:9fa0c5edd1a1
Child:
6:b59bc5e15cf3
diff -r 9fa0c5edd1a1 -r 32dbfaf578dd StarcraftEngine/StarcraftEngine.cpp
--- a/StarcraftEngine/StarcraftEngine.cpp	Tue May 12 15:54:51 2020 +0000
+++ b/StarcraftEngine/StarcraftEngine.cpp	Thu May 14 05:21:50 2020 +0000
@@ -33,7 +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);
+     _Acid.init(_Acid_height, _Acid_width, _speed);
      
 }
 
@@ -43,12 +43,12 @@
     _mag = pad.get_mag();
 }     
  
-int StarcraftEngine::find_life()
+int StarcraftEngine::find_life()  //get battleship's life
 {   int find_life = _Battleship.get_life();
     return find_life;
 } 
 
-int StarcraftEngine::find_score()
+int StarcraftEngine::find_score()  //get player's score
 {   int find_score = _Battleship.get_score();
     return find_score;
 } 
@@ -77,7 +77,7 @@
 {
      check_goal(pad);
      
-     // important to update battleship, laser and swarm before checking collisions so can
+     // important to update battleship, laser,boss and swarm before checking collisions so can
      // correct for it before updating the display
      
      _Battleship.update(_d,_mag);
@@ -91,7 +91,7 @@
      check_Battleship_collisions(pad);
 }
 
-void StarcraftEngine::check_Swarm_collisions(Gamepad &pad)
+void StarcraftEngine::check_Swarm_collisions(Gamepad &pad)  //check if the swarm over the bottom line and minus battleship life
 {
      // read current swarm attributes
      Vector2D Swarm_pos = _Swarm.get_pos();
@@ -111,7 +111,7 @@
     _Swarm.set_pos(Swarm_pos);
 } 
 
-void StarcraftEngine::check_Boss_collisions(Gamepad &pad)
+void StarcraftEngine::check_Boss_collisions(Gamepad &pad)  //check if the boss over the bottom line and minus battleship life
 {
      // read current Boss attributes
      Vector2D Boss_pos = _Boss.get_pos();
@@ -131,7 +131,39 @@
     _Boss.set_pos(Boss_pos);
 } 
 
-void StarcraftEngine::check_goal(Gamepad &pad)    
+void StarcraftEngine::check_Battleship_collisions(Gamepad &pad)  //check if the acid hit the battleship and minus life   
+{
+     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 < 10))  //if acid over the bottom line, initialize acid's position
+     {
+        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::check_goal(Gamepad &pad)  //check if the laser hit the swarn or boss and add score    
 {
      Vector2D Swarm_pos = _Swarm.get_pos();
      Vector2D Boss_pos = _Boss.get_pos();
@@ -173,7 +205,7 @@
          wait(0.1);
      }
       
-     if ((Laser_pos.y < 6)||(Battleship_pos.y - Laser_pos.y >= 20))
+     if ((Laser_pos.y < 6)||(Battleship_pos.y - Laser_pos.y >= 20))  //set the laser's range and initialize laser's position
      {
             Laser_pos.x = Battleship_pos.x + 3;    
             Laser_pos.y = Battleship_pos.y - 1;  
@@ -187,38 +219,6 @@
       _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