--- a/src/Physics.cc Thu Dec 04 14:30:13 2008 +0000
+++ b/src/Physics.cc Thu Dec 04 14:48:01 2008 +0000
@@ -65,13 +65,13 @@
/**
* Player walks on floor.
*/
-Vector PhysicsObject::walk (TimeMS dt, bool right) {
- // TODO: that dt should affect to something
- float velocity = 100;
+Vector PhysicsObject::walk_one_step (float partial, bool right) {
// which way we are walking
- float deltaX = right ? (velocity*dt)/1000 : -(velocity*dt)/1000;
+ float deltaX = right ? partial : -partial;
Vector reached = this->position;
-
+ if(reached.roundToInt() == (reached+Vector(deltaX, 0)).roundToInt()) {
+ return reached+Vector(deltaX, 0);
+ }
// Is there upward ramp
if(!possibleLocation(position+Vector(deltaX, 0))) {
// Yes. Then we check n pixels up
@@ -97,19 +97,27 @@
// If the fall is big enough, set the worm in the air
if (i >= 2) {
- Vector back = walk(dt, !right);
+// Vector back = walk(dt, !right);
this->inAir = true;
- this->velocity.x = right ? velocity : -velocity;
+// 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;
+// this->velocity = (reached-back)*1000/dt;
break;
}
}
}
// And we return where we got
return reached;
-
+}
+Vector PhysicsObject::walk (TimeMS dt, bool right) {
+ float velocity = PLAYER_WALK_SPEED;
+ float walkAmount = (velocity*dt)/1000;
+ Vector reached = this->position;
+ while(walkAmount > 0) {
+ walk_one_step((1 < walkAmount ? 1 : walkAmount), right);
+ walkAmount--;
+ }
}
/**
--- a/src/Physics.hh Thu Dec 04 14:30:13 2008 +0000
+++ b/src/Physics.hh Thu Dec 04 14:48:01 2008 +0000
@@ -202,6 +202,7 @@
* @return New position
*/
Vector walk(TimeMS, bool right);
+ Vector walk_one_step(float, bool);
/*
* Handle collision. TODO: This is not used. It probably should