Simplify main loop 2

This commit is contained in:
Miloslav Číž 2018-09-10 18:30:19 +02:00
parent 638987ba6e
commit 96046c8689

View file

@ -841,6 +841,10 @@ int main()
uint32_t previousTime = 0;
uint32_t dt;
int16_t moveDirection;
int16_t rotationDirection;
bool strafe;
while (pokitto.isRunning())
{
if (pokitto.update())
@ -851,10 +855,10 @@ int main()
dt = timeNow - previousTime;
previousTime = timeNow;
int16_t horizontalStep = (dt * PLAYER_SPEED * (pokitto.bBtn() ? 2 : 1)) / 1000;
Vector2D d = angleToDirection(player.mCamera.direction);
moveDirection = 0;
rotationDirection = 0;
strafe = false;
if (shotFired)
{
// update the shot
@ -874,63 +878,34 @@ int main()
else if (pokitto.cBtn())
{
shotPosition = player.mCamera.position;
shotDirection = d;
shotDirection = angleToDirection(player.mCamera.direction);
shotFired = true;
}
Vector2D moveOffset;
moveOffset.x = 0;
moveOffset.y = 0;
d.x = (d.x * horizontalStep) / UNITS_PER_SQUARE;
d.y = (d.y * horizontalStep) / UNITS_PER_SQUARE;
if (d.x == 0 && d.y == 0)
{
d.x = d.x > 0 ? horizontalStep : -1 * horizontalStep;
d.y = d.y > 0 ? horizontalStep : -1 * horizontalStep;
}
bool strafe = pokitto.aBtn();
if (pokitto.upBtn())
{
moveOffset = d;
}
moveDirection = 1;
else if (pokitto.downBtn())
{
moveOffset.x = -1 * d.x;
moveOffset.y = -1 * d.y;
}
int addition = 0;
moveDirection = -1;
if (pokitto.rightBtn())
addition = 1;
{
if (!strafe)
rotationDirection = 1;
else
moveDirection = 1;
}
else if (pokitto.leftBtn())
addition = -1;
if (strafe)
{
d = angleToDirection(player.mCamera.direction + UNITS_PER_SQUARE / 4);
d.x = (d.x * horizontalStep * addition) / UNITS_PER_SQUARE;
d.y = (d.y * horizontalStep * addition) / UNITS_PER_SQUARE;
moveOffset = d;
if (!strafe)
rotationDirection = -1;
else
moveDirection = -1;
}
else
{
int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000;
player.mCamera.direction += addition * rotationStep;
}
Unit prevHeight = player.mCamera.height;
moveCameraWithCollision(&player.mCamera,moveOffset,0,
floorHeightAt, 0, 0);
Unit heightDiff = player.mCamera.height - prevHeight;
player.update(moveDirection,strafe,rotationDirection,false,0,
floorHeightAt,0,false,dt);
}
}