diff --git a/assets/config.json b/assets/config.json index 9356487..df06df3 100644 --- a/assets/config.json +++ b/assets/config.json @@ -231,6 +231,11 @@ "frame_width": 256, "frame_height": 256 }, + "door_plain": + {"path": "assets/sprites/door_plain.png", + "frame_width": 256, + "frame_height": 256 + }, "dead_body_lootable": {"path": "assets/sprites/dead_body_lootable.png", "frame_width": 256, diff --git a/assets/map_tiles.json b/assets/map_tiles.json index a0e2623..af61b68 100644 --- a/assets/map_tiles.json +++ b/assets/map_tiles.json @@ -136,5 +136,11 @@ "display": 1218, "x": 128, "y": 128 + }, + { + "centered": true, + "display": 1087, + "x": 128, + "y": 128 } ] diff --git a/assets/textures/door_plain.png b/assets/textures/door_plain.png new file mode 100644 index 0000000..62a717b Binary files /dev/null and b/assets/textures/door_plain.png differ diff --git a/assets/tiles.json b/assets/tiles.json index c45d559..5a443c4 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -65,5 +65,13 @@ "foreground": "color:BAD", "background": "color:BAD", "id": 8 + }, + "door_plain": { + "texture": "assets/textures/door_plain.png", + "display": 1087, + "light": 0, + "foreground": "tiles/fg:wall_plain", + "background": "tiles/bg:wall_plain", + "id": 9 } } diff --git a/src/algos/maze.hpp b/src/algos/maze.hpp index d8c17d3..39bc41f 100644 --- a/src/algos/maze.hpp +++ b/src/algos/maze.hpp @@ -11,16 +11,16 @@ namespace maze { size_t $height = 0; Matrix& $walls; std::vector& $rooms; + std::unordered_map& $doors; std::vector& $dead_ends; std::unordered_map $ends_map; Room $no_rooms_region{0,0,0,0}; // BUG: instead of bool map it to the room? - std::unordered_map $doors; Pathing $pathing; Builder(Map& map) : $width(map.$width), $height(map.$height), $walls(map.$walls), - $rooms(map.$rooms), $dead_ends(map.$dead_ends), $pathing{$width, $height} + $rooms(map.$rooms), $doors(map.$doors), $dead_ends(map.$dead_ends), $pathing{$width, $height} { dbc::check($width % 2 == 1, "map width not an ODD number (perimter dead ends bug)"); dbc::check($height % 2 == 1, "map height not an ODD number (perimter dead ends bug)"); diff --git a/src/game/map.cpp b/src/game/map.cpp index 97c500f..9970a3e 100644 --- a/src/game/map.cpp +++ b/src/game/map.cpp @@ -62,7 +62,7 @@ bool Map::place_entity(size_t room_index, Point &out) { } bool Map::iswall(size_t x, size_t y) { - return $walls[y][x] == WALL_VALUE; + return !$doors.contains({x, y}) && $walls[y][x] == WALL_VALUE; } void Map::dump(int show_x, int show_y) { @@ -71,8 +71,7 @@ void Map::dump(int show_x, int show_y) { } bool Map::can_move(Point move_to) { - return inmap(move_to.x, move_to.y) && - !iswall(move_to.x, move_to.y); + return inmap(move_to.x, move_to.y) && !iswall(move_to.x, move_to.y); } Point Map::map_to_camera(const Point &loc, const Point &cam_orig) { diff --git a/src/game/map.hpp b/src/game/map.hpp index 9428785..d988bd7 100644 --- a/src/game/map.hpp +++ b/src/game/map.hpp @@ -55,6 +55,7 @@ public: Pathing $paths; std::vector $rooms; std::vector $dead_ends; + std::unordered_map $doors; Map(size_t width, size_t height); diff --git a/src/game/worldbuilder.cpp b/src/game/worldbuilder.cpp index 2691831..e8a5cdd 100644 --- a/src/game/worldbuilder.cpp +++ b/src/game/worldbuilder.cpp @@ -163,11 +163,25 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config } for(auto& at : $map.$dead_ends) { + if($map.$doors.contains(at)) continue; auto& entity_data = random_entity_data(config, gen_config); configure_entity_in_map(world, entity_data, at); } } +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_plain"); + + 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; + } +} + void WorldBuilder::place_stairs(DinkyECS::World& world, GameConfig& config) { auto& device_config = config.devices.json(); auto entity_data = device_config["STAIRS_DOWN"]; @@ -233,6 +247,7 @@ void WorldBuilder::place_entities(DinkyECS::World &world) { dbc::check(player_pos.location.x != 0 && player_pos.location.y != 0, "failed to place the player correctly"); + place_doors(world, config); randomize_entities(world, config); place_stairs(world, config); } diff --git a/src/game/worldbuilder.hpp b/src/game/worldbuilder.hpp index 891c05a..ff767da 100644 --- a/src/game/worldbuilder.hpp +++ b/src/game/worldbuilder.hpp @@ -26,6 +26,7 @@ class WorldBuilder { void generate(DinkyECS::World &world); void randomize_entities(DinkyECS::World &world, components::GameConfig &config); void place_stairs(DinkyECS::World& world, components::GameConfig& config); + void place_doors(DinkyECS::World& world, components::GameConfig& config); void configure_starting_items(DinkyECS::World &world); void stylize_rooms(); }; diff --git a/src/graphics/raycaster.cpp b/src/graphics/raycaster.cpp index 4b1bea5..0956a09 100644 --- a/src/graphics/raycaster.cpp +++ b/src/graphics/raycaster.cpp @@ -312,6 +312,7 @@ void Raycaster::cast_rays() { int draw_end = line_height / 2 + $height / 2 + $pitch; if(draw_end >= $height) draw_end = $height - 1; + // BUG: I thought I got rid of this auto texture = textures::get_surface($tiles[map_y][map_x]); // calculate value of wall_x