Introduced base structure for doors in maps

This commit is contained in:
Linus Probert 2019-03-10 19:33:47 +01:00
parent 3e43c30bcb
commit 7fbeaa3907
2 changed files with 27 additions and 1 deletions

View File

@ -35,12 +35,13 @@ create_room(void)
room = ec_malloc(sizeof(Room)); room = ec_malloc(sizeof(Room));
room->modifier.type = RMOD_TYPE_NONE; room->modifier.type = RMOD_TYPE_NONE;
room->visited = false;
for (i=0; i < MAP_ROOM_WIDTH; ++i) { for (i=0; i < MAP_ROOM_WIDTH; ++i) {
for (j=0; j < MAP_ROOM_HEIGHT; ++j) { for (j=0; j < MAP_ROOM_HEIGHT; ++j) {
room->tiles[i][j] = NULL; room->tiles[i][j] = NULL;
room->decorations[i][j] = NULL; room->decorations[i][j] = NULL;
room->traps[i][j] = NULL; room->traps[i][j] = NULL;
room->visited = false; room->doors[i][j] = NULL;
} }
} }
return room; return room;
@ -134,6 +135,26 @@ void map_add_decoration(Map *map, Position *tile_pos, MapTile *tile)
*oldTile = tile; *oldTile = tile;
} }
void
map_add_door(Map *map, Position *tile_pos, MapTile *tile)
{
const Position *cr = &map->currentRoom;
MapTile **oldTile = &map->rooms[cr->x][cr->y]->doors[tile_pos->x][tile_pos->y];
// Set the decoration sprites position to match tile pos
tile->sprite->pos = POS(tile_pos->x * TILE_DIMENSION + (map->currentRoom.x * GAME_VIEW_WIDTH),
tile_pos->y * TILE_DIMENSION + (map->currentRoom.y * GAME_VIEW_HEIGHT));
if (*oldTile != NULL) {
map_tile_destroy(*oldTile);
*oldTile = NULL;
}
tile->sprite->animate = false;
*oldTile = tile;
}
void void
map_add_trap(Map *map, Position *pos, Trap *trap) map_add_trap(Map *map, Position *pos, Trap *trap)
{ {
@ -313,6 +334,7 @@ void map_render(Map *map, Camera *cam)
for (j=0; j < MAP_ROOM_HEIGHT; ++j) { for (j=0; j < MAP_ROOM_HEIGHT; ++j) {
map_tile_render(room->tiles[i][j], cam); map_tile_render(room->tiles[i][j], cam);
map_tile_render(room->decorations[i][j], cam); map_tile_render(room->decorations[i][j], cam);
map_tile_render(room->doors[i][j], cam);
if (room->traps[i][j]) if (room->traps[i][j])
trap_render(room->traps[i][j], cam); trap_render(room->traps[i][j], cam);

View File

@ -47,6 +47,7 @@ typedef struct MapTile_t {
typedef struct Room_t { typedef struct Room_t {
MapTile* tiles[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; MapTile* tiles[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
MapTile* decorations[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; MapTile* decorations[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
MapTile* doors[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
Trap* traps[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; Trap* traps[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
RoomModifierData modifier; RoomModifierData modifier;
bool visited; bool visited;
@ -79,6 +80,9 @@ map_add_tile(Map *map, Position *tile_pos, MapTile*);
void void
map_add_decoration(Map *map, Position *tile_pos, MapTile*); map_add_decoration(Map *map, Position *tile_pos, MapTile*);
void
map_add_door(Map *map, Position *tile_pos, MapTile*);
void void
map_add_trap(Map*, Position*, Trap*); map_add_trap(Map*, Position*, Trap*);