git repos / saland

commit babf7c94

sago007 · 2018-09-29 18:41
babf7c94332ee3e8c7caf542fd70ce41e6082ba5 patch · browse files
parent ff9274c59f02a29a4a44a6340701d7c12dc8e9bc

Can now move between regionsx

Changed files

M src/saland/Game.cpp before
M src/saland/Game.hpp before
M src/saland/GameRegion.cpp before
M src/saland/GameRegion.hpp before
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 9251a54..b5080d2 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -147,9 +147,9 @@ struct Game::GameImpl {
sago::SagoTextField bottomField;
};
-Game::Game() {
- data.reset(new Game::GameImpl());
- data->lastUpdate = SDL_GetTicks();
+void Game::ResetWorld(int x, int y) {
+ data->gameRegion.SaveRegion();
+ data->gameRegion.Init(x, y);
data->human.reset(new Human());
data->gameRegion.placeables.push_back(data->human);
b2BodyDef myBodyDef;
@@ -165,6 +165,12 @@ Game::Game() {
myFixtureDef.density = 10.0f;
data->human->body->CreateFixture(&myFixtureDef); //add a fixture to the body
data->human->body->SetTransform(b2Vec2(data->human->X / 32.0f, data->human->Y / 32.0f),data->human->body->GetAngle());
+}
+
+Game::Game() {
+ data.reset(new Game::GameImpl());
+ data->lastUpdate = SDL_GetTicks();
+ ResetWorld(0,0);
data->bottomField.SetHolder(globalData.dataHolder);
data->bottomField.SetFontSize(20);
@@ -498,4 +504,20 @@ void Game::Update() {
data->lastUpdate = nowTime;
data->gameRegion.physicsBox->Step(deltaTime / 1000.0f / 60.0f, velocityIterations, positionIterations);
std::sort(data->gameRegion.placeables.begin(), data->gameRegion.placeables.end(), sort_placeable);
+ if (data->human->X < 0) {
+ ResetWorld(data->gameRegion.GetRegionX()-1, data->gameRegion.GetRegionY());
+ data->human->body->SetTransform(b2Vec2(data->gameRegion.world.tm.width, data->gameRegion.world.tm.height/2),data->human->body->GetAngle()) ;
+ }
+ if (data->human->X > data->gameRegion.world.tm.width*32) {
+ ResetWorld(data->gameRegion.GetRegionX()+1, data->gameRegion.GetRegionY());
+ data->human->body->SetTransform(b2Vec2(1, data->gameRegion.world.tm.height/2),data->human->body->GetAngle()) ;
+ }
+ if (data->human->Y < 0) {
+ ResetWorld(data->gameRegion.GetRegionX(), data->gameRegion.GetRegionY()-1);
+ data->human->body->SetTransform(b2Vec2(data->gameRegion.world.tm.width/2, data->gameRegion.world.tm.height),data->human->body->GetAngle()) ;
+ }
+ if (data->human->Y > data->gameRegion.world.tm.height*32) {
+ ResetWorld(data->gameRegion.GetRegionX(), data->gameRegion.GetRegionY()+1);
+ data->human->body->SetTransform(b2Vec2(data->gameRegion.world.tm.width/2, 1),data->human->body->GetAngle()) ;
+ }
}
diff --git a/src/saland/Game.hpp b/src/saland/Game.hpp index 07b89da..bcd6605 100644 --- a/src/saland/Game.hpp +++ b/src/saland/Game.hpp
@@ -39,6 +39,7 @@ public:
private:
struct GameImpl;
std::unique_ptr<GameImpl> data;
+ void ResetWorld(int region_x, int region_y);
};
#endif /* GAME_HPP */
diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp index 0ab547a..2945cdf 100644 --- a/src/saland/GameRegion.cpp +++ b/src/saland/GameRegion.cpp
@@ -41,7 +41,9 @@ void GameRegion::Init(int x, int y) {
loadMap = "maps/sample1.tmx";
}
b2Vec2 gravity(0.0f, 0.0f);
+ placeables.clear();
physicsBox.reset(new b2World(gravity));
+ world.managed_bodies.clear();
world.init(physicsBox, loadMap);
std::shared_ptr<MiscItem> barrel = std::make_shared<MiscItem>();
diff --git a/src/saland/GameRegion.hpp b/src/saland/GameRegion.hpp index 583b108..0093111 100644 --- a/src/saland/GameRegion.hpp +++ b/src/saland/GameRegion.hpp
@@ -37,6 +37,8 @@ public:
void SaveRegion();
World world;
uint32_t outerTile = 485;
+ int GetRegionX() {return region_x; }
+ int GetRegionY() {return region_y; }
private:
int region_x = 0;
int region_y = 0;