src/proto2/Physics.cc
changeset 179 c600984d0428
parent 178 2ba6279d1b67
child 180 bfe1077edab3
--- a/src/proto2/Physics.cc	Tue Dec 02 00:56:31 2008 +0000
+++ b/src/proto2/Physics.cc	Tue Dec 02 01:46:18 2008 +0000
@@ -60,20 +60,31 @@
             }
         }
     } else {
-       // Or downward ramp
-       for(int i = 0; i < 3; i++) {
-            // And when there is finally ground we can step on it
-            // If there is no gound we still step there, but will fall down
+        // Or downward ramp or flat
+        for(int i = 0; 1; i++) {
+
+            // And when there is finally ground we can step on
+            // it. If there is no gound we still step there,
+            // but will fall one pixel down
             if(possibleLocation(position+Vector(deltaX, i))) {
                 reached = position+Vector(deltaX, i);
             } else {
                 break;
             }
+            
+            // If the fall is big enough, set the worm in the air
+            if (i >= 2) {
+                this->inAir = true;
+                this->velocity.x = right ? 10 : -10;
+                // Avoid stepping two pixels down when it starts to free fall
+                reached.y -= 2;
+                break;
+            }
         }
     }
     // And we return where we got
     return reached;
- 
+
 }
 
 /**
@@ -128,10 +139,12 @@
         forceq.pop();
     }
 
-    // If the player has stopped and there's some ground under the feet
+    // If the player has stopped and there's some ground under some of the 3 some of the 3t
     // set inAir false
     if (this->velocity == Vector(0,0)) {
-        this->inAir = !world.collides(this->position+shape[2]+Vector(0, 1));
+        this->inAir = !world.collides(this->position+shape[1]+Vector(0, 1))
+                      && !world.collides(this->position+shape[2]+Vector(0, 1))
+                      && !world.collides(this->position+shape[3]+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)
@@ -148,9 +161,13 @@
     // If the worm is not in the air make it walk,
     // otherwise integrate the new position and velocity
     if (!this->inAir) {
+        //std::cout << "Tryin to walk" << std::endl;
         // It walks only if there's some vertical force
-        if (total.x != 0)
+        if (total.x != 0) {
+            std::cout << "Succeeding to walk" << std::endl;
             this->position = walk(total.x > 0);
+            this->velocity = Vector(0,0);
+        }
     }
 
     if(!possibleLocation(position)) {