Skip to content

Commit

Permalink
fix: Add pause/resume handling to Limo Ride "fast car" (both variations)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotHyper-474 committed Jan 30, 2025
1 parent c1899ff commit cf475ed
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
32 changes: 25 additions & 7 deletions preload/scripts/stages/limoRide.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LimoRideStage extends Stage
super('limoRide');
}

function buildStage()
override function buildStage()
{
super.buildStage();

Expand All @@ -34,10 +34,11 @@ class LimoRideStage extends Stage
// I don't know what it's for, but it's not used in the game.
// If you want to re-add it, go find it in version control.

fastCarTimer = new FlxTimer();
resetFastCar();
}

function onBeatHit(event:SongTimeScriptEvent)
override function onBeatHit(event:SongTimeScriptEvent)
{
// When overriding onBeatHit, make sure to call super.onBeatHit,
// otherwise boppers will not work.
Expand All @@ -48,6 +49,8 @@ class LimoRideStage extends Stage
}

var fastCarCanDrive:Bool = false;
var fastCarTimer:FlxTimer;
var fastCarSound:FunkinSound;

function resetFastCar():Void
{
Expand All @@ -64,16 +67,17 @@ class LimoRideStage extends Stage
fastCar.y = FlxG.random.int(140, 250);
fastCar.velocity.x = 0;
fastCarCanDrive = true;
fastCarSound = null;
}

function fastCarDrive():Void
{
FunkinSound.playOnce(Paths.soundRandom('carPass', 0, 1), 0.7);
fastCarSound = FunkinSound.playOnce(Paths.soundRandom('carPass', 0, 1), 0.7);

var fastCar = getNamedProp('fastCar');
fastCar.velocity.x = (FlxG.random.int(170, 220) / FlxG.elapsed) * 3;
fastCarCanDrive = false;
new FlxTimer().start(2, function(tmr:FlxTimer)
fastCarTimer.start(2, function(tmr:FlxTimer)
{
resetFastCar();
});
Expand All @@ -83,7 +87,7 @@ class LimoRideStage extends Stage
* If your stage uses additional assets not specified in the JSON,
* make sure to specify them like this, or they won't get cached in the loading screen.
*/
function fetchAssetPaths():Array<String>
override function fetchAssetPaths():Array<String>
{
var results:Array<String> = super.fetchAssetPaths();

Expand All @@ -98,16 +102,30 @@ class LimoRideStage extends Stage
/**
* Make sure the fast car is reset when the song restarts.
*/
function onSongRetry(event:ScriptEvent) {
override function onSongRetry(event:ScriptEvent) {
super.onSongRetry(event);
resetFastCar();
}

/**
* Make sure the fast car is reset when the song restarts.
*/
function onCountdownStart(event:ScriptEvent) {
override function onCountdownStart(event:ScriptEvent) {
super.onCountdownStart(event);
resetFastCar();
}

override function onPause(event:PauseScriptEvent) {
super.onPause(event);

if (fastCarTimer != null) fastCarTimer.active = false;
if (fastCarSound != null) fastCarSound.pause();
}

override function onResume(event:ScriptEvent) {
super.onResume(event);

if (fastCarTimer != null) fastCarTimer.active = true;
if (fastCarSound != null) fastCarSound.resume();
}
}
33 changes: 24 additions & 9 deletions preload/scripts/stages/limoRideErect.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LimoRideErectStage extends Stage
var shootingStarBeat:Int = 0;
var shootingStarOffset:Int = 2;

function buildStage()
override function buildStage()
{
super.buildStage();

Expand Down Expand Up @@ -115,12 +115,13 @@ class LimoRideErectStage extends Stage

getNamedProp('shootingStar').blend = 0;

fastCarTimer = new FlxTimer();
resetFastCar();
}

var _timer:Float = 0;

function onUpdate(event:UpdateScriptEvent):Void
override function onUpdate(event:UpdateScriptEvent):Void
{
super.onUpdate(event);

Expand Down Expand Up @@ -173,10 +174,9 @@ class LimoRideErectStage extends Stage

shootingStarBeat = beat;
shootingStarOffset = FlxG.random.int(4, 8);

}

function onBeatHit(event:SongTimeScriptEvent)
override function onBeatHit(event:SongTimeScriptEvent)
{
// When overriding onBeatHit, make sure to call super.onBeatHit,
// otherwise boppers will not work.
Expand Down Expand Up @@ -208,16 +208,17 @@ class LimoRideErectStage extends Stage
fastCar.y = FlxG.random.int(140, 250);
fastCar.velocity.x = 0;
fastCarCanDrive = true;
fastCarSound = null;
}

function fastCarDrive():Void
{
FunkinSound.playOnce(Paths.soundRandom('carPass', 0, 1), 0.7);
fastCarSound = FunkinSound.playOnce(Paths.soundRandom('carPass', 0, 1), 0.7);

var fastCar = getNamedProp('fastCar');
fastCar.velocity.x = (FlxG.random.int(170, 220) / FlxG.elapsed) * 3;
fastCarCanDrive = false;
new FlxTimer().start(2, function(tmr:FlxTimer)
fastCarTimer.start(2, function(tmr:FlxTimer)
{
resetFastCar();
});
Expand All @@ -227,7 +228,7 @@ class LimoRideErectStage extends Stage
* If your stage uses additional assets not specified in the JSON,
* make sure to specify them like this, or they won't get cached in the loading screen.
*/
function fetchAssetPaths():Array<String>
override function fetchAssetPaths():Array<String>
{
var results:Array<String> = super.fetchAssetPaths();

Expand All @@ -242,7 +243,7 @@ class LimoRideErectStage extends Stage
/**
* Make sure the fast car is reset when the song restarts.
*/
function onSongRetry(event:ScriptEvent) {
override function onSongRetry(event:ScriptEvent) {
super.onSongRetry(event);
resetFastCar();
shootingStarBeat = 0;
Expand All @@ -252,8 +253,22 @@ class LimoRideErectStage extends Stage
/**
* Make sure the fast car is reset when the song restarts.
*/
function onCountdownStart(event:ScriptEvent) {
override function onCountdownStart(event:ScriptEvent) {
super.onCountdownStart(event);
resetFastCar();
}

override function onPause(event:PauseScriptEvent) {
super.onPause(event);

if (fastCarTimer != null) fastCarTimer.active = false;
if (fastCarSound != null) fastCarSound.pause();
}

override function onResume(event:ScriptEvent) {
super.onResume(event);

if (fastCarTimer != null) fastCarTimer.active = true;
if (fastCarSound != null) fastCarSound.resume();
}
}

0 comments on commit cf475ed

Please sign in to comment.