Introduced base structure for doors in maps
This commit is contained in:
parent
3e43c30bcb
commit
7fbeaa3907
24
src/map.c
24
src/map.c
|
@ -35,12 +35,13 @@ create_room(void)
|
|||
|
||||
room = ec_malloc(sizeof(Room));
|
||||
room->modifier.type = RMOD_TYPE_NONE;
|
||||
room->visited = false;
|
||||
for (i=0; i < MAP_ROOM_WIDTH; ++i) {
|
||||
for (j=0; j < MAP_ROOM_HEIGHT; ++j) {
|
||||
room->tiles[i][j] = NULL;
|
||||
room->decorations[i][j] = NULL;
|
||||
room->traps[i][j] = NULL;
|
||||
room->visited = false;
|
||||
room->doors[i][j] = NULL;
|
||||
}
|
||||
}
|
||||
return room;
|
||||
|
@ -134,6 +135,26 @@ void map_add_decoration(Map *map, Position *tile_pos, MapTile *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
|
||||
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) {
|
||||
map_tile_render(room->tiles[i][j], cam);
|
||||
map_tile_render(room->decorations[i][j], cam);
|
||||
map_tile_render(room->doors[i][j], cam);
|
||||
|
||||
if (room->traps[i][j])
|
||||
trap_render(room->traps[i][j], cam);
|
||||
|
|
|
@ -47,6 +47,7 @@ typedef struct MapTile_t {
|
|||
typedef struct Room_t {
|
||||
MapTile* tiles[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];
|
||||
RoomModifierData modifier;
|
||||
bool visited;
|
||||
|
@ -79,6 +80,9 @@ map_add_tile(Map *map, Position *tile_pos, MapTile*);
|
|||
void
|
||||
map_add_decoration(Map *map, Position *tile_pos, MapTile*);
|
||||
|
||||
void
|
||||
map_add_door(Map *map, Position *tile_pos, MapTile*);
|
||||
|
||||
void
|
||||
map_add_trap(Map*, Position*, Trap*);
|
||||
|
||||
|
|
Loading…
Reference in New Issue