Fix jumping bug
This commit is contained in:
parent
fbd39cdcdf
commit
14edbb14db
1 changed files with 9 additions and 9 deletions
18
general.hpp
18
general.hpp
|
@ -303,6 +303,10 @@ class Player
|
||||||
public:
|
public:
|
||||||
RCL_Camera mCamera;
|
RCL_Camera mCamera;
|
||||||
RCL_Unit mVericalSpeed;
|
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;
|
bool mRunning;
|
||||||
RCL_Unit mHeadBob;
|
RCL_Unit mHeadBob;
|
||||||
bool mHeadBobUp;
|
bool mHeadBobUp;
|
||||||
|
@ -319,6 +323,7 @@ public:
|
||||||
mCamera.resolution.y = SCREEN_HEIGHT;
|
mCamera.resolution.y = SCREEN_HEIGHT;
|
||||||
mCamera.shear = 0;
|
mCamera.shear = 0;
|
||||||
mVericalSpeed = 0;
|
mVericalSpeed = 0;
|
||||||
|
mVericalSpeedPrev = 0;
|
||||||
mRunning = false;
|
mRunning = false;
|
||||||
mHeadBob = 0;
|
mHeadBob = 0;
|
||||||
mHeadBobUp = true;
|
mHeadBobUp = true;
|
||||||
|
@ -390,15 +395,8 @@ public:
|
||||||
if (heightDiff == 0)
|
if (heightDiff == 0)
|
||||||
mVericalSpeed = 0; // hit floor/ceiling
|
mVericalSpeed = 0; // hit floor/ceiling
|
||||||
|
|
||||||
if (jump && mVericalSpeed == 0)
|
if (jump && mVericalSpeed == 0 && mVericalSpeedPrev == 0)
|
||||||
{
|
mVericalSpeed = PLAYER_JUMP_SPEED; // jump
|
||||||
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 (shearDirection != 0)
|
if (shearDirection != 0)
|
||||||
mCamera.shear = RCL_clamp(mCamera.shear + shearDirection * 10,
|
mCamera.shear = RCL_clamp(mCamera.shear + shearDirection * 10,
|
||||||
|
@ -406,6 +404,8 @@ public:
|
||||||
else
|
else
|
||||||
mCamera.shear /= 2;
|
mCamera.shear /= 2;
|
||||||
|
|
||||||
|
mVericalSpeedPrev = mVericalSpeed;
|
||||||
|
|
||||||
if (computeHeight)
|
if (computeHeight)
|
||||||
mVericalSpeed -= (dt * GRAVITY_ACCELERATION) / 1000; // gravity
|
mVericalSpeed -= (dt * GRAVITY_ACCELERATION) / 1000; // gravity
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue