Add running
This commit is contained in:
parent
dc6b87187b
commit
14df2fa66b
2 changed files with 21 additions and 7 deletions
26
demo1.cpp
26
demo1.cpp
|
@ -688,6 +688,8 @@ pokitto.display.print(player.mCamera.direction);
|
|||
*/
|
||||
}
|
||||
|
||||
bool runReleased = false;
|
||||
|
||||
int main()
|
||||
{
|
||||
pokitto.begin();
|
||||
|
@ -716,7 +718,7 @@ int main()
|
|||
dt = timeNow - previousTime;
|
||||
previousTime = timeNow;
|
||||
|
||||
int16_t horizontalStep = (dt * PLAYER_SPEED) / 1000;
|
||||
int16_t horizontalStep = (dt * PLAYER_SPEED * (player.mRunning ? 2 : 1)) / 1000;
|
||||
int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000;
|
||||
|
||||
Vector2D d = angleToDirection(player.mCamera.direction);
|
||||
|
@ -735,19 +737,29 @@ int main()
|
|||
d.y = d.y > 0 ? horizontalStep : -1 * horizontalStep;
|
||||
}
|
||||
|
||||
bool strafe = pokitto.aBtn();
|
||||
bool lookUpDown = pokitto.cBtn();
|
||||
bool aButton = pokitto.aBtn();
|
||||
|
||||
if (pokitto.cBtn())
|
||||
{
|
||||
if (runReleased)
|
||||
{
|
||||
player.mRunning = !player.mRunning;
|
||||
runReleased = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
runReleased = true;
|
||||
|
||||
if (pokitto.upBtn())
|
||||
{
|
||||
if (lookUpDown)
|
||||
if (aButton)
|
||||
player.mCamera.shear = min(player.mCamera.shear + 10,60);
|
||||
else
|
||||
moveOffset = d;
|
||||
}
|
||||
else if (pokitto.downBtn())
|
||||
{
|
||||
if (lookUpDown)
|
||||
if (aButton)
|
||||
player.mCamera.shear = max(player.mCamera.shear - 10,-60);
|
||||
else
|
||||
{
|
||||
|
@ -758,7 +770,7 @@ int main()
|
|||
else
|
||||
player.mCamera.shear /= 2;
|
||||
|
||||
if (!lookUpDown)
|
||||
if (!aButton)
|
||||
player.mCamera.shear /= 2;
|
||||
|
||||
int addition = 0;
|
||||
|
@ -768,7 +780,7 @@ int main()
|
|||
else if (pokitto.leftBtn())
|
||||
addition = -1;
|
||||
|
||||
if (strafe)
|
||||
if (aButton)
|
||||
{
|
||||
d = angleToDirection(player.mCamera.direction + UNITS_PER_SQUARE / 4);
|
||||
d.x = (d.x * horizontalStep * addition) / UNITS_PER_SQUARE;
|
||||
|
|
|
@ -168,6 +168,7 @@ class Player
|
|||
public:
|
||||
Camera mCamera;
|
||||
Unit mVericalSpeed;
|
||||
bool mRunning;
|
||||
|
||||
Player()
|
||||
{
|
||||
|
@ -179,6 +180,7 @@ public:
|
|||
mCamera.resolution.y = SCREEN_HEIGHT;
|
||||
mCamera.shear = 0;
|
||||
mVericalSpeed = 0;
|
||||
mRunning = false;
|
||||
}
|
||||
|
||||
void setPosition(Unit x, Unit y)
|
||||
|
|
Loading…
Reference in a new issue