Simplify main loop 2
This commit is contained in:
parent
638987ba6e
commit
96046c8689
1 changed files with 23 additions and 48 deletions
69
demo2.cpp
69
demo2.cpp
|
@ -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,9 +855,9 @@ 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)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
else
|
||||
{
|
||||
int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000;
|
||||
player.mCamera.direction += addition * rotationStep;
|
||||
if (!strafe)
|
||||
rotationDirection = -1;
|
||||
else
|
||||
moveDirection = -1;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue