added TimeMS dt to walk, but it doesn't do anything yet
authornireco
Wed, 03 Dec 2008 12:21:38 +0000
changeset 181 62e0c2cfb714
parent 180 bfe1077edab3
child 182 84675387ca74
added TimeMS dt to walk, but it doesn't do anything yet
src/proto2/Physics.cc
src/proto2/Physics.hh
--- a/src/proto2/Physics.cc	Wed Dec 03 12:09:42 2008 +0000
+++ b/src/proto2/Physics.cc	Wed Dec 03 12:21:38 2008 +0000
@@ -49,8 +49,11 @@
 /**
  * Player walks on floor.
  */
-Vector PhysicsObject::walk (bool right) {
-    float deltaX = right ? 1 : -1; // which way we are walking
+Vector PhysicsObject::walk (TimeMS dt, bool right) {
+    // TODO: that dt should affect to something
+    float velocity = 100;
+    // which way we are walking
+    float deltaX = right ? (velocity*dt)/1000 : -(velocity*dt)/1000;
     Vector reached = this->position;
    
     // Is there upward ramp
@@ -78,10 +81,12 @@
             
             // If the fall is big enough, set the worm in the air
             if (i >= 2) {
+                Vector back = walk(dt, !right);
                 this->inAir = true;
-                this->velocity.x = right ? 10 : -10;
+                this->velocity.x = right ? velocity : -velocity;
                 // Avoid stepping two pixels down when it starts to free fall
                 reached.y -= 2;
+                this->velocity = (reached-back)*1000/dt;
                 break;
             }
         }
@@ -169,7 +174,7 @@
         // It walks only if there's some vertical force
         if (total.x != 0) {
             std::cout << "Succeeding to walk" << std::endl;
-            this->position = walk(total.x > 0);
+            this->position = walk(PHYSICS_TICK_MS, total.x > 0);
             this->velocity = Vector(0,0);
         }
     }
--- a/src/proto2/Physics.hh	Wed Dec 03 12:09:42 2008 +0000
+++ b/src/proto2/Physics.hh	Wed Dec 03 12:21:38 2008 +0000
@@ -196,7 +196,7 @@
      * @param right Boolean describing the movement direction.
      * @return New position
      */
-    Vector walk(bool right);
+    Vector walk(TimeMS, bool right);
 
     /*
      * Handle collision. TODO: This is not used. It probably should