git repos / saland

commit 0aed233b

Poul Sander · 2024-02-19 21:18
0aed233b56c65b904bfc080a9102a04427ab0b86 patch · browse files
parent 933145fa8b5d6e85db01bace82ed46cf9b583925

Started to create a dungeon region

Changed files

M src/saland/GameRegion.cpp before
M src/saland/GameRegion.hpp before
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<sago::tiled::TileObjectGroup>& 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<std::shared_ptr<Placeable> > placeables;
std::shared_ptr<b2World> physicsBox;
void SaveRegion();
@@ -67,6 +68,7 @@ private:
int region_x = 0;
int region_y = 0;
std::string mapFileName = "maps/sample1.tmx";
+ void InitCommon();
};
#endif /* GAMEREGION_HPP */