Skip to content

Commit

Permalink
Started to create a dungeon region
Browse files Browse the repository at this point in the history
  • Loading branch information
sago007 committed Feb 19, 2024
1 parent 933145f commit 0aed233
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/saland/GameRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/saland/GameRegion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 */
Expand Down

0 comments on commit 0aed233

Please sign in to comment.