jumppi toimii oikeisiin suuntiin
authorekku
Mon, 01 Dec 2008 23:43:05 +0000
changeset 170 fe74105c07ea
parent 169 71c5b12a2b3f
child 171 05f1c957e776
jumppi toimii oikeisiin suuntiin
src/proto2/GameState.cc
src/proto2/Physics.cc
src/proto2/Physics.hh
--- a/src/proto2/GameState.cc	Mon Dec 01 23:39:37 2008 +0000
+++ b/src/proto2/GameState.cc	Mon Dec 01 23:43:05 2008 +0000
@@ -19,8 +19,14 @@
     if (input & INPUT_MOVE_DOWN)
         da -= CROSSHAIR_ANGLE_SPEED;
 
-    if (input & INPUT_MOVE_JUMP)
-        jump();
+    if (input & INPUT_MOVE_JUMP) {
+        if ((input & INPUT_MOVE_LEFT))
+            jump(-1);
+        else if ((input & INPUT_MOVE_RIGHT))
+            jump(1);
+        else
+            jump(0);
+    }
 
     this->changeAim(da); // Move crosshair
 
--- 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;
     }
 }
--- a/src/proto2/Physics.hh	Mon Dec 01 23:39:37 2008 +0000
+++ b/src/proto2/Physics.hh	Mon Dec 01 23:43:05 2008 +0000
@@ -121,9 +121,10 @@
     void setFacing(bool facingRight);
 
     /**
-     * Handle ground-jumping
+     * Makes the player jump in the air.
+     * @param direction -1: jump left, 0: jump up, 1: jump right
      */
-    void jump();
+    void jump(int direction);
 
     /** 
      * Handle ground-bounce