Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Mon Apr 29 10:39:09 2019 +0000
Revision:
27:a1b41626f57c
Parent:
26:abbc19edc5c1
Child:
28:98848e6a77a2
Functional Room; Great Success;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17sm 25:112cbcb0b4a7 1 #include "Room.h"
el17sm 26:abbc19edc5c1 2
el17sm 26:abbc19edc5c1 3 // Constructor
el17sm 26:abbc19edc5c1 4 Room::Room()
el17sm 26:abbc19edc5c1 5 {
el17sm 27:a1b41626f57c 6 for (int i = 0; i < MAX_ENEMIES; i++)
el17sm 27:a1b41626f57c 7 {
el17sm 27:a1b41626f57c 8 valid_enemies[i] = false;
el17sm 27:a1b41626f57c 9 }
el17sm 26:abbc19edc5c1 10 enemies[0] = new Headless(20, 20);
el17sm 26:abbc19edc5c1 11 valid_enemies[0] = true;
el17sm 27:a1b41626f57c 12 enemies[1] = new Snake(20, 30);
el17sm 27:a1b41626f57c 13 valid_enemies[1] = true;
el17sm 27:a1b41626f57c 14 enemies[2] = new Snake(60, 30);
el17sm 27:a1b41626f57c 15 valid_enemies[2] = true;
el17sm 27:a1b41626f57c 16 _type = 0;
el17sm 27:a1b41626f57c 17 for (int layer = 0; layer < 3; layer++) {
el17sm 27:a1b41626f57c 18 for (int i = 0; i < screen_width; i++) {
el17sm 27:a1b41626f57c 19 for (int j = 0; j < screen_height; j++) {
el17sm 27:a1b41626f57c 20 _current_map[layer][j][i] = level_map[_type][layer][j][i];
el17sm 27:a1b41626f57c 21 }
el17sm 27:a1b41626f57c 22 }
el17sm 27:a1b41626f57c 23 }
el17sm 27:a1b41626f57c 24 for(int n = 0; n < 4; n++){
el17sm 27:a1b41626f57c 25 _doorways[n] = true;
el17sm 27:a1b41626f57c 26 };
el17sm 27:a1b41626f57c 27 }
el17sm 27:a1b41626f57c 28
el17sm 27:a1b41626f57c 29 Room::~Room()
el17sm 27:a1b41626f57c 30 {
el17sm 27:a1b41626f57c 31 for (int i = 0; i < MAX_ENEMIES; i++) {
el17sm 27:a1b41626f57c 32 if (valid_enemies[i]) {
el17sm 27:a1b41626f57c 33 delete enemies[i];
el17sm 27:a1b41626f57c 34 }
el17sm 27:a1b41626f57c 35 };
el17sm 27:a1b41626f57c 36 }
el17sm 27:a1b41626f57c 37
el17sm 27:a1b41626f57c 38 // Accessors
el17sm 27:a1b41626f57c 39 int * Room::get_current_map_2d(){
el17sm 27:a1b41626f57c 40 return ((int *) _current_map[0]);
el17sm 26:abbc19edc5c1 41 }
el17sm 26:abbc19edc5c1 42
el17sm 26:abbc19edc5c1 43 // Functions
el17sm 26:abbc19edc5c1 44 void Room::init()
el17sm 26:abbc19edc5c1 45 {
el17sm 27:a1b41626f57c 46 if(_doorways[0]){ // N
el17sm 27:a1b41626f57c 47 overlap(36, 0, 12, 10, (int *)wall_n[0], (int *)_current_map[0]);
el17sm 27:a1b41626f57c 48 overlap(36, 0, 12, 10, (int *)wall_n[1], (int *)_current_map[1]);
el17sm 27:a1b41626f57c 49 }
el17sm 27:a1b41626f57c 50 if(_doorways[1]){ // E
el17sm 27:a1b41626f57c 51 overlap(81, 22, 3, 11, (int *)wall_x[0], (int *)_current_map[0]);
el17sm 27:a1b41626f57c 52 overlap(81, 22, 3, 11, (int *)wall_x[0], (int *)_current_map[1]);
el17sm 27:a1b41626f57c 53 }
el17sm 27:a1b41626f57c 54 if(_doorways[2]){ // S
el17sm 27:a1b41626f57c 55 overlap(36, 45, 12, 3, (int *)wall_s[0], (int *)_current_map[0]);
el17sm 27:a1b41626f57c 56 overlap(36, 45, 12, 3, (int *)wall_s[1], (int *)_current_map[1]);
el17sm 27:a1b41626f57c 57 }
el17sm 27:a1b41626f57c 58 if(_doorways[3]){ // W
el17sm 27:a1b41626f57c 59 overlap(0, 22, 3, 11, (int *)wall_x[1], (int *)_current_map[0]);
el17sm 27:a1b41626f57c 60 overlap(0, 22, 3, 11, (int *)wall_x[1], (int *)_current_map[1]);
el17sm 27:a1b41626f57c 61 }
el17sm 26:abbc19edc5c1 62 }
el17sm 26:abbc19edc5c1 63
el17sm 27:a1b41626f57c 64 void Room::draw_room(N5110 &lcd)
el17sm 26:abbc19edc5c1 65 {
el17sm 27:a1b41626f57c 66 lcd.drawSprite(0, 0, screen_height, screen_width, (int *)_current_map[1]); // drawing 3d map
el17sm 26:abbc19edc5c1 67 }
el17sm 26:abbc19edc5c1 68
el17sm 27:a1b41626f57c 69 void Room::draw_room_overlay(N5110 &lcd)
el17sm 27:a1b41626f57c 70 {
el17sm 27:a1b41626f57c 71 lcd.drawSprite(0, 0, screen_height, screen_width, (int *)_current_map[2]);
el17sm 27:a1b41626f57c 72 }
el17sm 27:a1b41626f57c 73
el17sm 27:a1b41626f57c 74 void Room::overlap(int x, int y, int width, int height, int * object, int * map)
el17sm 27:a1b41626f57c 75 {
el17sm 27:a1b41626f57c 76 for(int i = 0; i < width; i++) {
el17sm 27:a1b41626f57c 77 for (int j = 0; j < height; j++) {
el17sm 27:a1b41626f57c 78 *((map+(y+j)*screen_width)+(x+i)) = *((object+j*width)+i);
el17sm 27:a1b41626f57c 79 }
el17sm 27:a1b41626f57c 80 }
el17sm 27:a1b41626f57c 81 }