diff --git a/assets/tiles.json b/assets/tiles.json index b6c7660..38bcee1 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -12,6 +12,7 @@ "texture": "assets/textures/wall_plain.png", "display": 9608, "light": 0, + "door": "door_plain", "foreground": "tiles/fg:wall_plain", "background": "tiles/bg:wall_plain", "id": 1 @@ -20,6 +21,7 @@ "texture": "assets/textures/glowing_moss_wall.png", "display": 9256, "light": 20, + "door": "door_wall_moss", "foreground": "tiles/fg:wall_moss", "background": "tiles/bg:wall_moss", "id": 2 diff --git a/src/game/worldbuilder.cpp b/src/game/worldbuilder.cpp index 5745f28..d0875f1 100644 --- a/src/game/worldbuilder.cpp +++ b/src/game/worldbuilder.cpp @@ -173,12 +173,30 @@ void WorldBuilder::place_doors(DinkyECS::World& world, GameConfig& config) { auto& device_config = config.devices.json(); auto entity_data = device_config["DOOR_PLAIN"]; auto& tiles = $map.tiles(); - - size_t door_id = textures::get_id("door_moss_wall"); + auto& walls = $map.walls(); for(auto [door_at, _] : $map.$doors) { - $map.$walls[door_at.y][door_at.x] = WALL_VALUE; - tiles[door_at.y][door_at.x] = door_id; + // note, we set this to WALL_VALUE so it renders as a wall but map.iswall will check if its a door for collision + walls[door_at.y][door_at.x] = WALL_VALUE; + + size_t moss_wall_id = textures::get_id("wall_moss"); + size_t plain_door_id = textures::get_id("door_plain"); + size_t moss_door_id = textures::get_id("door_moss_wall"); + + for(matrix::compass it{tiles, door_at.x, door_at.y}; it.next();) { + if(walls[it.y][it.x] == WALL_VALUE) { + // found a wall near the door, and since doors always have n/s/e/w walls it should be the one to use + size_t wall_id = tiles[it.y][it.x]; // this is wall to use + // change this to texture::door_for_wall(wall_id); + if(wall_id == moss_wall_id) { + tiles[door_at.y][door_at.x] = moss_door_id; + } else { + tiles[door_at.y][door_at.x] = plain_door_id; + } + + break; + } + } } }