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:
- 29:6b8411bb040a
- Parent:
- 28:98848e6a77a2
--- a/Room/Room.cpp Thu May 02 21:30:49 2019 +0000
+++ b/Room/Room.cpp Sat May 04 15:39:20 2019 +0000
@@ -3,27 +3,24 @@
// Constructor
Room::Room(int no_of_enemies)
{
- for (int i = 0; i < MAX_ENEMIES; i++)
+ for (int id = 0; id < MAX_ENEMIES; id++)
{
- valid_enemies[i] = i < no_of_enemies;
- if (i < no_of_enemies) {
- enemies_type[i] = rand() % 2;
+ valid_enemies[id] = id < no_of_enemies;
+ if (id < no_of_enemies) {
+ enemies_type[id] = rand() % 2;
+ _enemy_coord[id][0] = 11 + (rand() % 60);
+ _enemy_coord[id][1] = 18 + (rand() % 19);
}
}
+
_room_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[_room_type][layer][j][i];
- }
- }
- }
_doorways[0] = true;
_doorways[1] = true;
_doorways[2] = true;
_doorways[3] = true;
}
+// Deconstructor
Room::~Room()
{
terminate();
@@ -31,27 +28,31 @@
// Accessors
int * Room::get_current_map_2d(){
- return ((int *) _current_map[0]);
+ return ((int *)level_map[_room_type][0]);
+}
+
+bool * Room::get_doorways(){
+ return (bool *)_doorways;
}
// Functions
void Room::load()
{
- for (int i = 0; i<4; i++) {
- if (!_doorways[i]){
- overlap_wall(i); // Drawing walls on current map
- }
- }
- for (int i = 0; i < MAX_ENEMIES; i++) {
- if (valid_enemies[i]) {
- switch(enemies_type[i]){
+ for (int id = 0; id < MAX_ENEMIES; id++) {
+ if (valid_enemies[id]) {
+ switch(enemies_type[id]){
case 0 :
- enemies[i] = new Headless(20, 20);
+ enemies[id] = new Headless(_enemy_coord[id][0], _enemy_coord[id][1]);
break;
case 1 :
- enemies[i] = new Snake(20, 30);
+ enemies[id] = new Snake(_enemy_coord[id][0], _enemy_coord[id][1]);
break;
}
+// for every enemy
+// if (collision) {
+// relocate enemy
+// goto back
+// }
}
}
}
@@ -67,45 +68,45 @@
void Room::draw_room(N5110 &lcd)
{
- lcd.drawSprite(0, 0, screen_height, screen_width, (int *)_current_map[1]); // drawing 3d map
+ lcd.drawSprite(0, 0, screen_height, screen_width, (int *)level_map[_room_type][1]); // drawing 3d map
+ //draw_walls(lcd);
+
+}
+
+void Room::draw_walls(N5110 &lcd)
+{
+ if(_doorways[0]) { // N
+ lcd.drawSprite(36, 0, 12, 10, (int *)wall_n);
+ }
+ if(_doorways[1]) { // E
+ lcd.drawSprite(81, 15, 3, 11, (int *)wall_x[0]);
+ }
+ if(_doorways[2]) { // S
+ lcd.drawSprite(36, 45, 12, 3, (int *)wall_s);
+ }
+ if(_doorways[3]) { // W
+ lcd.drawSprite(0, 15, 3, 11, (int *)wall_x[1]);
+ }
}
void Room::draw_room_overlay(N5110 &lcd)
{
- lcd.drawSpriteTransparent(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);
- }
- }
+ lcd.drawSpriteTransparent(0, 0, screen_height, screen_width, (int *)level_map[_room_type][2]); // drawing 3d map overlay
+ //draw_walls_overlay(lcd);
}
-void Room::overlap_wall(int side)
+void Room::draw_walls_overlay(N5110 &lcd)
{
- switch(side) {
- case 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]);
- overlap(36, 0, 12, 10, (int *)wall_n[1], (int *)_current_map[2]);
- break;
- case 1 : // E
- overlap(81, 22, 3, 11, (int *)wall_x[0], (int *)_current_map[0]);
- overlap(81, 15, 3, 11, (int *)wall_x[0], (int *)_current_map[1]);
- overlap(81, 15, 3, 11, (int *)wall_x[0], (int *)_current_map[2]);
- break;
- case 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]);
- overlap(36, 45, 12, 3, (int *)wall_s[1], (int *)_current_map[2]);
- break;
- case 4 : // W
- overlap(0, 22, 3, 11, (int *)wall_x[1], (int *)_current_map[0]);
- overlap(0, 15, 3, 11, (int *)wall_x[1], (int *)_current_map[1]);
- overlap(0, 15, 3, 11, (int *)wall_x[1], (int *)_current_map[2]);
- break;
+ if(_doorways[0]) { // N
+ lcd.drawSpriteTransparent(36, 0, 12, 10, (int *)wall_n);
+ }
+ if(_doorways[1]) { // E
+ lcd.drawSpriteTransparent(81, 15, 3, 11, (int *)wall_x[0]);
+ }
+ if(_doorways[2]) { // S
+ lcd.drawSpriteTransparent(36, 45, 12, 3, (int *)wall_s);
+ }
+ if(_doorways[3]) { // W
+ lcd.drawSpriteTransparent(0, 15, 3, 11, (int *)wall_x[1]);
}
}
\ No newline at end of file