ELEC2645 (2018/19) / Mbed 2 deprecated fy14lkaa

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
fy14lkaa
Date:
Sat Apr 27 18:56:09 2019 +0000
Parent:
66:0123bd3dcbc6
Child:
68:175190a03cbd
Commit message:
added if statement to check if the bullet hits the top of the Alien.

Changed in this revision

SpaceInvadersEngine/SpaceInvadersEngine.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SpaceInvadersEngine/SpaceInvadersEngine.cpp	Sat Apr 27 18:42:35 2019 +0000
+++ b/SpaceInvadersEngine/SpaceInvadersEngine.cpp	Sat Apr 27 18:56:09 2019 +0000
@@ -66,6 +66,14 @@
     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 
+    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;
+        // audio feedback
+        pad.tone(750.0,0.1);
+    }
+
 }