Fix jumping bug

This commit is contained in:
Miloslav Číž 2018-09-30 14:48:39 +02:00
parent fbd39cdcdf
commit 14edbb14db

View file

@ -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
}