Update colliders when updating render objects

This commit is contained in:
2020-08-21 19:49:42 +02:00
parent 1b0a35cf5a
commit 12c6c9049f
2 changed files with 17 additions and 11 deletions
+12 -9
View File
@@ -99,7 +99,10 @@ void addStuff(SDLPP::Scene &scene, std::shared_ptr<SDLPP::Renderer> &r) {
posx += 0.45;
}
auto x = std::make_shared<Player>(0,0,0.2,0.2, r);
x->addCollision(SDLPP::Rect(0,0,1,1));
x->addCollision(SDLPP::Rect(0.3,0.7,0.05,0.31));
x->addCollision(SDLPP::Rect(0.65,0.7,0.05,0.31));
x->addCollision(SDLPP::Rect(0.2,0.3,0.6,0.45));
x->addCollision(SDLPP::Rect(0.35,0,0.3,0.3));
x->setTexture("5.png");
x->setId(PLAYER_ID);
x->setColiderColor("00FF00");
@@ -217,15 +220,15 @@ void doInput(std::shared_ptr<SDLPP::Scene> scene) {
for( auto &x : scene->getCollisions(*player) ) {
if( x->getId() == STONE_ID ) {
gravity = false;
auto stoneRect = x->getDoubleRect();
auto playerPos = player->getDoubleRect();
auto newPX = playerPos.first.first;
auto newPY = playerPos.first.second;
newPY = stoneRect.first.second - playerPos.second.second;
player->setPos(newPX, newPY);
if(player->isGravityEnabled())
if(player->isGravityEnabled()) {
auto stoneRect = x->getDoubleRect();
auto playerPos = player->getDoubleRect();
auto newPX = playerPos.first.first;
auto newPY = stoneRect.first.second - playerPos.second.second;
player->setPos(newPX, newPY);
player->setLastStand();
x->setHidden(true);
}
// x->setHidden(true);
}
if( x->getId() == DEATH ) {
std::cout << "Oh no, you died!" << std::endl;