From 58fae858ff58b20d2b45ca79578c2786e2cbc80a Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 25 Jan 2025 14:07:02 -0500 Subject: [PATCH] You can now go down to new levels but the whole setup isn't very good. I need to now move to having a global/master World and one for each level so I don't copy the player and other important things around on each level. --- levelmanager.cpp | 8 +++++++- worldbuilder.cpp | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/levelmanager.cpp b/levelmanager.cpp index b6d2bfa..50b4b11 100644 --- a/levelmanager.cpp +++ b/levelmanager.cpp @@ -20,12 +20,16 @@ size_t LevelManager::create_level(shared_ptr prev_world) { auto map = make_shared(GAME_MAP_X, GAME_MAP_Y); if(prev_world != nullptr) { - auto player = prev_world->get_the(); + auto& player = prev_world->get_the(); + player.entity = world->entity(); world->set_the(player); auto inventory = prev_world->get(player.entity); world->set(player.entity, inventory); + auto light = prev_world->get(player.entity); + world->set(player.entity, light); + world->set_the(prev_world->get_the()); auto& combat = prev_world->get(player.entity); world->set(player.entity, combat); @@ -34,6 +38,8 @@ size_t LevelManager::create_level(shared_ptr prev_world) { world->set(player.entity, motion); auto& tile = prev_world->get(player.entity); + + fmt::println("player tile is: {}", tile.chr); world->set(player.entity, tile); } diff --git a/worldbuilder.cpp b/worldbuilder.cpp index a9c1fb1..2b12643 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -7,6 +7,13 @@ using namespace fmt; using namespace components; +inline void check_player(DinkyECS::World &world) { + auto player = world.get_the(); + fmt::println("PLAYER ENTITY: {}", player.entity); + auto tile = world.get(player.entity); + dbc::check(tile.chr == "\ua66b", format("PLAYER TILE CHANGED {} != {}", tile.chr, "\ua66b")); +} + inline int make_split(Room &cur, bool horiz) { size_t dimension = horiz ? cur.height : cur.width; int min = dimension / WORLDBUILD_DIVISION; @@ -215,10 +222,11 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config int rand_entity = Random::uniform(0, keys.size() - 1); std::string key = keys[rand_entity]; auto entity_data = entity_db[key]; + check_player(world); // pass that to the config as it'll be a generic json auto entity = configure_entity_in_map(world, $map, entity_data, room_num); - (void)entity; + fmt::println("ENTITY: {}", entity); } } @@ -228,6 +236,11 @@ void WorldBuilder::place_entities(DinkyECS::World &world) { if(world.has_the()) { fmt::println("PLAYER ALREADY EXISTS LEAVING ALONE"); + auto& player = world.get_the(); + Point pos_out; + bool placed = $map.place_entity(0, pos_out); + dbc::check(placed, "failed to randomly place item in room"); + world.set(player.entity, {pos_out.x+1, pos_out.y+1}); } else { auto player_data = config.enemies["PLAYER_TILE"]; auto player_ent = configure_entity_in_map(world, $map, player_data, 0);