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()
|
int main()
|
||||||
{
|
{
|
||||||
pokitto.begin();
|
pokitto.begin();
|
||||||
|
@ -716,7 +718,7 @@ int main()
|
||||||
dt = timeNow - previousTime;
|
dt = timeNow - previousTime;
|
||||||
previousTime = timeNow;
|
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;
|
int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000;
|
||||||
|
|
||||||
Vector2D d = angleToDirection(player.mCamera.direction);
|
Vector2D d = angleToDirection(player.mCamera.direction);
|
||||||
|
@ -735,19 +737,29 @@ int main()
|
||||||
d.y = d.y > 0 ? horizontalStep : -1 * horizontalStep;
|
d.y = d.y > 0 ? horizontalStep : -1 * horizontalStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool strafe = pokitto.aBtn();
|
bool aButton = pokitto.aBtn();
|
||||||
bool lookUpDown = pokitto.cBtn();
|
|
||||||
|
if (pokitto.cBtn())
|
||||||
|
{
|
||||||
|
if (runReleased)
|
||||||
|
{
|
||||||
|
player.mRunning = !player.mRunning;
|
||||||
|
runReleased = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
runReleased = true;
|
||||||
|
|
||||||
if (pokitto.upBtn())
|
if (pokitto.upBtn())
|
||||||
{
|
{
|
||||||
if (lookUpDown)
|
if (aButton)
|
||||||
player.mCamera.shear = min(player.mCamera.shear + 10,60);
|
player.mCamera.shear = min(player.mCamera.shear + 10,60);
|
||||||
else
|
else
|
||||||
moveOffset = d;
|
moveOffset = d;
|
||||||
}
|
}
|
||||||
else if (pokitto.downBtn())
|
else if (pokitto.downBtn())
|
||||||
{
|
{
|
||||||
if (lookUpDown)
|
if (aButton)
|
||||||
player.mCamera.shear = max(player.mCamera.shear - 10,-60);
|
player.mCamera.shear = max(player.mCamera.shear - 10,-60);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -758,7 +770,7 @@ int main()
|
||||||
else
|
else
|
||||||
player.mCamera.shear /= 2;
|
player.mCamera.shear /= 2;
|
||||||
|
|
||||||
if (!lookUpDown)
|
if (!aButton)
|
||||||
player.mCamera.shear /= 2;
|
player.mCamera.shear /= 2;
|
||||||
|
|
||||||
int addition = 0;
|
int addition = 0;
|
||||||
|
@ -768,7 +780,7 @@ int main()
|
||||||
else if (pokitto.leftBtn())
|
else if (pokitto.leftBtn())
|
||||||
addition = -1;
|
addition = -1;
|
||||||
|
|
||||||
if (strafe)
|
if (aButton)
|
||||||
{
|
{
|
||||||
d = angleToDirection(player.mCamera.direction + UNITS_PER_SQUARE / 4);
|
d = angleToDirection(player.mCamera.direction + UNITS_PER_SQUARE / 4);
|
||||||
d.x = (d.x * horizontalStep * addition) / UNITS_PER_SQUARE;
|
d.x = (d.x * horizontalStep * addition) / UNITS_PER_SQUARE;
|
||||||
|
|
|
@ -168,6 +168,7 @@ class Player
|
||||||
public:
|
public:
|
||||||
Camera mCamera;
|
Camera mCamera;
|
||||||
Unit mVericalSpeed;
|
Unit mVericalSpeed;
|
||||||
|
bool mRunning;
|
||||||
|
|
||||||
Player()
|
Player()
|
||||||
{
|
{
|
||||||
|
@ -179,6 +180,7 @@ public:
|
||||||
mCamera.resolution.y = SCREEN_HEIGHT;
|
mCamera.resolution.y = SCREEN_HEIGHT;
|
||||||
mCamera.shear = 0;
|
mCamera.shear = 0;
|
||||||
mVericalSpeed = 0;
|
mVericalSpeed = 0;
|
||||||
|
mRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPosition(Unit x, Unit y)
|
void setPosition(Unit x, Unit y)
|
||||||
|
|
Loading…
Reference in a new issue