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