diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp index 99711d9..c4dc482 100644 --- a/src/saland/GameRegion.cpp +++ b/src/saland/GameRegion.cpp @@ -83,6 +83,7 @@ void GameRegion::SpawnPrefab(const Prefab& prefab, int destX, int destY) { } } ApplyPrefab(world.tm, destX, destY, prefab); + this->world.init_physics(this->physicsBox); } void GameRegion::SpawnItem(const ItemDef& def, float destX, float destY) { @@ -138,8 +139,8 @@ void GameRegion::SpawnItem(const ItemDef& def, float destX, float destY) { } } -std::string GameRegion::GetRegionType(int region_x, int region_y) const { - if (region_x == -1 && region_y == 0) { +static std::string GetRegionType(int region_x, int region_y) { + if (region_x < 0 && region_y == 0) { return "forrest"; } if (region_x == 0 && region_y == 0) { @@ -164,25 +165,32 @@ void GameRegion::ProcessRegionEnter(World& world) { } +static std::string RegionChooseMapTemplate(int region_x, int region_y) { + std::string loadMap = "maps/sample1.tmx"; + if (GetRegionType(region_x, region_y) == "forrest") { + loadMap = "maps/template_forrest.tmx"; + } + if (GetRegionType(region_x, region_y) == "start") { + loadMap = "maps/template_start.tmx"; + } + if (region_x == 0 && region_y == -2) { + loadMap = "maps/city_0x-2.tmx"; + } + if (region_x == 3 && region_y == 3) { + loadMap = "maps/template_forrest2.tmx"; + } + return loadMap; +} + + + void GameRegion::Init(int x, int y, const std::string& worldName, bool forceResetWorld) { region_x = x; region_y = y; mapFileName = createFileName(region_x, region_y, worldName); std::string loadMap = mapFileName; if (!sago::FileExists(loadMap.c_str()) || forceResetWorld) { - loadMap = "maps/sample1.tmx"; - if (GetRegionType(region_x, region_y) == "forrest") { - loadMap = "maps/template_forrest.tmx"; - } - if (GetRegionType(region_x, region_y) == "start") { - loadMap = "maps/template_start.tmx"; - } - if (region_x == 0 && region_y == -2) { - loadMap = "maps/city_0x-2.tmx"; - } - if (region_x == 3 && region_y == 3) { - loadMap = "maps/template_forrest2.tmx"; - } + loadMap = RegionChooseMapTemplate(region_x, region_y); } b2Vec2 gravity(0.0f, 0.0f); placeables.clear(); diff --git a/src/saland/GameRegion.hpp b/src/saland/GameRegion.hpp index d2911ce..04ebc53 100644 --- a/src/saland/GameRegion.hpp +++ b/src/saland/GameRegion.hpp @@ -61,7 +61,6 @@ public: void SpawnMonster(const MonsterDef& def, float destX, float destY) ; void SpawnItem(const ItemDef& def, float destX, float destY) ; void SpawnPrefab(const Prefab& prefab, int destX, int destY); - std::string GetRegionType(int x, int y) const; void ProcessRegionEnter(World& world); private: int region_x = 0; diff --git a/src/saland/model/World.cpp b/src/saland/model/World.cpp index b176d50..26164c5 100644 --- a/src/saland/model/World.cpp +++ b/src/saland/model/World.cpp @@ -91,6 +91,7 @@ void fill_blocking_tiles(std::vector& output, const sago::tiled::TileMap& output.resize(tm.height*tm.width); for (int i = 0; i < tm.height; ++i) { for (int j = 0; j < tm.width; ++j) { + output[i+j*tm.width] = false; uint32_t gid = sago::tiled::getTileFromLayer(tm, layer, i, j); if (gid == 0) { continue; @@ -276,8 +277,10 @@ void World::init(std::shared_ptr& world, const std::string& mapFileName init_tilemap(tm, blockingLayer, blockingLayer_overlay_1); init_physics(world); protected_tiles.resize(tm.height*tm.width); + for (int x=0; x < tm.width; ++x) { for (int y=0; y < tm.height; ++y) { + protected_tiles[x+y*tm.width] = false; if (x < 2 && y > tm.layers.at(0).height/2-6 && y < tm.layers.at(0).height/2+5) { protected_tiles[x+y*tm.width] = true; }