ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Revision:
38:4571537238ed
Parent:
37:8d8c8cce0bc7
Child:
39:7824f9080f59
--- a/RosenEngine/RosenEngine.cpp	Sat May 04 05:37:33 2019 +0000
+++ b/RosenEngine/RosenEngine.cpp	Sun May 05 08:50:15 2019 +0000
@@ -18,14 +18,23 @@
     // initialise the game parameters
     _ship.init(ship_width,ship_height,ship_speed,ship_xpos,ship_ypos);
     // place seeker above the ship
-    _enemy.init(3);
+    _no_shooters = 1;
+    _enemy.init(_no_shooters);
     _menu.init(16);
     _health.init(_shipno);
+    _times_run = 0;
+    _score = 0;
+    _dead = false;
 
 }
 void RosenEngine::reset()
 {
+    _enemy.init(_no_shooters);
     _health.init(_shipno);
+    _times_run = 0;
+    _score = 0;
+    _no_shooters = 1;
+    _dead = false;
 }
 
 void RosenEngine::read_input(Gamepad &pad)
@@ -61,6 +70,9 @@
         _ship.draw_ship(lcd,_shipno);
         _weapons.draw(lcd,pad,_shipno);
     }
+    if(_dead == true){
+       game_over(lcd);
+    }
 }
 
 void RosenEngine::update(Gamepad &pad)
@@ -93,6 +105,8 @@
     imperionw_shooter_collision(pad);
     check_health();
     rand_no();
+    scaling(timer(12));
+    
 }
 void RosenEngine::get_pos()
 {
@@ -235,17 +249,17 @@
     collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooter2_pos.x, _shooter2_pos.y,10,7);
     collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooter3_pos.x, _shooter3_pos.y,10,7);
 
-    if(collision1 == true) {
+    if(collision1 == true && _no_shooters == 1) {
         _health.update(1,pad);
         pad.tone(500,0.05);
         wait(0.05);
     }
-    if(collision2 == true) {
+    if(collision2 == true && _no_shooters == 2) {
         _health.update(1,pad);
         pad.tone(500,0.05);
         wait(0.05);
     }
-    if(collision3 == true) {
+    if(collision3 == true && _no_shooters == 3) {
         _health.update(1,pad);
         pad.tone(500,0.05);
         wait(0.05);
@@ -265,17 +279,17 @@
     collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw2_pos.x, _shooterw2_pos.y,2,2);
     collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw3_pos.x, _shooterw3_pos.y,2,2);
 
-    if(collision1 == true) {
+    if(collision1 == true && _no_shooters == 1) {
         _health.update(1,pad);
         pad.tone(500,0.05);
         wait(0.05);
     }
-    if(collision2 == true) {
+    if(collision2 == true && _no_shooters == 2) {
         _health.update(1,pad);
         pad.tone(500,0.05);
         wait(0.05);
     }
-    if(collision3 == true) {
+    if(collision3 == true && _no_shooters == 3) {
         _health.update(1,pad);
         pad.tone(500,0.05);
         wait(0.05);
@@ -313,17 +327,17 @@
     col1 = check_collision(_shooter1_pos.x,_shooter1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
     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) {
+    if (col1 == true && _no_shooters == 1) {
         pad.tone(500,0.05);
         _health.shooterh_update(1,5);
         wait(0.05);
     }
-    if (col2 == true) {
+    if (col2 == true && _no_shooters == 2) {
         _health.shooterh_update(2,5);
         pad.tone(500,0.05);
         wait(0.05);
     }
-    if (col3 == true) {
+    if (col3 == true && _no_shooters == 3) {
         _health.shooterh_update(3,5);
         pad.tone(500,0.05);
         wait(0.05);
@@ -336,7 +350,7 @@
     bool col3;
     if(ship_ypos > _shooter1_pos.y + 6) {
         col1 = check_collision1(_shooter1_pos.x,9,ship_xpos + 2,3);
-        if (col1 == true && A == true) {
+        if (col1 == true && A == true && _no_shooters == 1) {
             _health.shooterh_update(1,5);
             pad.tone(500,0.05);
             wait(0.05);
@@ -344,7 +358,7 @@
     }
     if(ship_ypos > _shooter2_pos.y + 6) {
         col2 = check_collision1(_shooter2_pos.x,9,ship_xpos + 2,3);
-        if (col2 == true && A == true) {
+        if (col2 == true && A == true && _no_shooters == 2) {
             _health.shooterh_update(2,5);
             pad.tone(500,0.05);
             wait(0.05);
@@ -352,17 +366,13 @@
     }
     if(ship_ypos > _shooter3_pos.y + 6) {
         col3 = check_collision1(_shooter3_pos.x,9,ship_xpos + 2,3);
-        if (col3 == true && A == true) {
+        if (col3 == true && A == true && _no_shooters == 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();
@@ -389,7 +399,7 @@
     
     Vector2D hp = _health.get_hp();
     if(hp.x <= 0){
-        printf("player deaad\n");
+        // printf("player deaad\n");
         _dead = true;
     } 
 }
@@ -397,6 +407,41 @@
 {
     srand(time(NULL));
     int rand_no = (rand() %45) + 1;
-    printf("random no = %d\n",rand_no);
+    // printf("random no = %d\n",rand_no);
     return rand_no;
+}
+float RosenEngine::timer(int fps)
+{
+    _times_run = _times_run + 1;
+    float time_frame = 1.0f/fps;
+    float time_elapsed = _times_run * time_frame; 
+    // printf("time elapsed = %f,time frame = %f, _times_run = %d\n",time_elapsed,time_frame,_times_run);
+    return time_elapsed;
+}
+void RosenEngine::score(int points)
+{
+    _score = _score + points;
+}
+bool RosenEngine::dead()
+{
+    return _dead;
+}
+
+void RosenEngine::scaling(float time_elapsed)
+{
+    if(time_elapsed > 10){
+        _no_shooters = _no_shooters + 1;
+        _enemy.sh_scaling(time_elapsed);
+    }
+    if(_no_shooters > 3){
+        _no_shooters = 3;
+        }
+    _enemy.set_noshooters(_no_shooters);
+    
+}
+void RosenEngine::game_over(N5110 &lcd)
+{
+    lcd.clear();
+    lcd.printString("Game Over ",2,2);
+    lcd.printString("Try dodging next time ",2,3);
 }
\ No newline at end of file