]> git.localhorst.tv Git - orbi.git/commitdiff
don't reset speed if heading away from a surface
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 6 May 2014 18:27:34 +0000 (20:27 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 6 May 2014 18:27:34 +0000 (20:27 +0200)
src/world/World.cpp

index 088712acae45ac2720322954a7f68eac3216fc25..faf7da910b5a34420bf5fdc13c55d5c7f625ed36 100644 (file)
@@ -40,20 +40,28 @@ void World::Update(float dt) {
 void World::BoundsCollision(Entity &e, float dt) {
        if (e.vbox.Top() < 0) {
                e.Move(Vector<float>(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<float>(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<float>(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<float>(-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<int>(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<int>(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<int>(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;
                }
        }