Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Files at this revision

API Documentation at this revision

Comitter:
el17sm
Date:
Tue May 07 09:43:36 2019 +0000
Parent:
37:a404860171a9
Child:
40:cbcbf6fc1421
Commit message:
Draws in layers;

Changed in this revision

RoomEngine/Room/Room.cpp Show annotated file Show diff for this revision Revisions of this file
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
--- a/RoomEngine/Room/Room.cpp	Tue May 07 03:47:39 2019 +0000
+++ b/RoomEngine/Room/Room.cpp	Tue May 07 09:43:36 2019 +0000
@@ -11,27 +11,49 @@
     for(int id = 0; id < MAX_ENEMIES; id++) {
         valid_collectibles[id] = false;
     }
-    if(room_type == 1){
-        valid_enemies[0] = true;
-        for (int id = 1; id < MAX_ENEMIES; id++)
-        {
-            valid_enemies[id] = id - 1 < no_of_enemies;
-            if (id - 1 < no_of_enemies) {
-                enemies_type[id] = rand() % 2;
-                _enemy_coord[id][0] = 15 + (rand() % 52);
-                _enemy_coord[id][1] = 14 + (rand() % 11);
-            }
+    if(room_type == 0) {
+        init_normal_room(no_of_enemies);
+    } else if (room_type == 1){
+        init_boss_room(no_of_enemies);
+    } else if (room_type == 2){
+        init_middle_walled_room(no_of_enemies);
+    } else if (room_type == 3){
+        init_side_walled_room(no_of_enemies);
+    }
+}
+
+void Room::init_normal_room(int no_of_enemies)
+{
+    for (int id = 0; id < MAX_ENEMIES; id++) {
+        valid_enemies[id] = id < no_of_enemies;
+        if (id < no_of_enemies) {
+            enemies_type[id] = rand() % 2;
+            _enemy_coord[id][0] = 15 + (rand() % 52);
+            _enemy_coord[id][1] = 14 + (rand() % 11);
         }
-        
+    }
+}
+
+void Room::init_middle_walled_room(int no_of_enemies)
+{
+    
+}
 
-    } else {
-            for (int id = 0; id < MAX_ENEMIES; id++) {
-                valid_enemies[id] = id < no_of_enemies;
-                if (id < no_of_enemies) {
-                    enemies_type[id] = rand() % 2;
-                    _enemy_coord[id][0] = 15 + (rand() % 52);
-                    _enemy_coord[id][1] = 14 + (rand() % 11);
-            }
+void Room::init_side_walled_room(int no_of_enemies)
+{
+    
+}
+
+void Room::init_boss_room(int no_of_enemies)
+{
+    valid_enemies[0] = true;
+    for (int id = 1; id < MAX_ENEMIES; id++)
+    {
+        valid_enemies[id] = id - 1 < no_of_enemies;
+        if (id - 1 < no_of_enemies) {
+            enemies_type[id] = rand() % 2;
+            _enemy_coord[id][0] = 15 + (rand() % 52);
+            _enemy_coord[id][1] = 14 + (rand() % 11);
         }
     }
 }
@@ -128,19 +150,19 @@
     }
 }
 
-void Room::draw_enemies(N5110 &lcd)
+void Room::draw_enemies(N5110 &lcd, int j)
 {
     for (int i = 0; i < MAX_ENEMIES; i++) {
-        if (valid_enemies[i]) {
+        if ((valid_enemies[i] && (enemies[i]->get_pos_y() == j))) {
             enemies[i]->draw(lcd);
         }
     }
 }
 
-void Room::draw_collectibles(N5110 &lcd)
+void Room::draw_collectibles(N5110 &lcd, int j)
 {
     for (int i = 0; i < MAX_ENEMIES; i++) {
-        if (valid_collectibles[i]) {
+        if ((valid_collectibles[i]) && (collectibles[i]->get_pos_y() == j)) {
             collectibles[i]->draw(lcd);
         }
     }
--- a/RoomEngine/Room/Room.h	Tue May 07 03:47:39 2019 +0000
+++ b/RoomEngine/Room/Room.h	Tue May 07 09:43:36 2019 +0000
@@ -22,6 +22,10 @@
     // Functions
     void draw_walls(N5110 &lcd);
     void draw_walls_overlay(N5110 &lcd);
+    void init_normal_room(int no_of_enemies);
+    void init_middle_walled_room(int no_of_enemies);
+    void init_side_walled_room(int no_of_enemies);
+    void init_boss_room(int no_of_enemies);
     
 public:
     // Constructors
@@ -38,8 +42,8 @@
     void unload();
     void draw_room(N5110 &lcd);
     void draw_room_overlay(N5110 &lcd);
-    void draw_enemies(N5110 &lcd);
-    void draw_collectibles(N5110 &lcd);
+    void draw_enemies(N5110 &lcd, int j);
+    void draw_collectibles(N5110 &lcd, int j);
     
     // Variables
     Entity *enemies[MAX_ENEMIES];
--- a/RoomEngine/RoomEngine.cpp	Tue May 07 03:47:39 2019 +0000
+++ b/RoomEngine/RoomEngine.cpp	Tue May 07 09:43:36 2019 +0000
@@ -405,9 +405,14 @@
 {   
     room->draw_room(lcd);
     //lcd.drawSprite(0,0,screen_height,screen_width,(char *)level_map[1]);
-    player->draw(lcd);
-    room->draw_enemies(lcd);
-    room->draw_collectibles(lcd);
+    for(int j = 0; j < HEIGHT; j++) {
+        if (j == player->get_pos_y()) {
+            player->draw(lcd);
+        }
+        room->draw_enemies(lcd, j);
+        room->draw_collectibles(lcd, j);   
+    }
+    
     room->draw_room_overlay(lcd);
     if (_L) {
         draw_health(lcd);