From d80587004c297c2f01feb3e3a543d985ac4437c0 Mon Sep 17 00:00:00 2001 From: Hyper_ Date: Wed, 29 Jan 2025 17:56:14 -0300 Subject: [PATCH] fix: Add pause/resume handling to Limo Ride "fast car" (both variations) --- preload/scripts/stages/limoRide.hxc | 228 +++++++------ preload/scripts/stages/limoRideErect.hxc | 416 ++++++++++++----------- 2 files changed, 345 insertions(+), 299 deletions(-) diff --git a/preload/scripts/stages/limoRide.hxc b/preload/scripts/stages/limoRide.hxc index 933eba84d..5d44d00c4 100644 --- a/preload/scripts/stages/limoRide.hxc +++ b/preload/scripts/stages/limoRide.hxc @@ -8,106 +8,130 @@ import funkin.graphics.shaders.OverlayBlend; class LimoRideStage extends Stage { - function new() - { - super('limoRide'); - } - - function buildStage() - { - super.buildStage(); - - // Apply sky shader. - var skyOverlay:OverlayBlend = new OverlayBlend(); - var sunOverlay:FlxSprite = new FlxSprite().loadGraphic(Paths.image('limo/limoOverlay')); - sunOverlay.setGraphicSize(Std.int(sunOverlay.width * 2)); - sunOverlay.updateHitbox(); - skyOverlay.funnyShit.input = sunOverlay.pixels; - var limoSunset:FlxSprite = getNamedProp('limoSunset'); - if (limoSunset == null) { - trace('[WARN] Could not retrieve limoSunset'); - } else { - limoSunset.shader = skyOverlay; - } - - // There's some commented-out shader BS in the original code. - // 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. - - resetFastCar(); - } - - function onBeatHit(event:SongTimeScriptEvent) - { - // When overriding onBeatHit, make sure to call super.onBeatHit, - // otherwise boppers will not work. - super.onBeatHit(event); - - if (FlxG.random.bool(10) && fastCarCanDrive) - fastCarDrive(); - } - - var fastCarCanDrive:Bool = false; - - function resetFastCar():Void - { - var fastCar = getNamedProp('fastCar'); - - if (fastCar == null) - return; - - // Props are inactive by default. - // Set active to true so position is calculated based on velocity. - fastCar.active = true; - - fastCar.x = -12600; - fastCar.y = FlxG.random.int(140, 250); - fastCar.velocity.x = 0; - fastCarCanDrive = true; - } - - function fastCarDrive():Void - { - 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) - { - resetFastCar(); - }); - } - - /** - * 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 - { - var results:Array = super.fetchAssetPaths(); - - // This graphic is applied by shader to the background, so it's not included in the default stage function. - results.push(Paths.image('limo/limoOverlay')); - results.push(Paths.sound('carPass0')); - results.push(Paths.sound('carPass1')); - - return results; - } - - /** - * Make sure the fast car is reset when the song restarts. - */ - function onSongRetry(event:ScriptEvent) { - super.onSongRetry(event); - resetFastCar(); - } - - /** - * Make sure the fast car is reset when the song restarts. - */ - function onCountdownStart(event:ScriptEvent) { - super.onCountdownStart(event); - resetFastCar(); - } + function new() + { + super('limoRide'); + } + + override function buildStage() + { + super.buildStage(); + + // Apply sky shader. + var skyOverlay:OverlayBlend = new OverlayBlend(); + var sunOverlay:FlxSprite = new FlxSprite().loadGraphic(Paths.image('limo/limoOverlay')); + sunOverlay.setGraphicSize(Std.int(sunOverlay.width * 2)); + sunOverlay.updateHitbox(); + skyOverlay.funnyShit.input = sunOverlay.pixels; + var limoSunset:FlxSprite = getNamedProp('limoSunset'); + if (limoSunset == null) + { + trace('[WARN] Could not retrieve limoSunset'); + } + else + { + limoSunset.shader = skyOverlay; + } + + // There's some commented-out shader BS in the original code. + // 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(); + } + + override function onBeatHit(event:SongTimeScriptEvent) + { + // When overriding onBeatHit, make sure to call super.onBeatHit, + // otherwise boppers will not work. + super.onBeatHit(event); + + if (FlxG.random.bool(10) && fastCarCanDrive) + fastCarDrive(); + } + + var fastCarCanDrive:Bool = false; + var fastCarSound:FunkinSound; + var fastCarTimer:FlxTimer; + + function resetFastCar():Void + { + var fastCar = getNamedProp('fastCar'); + + if (fastCar == null) + return; + + // Props are inactive by default. + // Set active to true so position is calculated based on velocity. + fastCar.active = true; + + fastCar.x = -12600; + fastCar.y = FlxG.random.int(140, 250); + fastCar.velocity.x = 0; + fastCarCanDrive = true; + } + + function fastCarDrive():Void + { + 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; + fastCarTimer.start(2, function(tmr:FlxTimer) { + resetFastCar(); + fastCarSound = null; + }); + } + + /** + * 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. + */ + override function fetchAssetPaths():Array + { + var results:Array = super.fetchAssetPaths(); + + // This graphic is applied by shader to the background, so it's not included in the default stage function. + results.push(Paths.image('limo/limoOverlay')); + results.push(Paths.sound('carPass0')); + results.push(Paths.sound('carPass1')); + + return results; + } + + /** + * Make sure the fast car is reset when the song restarts. + */ + override function onSongRetry(event:ScriptEvent) + { + super.onSongRetry(event); + resetFastCar(); + } + + /** + * Make sure the fast car is reset when the song restarts. + */ + 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..65e8fdf01 100644 --- a/preload/scripts/stages/limoRideErect.hxc +++ b/preload/scripts/stages/limoRideErect.hxc @@ -10,121 +10,124 @@ import flixel.addons.display.FlxBackdrop; class LimoRideErectStage extends Stage { - function new() - { - super('limoRideErect'); - } + function new() + { + super('limoRideErect'); + } var colorShader:AdjustColorShader; - var mist1:FlxBackdrop; - var mist2:FlxBackdrop; - var mist3:FlxBackdrop; - var mist4:FlxBackdrop; - var mist5:FlxBackdrop; - - var shootingStarBeat:Int = 0; - var shootingStarOffset:Int = 2; - - function buildStage() - { - super.buildStage(); - - // Apply sky shader. - var skyOverlay:OverlayBlend = new OverlayBlend(); - var sunOverlay:FlxSprite = new FlxSprite().loadGraphic(Paths.image('limo/limoOverlay')); - sunOverlay.setGraphicSize(Std.int(sunOverlay.width * 2)); - sunOverlay.updateHitbox(); - skyOverlay.funnyShit.input = sunOverlay.pixels; - var limoSunset:FlxSprite = getNamedProp('limoSunset'); - if (limoSunset == null) { - trace('[WARN] Could not retrieve limoSunset'); - } else { - //limoSunset.shader = skyOverlay; - } - - // There's some commented-out shader BS in the original code. - // 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. + var mist1:FlxBackdrop; + var mist2:FlxBackdrop; + var mist3:FlxBackdrop; + var mist4:FlxBackdrop; + var mist5:FlxBackdrop; + + var shootingStarBeat:Int = 0; + var shootingStarOffset:Int = 2; + + override function buildStage() + { + super.buildStage(); + + // Apply sky shader. + var skyOverlay:OverlayBlend = new OverlayBlend(); + var sunOverlay:FlxSprite = new FlxSprite().loadGraphic(Paths.image('limo/limoOverlay')); + sunOverlay.setGraphicSize(Std.int(sunOverlay.width * 2)); + sunOverlay.updateHitbox(); + skyOverlay.funnyShit.input = sunOverlay.pixels; + var limoSunset:FlxSprite = getNamedProp('limoSunset'); + if (limoSunset == null) + { + trace('[WARN] Could not retrieve limoSunset'); + } + else + { + // limoSunset.shader = skyOverlay; + } + + // There's some commented-out shader BS in the original code. + // 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. colorShader = new AdjustColorShader(); mist1 = new FlxBackdrop(Paths.image('limo/erect/mistMid'), 0x01); - mist1.setPosition(-650, -100); - mist1.scrollFactor.set(1.1, 1.1); - mist1.zIndex = 400; + mist1.setPosition(-650, -100); + mist1.scrollFactor.set(1.1, 1.1); + mist1.zIndex = 400; mist1.blend = 0; - mist1.color = 0xFFc6bfde; - mist1.alpha = 0.4; - mist1.velocity.x = 1700; + mist1.color = 0xFFc6bfde; + mist1.alpha = 0.4; + mist1.velocity.x = 1700; - PlayState.instance.currentStage.add(mist1); - PlayState.instance.currentStage.refresh(); // Apply z-index. + PlayState.instance.currentStage.add(mist1); + PlayState.instance.currentStage.refresh(); // Apply z-index. - mist2 = new FlxBackdrop(Paths.image('limo/erect/mistBack'), 0x01); - mist2.setPosition(-650, -100); - mist2.scrollFactor.set(1.2, 1.2); - mist2.zIndex = 401; + mist2 = new FlxBackdrop(Paths.image('limo/erect/mistBack'), 0x01); + mist2.setPosition(-650, -100); + mist2.scrollFactor.set(1.2, 1.2); + mist2.zIndex = 401; mist2.blend = 0; - mist2.color = 0xFF6a4da1; - mist2.alpha = 1; - mist2.velocity.x = 2100; - mist1.scale.set(1.3, 1.3); - - PlayState.instance.currentStage.add(mist2); - PlayState.instance.currentStage.refresh(); // Apply z-index. - - mist3 = new FlxBackdrop(Paths.image('limo/erect/mistMid'), 0x01); - mist3.setPosition(-650, -100); - mist3.scrollFactor.set(0.8, 0.8); - mist3.zIndex = 99; - mist3.blend = 0; - mist3.color = 0xFFa7d9be; - mist3.alpha = 0.5; - mist3.velocity.x = 900; - mist3.scale.set(1.5, 1.5); - - PlayState.instance.currentStage.add(mist3); - PlayState.instance.currentStage.refresh(); // Apply z-index. - - - mist4 = new FlxBackdrop(Paths.image('limo/erect/mistBack'), 0x01); - mist4.setPosition(-650, -380); - mist4.scrollFactor.set(0.6, 0.6); - mist4.zIndex = 98; + mist2.color = 0xFF6a4da1; + mist2.alpha = 1; + mist2.velocity.x = 2100; + mist1.scale.set(1.3, 1.3); + + PlayState.instance.currentStage.add(mist2); + PlayState.instance.currentStage.refresh(); // Apply z-index. + + mist3 = new FlxBackdrop(Paths.image('limo/erect/mistMid'), 0x01); + mist3.setPosition(-650, -100); + mist3.scrollFactor.set(0.8, 0.8); + mist3.zIndex = 99; + mist3.blend = 0; + mist3.color = 0xFFa7d9be; + mist3.alpha = 0.5; + mist3.velocity.x = 900; + mist3.scale.set(1.5, 1.5); + + PlayState.instance.currentStage.add(mist3); + PlayState.instance.currentStage.refresh(); // Apply z-index. + + mist4 = new FlxBackdrop(Paths.image('limo/erect/mistBack'), 0x01); + mist4.setPosition(-650, -380); + mist4.scrollFactor.set(0.6, 0.6); + mist4.zIndex = 98; mist4.blend = 0; - mist4.color = 0xFF9c77c7; - mist4.alpha = 1; - mist4.velocity.x = 700; - mist4.scale.set(1.5, 1.5); - - PlayState.instance.currentStage.add(mist4); - PlayState.instance.currentStage.refresh(); // Apply z-index. - - mist5 = new FlxBackdrop(Paths.image('limo/erect/mistMid'), 0x01); - mist5.setPosition(-650, -400); - mist5.scrollFactor.set(0.2, 0.2); - mist5.zIndex = 15; - mist5.blend = 0; - mist5.color = 0xFFE7A480; - mist5.alpha = 1; - mist5.velocity.x = 100; - mist5.scale.set(1.5, 1.5); - - PlayState.instance.currentStage.add(mist5); - PlayState.instance.currentStage.refresh(); // Apply z-index. - - getNamedProp('shootingStar').blend = 0; - - resetFastCar(); - } + mist4.color = 0xFF9c77c7; + mist4.alpha = 1; + mist4.velocity.x = 700; + mist4.scale.set(1.5, 1.5); + + PlayState.instance.currentStage.add(mist4); + PlayState.instance.currentStage.refresh(); // Apply z-index. + + mist5 = new FlxBackdrop(Paths.image('limo/erect/mistMid'), 0x01); + mist5.setPosition(-650, -400); + mist5.scrollFactor.set(0.2, 0.2); + mist5.zIndex = 15; + mist5.blend = 0; + mist5.color = 0xFFE7A480; + mist5.alpha = 1; + mist5.velocity.x = 100; + mist5.scale.set(1.5, 1.5); + + PlayState.instance.currentStage.add(mist5); + PlayState.instance.currentStage.refresh(); // Apply z-index. + + getNamedProp('shootingStar').blend = 0; + + fastCarTimer = new FlxTimer(); + resetFastCar(); + } - var _timer:Float = 0; + var _timer:Float = 0; - function onUpdate(event:UpdateScriptEvent):Void - { - super.onUpdate(event); + override function onUpdate(event:UpdateScriptEvent):Void + { + super.onUpdate(event); - _timer += event.elapsed; + _timer += event.elapsed; mist1.y = 100 + (Math.sin(_timer)*200); mist2.y = 0 + (Math.sin(_timer*0.8)*100); mist3.y = -20 + (Math.sin(_timer*0.5)*200); @@ -134,126 +137,145 @@ class LimoRideErectStage extends Stage if(PlayState.instance.currentStage.getBoyfriend() != null && PlayState.instance.currentStage.getBoyfriend().shader == null){ PlayState.instance.currentStage.getBoyfriend().shader = colorShader; - PlayState.instance.currentStage.getGirlfriend().shader = colorShader; - PlayState.instance.currentStage.getDad().shader = colorShader; - getNamedProp('limoDancer1').shader = colorShader; + PlayState.instance.currentStage.getGirlfriend().shader = colorShader; + PlayState.instance.currentStage.getDad().shader = colorShader; + getNamedProp('limoDancer1').shader = colorShader; getNamedProp('limoDancer2').shader = colorShader; - getNamedProp('limoDancer3').shader = colorShader; + getNamedProp('limoDancer3').shader = colorShader; getNamedProp('limoDancer4').shader = colorShader; getNamedProp('limoDancer5').shader = colorShader; getNamedProp('fastCar').shader = colorShader; - // PlayState.instance.currentStage.getBoyfriend().visible = false; - // PlayState.instance.currentStage.getGirlfriend().visible = false; - // PlayState.instance.currentStage.getDad().visible = false; - // getNamedProp('limo').visible = false; - // getNamedProp('limoDancer1').visible = false; + // PlayState.instance.currentStage.getBoyfriend().visible = false; + // PlayState.instance.currentStage.getGirlfriend().visible = false; + // PlayState.instance.currentStage.getDad().visible = false; + // getNamedProp('limo').visible = false; + // getNamedProp('limoDancer1').visible = false; // getNamedProp('limoDancer2').visible = false; - // getNamedProp('limoDancer3').visible = false; + // getNamedProp('limoDancer3').visible = false; // getNamedProp('limoDancer4').visible = false; // getNamedProp('limoDancer5').visible = false; // getNamedProp('fastCar').visible = false; - // getNamedProp('bgLimo').visible = false; - // getNamedProp('limoSunset').visible = false; - // getNamedProp('shootingStar').visible = false; - - colorShader.hue = -30; - colorShader.saturation = -20; - colorShader.contrast = 0; - colorShader.brightness = -30; + // getNamedProp('bgLimo').visible = false; + // getNamedProp('limoSunset').visible = false; + // getNamedProp('shootingStar').visible = false; + + colorShader.hue = -30; + colorShader.saturation = -20; + colorShader.contrast = 0; + colorShader.brightness = -30; } } - function doShootingStar(beat:Int):Void - { + function doShootingStar(beat:Int):Void + { getNamedProp('shootingStar').x = FlxG.random.int(50,900); getNamedProp('shootingStar').y = FlxG.random.int(-10,20); - getNamedProp('shootingStar').flipX = FlxG.random.bool(50); - getNamedProp('shootingStar').animation.play('shooting star'); + getNamedProp('shootingStar').flipX = FlxG.random.bool(50); + getNamedProp('shootingStar').animation.play('shooting star'); - shootingStarBeat = beat; - shootingStarOffset = FlxG.random.int(4, 8); - - } + shootingStarBeat = beat; + shootingStarOffset = FlxG.random.int(4, 8); + } - function onBeatHit(event:SongTimeScriptEvent) - { - // When overriding onBeatHit, make sure to call super.onBeatHit, - // otherwise boppers will not work. - super.onBeatHit(event); + override function onBeatHit(event:SongTimeScriptEvent) + { + // When overriding onBeatHit, make sure to call super.onBeatHit, + // otherwise boppers will not work. + super.onBeatHit(event); if (FlxG.random.bool(10) && fastCarCanDrive) fastCarDrive(); - if (FlxG.random.bool(10) && event.beat > (shootingStarBeat + shootingStarOffset)) - { - doShootingStar(event.beat); - } - } + if (FlxG.random.bool(10) && event.beat > (shootingStarBeat + shootingStarOffset)) + { + doShootingStar(event.beat); + } + } - var fastCarCanDrive:Bool = false; + var fastCarCanDrive:Bool = false; + var fastCarSound:FunkinSound; + var fastCarTimer:FlxTimer; - function resetFastCar():Void - { - var fastCar = getNamedProp('fastCar'); + function resetFastCar():Void + { + var fastCar = getNamedProp('fastCar'); if (fastCar == null) return; - // Props are inactive by default. - // Set active to true so position is calculated based on velocity. - fastCar.active = true; - - fastCar.x = -12600; - fastCar.y = FlxG.random.int(140, 250); - fastCar.velocity.x = 0; - fastCarCanDrive = true; - } - - function fastCarDrive():Void - { - 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) - { - resetFastCar(); - }); - } - - /** - * 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 - { - var results:Array = super.fetchAssetPaths(); - - // This graphic is applied by shader to the background, so it's not included in the default stage function. - results.push(Paths.image('limo/limoOverlay')); - results.push(Paths.sound('carPass0')); - results.push(Paths.sound('carPass1')); - - return results; - } - - /** - * Make sure the fast car is reset when the song restarts. - */ - function onSongRetry(event:ScriptEvent) { - super.onSongRetry(event); - resetFastCar(); - shootingStarBeat = 0; - shootingStarOffset = 2; - } - - /** - * Make sure the fast car is reset when the song restarts. - */ - function onCountdownStart(event:ScriptEvent) { - super.onCountdownStart(event); - resetFastCar(); - } + // Props are inactive by default. + // Set active to true so position is calculated based on velocity. + fastCar.active = true; + + fastCar.x = -12600; + fastCar.y = FlxG.random.int(140, 250); + fastCar.velocity.x = 0; + fastCarCanDrive = true; + } + + function fastCarDrive():Void + { + 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; + fastCarTimer.start(2, function(tmr:FlxTimer) { + resetFastCar(); + fastCarSound = null; + }); + } + + /** + * 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. + */ + override function fetchAssetPaths():Array + { + var results:Array = super.fetchAssetPaths(); + + // This graphic is applied by shader to the background, so it's not included in the default stage function. + results.push(Paths.image('limo/limoOverlay')); + results.push(Paths.sound('carPass0')); + results.push(Paths.sound('carPass1')); + + return results; + } + + /** + * Make sure the fast car is reset when the song restarts. + */ + override function onSongRetry(event:ScriptEvent) + { + super.onSongRetry(event); + resetFastCar(); + shootingStarBeat = 0; + shootingStarOffset = 2; + } + + /** + * Make sure the fast car is reset when the song restarts. + */ + 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(); + } }