Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Files at this revision

API Documentation at this revision

Comitter:
el17sm
Date:
Thu May 09 01:57:49 2019 +0000
Parent:
46:f09711580d4a
Child:
48:f7d9ae3e554d
Commit message:
Full Game Complete;; Added scoring system;; ; To do: ; Commenting and Doxygen;; Shortening of a few functions;

Changed in this revision

RoomEngine/Room/Room.h Show annotated file Show diff for this revision Revisions of this file
RoomEngine/RoomEngine.cpp Show annotated file Show diff for this revision Revisions of this file
RoomEngine/RoomEngine.h Show annotated file Show diff for this revision Revisions of this file
Title/Title.cpp Show annotated file Show diff for this revision Revisions of this file
Title/Title.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
sprites.h Show annotated file Show diff for this revision Revisions of this file
--- a/RoomEngine/Room/Room.h	Wed May 08 20:47:52 2019 +0000
+++ b/RoomEngine/Room/Room.h	Thu May 09 01:57:49 2019 +0000
@@ -36,7 +36,6 @@
     void init_side_walled_room();
     void init_boss_room();
     void rand_enemy_coordinate(int id);
-    bool enemies_exist();
     
 public:
     // Constructors
@@ -62,6 +61,7 @@
     void draw(N5110 &lcd, int j);    
     void draw_room(N5110 &lcd);
     void draw_room_overlay(N5110 &lcd);
+    bool enemies_exist();
     
     // Variables
     Entity *enemies[MAX_ENEMIES];
--- a/RoomEngine/RoomEngine.cpp	Wed May 08 20:47:52 2019 +0000
+++ b/RoomEngine/RoomEngine.cpp	Thu May 09 01:57:49 2019 +0000
@@ -109,11 +109,11 @@
     mapped_coord = gamepad.get_mapped_coord();
 }
 
-void RoomEngine::update()
+void RoomEngine::update(int &number_of_enemies_killed)
 {
     room->update_doorways();
     check_damage();
-    check_enemies_death();
+    check_enemies_death(number_of_enemies_killed);
     check_walls_collision();
     move();
     player->buttons(_A, _B, _Y, _X);
@@ -274,7 +274,7 @@
     }
 }
 
-void RoomEngine::check_enemies_death()
+void RoomEngine::check_enemies_death(int &number_of_enemies_killed)
 {
     // Enemy Death
     for (int i = 0; i < MAX_ENEMIES; i++) {
@@ -290,6 +290,7 @@
             }
             delete room->enemies[i];
             room->valid_enemies[i] = false;
+            number_of_enemies_killed++;
         }
     }
 }
--- a/RoomEngine/RoomEngine.h	Wed May 08 20:47:52 2019 +0000
+++ b/RoomEngine/RoomEngine.h	Thu May 09 01:57:49 2019 +0000
@@ -27,7 +27,7 @@
     void update_current_room();
     
     void read_input(Gamepad &gamepad);
-    void update();
+    void update(int &number_of_enemies_killed);
     void render(N5110 &lcd, Gamepad &gamepad);
     
     int check_player_room_position();
@@ -65,7 +65,7 @@
     void check_damage();
     void check_damage_player();
     void check_damage_enemies();
-    void check_enemies_death();
+    void check_enemies_death(int &number_of_enemies_killed);
     void check_walls_collision();
     
     void move();
--- a/Title/Title.cpp	Wed May 08 20:47:52 2019 +0000
+++ b/Title/Title.cpp	Thu May 09 01:57:49 2019 +0000
@@ -35,7 +35,7 @@
         } else if (title_option == 2) {
             title_option_credit(lcd, gamepad);
         } else if (title_option == 3) {
-            title_option_hi_scores(lcd);
+            title_option_tutorial(lcd, gamepad);
         }
     }
     player.~Player();
@@ -113,7 +113,45 @@
     }
 }
 
-void Title::title_option_hi_scores(N5110 &lcd)
+void Title::title_option_tutorial(N5110 &lcd, Gamepad &gamepad)
 {
-    
+    lcd.clear();
+    lcd.printString("Use the joypad", 0, 0);
+    lcd.printString("to move the", 0, 1);
+    lcd.printString("player", 0, 2);
+    lcd.printString("Use buttons", 0, 3);
+    lcd.printString("ABXY to shoot", 0, 4);
+    lcd.printString("directionally", 0, 5);
+    lcd.refresh();
+    wait(0.05);
+    while(!gamepad.check_event(Gamepad::A_PRESSED)) {
+    }
+    wait(0.05);
+    while(gamepad.check_event(Gamepad::A_PRESSED)) {
+    }
+    lcd.clear();
+    lcd.printString("Hold L to", 0, 0);
+    lcd.printString("show player", 0, 1);
+    lcd.printString("health", 0, 2);
+    lcd.printString("Hold Back", 0, 3);
+    lcd.printString("to view a", 0, 4);
+    lcd.printString("minimap", 0, 5);
+    lcd.refresh();
+    wait(0.05);
+    while(!gamepad.check_event(Gamepad::A_PRESSED)) {
+    }
+    wait(0.05);
+    while(gamepad.check_event(Gamepad::A_PRESSED)) {
+    }
+    lcd.clear();
+    lcd.printString("Press Start", 0, 0);
+    lcd.printString("to pause", 0, 1);
+    lcd.printString("the game", 0, 2);
+    lcd.refresh();
+    wait(0.05);
+    while(!gamepad.check_event(Gamepad::A_PRESSED)) {
+    }
+    wait(0.05);
+    while(gamepad.check_event(Gamepad::A_PRESSED)) {
+    }
 }
--- a/Title/Title.h	Wed May 08 20:47:52 2019 +0000
+++ b/Title/Title.h	Thu May 09 01:57:49 2019 +0000
@@ -19,7 +19,7 @@
     
     void title_option_option(N5110 &lcd, Gamepad &gamepad, Player &player, float &global_contrast);
     void title_option_credit(N5110 &lcd, Gamepad &gamepad);
-    void title_option_hi_scores(N5110 &lcd);
+    void title_option_tutorial(N5110 &lcd, Gamepad &gamepad);
     
 public:
     // Constructor
--- 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)) {
+    }
+}
--- a/main.h	Wed May 08 20:47:52 2019 +0000
+++ b/main.h	Thu May 09 01:57:49 2019 +0000
@@ -20,6 +20,8 @@
 float global_contrast = 0.5;
 int boss_room_number;
 bool boss_room_exist;
+int number_of_enemies_killed;
+int total_time;
 int no_of_doorways;
 int boss_room_counter = 0;
 int prev_room_x = MAX_ROOMS_MAP_X;
@@ -42,6 +44,8 @@
 void init();
 void game_loop();
 void game_over();
+void win();
+void display_stats();
 void generate_room();
 void update_room_coords();
 
--- a/sprites.h	Wed May 08 20:47:52 2019 +0000
+++ b/sprites.h	Thu May 09 01:57:49 2019 +0000
@@ -94,12 +94,12 @@
     },
     {
         {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,0,0,1,0,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
-        {1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,1,0,0,1,1,0,0,0,1,0},
-        {1,1,1,1,0,0,1,0,0,1,1,0,0,1,1,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1},
-        {1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,1,0,0,0,1,1,0},
-        {1,0,0,1,0,0,1,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,1,0,0,1,0,0,0,1,1,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,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0},
+        {0,0,0,1,0,0,1,0,1,0,1,1,1,0,1,1,1,0,1,1,0,0,0,0,0,1,1,0,0,1,0,0},
+        {0,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,0},
+        {0,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,0,1,0,0},
+        {0,0,0,1,0,0,1,1,1,0,0,1,1,0,1,1,1,0,1,0,0,0,1,0,1,1,1,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,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
     }
@@ -178,6 +178,77 @@
     {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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
 };
 
+const char minimap_sprite[4][15][20] = {
+    {
+        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+        {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,1,1,0,1,1,1,0,1,1,0,1,1,0,0,1,0},
+        {0,1,0,0,1,0,1,1,0,1,1,0,0,1,0,0,0,0,1,0},
+        {0,1,0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,0,1,0},
+        {0,1,0,0,1,0,1,1,0,1,0,0,1,0,0,1,0,0,1,0},
+        {0,1,0,0,1,1,0,1,1,1,1,1,0,1,1,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+        {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+        {0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0},
+        {0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0},
+        {0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0},
+        {0,1,2,2,1,2,1,2,1,1,1,2,1,2,1,2,2,2,1,0},
+        {0,1,2,2,1,2,1,2,1,2,1,2,1,2,1,2,2,2,1,0},
+        {0,1,2,2,1,1,1,2,1,2,1,2,1,2,1,2,2,2,1,0},
+        {0,1,2,2,2,1,2,2,1,2,1,2,1,2,1,2,2,2,1,0},
+        {0,1,2,2,2,1,2,2,1,1,1,2,1,1,1,2,2,2,1,0},
+        {0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0},
+        {0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0},
+        {0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0},
+        {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+    }
+};
+
 const char level_map[3][48][84] = { // map[map number][2d/3d/overlay][y][x]
     {
         {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,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},