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 29, 2025
1 parent c1899ff commit d805870
Show file tree
Hide file tree
Showing 2 changed files with 345 additions and 299 deletions.
228 changes: 126 additions & 102 deletions preload/scripts/stages/limoRide.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
{
var results:Array<String> = 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<String>
{
var results:Array<String> = 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();
}
}
Loading

0 comments on commit d805870

Please sign in to comment.