diff --git a/assets/devices.json b/assets/devices.json index aa01b7d..4356d7c 100644 --- a/assets/devices.json +++ b/assets/devices.json @@ -2,10 +2,12 @@ "STAIRS_DOWN": { "id": "STAIRS_DOWN", "name": "Stairs Down", + "placement": "fixed", "foreground": [24, 205, 189], "background": [24, 205, 189], "description": "Stairs that go down further into the dungeon.", "inventory_count": 0, + "randomized": false, "components": [ {"type": "Tile", "config": {"chr": "\u2ac5"}}, {"type": "Device", @@ -20,11 +22,26 @@ "background": [24, 205, 189], "description": "Stairs that go up, for the weak.", "inventory_count": 0, + "placement": "fixed", "components": [ {"type": "Tile", "config": {"chr": "\u2259"}}, {"type": "Device", "config": {"test": true}, "events": ["Events::GUI::STAIRS_UP"] } ] + }, + "SPIKE_TRAP": { + "id": "SPIKE_TRAP", + "name": "Spike trap", + "foreground": [24, 205, 189], + "background": [24, 205, 189], + "description": "Spikes stab you from the floor.", + "inventory_count": 0, + "components": [ + {"type": "Tile", "config": {"chr": "\u1ac7"}}, + {"type": "Device", + "config": {"test": true}, "events": ["Events::GUI::TRAP"] + } + ] } } diff --git a/constants.hpp b/constants.hpp index ed8710e..6878497 100644 --- a/constants.hpp +++ b/constants.hpp @@ -27,8 +27,6 @@ constexpr wchar_t UI_BASE_CHAR = L'█'; constexpr int BG_BOX_OFFSET=5; // NOTE: max seems to be about x=240, y=120 -constexpr int GAME_MAP_X=80; -constexpr int GAME_MAP_Y=40; constexpr int INVENTORY_PIXEL_X=50; constexpr int INVENTORY_PIXEL_Y=50; constexpr int INVENTORY_WIDTH=99; diff --git a/devices.cpp b/devices.cpp index 796781e..1969c20 100644 --- a/devices.cpp +++ b/devices.cpp @@ -14,6 +14,8 @@ namespace components { events.push_back(Events::GUI::STAIRS_DOWN); } else if(name == "Events::GUI::STAIRS_UP") { events.push_back(Events::GUI::STAIRS_UP); + } else if(name == "Events::GUI::TRAP") { + events.push_back(Events::GUI::TRAP); } else { dbc::sentinel(fmt::format("Unknown device event {}", name)); } diff --git a/events.hpp b/events.hpp index f15dfff..38f0d5e 100644 --- a/events.hpp +++ b/events.hpp @@ -2,7 +2,7 @@ namespace Events { enum GUI { - START, COMBAT, LOOT, DEATH, STAIRS_UP, STAIRS_DOWN + START, COMBAT, LOOT, DEATH, STAIRS_UP, STAIRS_DOWN, TRAP }; struct Combat { diff --git a/gui.cpp b/gui.cpp index a38ca33..d4aa9bb 100644 --- a/gui.cpp +++ b/gui.cpp @@ -297,6 +297,9 @@ void GUI::handle_world_events() { (bool)device.config["test"])); // toggle_modal(&$next_level_ui, $next_level); } break; + case eGUI::TRAP: { + $status_ui.log("You stepped on a TRAP!"); + } break; default: $status_ui.log(format("INVALID EVENT! {},{}", evt, entity)); } diff --git a/levelmanager.cpp b/levelmanager.cpp index 8441298..9cff359 100644 --- a/levelmanager.cpp +++ b/levelmanager.cpp @@ -13,6 +13,13 @@ LevelManager::LevelManager() { create_level(); } +LevelScaling LevelManager::scale_level() { + return { + 30 + (5 * int($current_level)), + 20 + (5 * int($current_level)) + }; +} + size_t LevelManager::create_level(shared_ptr prev_world) { auto world = make_shared(); @@ -22,7 +29,9 @@ size_t LevelManager::create_level(shared_ptr prev_world) { save::load_configs(*world); } - auto map = make_shared(GAME_MAP_X, GAME_MAP_Y); + auto scaling = scale_level(); + + auto map = make_shared(scaling.map_width, scaling.map_height); WorldBuilder builder(*map); builder.generate(*world); diff --git a/levelmanager.hpp b/levelmanager.hpp index 365acbd..c8bf0f6 100644 --- a/levelmanager.hpp +++ b/levelmanager.hpp @@ -17,6 +17,11 @@ struct GameLevel { shared_ptr collision; }; +struct LevelScaling { + int map_width=40; + int map_height=50; +}; + class LevelManager { public: std::vector $levels; @@ -30,4 +35,5 @@ class LevelManager { GameLevel ¤t(); size_t current_index() { return $current_level; } GameLevel &get(size_t index); + LevelScaling scale_level(); }; diff --git a/point.hpp b/point.hpp index 684cf50..50e57cd 100644 --- a/point.hpp +++ b/point.hpp @@ -15,7 +15,7 @@ struct Point { typedef std::vector PointList; -struct PointHash { +template<> struct std::hash { size_t operator()(const Point& p) const { return std::hash()(p.x) ^ std::hash()(p.y); } diff --git a/render.hpp b/render.hpp index d66d0d4..acb2b2f 100644 --- a/render.hpp +++ b/render.hpp @@ -25,8 +25,6 @@ struct RenderConfig { wchar_t bg_tile = BG_TILE; wchar_t ui_base_char = UI_BASE_CHAR; int bg_box_offset=BG_BOX_OFFSET; - int game_map_x=GAME_MAP_X; - int game_map_y=GAME_MAP_Y; }; struct SFMLRender { diff --git a/spatialmap.hpp b/spatialmap.hpp index 44da144..97a6266 100644 --- a/spatialmap.hpp +++ b/spatialmap.hpp @@ -7,7 +7,8 @@ typedef std::vector EntityList; -typedef std::unordered_map PointEntityMap; +// Point's has is in point.hpp +typedef std::unordered_map PointEntityMap; struct FoundEntities { bool found; diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 5cccc79..ab31cd5 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -216,8 +216,12 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config json& entity_db = select_entity_type(config, gen_config); std::vector keys; - for(auto &el : entity_db.items()) { - keys.push_back(el.key()); + for(auto& el : entity_db.items()) { + auto& data = el.value(); + + if(data["placement"] == nullptr) { + keys.push_back(el.key()); + } } int rand_entity = Random::uniform(0, keys.size() - 1); @@ -230,6 +234,14 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config } } +inline void place_stairs(DinkyECS::World& world, GameConfig& config, Map& map) { + auto& device_config = config.devices.json(); + auto entity_data = device_config["STAIRS_DOWN"]; + int last_room = map.room_count() - 1; + auto entity = configure_entity_in_map(world, map, entity_data, last_room); + check_player(world, entity); +} + void WorldBuilder::place_entities(DinkyECS::World &world) { auto &config = world.get_the(); // configure a player as a fact of the world @@ -251,6 +263,7 @@ void WorldBuilder::place_entities(DinkyECS::World &world) { } randomize_entities(world, config); + place_stairs(world, config, $map); } void WorldBuilder::generate(DinkyECS::World &world) {