Game For ECE 2035

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Revision:
16:06a88c0110ff
Parent:
15:05592aaa468c
diff -r 05592aaa468c -r 06a88c0110ff main.cpp
--- a/main.cpp	Fri Dec 03 09:50:47 2021 +0000
+++ b/main.cpp	Fri Dec 03 10:52:08 2021 +0000
@@ -30,7 +30,7 @@
     int px, py; // Previous locations
     int has_key;
     int spell;
-    int god;
+    int god,god_walk;
     int won;
     int HP,MP;
     int talked;
@@ -126,6 +126,10 @@
                 Player.y--;
 
             }
+            if (north->walkable && north == NULL && Player.god_walk && Player.god ) {
+                Player.y-=3;
+
+            }
             break;
         }
         case GO_RIGHT: {
@@ -133,6 +137,9 @@
             if (east->walkable && east == NULL || east->type == (PORTAL || PLANT) && Player.x != 0 || Player.god ) {
                 Player.x++;
             }
+            if (east->walkable && east == NULL && Player.god_walk && Player.god ) {
+                Player.x+=3;
+            }
             break;
         }
         case GO_DOWN:  {
@@ -140,6 +147,10 @@
             if (south->walkable && south == NULL || south->type ==(PORTAL || PLANT) && Player.y != 0 || Player.god ) {
                 Player.y++;
             }
+            if (south->walkable && south == NULL && Player.god_walk && Player.god ) {
+                Player.y+=3;
+
+            }
             break;
         }
         case GO_LEFT: {
@@ -147,6 +158,10 @@
             if (west->walkable && west == NULL || west->type == (PORTAL || PLANT) && Player.x != 0 || Player.god  ) {
                 Player.x--;
             }
+            
+            if (west->walkable && west == NULL && Player.god_walk && Player.god ) {
+                Player.x-=3;
+            }
             break;
         }
         case ACTION_BUTTON: {
@@ -156,27 +171,44 @@
             MapItem* east = get_east(Player.x,Player.y);
             MapItem* curr =  get_here(Player.x,Player.y);
 
-            if((east->type == NPC||west->type == NPC||north->type == NPC||south->type == NPC)&& Player.has_key == 1) {
+            if(east->type == NPC||west->type == NPC||north->type == NPC||south->type == NPC){
+                if( Player.has_key == 1)
+                 {
                 npc_speech2();
+                }
+                else
+                    npc_speech1();   
             }
 
-            if(east->type == NPC||west->type == NPC||north->type == NPC||south->type == NPC && Player.has_key == 0 ) {
-                npc_speech1();
-                
-                Player.talked = 1;
+           
+
+            if(east->type == NPCT||west->type == NPCT||north->type == NPCT||south->type == NPCT ) {
+                if( Player.has_key == 1)
+                 {
+                npc2_speech2();
+                }
+                else
+                    npc2_speech1();   
             }
-
-            if(east->type == NPCT||west->type == NPCT||north->type == NPCT||south->type == NPCT && Player.has_key == 0 ) {
-                npc2_speech();
-                Player.talked = 1;
-            }
+            
 
             if(north->type == PORTAL||south->type == PORTAL||east->type == PORTAL||west->type == PORTAL) {
                 set_active_map(1);
                 Player.x = Player.y = 7;
             }
+            if(north->type == KEY||south->type == KEY||east->type == KEY||west->type == KEY) {
+            pick_key();
+            map_erase(26,13);
+            }
 
-
+            
+            if(Player.HP<50){
+                heal_up();
+                }
+            if (Player.MP<50){
+                mag_up();
+                }
+            
 
             if(east->type == ENEMY1||west->type == ENEMY1||north->type == ENEMY1||south->type == ENEMY1) {
                 Player.HP-=2;
@@ -266,6 +298,7 @@
                 map_erase(15,9);
                 Player.has_key = 1;
                 
+                
             
 }
 }
@@ -275,6 +308,7 @@
 
         if(north->type == PORTAl||south->type == PORTAl||east->type == PORTAl||west->type == PORTAl) {
             set_active_map(0);
+            add_key(26,13);
             Player.x=20;
             Player.y = 36;
         }
@@ -292,11 +326,7 @@
             if(Player.HP < 100) {
                 fruit();
                 Player.HP += 5;
-                north->data = NULL;
-                south->data = NULL;
-                east->data = NULL;
-                west->data = NULL;
-                curr->data = NULL;
+                
             } else
                 no_fruit();
 
@@ -321,8 +351,10 @@
         Player.god = !Player.god;
         if (Player.god) {
             god_modeOn();
+            Player.god_walk = !Player.god_walk;
         } else
             god_modeOff();
+            Player.god_walk = Player.god_walk;
 
     }
     break;
@@ -531,10 +563,14 @@
         // 3. Update game (update_game)
         update_game(action);
         // 3b. Check for game over
-        if(Player.won == 1 || Player.HP <= 0) {
+        if(Player.HP <= 0) {
             draw_gameover();
             break;
         }
+        if(Player.won == 1 ){
+            draw_win();
+            break;
+            }
         // 4. Draw frame (draw_game)
         draw_game(true);