src/proto2/Physics.cc
changeset 170 fe74105c07ea
parent 169 71c5b12a2b3f
child 171 05f1c957e776
--- a/src/proto2/Physics.cc	Mon Dec 01 23:39:37 2008 +0000
+++ b/src/proto2/Physics.cc	Mon Dec 01 23:43:05 2008 +0000
@@ -54,7 +54,7 @@
             }
         }
     } else {
-        for(int i = 0; i < 3; i++) {
+       for(int i = 0; i < 3; i++) {
             if(possibleLocation(position+Vector(deltaX, i))) {
                 reached = position+Vector(deltaX, i);
             } else {
@@ -66,11 +66,26 @@
  
 }
 
-void PhysicsObject::jump () {
+/**
+ * Makes the player jump in the air.
+ * @param direction -1: jump left, 0: jump up, 1: jump right
+ */
+void PhysicsObject::jump (int direction) {
     // Jump only if player is "on the ground"
     if (!this->inAir) {
  	    velocity.y = -100;
-        velocity.x += facingRight ? 20 : -20;
+        switch (direction) {
+            case 1:
+                velocity.x += 20;
+                break;
+            case -1:
+                velocity.x -= 20;
+                break;
+            case 0:
+                break;
+            default:
+                throw std::logic_error("Invalid jump direction");
+        }
 	    inAir = true;
     }
 }