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.
This commit is contained in:
parent
2825faf038
commit
58fae858ff
2 changed files with 21 additions and 2 deletions
|
@ -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);
|
auto map = make_shared<Map>(GAME_MAP_X, GAME_MAP_Y);
|
||||||
|
|
||||||
if(prev_world != nullptr) {
|
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);
|
world->set_the<Player>(player);
|
||||||
|
|
||||||
auto inventory = prev_world->get<Inventory>(player.entity);
|
auto inventory = prev_world->get<Inventory>(player.entity);
|
||||||
world->set<Inventory>(player.entity, inventory);
|
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>());
|
world->set_the<Debug>(prev_world->get_the<Debug>());
|
||||||
auto& combat = prev_world->get<Combat>(player.entity);
|
auto& combat = prev_world->get<Combat>(player.entity);
|
||||||
world->set<Combat>(player.entity, combat);
|
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);
|
world->set<Motion>(player.entity, motion);
|
||||||
|
|
||||||
auto& tile = prev_world->get<Tile>(player.entity);
|
auto& tile = prev_world->get<Tile>(player.entity);
|
||||||
|
|
||||||
|
fmt::println("player tile is: {}", tile.chr);
|
||||||
world->set<Tile>(player.entity, tile);
|
world->set<Tile>(player.entity, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,13 @@
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
using namespace components;
|
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) {
|
inline int make_split(Room &cur, bool horiz) {
|
||||||
size_t dimension = horiz ? cur.height : cur.width;
|
size_t dimension = horiz ? cur.height : cur.width;
|
||||||
int min = dimension / WORLDBUILD_DIVISION;
|
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);
|
int rand_entity = Random::uniform<int>(0, keys.size() - 1);
|
||||||
std::string key = keys[rand_entity];
|
std::string key = keys[rand_entity];
|
||||||
auto entity_data = entity_db[key];
|
auto entity_data = entity_db[key];
|
||||||
|
check_player(world);
|
||||||
|
|
||||||
// pass that to the config as it'll be a generic json
|
// pass that to the config as it'll be a generic json
|
||||||
auto entity = configure_entity_in_map(world, $map, entity_data, room_num);
|
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>()) {
|
if(world.has_the<Player>()) {
|
||||||
fmt::println("PLAYER ALREADY EXISTS LEAVING ALONE");
|
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 {
|
} else {
|
||||||
auto player_data = config.enemies["PLAYER_TILE"];
|
auto player_data = config.enemies["PLAYER_TILE"];
|
||||||
auto player_ent = configure_entity_in_map(world, $map, player_data, 0);
|
auto player_ent = configure_entity_in_map(world, $map, player_data, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue