--- a/src/proto2/Physics.cc Mon Dec 01 22:58:15 2008 +0000
+++ b/src/proto2/Physics.cc Mon Dec 01 23:32:17 2008 +0000
@@ -43,66 +43,27 @@
}
Vector PhysicsObject::walk (bool right) {
- Vector cursor = this->position + (right ? Vector(1,0) : Vector(-1,0));
+ float deltaX = right ? 1 : -1;
Vector reached = this->position;
-
- //for(int steps = 0; steps < 3; steps++) {
-
- // Go up but not if the wall is over two pixels
- if(world.collides(cursor+shape[2])) {
- for(int height = 0, max = 2; height < max+42; height++) {
-
- if(height >= max)
- return reached;
-
- cursor.y--;
- if(!world.collides(cursor+shape[2])) {
- // Check that the other parts of the worm don't collide with anything
- if(possibleLocation(cursor)) {
- reached = cursor;
- continue;
- } else {
- // Can't get any further
- return reached;
- }
+
+ if(!possibleLocation(position+Vector(deltaX, 0))) {
+ for(int i = 1; i < 3; i++) {
+ if(possibleLocation(position+Vector(deltaX, -i))) {
+ reached = position+Vector(deltaX, -i);
+ break;
}
}
} else {
- if(possibleLocation(cursor)) {
- reached = cursor;
- }
- // Start checking if the lower squares are empty
-
- for(int depth = 0, max = 3; depth < max+42; depth++) {
-
- if(depth >= max) {
- // We can start a free fall now
- //
- // TODO it should be set inAir if it falls from a cliff
-// this->inAir = true;
-
- // Put some speed there to make loke smoother
- //this->velocity.y = -5;
- return reached;
- }
-
- cursor.y++;
- if(!world.collides(cursor+shape[2])) {
- // Check that the other parts of the worm don't collide with anything
- if(possibleLocation(cursor)) {
- reached = cursor;
- continue;
- } else {
- // Can't get any further
- return reached;
- }
+ for(int i = 0; i < 3; i++) {
+ if(possibleLocation(position+Vector(deltaX, i))) {
+ reached = position+Vector(deltaX, i);
+ } else {
+ break;
}
}
- }
-
- // cursor.x += right ? 1 : -1;
- //}
+ }
return reached;
+
}
void PhysicsObject::jump () {
@@ -168,7 +129,7 @@
const Vector unitVector = diffVec / diffVec.length();
Vector reached = position;
- while ((position-reached).length() < diffVec.length()) {
+ while ((position-reached).sqrLength() < diffVec.sqrLength()) {
// Check if any of the shapes points collide
for (uint64_t i = 0; i < shape.size(); i++) {
if (world.getType(reached+shape[i]) != EMPTY) { // Collision