diff --git a/general.hpp b/general.hpp index b0bf033..1581f8e 100644 --- a/general.hpp +++ b/general.hpp @@ -303,6 +303,10 @@ class Player public: RCL_Camera mCamera; RCL_Unit mVericalSpeed; + RCL_Unit mVericalSpeedPrev; /* In order to detect whether player is standing + on ground (for jumping) we need the derivative + of vertical speed (not just the vertical + speed) => we need two values. */ bool mRunning; RCL_Unit mHeadBob; bool mHeadBobUp; @@ -319,6 +323,7 @@ public: mCamera.resolution.y = SCREEN_HEIGHT; mCamera.shear = 0; mVericalSpeed = 0; + mVericalSpeedPrev = 0; mRunning = false; mHeadBob = 0; mHeadBobUp = true; @@ -390,15 +395,8 @@ public: if (heightDiff == 0) mVericalSpeed = 0; // hit floor/ceiling - if (jump && mVericalSpeed == 0) - { - int16_t camX = RCL_divRoundDown(mCamera.position.x,RCL_UNITS_PER_SQUARE); - int16_t camY = RCL_divRoundDown(mCamera.position.y,RCL_UNITS_PER_SQUARE); - - if (mCamera.height - RCL_CAMERA_COLL_HEIGHT_BELOW - - floorHeightFunction(camX,camY) < 2) - mVericalSpeed = PLAYER_JUMP_SPEED; // jump - } + if (jump && mVericalSpeed == 0 && mVericalSpeedPrev == 0) + mVericalSpeed = PLAYER_JUMP_SPEED; // jump if (shearDirection != 0) mCamera.shear = RCL_clamp(mCamera.shear + shearDirection * 10, @@ -406,6 +404,8 @@ public: else mCamera.shear /= 2; + mVericalSpeedPrev = mVericalSpeed; + if (computeHeight) mVericalSpeed -= (dt * GRAVITY_ACCELERATION) / 1000; // gravity }