Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MotionSensor
Diff: Room/Room.cpp
- Revision:
- 27:a1b41626f57c
- Parent:
- 26:abbc19edc5c1
- Child:
- 28:98848e6a77a2
diff -r abbc19edc5c1 -r a1b41626f57c Room/Room.cpp
--- a/Room/Room.cpp Mon Apr 29 02:45:17 2019 +0000
+++ b/Room/Room.cpp Mon Apr 29 10:39:09 2019 +0000
@@ -3,19 +3,79 @@
// Constructor
Room::Room()
{
+ for (int i = 0; i < MAX_ENEMIES; i++)
+ {
+ valid_enemies[i] = false;
+ }
enemies[0] = new Headless(20, 20);
valid_enemies[0] = true;
+ enemies[1] = new Snake(20, 30);
+ valid_enemies[1] = true;
+ enemies[2] = new Snake(60, 30);
+ valid_enemies[2] = true;
+ _type = 0;
+ for (int layer = 0; layer < 3; layer++) {
+ for (int i = 0; i < screen_width; i++) {
+ for (int j = 0; j < screen_height; j++) {
+ _current_map[layer][j][i] = level_map[_type][layer][j][i];
+ }
+ }
+ }
+ for(int n = 0; n < 4; n++){
+ _doorways[n] = true;
+ };
+}
+
+Room::~Room()
+{
+ for (int i = 0; i < MAX_ENEMIES; i++) {
+ if (valid_enemies[i]) {
+ delete enemies[i];
+ }
+ };
+}
+
+// Accessors
+int * Room::get_current_map_2d(){
+ return ((int *) _current_map[0]);
}
// Functions
void Room::init()
{
-
+ if(_doorways[0]){ // N
+ overlap(36, 0, 12, 10, (int *)wall_n[0], (int *)_current_map[0]);
+ overlap(36, 0, 12, 10, (int *)wall_n[1], (int *)_current_map[1]);
+ }
+ if(_doorways[1]){ // E
+ overlap(81, 22, 3, 11, (int *)wall_x[0], (int *)_current_map[0]);
+ overlap(81, 22, 3, 11, (int *)wall_x[0], (int *)_current_map[1]);
+ }
+ if(_doorways[2]){ // S
+ overlap(36, 45, 12, 3, (int *)wall_s[0], (int *)_current_map[0]);
+ overlap(36, 45, 12, 3, (int *)wall_s[1], (int *)_current_map[1]);
+ }
+ if(_doorways[3]){ // W
+ overlap(0, 22, 3, 11, (int *)wall_x[1], (int *)_current_map[0]);
+ overlap(0, 22, 3, 11, (int *)wall_x[1], (int *)_current_map[1]);
+ }
}
-void Room::draw_enemies(N5110 &lcd)
+void Room::draw_room(N5110 &lcd)
{
-
+ lcd.drawSprite(0, 0, screen_height, screen_width, (int *)_current_map[1]); // drawing 3d map
}
-// Accessors
\ No newline at end of file
+void Room::draw_room_overlay(N5110 &lcd)
+{
+ lcd.drawSprite(0, 0, screen_height, screen_width, (int *)_current_map[2]);
+}
+
+void Room::overlap(int x, int y, int width, int height, int * object, int * map)
+{
+ for(int i = 0; i < width; i++) {
+ for (int j = 0; j < height; j++) {
+ *((map+(y+j)*screen_width)+(x+i)) = *((object+j*width)+i);
+ }
+ }
+}
\ No newline at end of file