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.

main
Zed A. Shaw 2 weeks ago
parent 2825faf038
commit 58fae858ff
  1. 8
      levelmanager.cpp
  2. 15
      worldbuilder.cpp

@ -20,12 +20,16 @@ size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
auto map = make_shared<Map>(GAME_MAP_X, GAME_MAP_Y);
if(prev_world != nullptr) {
auto player = prev_world->get_the<Player>();
auto& player = prev_world->get_the<Player>();
player.entity = world->entity();
world->set_the<Player>(player);
auto inventory = prev_world->get<Inventory>(player.entity);
world->set<Inventory>(player.entity, inventory);
auto light = prev_world->get<LightSource>(player.entity);
world->set<LightSource>(player.entity, light);
world->set_the<Debug>(prev_world->get_the<Debug>());
auto& combat = prev_world->get<Combat>(player.entity);
world->set<Combat>(player.entity, combat);
@ -34,6 +38,8 @@ size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
world->set<Motion>(player.entity, motion);
auto& tile = prev_world->get<Tile>(player.entity);
fmt::println("player tile is: {}", tile.chr);
world->set<Tile>(player.entity, tile);
}

@ -7,6 +7,13 @@
using namespace fmt;
using namespace components;
inline void check_player(DinkyECS::World &world) {
auto player = world.get_the<Player>();
fmt::println("PLAYER ENTITY: {}", player.entity);
auto tile = world.get<Tile>(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<int>(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<Player>()) {
fmt::println("PLAYER ALREADY EXISTS LEAVING ALONE");
auto& player = world.get_the<Player>();
Point pos_out;
bool placed = $map.place_entity(0, pos_out);
dbc::check(placed, "failed to randomly place item in room");
world.set<Position>(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);

Loading…
Cancel
Save