From 7fbeaa390773976e7904b89d5819c928ad1859a5 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 10 Mar 2019 19:33:47 +0100 Subject: [PATCH] Introduced base structure for doors in maps --- src/map.c | 24 +++++++++++++++++++++++- src/map.h | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/map.c b/src/map.c index ae5e9ca..66c112a 100644 --- a/src/map.c +++ b/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); diff --git a/src/map.h b/src/map.h index 3ef2957..6bd3638 100644 --- a/src/map.h +++ b/src/map.h @@ -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*);