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