ELEC2645 (2018/19) / Mbed 2 deprecated fy14lkaa

Dependencies:   mbed

Revision:
68:175190a03cbd
Parent:
67:4299b64ad5fc
Child:
69:19f1ad7b548e
--- a/SpaceInvadersEngine/SpaceInvadersEngine.cpp	Sat Apr 27 18:56:09 2019 +0000
+++ b/SpaceInvadersEngine/SpaceInvadersEngine.cpp	Sat Apr 27 19:04:41 2019 +0000
@@ -66,7 +66,7 @@
     Vector2D bullet_velocity = _bullet.get_velocity();
     //check if the bullet hit the top of the alien
 
-  // check if the bullet hits top of the Alien 
+    // check if the bullet hits top of the Alien
     if (bullet_pos.y <= 1) {  //  1 due to 1 pixel boundary
         bullet_pos.y = 1;  // bounce off ceiling without going off screen
         bullet_velocity.y = -bullet_velocity.y;
@@ -74,7 +74,21 @@
         pad.tone(750.0,0.1);
     }
 
+    // check if the bullet hits bottom of the Alien
+    else if (bullet_pos.y + _bullet_size >= (HEIGHT-1) ) { // bottom pixel is 47
+        // hit bottom
+        bullet_pos.y = (HEIGHT-1) - _bullet_size;  // stops bullet going off screen
+        bullet_velocity.y = -bullet_velocity.y;
+        // audio feedback
+        pad.tone(750.0,0.1);
+    }
+
+    // update bullet parameters
+    _bullet.set_velocity(bullet_velocity);
+    _bullet.set_pos(bullet_pos);
 }
 
 
 
+
+