comments and bomb forces
authorekku
Tue, 02 Dec 2008 00:48:21 +0000
changeset 177 fb144e957c3a
parent 176 9e4e272c2ec6
child 178 2ba6279d1b67
comments and bomb forces
src/proto2/Physics.cc
--- a/src/proto2/Physics.cc	Tue Dec 02 00:47:14 2008 +0000
+++ b/src/proto2/Physics.cc	Tue Dec 02 00:48:21 2008 +0000
@@ -128,28 +128,29 @@
         forceq.pop();
     }
 
-    // TODO: This is _ugly_ (but not so ugly as the last one I think)
-    // hack. I think we should handle walking from the collision
-    // detection code.
-
-    if (this->velocity.sqrLength() < PLAYER_MIN_SPEED * PLAYER_MIN_SPEED) {
+    // If the player has stopped and there's some ground under the feet
+    // set inAir false
+    if (this->velocity == Vector(0,0)) {
         this->inAir = !world.collides(this->position+shape[2]+Vector(0, 1));
+        // If, however, there's a force caused by a bomb, e.g., set it in air.
+        // Still, we have to be able to separate forces caused by walking attempts
+        // and bombs etc (+0.1 because float comparison can be dangerous)
+        if (total.y < 0 || abs(total.x) > PLAYER_MOVE_FORCE + 0.1)
+            this->inAir = true;
     }
 
     if(!possibleLocation(position)) {
         //if we are trapped in ground form dirtball or something
-        //we might want to just return and stuff velocity to some value
-//        return;
+        //we might want to just return and set velocity to some value
+        //return;
     }
 
-    if(!possibleLocation(position)) {
-        Engine::log(DEBUG, "great failure") << "great failure";
-        func1();
-    }
+    // If the worm is not in the air make it walk,
+    // otherwise integrate the new position and velocity
     if (!this->inAir) {
+        // It walks only if there's some vertical force
         if (total.x != 0)
             this->position = walk(total.x > 0);
-        //total.x = 0;
     }
 
     if(!possibleLocation(position)) {
@@ -158,6 +159,7 @@
     }
     Vector newPosition;
     Vector velAfterTick;
+    // Calculate new position and velocity to the given references
     integrate(total, PHYSICS_TICK_MS, newPosition, velAfterTick);
     this->velocity = velAfterTick;
 
@@ -183,7 +185,6 @@
                 reached = reached - unitVector; // Return to last point
                 collided = true;
                 if (this->velocity.sqrLength() < PLAYER_MIN_SPEED * PLAYER_MIN_SPEED) {
-                    this->inAir = false;
                     this->velocity = Vector(0,0);
                 }
                 break;