Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Revision:
47:6e31b195ce3c
Parent:
46:f09711580d4a
Child:
48:f7d9ae3e554d
diff -r f09711580d4a -r 6e31b195ce3c main.cpp
--- a/main.cpp	Wed May 08 20:47:52 2019 +0000
+++ b/main.cpp	Thu May 09 01:57:49 2019 +0000
@@ -15,10 +15,11 @@
     init();
     
     while(1) { // Gameloop
-    
         boss_room_exist = false;
+        number_of_enemies_killed = 0;
+        total_time = 0;
+        
         title.main(lcd, gamepad, global_contrast);
-        
         srand(title.get_seed());
         player = new Player(39, 27);
         room_engine = new RoomEngine(global_contrast);
@@ -64,12 +65,16 @@
             room_engine->entrance_scene(lcd, gamepad);
             while(room_engine->check_player_room_position() == INSIDE) {  // Room actions
                 room_engine->read_input(gamepad);
-                room_engine->update();
+                room_engine->update(number_of_enemies_killed);
                 room_engine->render(lcd, gamepad);
                 minimap_detection();
+                total_time++;
                 if  (player->get_hp() <= 0) {
                     goto gameover;
                 }
+                if ((rooms[room_y][room_x]->get_room_type() == 10) && !(rooms[room_y][room_x]->enemies_exist())){
+                    goto winner;
+                }
             }
             room_engine->exit_scene(lcd, gamepad);
             rooms[room_y][room_x]->unload();
@@ -79,6 +84,14 @@
     }
     gameover : {
         game_over();
+        goto displaystats;
+    }
+    winner : {
+        win();
+        goto displaystats;
+    }
+    displaystats : {
+        display_stats();
     }
 }
 
@@ -108,23 +121,6 @@
     boss_room_counter++;
 }
 
-void game_over()
-{
-    while(1){   // Game Over Screen Loop
-                lcd.clear();
-                lcd.setContrast(global_contrast);
-                lcd.printString("Game Over", 0, 0);
-                lcd.printString("Retry?", 0, 1);
-                lcd.refresh();
-                while(!gamepad.check_event(Gamepad::A_PRESSED)) {
-                }
-                wait(0.05);
-                while(gamepad.check_event(Gamepad::A_PRESSED)) {
-                }
-                break;
-            }
-}
-
 void update_room_coords()
 {
     prev_room_x = room_x;
@@ -261,7 +257,68 @@
 {
     while(gamepad.check_event(Gamepad::BACK_PRESSED)) {
         lcd.clear();
+        for (int j = 0; j < MAX_ROOMS_MAP_Y; j++) {
+            for (int i = 0; i < MAX_ROOMS_MAP_X; i++) {
+                if (valid_rooms[j][i]) {
+                    lcd.drawSprite(33 + (i-room_x)*20, 17 + (j-room_y)*15, 15, 20, (char *)minimap_sprite[0]);
+                    if (rooms[j][i]->get_room_type() == 10) {
+                        lcd.drawSprite(33 + (i-room_x)*20, 17 + (j-room_y)*15, 15, 20, (char *)minimap_sprite[2]);
+                    } else if (rooms[j][i]->enemies_exist()) {
+                        lcd.drawSprite(33 + (i-room_x)*20, 17 + (j-room_y)*15, 15, 20, (char *)minimap_sprite[1]);
+                    }
+                    if (rooms[j][i]->get_doorway(0)) {
+                        lcd.drawLine(42 + (i-room_x)*20, 17 + (j-room_y)*15, 43 + (i-room_x)*20, 17 + (j-room_y)*15, 1);
+                    }
+                    if (rooms[j][i]->get_doorway(1)) {
+                        lcd.drawLine(52 + (i-room_x)*20, 23 + (j-room_y)*15, 52 + (i-room_x)*20, 24 + (j-room_y)*15, 1);
+                    }
+                    if (rooms[j][i]->get_doorway(2)) {
+                        lcd.drawLine(42 + (i-room_x)*20, 31 + (j-room_y)*15, 43 + (i-room_x)*20, 31 + (j-room_y)*15, 1);
+                    }
+                    if (rooms[j][i]->get_doorway(3)) {
+                        lcd.drawLine(33 + (i-room_x)*20, 23 + (j-room_y)*15, 33 + (i-room_x)*20, 24 + (j-room_y)*15, 1);
+                    }
+                }
+            }
+        }
+        lcd.drawSpriteTransparent(33, 17, 15, 20, (char *)minimap_sprite[3]);
         lcd.refresh();
         wait_ms(1000/40);
     };
 }
+
+void game_over()
+{
+    lcd.clear();
+    lcd.setContrast(global_contrast);
+    lcd.printString("Game Over", 0, 0);
+    lcd.printString("Retry?", 0, 1);        
+}
+
+void win()
+{
+    lcd.clear();
+    lcd.setContrast(global_contrast);
+    lcd.printString("You won!", 0, 0);
+}
+
+void display_stats()
+{
+    lcd.printString("Enemies Killed:", 0, 2);
+    char kills[10];
+    sprintf(kills, "%d enemies", number_of_enemies_killed);
+    lcd.printString(kills, 0, 3);
+    lcd.printString("Time:", 0, 4);
+    char total_duration[10];
+    sprintf(total_duration, "%d seconds", (total_time/40));
+    lcd.printString(total_duration, 0, 5);
+    lcd.refresh();
+    while(gamepad.check_event(Gamepad::A_PRESSED)) {
+    }
+    wait(0.05);
+    while(!gamepad.check_event(Gamepad::A_PRESSED)) {
+    }
+    wait(0.05);
+    while(gamepad.check_event(Gamepad::A_PRESSED)) {
+    }
+}