Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Thu May 02 21:30:49 2019 +0000
Revision:
28:98848e6a77a2
Parent:
27:a1b41626f57c
Child:
29:6b8411bb040a
Entrance and Exit done

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 28:98848e6a77a2 4 Room::Room(int no_of_enemies)
el17sm 26:abbc19edc5c1 5 {
el17sm 27:a1b41626f57c 6 for (int i = 0; i < MAX_ENEMIES; i++)
el17sm 27:a1b41626f57c 7 {
el17sm 28:98848e6a77a2 8 valid_enemies[i] = i < no_of_enemies;
el17sm 28:98848e6a77a2 9 if (i < no_of_enemies) {
el17sm 28:98848e6a77a2 10 enemies_type[i] = rand() % 2;
el17sm 28:98848e6a77a2 11 }
el17sm 27:a1b41626f57c 12 }
el17sm 28:98848e6a77a2 13 _room_type = 0;
el17sm 27:a1b41626f57c 14 for (int layer = 0; layer < 3; layer++) {
el17sm 27:a1b41626f57c 15 for (int i = 0; i < screen_width; i++) {
el17sm 27:a1b41626f57c 16 for (int j = 0; j < screen_height; j++) {
el17sm 28:98848e6a77a2 17 _current_map[layer][j][i] = level_map[_room_type][layer][j][i];
el17sm 27:a1b41626f57c 18 }
el17sm 27:a1b41626f57c 19 }
el17sm 27:a1b41626f57c 20 }
el17sm 28:98848e6a77a2 21 _doorways[0] = true;
el17sm 28:98848e6a77a2 22 _doorways[1] = true;
el17sm 28:98848e6a77a2 23 _doorways[2] = true;
el17sm 28:98848e6a77a2 24 _doorways[3] = true;
el17sm 27:a1b41626f57c 25 }
el17sm 27:a1b41626f57c 26
el17sm 27:a1b41626f57c 27 Room::~Room()
el17sm 27:a1b41626f57c 28 {
el17sm 28:98848e6a77a2 29 terminate();
el17sm 27:a1b41626f57c 30 }
el17sm 27:a1b41626f57c 31
el17sm 27:a1b41626f57c 32 // Accessors
el17sm 27:a1b41626f57c 33 int * Room::get_current_map_2d(){
el17sm 27:a1b41626f57c 34 return ((int *) _current_map[0]);
el17sm 26:abbc19edc5c1 35 }
el17sm 26:abbc19edc5c1 36
el17sm 26:abbc19edc5c1 37 // Functions
el17sm 28:98848e6a77a2 38 void Room::load()
el17sm 26:abbc19edc5c1 39 {
el17sm 28:98848e6a77a2 40 for (int i = 0; i<4; i++) {
el17sm 28:98848e6a77a2 41 if (!_doorways[i]){
el17sm 28:98848e6a77a2 42 overlap_wall(i); // Drawing walls on current map
el17sm 28:98848e6a77a2 43 }
el17sm 27:a1b41626f57c 44 }
el17sm 28:98848e6a77a2 45 for (int i = 0; i < MAX_ENEMIES; i++) {
el17sm 28:98848e6a77a2 46 if (valid_enemies[i]) {
el17sm 28:98848e6a77a2 47 switch(enemies_type[i]){
el17sm 28:98848e6a77a2 48 case 0 :
el17sm 28:98848e6a77a2 49 enemies[i] = new Headless(20, 20);
el17sm 28:98848e6a77a2 50 break;
el17sm 28:98848e6a77a2 51 case 1 :
el17sm 28:98848e6a77a2 52 enemies[i] = new Snake(20, 30);
el17sm 28:98848e6a77a2 53 break;
el17sm 28:98848e6a77a2 54 }
el17sm 28:98848e6a77a2 55 }
el17sm 27:a1b41626f57c 56 }
el17sm 28:98848e6a77a2 57 }
el17sm 28:98848e6a77a2 58
el17sm 28:98848e6a77a2 59 void Room::unload()
el17sm 28:98848e6a77a2 60 {
el17sm 28:98848e6a77a2 61 for (int i = 0; i < MAX_ENEMIES; i++) {
el17sm 28:98848e6a77a2 62 if (valid_enemies[i]) {
el17sm 28:98848e6a77a2 63 delete enemies[i];
el17sm 28:98848e6a77a2 64 }
el17sm 28:98848e6a77a2 65 };
el17sm 26:abbc19edc5c1 66 }
el17sm 26:abbc19edc5c1 67
el17sm 27:a1b41626f57c 68 void Room::draw_room(N5110 &lcd)
el17sm 26:abbc19edc5c1 69 {
el17sm 27:a1b41626f57c 70 lcd.drawSprite(0, 0, screen_height, screen_width, (int *)_current_map[1]); // drawing 3d map
el17sm 26:abbc19edc5c1 71 }
el17sm 26:abbc19edc5c1 72
el17sm 27:a1b41626f57c 73 void Room::draw_room_overlay(N5110 &lcd)
el17sm 27:a1b41626f57c 74 {
el17sm 28:98848e6a77a2 75 lcd.drawSpriteTransparent(0, 0, screen_height, screen_width, (int *)_current_map[2]);
el17sm 27:a1b41626f57c 76 }
el17sm 27:a1b41626f57c 77
el17sm 27:a1b41626f57c 78 void Room::overlap(int x, int y, int width, int height, int * object, int * map)
el17sm 27:a1b41626f57c 79 {
el17sm 27:a1b41626f57c 80 for(int i = 0; i < width; i++) {
el17sm 27:a1b41626f57c 81 for (int j = 0; j < height; j++) {
el17sm 27:a1b41626f57c 82 *((map+(y+j)*screen_width)+(x+i)) = *((object+j*width)+i);
el17sm 27:a1b41626f57c 83 }
el17sm 27:a1b41626f57c 84 }
el17sm 28:98848e6a77a2 85 }
el17sm 28:98848e6a77a2 86
el17sm 28:98848e6a77a2 87 void Room::overlap_wall(int side)
el17sm 28:98848e6a77a2 88 {
el17sm 28:98848e6a77a2 89 switch(side) {
el17sm 28:98848e6a77a2 90 case 0 : // N
el17sm 28:98848e6a77a2 91 overlap(36, 0, 12, 10, (int *)wall_n[0], (int *)_current_map[0]);
el17sm 28:98848e6a77a2 92 overlap(36, 0, 12, 10, (int *)wall_n[1], (int *)_current_map[1]);
el17sm 28:98848e6a77a2 93 overlap(36, 0, 12, 10, (int *)wall_n[1], (int *)_current_map[2]);
el17sm 28:98848e6a77a2 94 break;
el17sm 28:98848e6a77a2 95 case 1 : // E
el17sm 28:98848e6a77a2 96 overlap(81, 22, 3, 11, (int *)wall_x[0], (int *)_current_map[0]);
el17sm 28:98848e6a77a2 97 overlap(81, 15, 3, 11, (int *)wall_x[0], (int *)_current_map[1]);
el17sm 28:98848e6a77a2 98 overlap(81, 15, 3, 11, (int *)wall_x[0], (int *)_current_map[2]);
el17sm 28:98848e6a77a2 99 break;
el17sm 28:98848e6a77a2 100 case 2: // S
el17sm 28:98848e6a77a2 101 overlap(36, 45, 12, 3, (int *)wall_s[0], (int *)_current_map[0]);
el17sm 28:98848e6a77a2 102 overlap(36, 45, 12, 3, (int *)wall_s[1], (int *)_current_map[1]);
el17sm 28:98848e6a77a2 103 overlap(36, 45, 12, 3, (int *)wall_s[1], (int *)_current_map[2]);
el17sm 28:98848e6a77a2 104 break;
el17sm 28:98848e6a77a2 105 case 4 : // W
el17sm 28:98848e6a77a2 106 overlap(0, 22, 3, 11, (int *)wall_x[1], (int *)_current_map[0]);
el17sm 28:98848e6a77a2 107 overlap(0, 15, 3, 11, (int *)wall_x[1], (int *)_current_map[1]);
el17sm 28:98848e6a77a2 108 overlap(0, 15, 3, 11, (int *)wall_x[1], (int *)_current_map[2]);
el17sm 28:98848e6a77a2 109 break;
el17sm 28:98848e6a77a2 110 }
el17sm 27:a1b41626f57c 111 }