ambitious-knife-25690
03/02/2023, 7:53 PMtall-teacher-57409
03/02/2023, 7:53 PMenough-traffic-32226
03/02/2023, 7:53 PMenough-traffic-32226
03/02/2023, 7:56 PMtall-teacher-57409
03/02/2023, 7:58 PMambitious-knife-25690
03/02/2023, 7:59 PMambitious-knife-25690
03/02/2023, 7:59 PMenough-traffic-32226
03/02/2023, 8:00 PMtall-teacher-57409
03/02/2023, 8:00 PMtall-teacher-57409
03/02/2023, 8:00 PMtall-teacher-57409
03/02/2023, 8:00 PMambitious-knife-25690
03/02/2023, 8:01 PMambitious-knife-25690
03/02/2023, 8:01 PMambitious-knife-25690
03/02/2023, 8:01 PMenough-traffic-32226
03/02/2023, 8:02 PMenough-traffic-32226
03/02/2023, 8:03 PMtall-teacher-57409
03/02/2023, 8:03 PMtall-teacher-57409
03/02/2023, 8:03 PMwitty-island-52596
03/02/2023, 8:03 PMwitty-island-52596
03/02/2023, 8:04 PMenough-traffic-32226
03/02/2023, 8:06 PMhx
if (FlxG.keys.anyPressed([SHIFT, CONTROL]))
{
if (playerRunning == false)
{
playerRunning = true;
speedTween.cancel();
maxVelocity.set(180, JUMP_SPEED);
trace('running');
}
}
else if (playerRunning == true)
{
playerRunning = false;
speedTween();
trace('no longer running');
}enough-traffic-32226
03/02/2023, 8:07 PMhx
var speedTween:FlxTween;
//pretend the new function is here
speedTween = FlxTween.tween(maxVelocity, {x: 90}, 0.75);witty-island-52596
03/02/2023, 8:13 PMhx
inline static var RUN_SPEED = 180;
inline static var WALK_SPEED = 90;
/** the time it takes to increase maxspeed to run speed */
inline static var SPEED_UP_TIME = 0.5;//seconds
/** the amount max speed increases by each second when holding run */
inline static var SPEED_INCREASE = (RUN_SPEED - WALK_SPEED) / SPEED_UP_TIME;
...elsewhere...
hx
// in update(elapsed:Float)
var runPressed = FlxG.keys.pressed([SHIFT, CONTROL]);
if (runPressed && maxVelocity.x < RUN_SPEED)
{
// increase max speed
maxVelocity.x += SPEED_INCREASE * elapsed;
// prevent it from going too high
if (maxVelocity.x > RUN_SPEED)
maxVelocity.x = RUN_SPEED;
}
else if (runPressed == false && maxVelocity.x > WALK_SPEED)
{
// decrease max speed
maxVelocity.x = SPEED_INCREASE * elapsed;
// prevent it from going too low
if (maxVelocity.x < WALK_SPEED)
maxVelocity.x = WALK_SPEED;
}witty-island-52596
03/02/2023, 8:13 PMwitty-island-52596
03/02/2023, 8:13 PMwitty-island-52596
03/02/2023, 8:14 PMambitious-knife-25690
03/02/2023, 8:14 PMelegant-twilight-61392
03/02/2023, 8:20 PMenough-traffic-32226
03/02/2023, 8:20 PMelegant-twilight-61392
03/02/2023, 8:20 PM