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
Room/Room.cpp
- Committer:
- el17sm
- Date:
- 2019-05-04
- Revision:
- 29:6b8411bb040a
- Parent:
- 28:98848e6a77a2
File content as of revision 29:6b8411bb040a:
#include "Room.h"
// Constructor
Room::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] = 11 + (rand() % 60);
_enemy_coord[id][1] = 18 + (rand() % 19);
}
}
_room_type = 0;
_doorways[0] = true;
_doorways[1] = true;
_doorways[2] = true;
_doorways[3] = true;
}
// Deconstructor
Room::~Room()
{
terminate();
}
// Accessors
int * Room::get_current_map_2d(){
return ((int *)level_map[_room_type][0]);
}
bool * Room::get_doorways(){
return (bool *)_doorways;
}
// Functions
void Room::load()
{
for (int id = 0; id < MAX_ENEMIES; id++) {
if (valid_enemies[id]) {
switch(enemies_type[id]){
case 0 :
enemies[id] = new Headless(_enemy_coord[id][0], _enemy_coord[id][1]);
break;
case 1 :
enemies[id] = new Snake(_enemy_coord[id][0], _enemy_coord[id][1]);
break;
}
// for every enemy
// if (collision) {
// relocate enemy
// goto back
// }
}
}
}
void Room::unload()
{
for (int i = 0; i < MAX_ENEMIES; i++) {
if (valid_enemies[i]) {
delete enemies[i];
}
};
}
void Room::draw_room(N5110 &lcd)
{
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 *)level_map[_room_type][2]); // drawing 3d map overlay
//draw_walls_overlay(lcd);
}
void Room::draw_walls_overlay(N5110 &lcd)
{
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]);
}
}