From: Daniel Karbach Date: Tue, 6 May 2014 18:27:34 +0000 (+0200) Subject: don't reset speed if heading away from a surface X-Git-Url: http://git.localhorst.tv/?p=orbi.git;a=commitdiff_plain;h=7fccdf2cd07afb3afdc0b854e9a03130ef202eec don't reset speed if heading away from a surface --- diff --git a/src/world/World.cpp b/src/world/World.cpp index 088712a..faf7da9 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -40,20 +40,28 @@ void World::Update(float dt) { void World::BoundsCollision(Entity &e, float dt) { if (e.vbox.Top() < 0) { e.Move(Vector(0, -e.vbox.Top())); - e.vel.y = 0; + if (e.vel.y < 0) { + e.vel.y = 0; + } } if (e.vbox.Bottom() > size.y) { e.Move(Vector(0, size.y - e.vbox.Bottom())); - e.vel.y = 0; + if (e.vel.y > 0) { + e.vel.y = 0; + } e.onGround = true; } if (e.hbox.Right() > size.x) { e.Move(Vector(size.x - e.hbox.Right(), 0)); - e.vel.x = 0; + if (e.vel.x > 0) { + e.vel.x = 0; + } } if (e.hbox.Left() < 0) { e.Move(Vector(-e.hbox.Left(), 0)); - e.vel.x = 0; + if (e.vel.x < 0) { + e.vel.x = 0; + } } } @@ -66,7 +74,9 @@ void World::TileCollision(Entity &e, float dt) { const Tile &tile = TileAt(Vector(x, y)); if (tile.IsSolid()) { response.y = y + 1 - e.vbox.Top(); - e.vel.y = 0; + if (e.vel.y < 0) { + e.vel.y = 0; + } break; } } @@ -78,7 +88,9 @@ void World::TileCollision(Entity &e, float dt) { if (tile.IsSolid()) { response.y = y - e.vbox.Bottom(); e.onGround = true; - e.vel.y = 0; + if (e.vel.y > 0) { + e.vel.y = 0; + } break; } } @@ -91,7 +103,9 @@ void World::TileCollision(Entity &e, float dt) { if (tile.IsSolid()) { response.y = -1; e.onGround = true; - e.vel.y = 0; + if (e.vel.y > 0) { + e.vel.y = 0; + } break; } } @@ -103,7 +117,9 @@ void World::TileCollision(Entity &e, float dt) { const Tile &tile = TileAt(Vector(x, y)); if (tile.IsSolid()) { response.x = x + 1 - e.hbox.Left(); - e.vel.x = 0; + if (e.vel.x < 0) { + e.vel.x = 0; + } break; } } @@ -114,7 +130,9 @@ void World::TileCollision(Entity &e, float dt) { const Tile &tile = TileAt(Vector(x, y)); if (tile.IsSolid()) { response.x = x - e.hbox.Right(); - e.vel.x = 0; + if (e.vel.x > 0) { + e.vel.x = 0; + } break; } }