Add jumping

This commit is contained in:
Miloslav Číž 2018-09-08 07:45:54 +02:00
parent a8b2a06aa2
commit d7aad665e2

View file

@ -675,13 +675,13 @@ class Character
{
public:
Camera mCamera;
Unit mVericalSpeed;
Character()
{
mCamera.position.x = 7807;//UNITS_PER_SQUARE * 1;
mCamera.position.y = 18489;//UNITS_PER_SQUARE * 5;
mCamera.direction = -3550;//200;
mCamera.fovAngle = UNITS_PER_SQUARE / 4;
mCamera.height = UNITS_PER_SQUARE * 3;
mCamera.resolution.x = 110 / SUBSAMPLE;
mCamera.resolution.y = 88;
@ -691,7 +691,9 @@ public:
mCamera.collisionHeightBelow = UNITS_PER_SQUARE;
mCamera.collisionHeightAbove = UNITS_PER_SQUARE / 3;
mCamera.collisionStepHeight = UNITS_PER_SQUARE / 2;
}
mVericalSpeed = 0;
}
};
Character player;
@ -848,13 +850,13 @@ int main()
{
draw();
int16_t step = max(1,UNITS_PER_SQUARE / (p.bBtn() ? 7 : 15));
int16_t step = max(1,UNITS_PER_SQUARE / 15);
const int16_t step2 = max(UNITS_PER_SQUARE / 40,1);
Vector2D d = angleToDirection(player.mCamera.direction);
Vector2D moveOffset;
Unit heightOffset = -100;
Unit heightOffset = player.mVericalSpeed;
moveOffset.x = 0;
moveOffset.y = 0;
@ -916,8 +918,28 @@ int main()
else
player.mCamera.direction += addition * step2;
Unit prevHeight = player.mCamera.height;
moveCameraWithCollision(&player.mCamera,moveOffset,heightOffset,
floorHeightAt, ceilingHeightAt);
Unit heightDiff = player.mCamera.height - prevHeight;
if (heightDiff == 0)
player.mVericalSpeed = 0; // hit floor/ceiling
if (player.mVericalSpeed == 0 && p.bBtn())
{
int16_t camX = divRoundDown(player.mCamera.position.x,UNITS_PER_SQUARE);
int16_t camY = divRoundDown(player.mCamera.position.y,UNITS_PER_SQUARE);
if (player.mCamera.height - player.mCamera.collisionHeightBelow -
floorHeightAt(camX,camY) < 2)
player.mVericalSpeed = 200; // jump
}
player.mVericalSpeed -= 20; // gravity
}
}