diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp index 37a42c2..778cb66 100644 --- a/src/saland/GameRegion.cpp +++ b/src/saland/GameRegion.cpp @@ -289,6 +289,24 @@ static std::string RegionChooseMapTemplate(int region_x, int region_y) { return loadMap; } +void GameRegion::InitCommon() { + placeables.clear(); + physicsBox.reset(new b2World(b2Vec2(0.0f, 0.0f))); + world.managed_bodies.clear(); + + liqudHandler["water"].blockingLayer = world.blockingLayer; + liqudHandler["water"].blockingLayer_overlay_1 = world.blockingLayer_overlay_1; + liqudHandler["water"].setupTiles(16); + liqudHandler["lava"].blockingLayer = world.blockingLayer; + liqudHandler["lava"].blockingLayer_overlay_1 = world.blockingLayer_overlay_1; + liqudHandler["lava"].setupTiles(16); + +} + +void GameRegion::InitDungeon(const std::string& dungeonName, const std::string& dungeonType, bool forceResetWorld) { + InitCommon(); + world.init(physicsBox, "maps/"+dungeonName+".tmx"); +} void GameRegion::Init(int x, int y, const std::string& worldName, bool forceResetWorld) { @@ -301,19 +319,10 @@ void GameRegion::Init(int x, int y, const std::string& worldName, bool forceRese loadMap = RegionChooseMapTemplate(region_x, region_y); newRegion = true; } - b2Vec2 gravity(0.0f, 0.0f); - placeables.clear(); - physicsBox.reset(new b2World(gravity)); - world.managed_bodies.clear(); - world.init(physicsBox, loadMap); - ScanPrefabs("prefabs01"); - - liqudHandler["water"].blockingLayer = world.blockingLayer; - liqudHandler["water"].blockingLayer_overlay_1 = world.blockingLayer_overlay_1; - liqudHandler["lava"].blockingLayer = world.blockingLayer; - liqudHandler["lava"].blockingLayer_overlay_1 = world.blockingLayer_overlay_1; - liqudHandler["lava"].setupTiles(16); + InitCommon(); + ScanPrefabs("prefabs01"); + world.init(physicsBox, loadMap); const std::vector& object_groups = world.tm.object_groups; diff --git a/src/saland/GameRegion.hpp b/src/saland/GameRegion.hpp index 4af6e18..47ba584 100644 --- a/src/saland/GameRegion.hpp +++ b/src/saland/GameRegion.hpp @@ -43,6 +43,7 @@ class GameRegion { public: GameRegion(); void Init(int x, int y, const std::string& worldName, bool forceResetWorld); + void InitDungeon(const std::string& dungeonName, const std::string& dungeonType, bool forceResetWorld); std::vector > placeables; std::shared_ptr physicsBox; void SaveRegion(); @@ -67,6 +68,7 @@ class GameRegion { int region_x = 0; int region_y = 0; std::string mapFileName = "maps/sample1.tmx"; + void InitCommon(); }; #endif /* GAMEREGION_HPP */