ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Revision:
36:c25417f0d150
Parent:
35:3341f2bd0408
Child:
37:8d8c8cce0bc7
diff -r 3341f2bd0408 -r c25417f0d150 RosenEngine/RosenEngine.cpp
--- a/RosenEngine/RosenEngine.cpp	Fri May 03 09:41:53 2019 +0000
+++ b/RosenEngine/RosenEngine.cpp	Fri May 03 18:56:06 2019 +0000
@@ -91,6 +91,7 @@
     imperionw_seeker_collision(pad);
     kestrelw_shooter_collision(pad);
     imperionw_shooter_collision(pad);
+    check_health();
 }
 void RosenEngine::get_pos()
 {
@@ -134,10 +135,6 @@
     _menu.update(_d);
     _menu.disp_ships(lcd);
 }
-void RosenEngine::score(int points)
-{
-    _score = _score + points;
-}
 bool RosenEngine::check_collision(int xpos1, int ypos1,int width1,int height1,int xpos2, int ypos2,int width2,int height2)
 {
     // Create arrays of all positions with appropriate height and length
@@ -290,7 +287,7 @@
     bool collision;
     collision = check_collision(seeker_pos.x,seeker_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
     if (collision == true) {
-        _enemy.reset_seeker();
+        _health.seekerh_update(5);
         pad.tone(500,0.05);
         wait(0.05);
     }
@@ -302,7 +299,7 @@
     if(ship_ypos > seeker_pos.y + 6) {
         collision = check_collision1(seeker_pos.x,9,ship_xpos + 2,3);
         if (collision == true && A == true) {
-            _enemy.reset_seeker();
+            _health.seekerh_update(5);
             pad.tone(500,0.05);
             wait(0.05);
         }
@@ -316,17 +313,17 @@
     col2 = check_collision(_shooter2_pos.x,_shooter2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
     col3 = check_collision(_shooter3_pos.x,_shooter3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
     if (col1 == true) {
-        _enemy.reset_shooter(1);
         pad.tone(500,0.05);
+        _health.shooterh_update(1,5);
         wait(0.05);
     }
     if (col2 == true) {
-        _enemy.reset_shooter(2);
+        _health.shooterh_update(2,5);
         pad.tone(500,0.05);
         wait(0.05);
     }
     if (col3 == true) {
-        _enemy.reset_shooter(3);
+        _health.shooterh_update(3,5);
         pad.tone(500,0.05);
         wait(0.05);
     }
@@ -339,7 +336,7 @@
     if(ship_ypos > _shooter1_pos.y + 6) {
         col1 = check_collision1(_shooter1_pos.x,9,ship_xpos + 2,3);
         if (col1 == true && A == true) {
-            _enemy.reset_shooter(1);
+            _health.shooterh_update(1,5);
             pad.tone(500,0.05);
             wait(0.05);
         }
@@ -347,7 +344,7 @@
     if(ship_ypos > _shooter2_pos.y + 6) {
         col2 = check_collision1(_shooter2_pos.x,9,ship_xpos + 2,3);
         if (col2 == true && A == true) {
-            _enemy.reset_shooter(2);
+            _health.shooterh_update(2,5);
             pad.tone(500,0.05);
             wait(0.05);
         }
@@ -355,9 +352,43 @@
     if(ship_ypos > _shooter3_pos.y + 6) {
         col3 = check_collision1(_shooter3_pos.x,9,ship_xpos + 2,3);
         if (col3 == true && A == true) {
-            _enemy.reset_shooter(3);
+            _health.shooterh_update(3,5);
             pad.tone(500,0.05);
             wait(0.05);
         }
     }
+}
+void RosenEngine::score(int points)
+{
+    _score = _score + points;
+}
+void RosenEngine::check_health()
+{
+    int seeker_health = _health.get_seekerh();
+    int shooter1_health = _health.get_shooterh(1);
+    int shooter2_health = _health.get_shooterh(2);
+    int shooter3_health = _health.get_shooterh(3);
+    
+    if(seeker_health == 0){
+        _enemy.reset_seeker();
+        _health.reset_seekerh();
+    }
+    if(shooter1_health == 0){
+        _enemy.reset_shooter(1);
+        _health.reset_shooterh(1);
+    }
+    if(shooter2_health == 0){
+        _enemy.reset_shooter(2);
+        _health.reset_shooterh(2);
+    }
+    if(shooter3_health == 0){
+        _enemy.reset_shooter(3);
+        _health.reset_shooterh(3);
+    }
+    
+    Vector2D hp = _health.get_hp();
+    if(hp.x <= 0){
+        printf("player deaad\n");
+        _dead = true;
+    } 
 }
\ No newline at end of file