Rex Raj / Mbed 2 deprecated el17rrrs

Dependencies:   mbed Gamepad N5110 mbed-rtos

Revision:
5:016a7315b75d
Parent:
4:4d673fb2d9dc
Child:
6:1fcfd331c047
--- a/GameEngine/GameEngine.cpp	Sun May 05 17:41:46 2019 +0000
+++ b/GameEngine/GameEngine.cpp	Mon May 06 18:29:49 2019 +0000
@@ -9,6 +9,8 @@
 {
 
 }
+
+// draws the background of the game
 int backgrounds [48][84] = {
     
 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
@@ -61,6 +63,8 @@
 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
 
 };
+
+// draws alphabet r in morse code
 int r [3][13] = {
     
 {0,1,0,0,0,0,0,0,0,0,0,1,0},
@@ -69,6 +73,7 @@
 
 };
 
+// draws alphabet e in morse code
 int e [3][3] = {
     
 {0,1,0},
@@ -77,6 +82,7 @@
 
 };
 
+// draws alphabet x in morse code
 int x [3][19] = {
     
 {0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
@@ -85,6 +91,7 @@
 
 };
 
+// draws explosion 
 int explosion [23] [23] = {
 
 {0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0},
@@ -249,8 +256,6 @@
     // Animations and sound effect for the both the player's and enemy' spacecraft when they are dead
     spacecraft_dead(lcd,pad);
     enemy_dead(lcd,pad);
-    // Check if mission one had been failed or pass to provide appropriate animation and sound effect
-    check_mission_one(pad);
     
 }
 
@@ -274,8 +279,6 @@
     // Animations and sound effect for the both the player's and enemy' spacecraft when they are dead
     spacecraft2_dead(lcd,pad);
     enemy2_dead(lcd,pad);
-    // Check if mission two had been failed or pass to provide appropriate animation and sound effect
-    check_mission_two(pad);
 
 }
 
@@ -294,8 +297,6 @@
     // Animations and sound effect for the both the player's and enemy' spacecraft
     spacecraft3_dead(lcd,pad);
     enemy3_dead(lcd,pad);
-    // Check if mission three had been failed or pass to provide appropriate animation and sound effect
-    check_mission_three(pad);
 
 }
 void GameEngine::check_enemy_collisions(Gamepad &pad)
@@ -422,66 +423,66 @@
     _beam.set_pos(beam_pos);
 }
 
-void GameEngine::check_playerbeam_collision(Gamepad &pad)
+void GameEngine::check_playerbeam_collision(Gamepad &pad) // check if player's spacecraft beam has collided with the edges of screen or enemy
 {
     Vector2D p1_pos = _p1.get_pos(); // Get player's spacecraft position
     Vector2D beam_pos = _beam.get_pos(); // Get player's spacecraft beam position
     
-        if((_R == true)|| (_L == true)){ // 
+        if((_R == true)|| (_L == true)){ 
                 _beam.init(_beam_size,p1_pos.x,p1_pos.y); //Initialise the beam
-                if (beam_pos.x + _beam_size > WIDTH || (spacebeam == true)){
-                _R = false;
+                if ((beam_pos.x + _beam_size > WIDTH) || (spacebeam == true)){ // if hits the enemy or the wall
+                _R = false; // Then set the boolean _R and _L to false
                 _L = false;
     }
 }
 }
 
-void GameEngine::check_enemybeam_collisions(Gamepad &pad)
+void GameEngine::check_enemybeam_collisions(Gamepad &pad) // check if enemy beam has collided with the edges of screen or spacecraft in stage one
 {
     Vector2D enemybeam_pos = _enemybeam.get_pos(); // Get first enemy's beam position
 
-    if ((_ebeam == true)||(enemybeam_pos.x - _beam_size < 0)) {
-    _enemybeam.init(_beam_size,_e1a,_e1b); // Initialise the enemy beam 
-    _ebeam = false;
+    if ((_ebeam == true)||(enemybeam_pos.x - _beam_size < 0)) { // if hits the speacecraft or the wall
+    _enemybeam.init(_beam_size,_e1a,_e1b); // Initialise the enemy beam in stage one
+    _ebeam = false; // Then set the boolean _ebeam to false
     }
 }
 
-void GameEngine::check_enemybeam2_collisions(Gamepad &pad)
+void GameEngine::check_enemybeam2_collisions(Gamepad &pad) // check if enemy beam has collided with the edges of screen or spacecraft in stage two
 {
-    Vector2D enemy21_pos = _e21.get_enemy21_pos();
-    Vector2D enemy22_pos = _e22.get_enemy22_pos();
-    Vector2D enemybeam21_pos = _enemybeam2.get_pos_21();
-    Vector2D enemybeam22_pos = _enemybeam2.get_pos_22();
-    // P2 has scored
-    if ((_ebeam21 == true)||(_ebeam22 == true)||(enemybeam21_pos.x - _beam2_size < 0)||(enemybeam22_pos.x - _beam2_size < 0)) {
-    _enemybeam2.init(_beam2_size,enemy21_pos.x,enemy21_pos.y,enemy22_pos.x,enemy22_pos.y);
-    _ebeam21 = false;
+    Vector2D enemy21_pos = _e21.get_enemy21_pos(); // Get first enemy's position in stage two
+    Vector2D enemy22_pos = _e22.get_enemy22_pos(); // Get second enemy's position in stage two
+    Vector2D enemybeam21_pos = _enemybeam2.get_pos_21(); // Get first enemy's beam position in stage two
+    Vector2D enemybeam22_pos = _enemybeam2.get_pos_22(); // Get second enemy's beam position in stage two
+   
+    if ((_ebeam21 == true)||(_ebeam22 == true)||(enemybeam21_pos.x - _beam2_size < 0)||(enemybeam22_pos.x - _beam2_size < 0)) {  // if hits the speacecraft or the wall
+    _enemybeam2.init(_beam2_size,enemy21_pos.x,enemy21_pos.y,enemy22_pos.x,enemy22_pos.y); // Initialise the enemy beam in stage two
+    _ebeam21 = false; // Then set the boolean _ebeam21 and _ebeam22 to false
     _ebeam22 = false;
     }
 }
 
-void GameEngine::check_enemybeam3_collisions(Gamepad &pad)
+void GameEngine::check_enemybeam3_collisions(Gamepad &pad) // check if enemy beam has collided with the edges of screen or spacecraft in stage three
 {
-    Vector2D enemyboss_pos = _e3.get_enemyboss_pos();
-    Vector2D enemy1_pos = _e3.get_enemy1_pos();
-    Vector2D enemy2_pos = _e3.get_enemy2_pos();
+    Vector2D enemyboss_pos = _e3.get_enemyboss_pos(); // Get boss enemy's position in stage three
+    Vector2D enemy1_pos = _e3.get_enemy1_pos(); // Get first regular enemy's position in stage three
+    Vector2D enemy2_pos = _e3.get_enemy2_pos(); // Get second regular enemy's position in stage three
     
-    Vector2D enemybossbeam3_pos = _enemybeam3.get_pos_boss();
-    Vector2D enemy1beam3_pos = _enemybeam3.get_pos_enemy1();
-    Vector2D enemy2beam3_pos = _enemybeam3.get_pos_enemy2();
-    // P2 has scored
-    if ((_ebeam3boss == true)||(_ebeam31 == true)||(_ebeam32 == true)||(enemybossbeam3_pos.x - _beam_size < 0)||(enemy1beam3_pos.x - _beam_size < 0)||(enemy2beam3_pos.x - _beam_size < 0)) {
-    _enemybeam3.init(_beam_size,enemyboss_pos.x,enemyboss_pos.y,enemy1_pos.x,enemy1_pos.y,enemy2_pos.x,enemy2_pos.y);
-    _ebeam3boss = false;
+    Vector2D enemybossbeam3_pos = _enemybeam3.get_pos_boss(); // Get boss enemy's beam position in stage three
+    Vector2D enemy1beam3_pos = _enemybeam3.get_pos_enemy1(); // Get first regular enemy's beam position in stage three
+    Vector2D enemy2beam3_pos = _enemybeam3.get_pos_enemy2(); // Get second regular enemy's beam position in stage three
+    
+    if ((_ebeam3boss == true)||(_ebeam31 == true)||(_ebeam32 == true)||(enemybossbeam3_pos.x - _beam_size < 0)||(enemy1beam3_pos.x - _beam_size < 0)||(enemy2beam3_pos.x - _beam_size < 0)) { // if hits the speacecraft or the wall
+    _enemybeam3.init(_beam_size,enemyboss_pos.x,enemyboss_pos.y,enemy1_pos.x,enemy1_pos.y,enemy2_pos.x,enemy2_pos.y);  // Initialise the enemy beam in stage three
+    _ebeam3boss = false; // Then set boolean _ebeam3boss,_ebeam31, _ebeam32 to false
     _ebeam31 = false;
     _ebeam32 = false;
     }
 }
 
-void GameEngine::check_spacecraft_collisions(Gamepad &pad)
+void GameEngine::check_spacecraft_collisions(Gamepad &pad) // check spacecraft collision with enemy beam in stage one
 {
-    Vector2D enemybeam_pos = _enemybeam.get_pos();
-    Vector2D p1_pos = _p1.get_pos();
+    Vector2D enemybeam_pos = _enemybeam.get_pos(); // Gets the position of the enemy's beam in stage one
+    Vector2D p1_pos = _p1.get_pos();               // Gets the position of the player's spacecraft
 
      // see if beam has hit the enemy by checking for overlaps
     if (
@@ -490,20 +491,20 @@
         (enemybeam_pos.x >= _p1x) && //left
         (enemybeam_pos.x <= _p1x + 11)  //right
     ) {
-        _p1.add_health();
-        _ebeam = true;
-        pad.tone(1000.0,0.1);
+        _p1.add_health(); // adds health 
+        _ebeam = true;    // sets boolean to true to initialise beam
+        pad.tone(1000.0,0.1); // outputs sound if it hits the player's spacecraft
     }
-    
+    // write new attributes
     _enemybeam.set_pos(enemybeam_pos);
     
 }
 
-void GameEngine::check_spacecraft2_collisions(Gamepad &pad)
+void GameEngine::check_spacecraft2_collisions(Gamepad &pad) // check spacecraft collision with enemy beam in stage two
 {
-    Vector2D enemybeam21_pos = _enemybeam2.get_pos_21();
-    Vector2D enemybeam22_pos = _enemybeam2.get_pos_22();
-    Vector2D p1_pos = _p1.get_pos();
+    Vector2D enemybeam21_pos = _enemybeam2.get_pos_21(); // Gets the position of the first enemy's beam in stage two
+    Vector2D enemybeam22_pos = _enemybeam2.get_pos_22(); // Gets the position of the second enemy's beam in stage two
+    Vector2D p1_pos = _p1.get_pos(); // Gets the position of the player's spacecraft
 
      // see if beam has hit the enemy by checking for overlaps
     if (
@@ -512,9 +513,9 @@
         (enemybeam21_pos.x >= _p1x) && //left
         (enemybeam21_pos.x <= _p1x + 11)  //right
     ) {
-        _p1.add_health();
-        _ebeam21 = true;
-        pad.tone(1000.0,0.1);
+        _p1.add_health(); // adds health
+        _ebeam21 = true;  // sets boolean to true to initialise beam
+        pad.tone(1000.0,0.1); // outputs sound if it hits the player's spacecraft
     }
     else if (
         (enemybeam22_pos.y >= p1_pos.y) && //top
@@ -522,22 +523,23 @@
         (enemybeam22_pos.x >= _p1x) && //left
         (enemybeam22_pos.x <= _p1x + 11)  //right
     ) {
-        _p1.add_health();
-        _ebeam22 = true;
-        pad.tone(1000.0,0.1);
+        _p1.add_health(); // adds health
+        _ebeam22 = true;  // sets boolean to true to initialise beam
+        pad.tone(1000.0,0.1); // outputs sound if it hits the player's spacecraft
     }
+    // write new attributes
     _enemybeam2.set_pos_21(enemybeam21_pos);
     _enemybeam2.set_pos_22(enemybeam22_pos);
     
 }
 
-void GameEngine::check_spacecraft3_collisions(Gamepad &pad)
+void GameEngine::check_spacecraft3_collisions(Gamepad &pad) // check spacecraft collision with enemy beam in stage three
 {
-    Vector2D enemybossbeam_pos = _enemybeam3.get_pos_boss();
-    Vector2D enemy1beam_pos = _enemybeam3.get_pos_enemy1();
-    Vector2D enemy2beam_pos = _enemybeam3.get_pos_enemy2();
+    Vector2D enemybossbeam_pos = _enemybeam3.get_pos_boss(); // Gets the position of the boss enemy's beam in stage three
+    Vector2D enemy1beam_pos = _enemybeam3.get_pos_enemy1();  // Gets the position of the first enemy's beam in stage three
+    Vector2D enemy2beam_pos = _enemybeam3.get_pos_enemy2();  // Gets the position of the second enemy's beam in stage three
     
-    Vector2D p1_pos = _p1.get_pos();
+    Vector2D p1_pos = _p1.get_pos(); // Gets the position of the player's spacecraft
 
      // see if beam has hit the enemy by checking for overlaps
     if (
@@ -546,8 +548,8 @@
         (enemybossbeam_pos.x >= _p1x) && //left
         (enemybossbeam_pos.x <= _p1x + 11)  //right
     ) {
-        _p1.add_health();
-        _ebeam3boss = true;
+        _p1.add_health();   // adds health
+        _ebeam3boss = true; // sets boolean to true to initialise beam
         pad.tone(1000.0,0.1);
     }
     else if (
@@ -556,8 +558,8 @@
         (enemy1beam_pos.x >= _p1x) && //left
         (enemy1beam_pos.x <= _p1x + 11)  //right
     ) {
-        _p1.add_health();
-        _ebeam31 = true;
+        _p1.add_health(); // adds health
+        _ebeam31 = true;  // sets boolean to true to initialise beam
         pad.tone(1000.0,0.1);
     }
     else if (
@@ -566,56 +568,58 @@
         (enemy2beam_pos.x >= _p1x) && //left
         (enemy2beam_pos.x <= _p1x + 11)  //right
     ) {
-        _p1.add_health();
-        _ebeam32 = true;
-        pad.tone(1000.0,0.1);
+        _p1.add_health(); // adds health
+        _ebeam32 = true;  // sets boolean to true to initialise beam
+        pad.tone(1000.0,0.1); // outputs sound if it hits the player's spacecraft
     }
-    
+    // write new attributes
     _enemybeam3.set_pos_boss(enemybossbeam_pos);
     _enemybeam3.set_pos_enemy1(enemy1beam_pos);
     _enemybeam3.set_pos_enemy2(enemy2beam_pos);
     
 }
 
-void GameEngine::check_wall_collisions(Gamepad &pad)
+void GameEngine::check_wall_collisions(Gamepad &pad) // check wall collision for enemies in stage two
 {
-    // read current ball attributes
+    // read current attributes of the enemies 
     Vector2D enemy21_pos = _e21.get_enemy21_pos();
     Vector2D enemy22_pos = _e22.get_enemy22_pos();
     Vector2D enemy21_movement = _e21.get_movement();
     Vector2D enemy22_movement = _e22.get_movement();
 
     // check if hit top wall
+    // first enemy
     if (enemy21_pos.y <= 1) {  //  1 due to 1 pixel boundary
         enemy21_pos.y = 1;  // bounce off ceiling without going off screen
         enemy21_movement.y = -enemy21_movement.y;
     }
+    //second enemy
+    else if (enemy22_pos.y <= 1) { 
+        enemy22_pos.y = 1; 
+        enemy22_movement.y = -enemy22_movement.y;
+    }
     // check if hit bottom wall
+    // first enemy
     else if (enemy21_pos.y + 7 >= (HEIGHT-1) ) { // bottom pixel is 47
-        // hit bottom
         enemy21_pos.y = (HEIGHT-1) - 7;  // stops ball going off screen
         enemy21_movement.y = -enemy21_movement.y;
-        // audio feedback
-    } else if (enemy22_pos.y + 7 >= (HEIGHT-1) ) { // bottom pixel is 47
-        // hit bottom
-        enemy22_pos.y = (HEIGHT-1) - 7;  // stops ball going off screen
+    // second enemy    
+    } else if (enemy22_pos.y + 7 >= (HEIGHT-1) ) { 
+        enemy22_pos.y = (HEIGHT-1) - 7;  
         enemy22_movement.y = -enemy22_movement.y;
-        // audio feedback
-    } else if (enemy22_pos.y <= 1) {  //  1 due to 1 pixel boundary
-        enemy22_pos.y = 1;  // bounce off ceiling without going off screen
-        enemy22_movement.y = -enemy22_movement.y;
-    }
+        
+    } 
 
-    // update ball parameters
+    // update first and second enemy parameters
     _e21.set_movement(enemy21_movement);
     _e22.set_movement(enemy22_movement);
     _e21.set_enemy21_pos(enemy21_pos);
     _e22.set_enemy22_pos(enemy22_pos);
 }
 
-void GameEngine::check_wall2_collisions(Gamepad &pad)
+void GameEngine::check_wall2_collisions(Gamepad &pad) // check wall collision for enemies in stage three
 {
-    // read current ball attributes
+    // read current enemy attributes for boss in stage three
     Vector2D enemyboss_pos = _e3.get_enemyboss_pos();
     Vector2D enemyboss_movement = _e3.get_movement();
 
@@ -626,83 +630,80 @@
     }
     // check if hit bottom wall
     else if (enemyboss_pos.y + 12 >= (HEIGHT-1) ) { // bottom pixel is 47
-        // hit bottom
         enemyboss_pos.y = (HEIGHT-1) - 12;  // stops ball going off screen
         enemyboss_movement.y = -enemyboss_movement.y;
-        // audio feedback
-    }else if (enemyboss_pos.x + 12 >= (WIDTH-1) ) { // bottom pixel is 47
-        // hit bottom
+    // check if hit right wall    
+    }else if (enemyboss_pos.x + 12 >= (WIDTH-1) ) { // right pixel is 83 
         enemyboss_pos.x = (WIDTH-1) - 12;  // stops ball going off screen
         enemyboss_movement.x = -enemyboss_movement.x;
-        // audio feedback
-    }else if (enemyboss_pos.x <= WIDTH/2) {  //  1 due to 1 pixel boundary
+    // check if left right wall      
+    }else if (enemyboss_pos.x <= WIDTH/2) {  // half the width (42)
         enemyboss_pos.x = WIDTH/2;  // bounce off ceiling without going halfway
         enemyboss_movement.x = -enemyboss_movement.x;
     }
-    
+    // update boss enemy parameters
     _e3.set_movement(enemyboss_movement);
     _e3.set_enemyboss_pos(enemyboss_pos);
     
 }
 
-void GameEngine::enemy_dead(N5110 &lcd, Gamepad &pad){
-    int e1_health = _e1.get_health();
-    Vector2D e1_pos = _e1.get_enemy_pos();
-    if (e1_health == 10){
+void GameEngine::enemy_dead(N5110 &lcd, Gamepad &pad){ // animation when the enemy is dead in stage one
+
+    int e1_health = _e1.get_health();      // Gets the health of the enemy 
+    Vector2D e1_pos = _e1.get_enemy_pos(); // Gets the position of the enemy
+    
+    if (e1_health == 10){ 
+       // explodes and outputs sound if the enemy is dead
         lcd.drawSprite(e1_pos.x-10,e1_pos.y-10,23,23,(int *)explosion);
         pad.tone(1000.0,0.5);
         pad.tone(800.0,0.5);
         pad.tone(600.0,0.5);
         pad.tone(400.0,0.5);
-       // lcd.refresh();
         wait(0.5);
-        lcd.drawSprite(e1_pos.x-10,e1_pos.y-10,23,23,(int *)explosion);
         _e1.update();
-      //  wait(2.0);
-        _stage = 2;
-        _e1.add_health();
+        lcd.drawSprite(e1_pos.x-10,e1_pos.y-10,23,23,(int *)explosion);
+        _stage = 2;  // mission one pass
         lcd.refresh();
     }
     
 }
 
-void GameEngine::enemy2_dead(N5110 &lcd, Gamepad &pad){
+void GameEngine::enemy2_dead(N5110 &lcd, Gamepad &pad){ // animation when the enemy is dead in stage two
     
-    int e21_health = _e21.get_health();
-    int e22_health = _e22.get_health();
+    int e21_health = _e21.get_health();    // Gets the health of the first enemy
+    int e22_health = _e22.get_health();    // Gets the health of the second enemy
     
-    Vector2D e21_pos = _e21.get_enemy21_pos();
-    Vector2D e22_pos = _e22.get_enemy22_pos();
+    Vector2D e21_pos = _e21.get_enemy21_pos(); // Gets the position of the first enemy
+    Vector2D e22_pos = _e22.get_enemy22_pos(); // Gets the position of the second enemy
     
-    if ((e21_health >= 10) && (e22_health >= 10)){
+    if ((e21_health >= 10) && (e22_health >= 10)){ 
+    // explodes and outputs sound if the enemy is dead
         lcd.drawSprite(e21_pos.x-10,e21_pos.y-10,23,23,(int *)explosion);
         lcd.drawSprite(e22_pos.x-10,e22_pos.y-10,23,23,(int *)explosion);
         pad.tone(1000.0,0.5);
         pad.tone(800.0,0.5);
         pad.tone(600.0,0.5);
         pad.tone(400.0,0.5);
-       // lcd.refresh();
         wait(0.2);
         lcd.drawSprite(e21_pos.x-10,e21_pos.y-10,23,23,(int *)explosion);
         lcd.drawSprite(e22_pos.x-10,e22_pos.y-10,23,23,(int *)explosion);
-        _stage = 4;
-        _e21.add_health();
-        _e22.add_health();
+        _stage = 4;    // mission two pass
         lcd.refresh();
     }
     
 }
 
-void GameEngine::enemy3_dead(N5110 &lcd, Gamepad &pad){
+void GameEngine::enemy3_dead(N5110 &lcd, Gamepad &pad){ // animation when the enemy is dead in stage three
+    
+    int e3boss_health = _e3.get_health_boss();  // Gets the health of the boss enemy
+    int e31_health = _e3.get_health_enemy1();   // Gets the health of the first enemy
+    int e32_health = _e3.get_health_enemy2();   // Gets the health of the second enemy
     
-    int e3boss_health = _e3.get_health_boss();
-    int e31_health = _e3.get_health_enemy1();
-    int e32_health = _e3.get_health_enemy2();
+    Vector2D e3boss_pos = _e3.get_enemyboss_pos(); // Gets the position of the boss enemy
+    Vector2D e31_pos = _e3.get_enemy1_pos();       // Gets the position of the first enemy
+    Vector2D e32_pos = _e3.get_enemy2_pos();       // Gets the position of the second enemy
     
-    Vector2D e3boss_pos = _e3.get_enemyboss_pos();
-    Vector2D e31_pos = _e3.get_enemy1_pos();
-    Vector2D e32_pos = _e3.get_enemy2_pos();
-    
+    // explodes and outputs sound if the enemy is dead
     if ((e3boss_health >= 10) && (e31_health >= 10) && (e32_health >= 10)){
         lcd.drawSprite(e3boss_pos.x-10,e3boss_pos.y-10,23,23,(int *)explosion);
         lcd.drawSprite(e31_pos.x-10,e31_pos.y-10,23,23,(int *)explosion);
@@ -711,28 +712,24 @@
         pad.tone(800.0,0.5);
         pad.tone(600.0,0.5);
         pad.tone(400.0,0.5);
-       // lcd.refresh();
         wait(0.2);
         lcd.drawSprite(e3boss_pos.x-10,e3boss_pos.y-10,23,23,(int *)explosion);
         lcd.drawSprite(e31_pos.x-10,e31_pos.y-10,23,23,(int *)explosion);
         lcd.drawSprite(e32_pos.x-10,e32_pos.y-10,23,23,(int *)explosion);
-        _stage = 6;
-        _e3.add_health_boss();
-        _e3.add_health_enemy1();
-        _e3.add_health_enemy2();
+        _stage = 6;   // mission three pass
         lcd.refresh();
     }
     
 }
 
-void GameEngine::spacecraft_dead(N5110 &lcd, Gamepad &pad)
-{
-   
-    int p1_health = _p1.get_health();
-    Vector2D p1_pos = _p1.get_pos();
+void GameEngine::spacecraft_dead(N5110 &lcd, Gamepad &pad) // animation when the player's spacecraft is dead in stage one
+{  
+    int p1_health = _p1.get_health(); // Gets the health of the player spacecraft
+    Vector2D p1_pos = _p1.get_pos();  // Gets the position of the player's spacecraft
     
     if (p1_health == 6){
         
+        // explodes and outputs sound if the enemy is dead
         lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion);
         pad.tone(1000.0,0.5);
         pad.tone(800.0,0.5);
@@ -743,48 +740,21 @@
         wait(0.1);
         lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion);
         _p1.update_move();
-      //  wait(2.0);
-        _stage = 1; 
-        _p1.add_health();
+        _stage = 1;         // mission one fail
         lcd.refresh();
     }
     
 }
 
-void GameEngine::spacecraft2_dead(N5110 &lcd, Gamepad &pad)
+void GameEngine::spacecraft2_dead(N5110 &lcd, Gamepad &pad) // animation when the player's spacecraft is dead in stage two
 {
    
-    int p1_health = _p1.get_health();
-    Vector2D p1_pos = _p1.get_pos();
+    int p1_health = _p1.get_health(); // Gets the health of the player spacecraft
+    Vector2D p1_pos = _p1.get_pos();  // Gets the position of the player's spacecraft
     
     if (p1_health == 6){
         
-        lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion);
-        pad.tone(1000.0,0.5);
-        pad.tone(800.0,0.5);
-        pad.tone(600.0,0.5);
-        pad.tone(400.0,0.5);
-        wait(0.5);
-        lcd.refresh();
-        wait(0.1);
-        lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion);
-        _p1.update_move();
-      //  wait(2.0);
-        _stage = 3;
-        _p1.add_health();
-        lcd.refresh();
-    }
-    
-}
-
-void GameEngine::spacecraft3_dead(N5110 &lcd, Gamepad &pad)
-{
-   
-    int p1_health = _p1.get_health();
-    Vector2D p1_pos = _p1.get_pos();
-    
-    if (p1_health == 6){
-        
+        // explodes and outputs sound if the enemy is dead
         lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion);
         pad.tone(1000.0,0.5);
         pad.tone(800.0,0.5);
@@ -795,99 +765,34 @@
         wait(0.1);
         lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion);
         _p1.update_move();
-      //  wait(2.0);
-        _stage = 5;
-        _p1.add_health();
+        _stage = 3;   // mission two fail
         lcd.refresh();
     }
     
 }
 
-void GameEngine::check_mission_one(Gamepad &pad){
-    
- if (_stage == 1){
-    pad.tone(233.0,0.5);
-    wait(0.5);
-    pad.tone(184.0,0.5);
-    wait(0.5);
-    pad.tone(174.0,2.0);
-    wait(1.0);
- } else if (_stage == 2){
-     
-     pad.leds_off();
-     pad.tone(184.0,0.2);
-     wait(0.5);
-     pad.tone(233.0,0.2);
-     wait(0.5);
-     pad.tone(184.0,0.2);
-     wait(0.5);
-     pad.tone(233.0,0.2);
-     wait(0.5);
-     pad.tone(184.0,0.2);
-     wait(0.5);
-     pad.tone(233.0,0.2);
-     wait(0.5);
-     pad.tone(184.0,2.0);
-     wait(0.5);
- }
-}
-
-void GameEngine::check_mission_two(Gamepad &pad){
+void GameEngine::spacecraft3_dead(N5110 &lcd, Gamepad &pad) // animation when the player's spacecraft is dead in stage three
+{
+    int p1_health = _p1.get_health(); // Gets the health of the player spacecraft
+    Vector2D p1_pos = _p1.get_pos();  // Gets the position of the player's spacecraft
     
- if (_stage == 3){
-    pad.tone(233.0,0.5);
-    wait(0.5);
-    pad.tone(184.0,0.5);
-    wait(0.5);
-    pad.tone(174.0,2.0);
-    wait(1.0);
- } else if (_stage == 4){
-     
-     pad.leds_off();
-     pad.tone(184.0,0.2);
-     wait(0.5);
-     pad.tone(233.0,0.2);
-     wait(0.5);
-     pad.tone(184.0,0.2);
-     wait(0.5);
-     pad.tone(233.0,0.2);
-     wait(0.5);
-     pad.tone(184.0,0.2);
-     wait(0.5);
-     pad.tone(233.0,0.2);
-     wait(0.5);
-     pad.tone(184.0,2.0);
-     wait(0.5);
- }
-}
-
-void GameEngine::check_mission_three(Gamepad &pad){
+    if (p1_health == 6){
+        
+        // explodes and outputs sound if the enemy is dead
+        lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion);
+        pad.tone(1000.0,0.5);
+        pad.tone(800.0,0.5);
+        pad.tone(600.0,0.5);
+        pad.tone(400.0,0.5);
+        wait(0.5);
+        lcd.refresh();
+        wait(0.1);
+        lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion);
+        _p1.update_move();
+        _stage = 5;        // mission three fail
+        lcd.refresh();
+    }
     
- if (_stage == 5){
-    pad.tone(233.0,0.5);
-    wait(0.5);
-    pad.tone(184.0,0.5);
-    wait(0.5);
-    pad.tone(174.0,2.0);
-    wait(1.0);
- } else if (_stage == 6 ){
-     
-     pad.leds_off();
-     pad.tone(184.0,0.2);
-     wait(0.5);
-     pad.tone(233.0,0.2);
-     wait(0.5);
-     pad.tone(184.0,0.2);
-     wait(0.5);
-     pad.tone(233.0,0.2);
-     wait(0.5);
-     pad.tone(184.0,0.2);
-     wait(0.5);
-     pad.tone(233.0,0.2);
-     wait(0.5);
-     pad.tone(184.0,2.0);
-     wait(0.5);
- }
 }
 
 void GameEngine::draw_enemy_health(N5110 &lcd)
@@ -895,7 +800,7 @@
     // get health of the enemy 
     int e1_health = _e1.get_health();
     
-    if (e21_health < 10){
+    if (e1_health <= 10){
     lcd.drawRect(62,42,20,4,FILL_TRANSPARENT);
     lcd.drawRect(62,42,20-2*e1_health,4,FILL_BLACK);
     }
@@ -911,7 +816,7 @@
     // get health of the enemy 
     int e21_health = _e21.get_health();
     
-    if (e21_health < 10){
+    if (e21_health <= 10){
     lcd.drawRect(2,42,20,4,FILL_TRANSPARENT);
     lcd.drawRect(2,42,20-2*e21_health,4,FILL_BLACK);
     }
@@ -925,7 +830,7 @@
     // get health of the enemy 
     int e22_health = _e22.get_health();
     
-    if (e22_health < 10){
+    if (e22_health <= 10){
     lcd.drawRect(62,42,20,4,FILL_TRANSPARENT);
     lcd.drawRect(62,42,20-2*e22_health,4,FILL_BLACK);
     }
@@ -942,21 +847,21 @@
     int e3enemy1_health = _e3.get_health_enemy1();
     int e3enemy2_health = _e3.get_health_enemy2();
     
-    if (e3boss_health < 10){
+    if (e3boss_health <= 10){
     lcd.drawRect(62,42,20,4,FILL_TRANSPARENT);
     lcd.drawRect(62,42,20-2*e3boss_health,4,FILL_BLACK);
     }
     else {
     lcd.drawRect(62,42,20,4,FILL_TRANSPARENT);
     }
-    if (e3enemy1_health < 10){
+    if (e3enemy1_health <= 10){
     lcd.drawRect(2,42,20,4,FILL_TRANSPARENT);
     lcd.drawRect(2,42,20-2*e3enemy1_health,4,FILL_BLACK);
     }
     else {
     lcd.drawRect(2,42,20,4,FILL_TRANSPARENT);
     }    
-    if (e3enemy2_health < 10){
+    if (e3enemy2_health <= 10){
     lcd.drawRect(62,2,20,4,FILL_TRANSPARENT);
     lcd.drawRect(62,2,20-2*e3enemy2_health,4,FILL_BLACK);
     }
@@ -970,9 +875,10 @@
     //get the health of the spacecraft 
     int p1_health = _p1.get_health();
     
-    if (p1_health == 0){
+    if (p1_health == 0){ // All the lights are switched on
         pad.leds_on();
-    }else if (p1_health == 1){
+        
+    }else if (p1_health == 1){ // Switches off the left most light
         pad.led(1,0);
         pad.led(2,1);
         pad.led(3,1);
@@ -980,14 +886,14 @@
         pad.led(5,1);
         pad.led(6,1);
         
-    }else if (p1_health == 2){
+    }else if (p1_health == 2){ // Switches of the two left most lights
         pad.led(1,0);
         pad.led(2,0);
         pad.led(3,1);
         pad.led(4,1);
         pad.led(5,1);
         pad.led(6,1);
-    }else if (p1_health == 3){
+    }else if (p1_health == 3){ // Swtiches of the three left most lights
         pad.led(1,0);
         pad.led(2,0);
         pad.led(3,0);
@@ -995,7 +901,7 @@
         pad.led(5,1);
         pad.led(6,1);
         
-    }else if (p1_health == 4){
+    }else if (p1_health == 4){ // Switches off the four left most lights
         pad.led(1,0);
         pad.led(2,0);
         pad.led(3,0);
@@ -1003,7 +909,7 @@
         pad.led(5,1);
         pad.led(6,1);
         
-    }else if (p1_health == 5){
+    }else if (p1_health == 5){ // Switches the five left most light
         pad.led(1,0);
         pad.led(2,0);
         pad.led(3,0);
@@ -1012,19 +918,19 @@
         pad.led(6,1);
         
     } else {
-        pad.leds_off();
+        pad.leds_off(); // Switches all the Led light off
     }
         
 }
     
 int GameEngine::get_game_stage() {
     int stage = _stage;
-    return stage;    
+    return stage;    // Gets the value of the stage
 }
 
 int GameEngine::restart_game_stage() {
+    
     int stage = _stage;
-    
-    stage = 0;
+    stage = 0;  // sets the stage to be zero 
     return stage;    
 }        
\ No newline at end of file