From cf475ed0aa31042308e533720909779fb1bd7f19 Mon Sep 17 00:00:00 2001 From: Hyper_ Date: Thu, 30 Jan 2025 14:15:05 -0300 Subject: [PATCH] fix: Add pause/resume handling to Limo Ride "fast car" (both variations) --- preload/scripts/stages/limoRide.hxc | 32 ++++++++++++++++++----- preload/scripts/stages/limoRideErect.hxc | 33 +++++++++++++++++------- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/preload/scripts/stages/limoRide.hxc b/preload/scripts/stages/limoRide.hxc index 933eba84d..e8e8f1994 100644 --- a/preload/scripts/stages/limoRide.hxc +++ b/preload/scripts/stages/limoRide.hxc @@ -13,7 +13,7 @@ class LimoRideStage extends Stage super('limoRide'); } - function buildStage() + override function buildStage() { super.buildStage(); @@ -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. @@ -48,6 +49,8 @@ class LimoRideStage extends Stage } var fastCarCanDrive:Bool = false; + var fastCarTimer:FlxTimer; + var fastCarSound:FunkinSound; function resetFastCar():Void { @@ -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(); }); @@ -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 + override function fetchAssetPaths():Array { var results:Array = super.fetchAssetPaths(); @@ -98,7 +102,7 @@ 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(); } @@ -106,8 +110,22 @@ class LimoRideStage 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(); + } } diff --git a/preload/scripts/stages/limoRideErect.hxc b/preload/scripts/stages/limoRideErect.hxc index bc54e08b5..b1e86e6cf 100644 --- a/preload/scripts/stages/limoRideErect.hxc +++ b/preload/scripts/stages/limoRideErect.hxc @@ -25,7 +25,7 @@ class LimoRideErectStage extends Stage var shootingStarBeat:Int = 0; var shootingStarOffset:Int = 2; - function buildStage() + override function buildStage() { super.buildStage(); @@ -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); @@ -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. @@ -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(); }); @@ -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 + override function fetchAssetPaths():Array { var results:Array = super.fetchAssetPaths(); @@ -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; @@ -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(); + } }