2022-07-22 22:25:19 -04:00
|
|
|
package funkin.play;
|
2020-10-27 06:35:23 -04:00
|
|
|
|
2023-05-31 03:03:10 -04:00
|
|
|
import flixel.FlxG;
|
2020-10-27 06:35:23 -04:00
|
|
|
import flixel.FlxObject;
|
2022-08-16 20:26:34 -04:00
|
|
|
import flixel.FlxSprite;
|
2024-03-16 00:55:57 -04:00
|
|
|
import flixel.input.touch.FlxTouch;
|
2020-10-28 03:03:32 -04:00
|
|
|
import flixel.util.FlxColor;
|
|
|
|
import flixel.util.FlxTimer;
|
2024-03-16 00:55:57 -04:00
|
|
|
import funkin.audio.FunkinSound;
|
2024-01-16 16:49:15 -05:00
|
|
|
import funkin.graphics.FunkinSprite;
|
2022-04-18 20:39:41 -04:00
|
|
|
import funkin.modding.events.ScriptEvent;
|
|
|
|
import funkin.modding.events.ScriptEventDispatcher;
|
2024-02-15 17:25:28 -05:00
|
|
|
import funkin.play.character.BaseCharacter;
|
2023-11-07 04:04:22 -05:00
|
|
|
import funkin.ui.freeplay.FreeplayState;
|
2024-02-15 17:25:28 -05:00
|
|
|
import funkin.ui.MusicBeatSubState;
|
|
|
|
import funkin.ui.story.StoryMenuState;
|
2024-03-16 00:55:57 -04:00
|
|
|
import funkin.util.MathUtil;
|
2024-02-15 17:25:28 -05:00
|
|
|
import openfl.utils.Assets;
|
2020-10-27 06:35:23 -04:00
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
/**
|
|
|
|
* A substate which renders over the PlayState when the player dies.
|
|
|
|
* Displays the player death animation, plays the music, and handles restarting the song.
|
2023-06-08 16:30:45 -04:00
|
|
|
*
|
2022-03-21 00:19:05 -04:00
|
|
|
* The newest implementation uses a substate, which prevents having to reload the song and stage each reset.
|
|
|
|
*/
|
2024-03-16 00:55:57 -04:00
|
|
|
@:nullSafety
|
2023-06-01 18:52:58 -04:00
|
|
|
class GameOverSubState extends MusicBeatSubState
|
2020-10-27 06:35:23 -04:00
|
|
|
{
|
2024-01-17 23:14:28 -05:00
|
|
|
/**
|
|
|
|
* The currently active GameOverSubState.
|
|
|
|
* There should be only one GameOverSubState in existance at a time, we can use a singleton.
|
|
|
|
*/
|
2024-03-16 00:55:57 -04:00
|
|
|
public static var instance:Null<GameOverSubState> = null;
|
2024-01-17 23:14:28 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
/**
|
|
|
|
* Which alternate animation on the character to use.
|
|
|
|
* You can set this via script.
|
|
|
|
* For example, playing a different animation when BF dies in Week 4
|
|
|
|
* or Pico dies in Weekend 1.
|
|
|
|
*/
|
2024-03-16 00:55:57 -04:00
|
|
|
public static var animationSuffix:String = '';
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Which alternate game over music to use.
|
|
|
|
* You can set this via script.
|
|
|
|
* For example, the bf-pixel script sets this to `-pixel`
|
|
|
|
* and the pico-playable script sets this to `Pico`.
|
|
|
|
*/
|
2024-03-16 00:55:57 -04:00
|
|
|
public static var musicSuffix:String = '';
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Which alternate "blue ball" sound effect to use.
|
|
|
|
*/
|
2024-03-16 00:55:57 -04:00
|
|
|
public static var blueBallSuffix:String = '';
|
|
|
|
|
|
|
|
static var blueballed:Bool = false;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The boyfriend character.
|
|
|
|
*/
|
2024-03-16 00:55:57 -04:00
|
|
|
var boyfriend:Null<BaseCharacter> = null;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The invisible object in the scene which the camera focuses on.
|
|
|
|
*/
|
|
|
|
var cameraFollowPoint:FlxObject;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The music playing in the background of the state.
|
|
|
|
*/
|
2024-02-18 03:02:36 -05:00
|
|
|
var gameOverMusic:Null<FunkinSound> = null;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the player has confirmed and prepared to restart the level.
|
|
|
|
* This means the animation and transition have already started.
|
|
|
|
*/
|
|
|
|
var isEnding:Bool = false;
|
|
|
|
|
2024-02-18 03:02:36 -05:00
|
|
|
/**
|
|
|
|
* Whether the death music is on its first loop.
|
|
|
|
*/
|
|
|
|
var isStarting:Bool = true;
|
|
|
|
|
2023-12-19 01:27:58 -05:00
|
|
|
var isChartingMode:Bool = false;
|
|
|
|
|
2024-05-07 14:01:00 -04:00
|
|
|
var mustNotExit:Bool = false;
|
|
|
|
|
2023-12-19 01:57:39 -05:00
|
|
|
var transparent:Bool;
|
|
|
|
|
2024-03-16 00:55:57 -04:00
|
|
|
static final CAMERA_ZOOM_DURATION:Float = 0.5;
|
|
|
|
|
2024-03-01 08:13:06 -05:00
|
|
|
var targetCameraZoom:Float = 1.0;
|
|
|
|
|
2023-12-19 01:57:39 -05:00
|
|
|
public function new(params:GameOverParams)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
super();
|
2023-12-19 01:27:58 -05:00
|
|
|
|
|
|
|
this.isChartingMode = params?.isChartingMode ?? false;
|
2023-12-19 01:57:39 -05:00
|
|
|
transparent = params.transparent;
|
2024-03-16 00:55:57 -04:00
|
|
|
|
|
|
|
cameraFollowPoint = new FlxObject(PlayState.instance.cameraFollowPoint.x, PlayState.instance.cameraFollowPoint.y, 1, 1);
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the game over configuration to the default.
|
|
|
|
*/
|
2024-03-16 00:55:57 -04:00
|
|
|
public static function reset():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2024-03-16 00:55:57 -04:00
|
|
|
animationSuffix = '';
|
|
|
|
musicSuffix = '';
|
|
|
|
blueBallSuffix = '';
|
|
|
|
blueballed = false;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
2024-03-16 00:55:57 -04:00
|
|
|
public override function create():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2024-01-17 23:14:28 -05:00
|
|
|
if (instance != null)
|
|
|
|
{
|
|
|
|
// TODO: Do something in this case? IDK.
|
2024-03-16 00:55:57 -04:00
|
|
|
FlxG.log.warn('WARNING: GameOverSubState instance already exists. This should not happen.');
|
2024-01-17 23:14:28 -05:00
|
|
|
}
|
|
|
|
instance = this;
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
super.create();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set up the visuals
|
|
|
|
//
|
|
|
|
|
2024-03-10 19:35:41 -04:00
|
|
|
var playState = PlayState.instance;
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
// Add a black background to the screen.
|
2024-03-16 00:55:57 -04:00
|
|
|
var bg:FunkinSprite = new FunkinSprite().makeSolidColor(FlxG.width * 2, FlxG.height * 2, FlxColor.BLACK);
|
2023-12-19 01:57:39 -05:00
|
|
|
// We make this transparent so that we can see the stage underneath during debugging,
|
|
|
|
// but it's normally opaque.
|
|
|
|
bg.alpha = transparent ? 0.25 : 1.0;
|
2023-01-22 22:25:45 -05:00
|
|
|
bg.scrollFactor.set();
|
2024-01-16 00:03:30 -05:00
|
|
|
bg.screenCenter();
|
2023-01-22 22:25:45 -05:00
|
|
|
add(bg);
|
|
|
|
|
2023-06-01 18:52:58 -04:00
|
|
|
// Pluck Boyfriend from the PlayState and place him (in the same position) in the GameOverSubState.
|
2023-01-22 22:25:45 -05:00
|
|
|
// We can then play the character's `firstDeath` animation.
|
2024-03-19 23:25:56 -04:00
|
|
|
if (PlayState.instance.isMinimalMode) {}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boyfriend = PlayState.instance.currentStage.getBoyfriend(true);
|
|
|
|
boyfriend.isDead = true;
|
|
|
|
add(boyfriend);
|
|
|
|
boyfriend.resetCharacter();
|
|
|
|
}
|
2023-05-31 03:03:10 -04:00
|
|
|
|
2024-03-16 00:55:57 -04:00
|
|
|
setCameraTarget();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set up the audio
|
|
|
|
//
|
|
|
|
|
|
|
|
// The conductor now represents the BPM of the game over music.
|
|
|
|
Conductor.instance.update(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@:nullSafety(Off)
|
|
|
|
function setCameraTarget():Void
|
|
|
|
{
|
2024-05-15 16:50:34 -04:00
|
|
|
if (PlayState.instance.isMinimalMode || boyfriend == null) return;
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
// Assign a camera follow point to the boyfriend's position.
|
2024-03-27 01:40:22 -04:00
|
|
|
cameraFollowPoint = new FlxObject(PlayState.instance.cameraFollowPoint.x, PlayState.instance.cameraFollowPoint.y, 1, 1);
|
2023-01-22 22:25:45 -05:00
|
|
|
cameraFollowPoint.x = boyfriend.getGraphicMidpoint().x;
|
|
|
|
cameraFollowPoint.y = boyfriend.getGraphicMidpoint().y;
|
2023-10-11 01:04:56 -04:00
|
|
|
var offsets:Array<Float> = boyfriend.getDeathCameraOffsets();
|
|
|
|
cameraFollowPoint.x += offsets[0];
|
|
|
|
cameraFollowPoint.y += offsets[1];
|
2023-01-22 22:25:45 -05:00
|
|
|
add(cameraFollowPoint);
|
|
|
|
|
|
|
|
FlxG.camera.target = null;
|
2024-03-16 00:55:57 -04:00
|
|
|
FlxG.camera.follow(cameraFollowPoint, LOCKON, Constants.DEFAULT_CAMERA_FOLLOW_RATE / 2);
|
|
|
|
targetCameraZoom = (PlayState?.instance?.currentStage?.camZoom ?? 1.0) * boyfriend.getDeathCameraZoom();
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
2024-03-16 00:55:57 -04:00
|
|
|
/**
|
|
|
|
* Forcibly reset the camera zoom level to that of the current stage.
|
|
|
|
* This prevents camera zoom events from adversely affecting the game over state.
|
|
|
|
*/
|
2024-02-15 17:25:28 -05:00
|
|
|
public function resetCameraZoom():Void
|
|
|
|
{
|
|
|
|
// Apply camera zoom level from stage data.
|
|
|
|
FlxG.camera.zoom = PlayState?.instance?.currentStage?.camZoom ?? 1.0;
|
|
|
|
}
|
|
|
|
|
2023-06-01 00:31:32 -04:00
|
|
|
var hasStartedAnimation:Bool = false;
|
|
|
|
|
2024-03-16 00:55:57 -04:00
|
|
|
override function update(elapsed:Float):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-06-01 00:31:32 -04:00
|
|
|
if (!hasStartedAnimation)
|
|
|
|
{
|
|
|
|
hasStartedAnimation = true;
|
|
|
|
|
2024-03-27 01:40:22 -04:00
|
|
|
if (boyfriend == null || PlayState.instance.isMinimalMode)
|
2023-06-01 00:31:32 -04:00
|
|
|
{
|
2024-03-19 23:25:56 -04:00
|
|
|
// Play the "blue balled" sound. May play a variant if one has been assigned.
|
|
|
|
playBlueBalledSFX();
|
2023-06-01 00:31:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-16 00:55:57 -04:00
|
|
|
if (boyfriend.hasAnimation('fakeoutDeath') && FlxG.random.bool((1 / 4096) * 100))
|
|
|
|
{
|
|
|
|
boyfriend.playAnimation('fakeoutDeath', true, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boyfriend.playAnimation('firstDeath', true, false); // ignoreOther is set to FALSE since you WANT to be able to mash and confirm game over!
|
|
|
|
// Play the "blue balled" sound. May play a variant if one has been assigned.
|
|
|
|
playBlueBalledSFX();
|
|
|
|
}
|
2023-06-01 00:31:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-01 08:13:06 -05:00
|
|
|
// Smoothly lerp the camera
|
|
|
|
FlxG.camera.zoom = MathUtil.smoothLerp(FlxG.camera.zoom, targetCameraZoom, elapsed, CAMERA_ZOOM_DURATION);
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
//
|
|
|
|
// Handle user inputs.
|
|
|
|
//
|
|
|
|
|
|
|
|
// MOBILE ONLY: Restart the level when tapping Boyfriend.
|
|
|
|
if (FlxG.onMobile)
|
|
|
|
{
|
2024-03-16 00:55:57 -04:00
|
|
|
var touch:FlxTouch = FlxG.touches.getFirst();
|
2023-01-22 22:25:45 -05:00
|
|
|
if (touch != null)
|
|
|
|
{
|
2024-03-16 00:55:57 -04:00
|
|
|
if (boyfriend == null || touch.overlaps(boyfriend))
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
confirmDeath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// KEYBOARD ONLY: Restart the level when pressing the assigned key.
|
2024-06-06 16:44:20 -04:00
|
|
|
if (controls.ACCEPT && blueballed && !mustNotExit)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-06-04 01:19:08 -04:00
|
|
|
blueballed = false;
|
2023-01-22 22:25:45 -05:00
|
|
|
confirmDeath();
|
|
|
|
}
|
|
|
|
|
|
|
|
// KEYBOARD ONLY: Return to the menu when pressing the assigned key.
|
2024-05-07 14:01:00 -04:00
|
|
|
if (controls.BACK && !mustNotExit)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-06-04 01:19:08 -04:00
|
|
|
blueballed = false;
|
2023-06-15 14:31:49 -04:00
|
|
|
PlayState.instance.deathCounter = 0;
|
|
|
|
// PlayState.seenCutscene = false; // old thing...
|
2024-03-16 00:55:57 -04:00
|
|
|
if (gameOverMusic != null) gameOverMusic.stop();
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-12-19 01:27:58 -05:00
|
|
|
if (isChartingMode)
|
|
|
|
{
|
|
|
|
this.close();
|
|
|
|
if (FlxG.sound.music != null) FlxG.sound.music.pause(); // Don't reset song position!
|
|
|
|
PlayState.instance.close(); // This only works because PlayState is a substate!
|
2024-05-15 16:50:34 -04:00
|
|
|
return;
|
2023-12-19 01:27:58 -05:00
|
|
|
}
|
|
|
|
else if (PlayStatePlaylist.isStoryMode)
|
|
|
|
{
|
2024-03-28 22:33:50 -04:00
|
|
|
openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new StoryMenuState(sticker)));
|
2023-12-19 01:27:58 -05:00
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
else
|
2023-12-19 01:27:58 -05:00
|
|
|
{
|
2024-03-28 22:33:50 -04:00
|
|
|
openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> FreeplayState.build(sticker)));
|
2023-12-19 01:27:58 -05:00
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
2024-02-18 03:02:36 -05:00
|
|
|
if (gameOverMusic != null && gameOverMusic.playing)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
// Match the conductor to the music.
|
|
|
|
// This enables the stepHit and beatHit events.
|
2023-12-14 16:56:20 -05:00
|
|
|
Conductor.instance.update(gameOverMusic.time);
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
2024-03-16 00:55:57 -04:00
|
|
|
else if (boyfriend != null)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2024-03-19 23:25:56 -04:00
|
|
|
if (PlayState.instance.isMinimalMode)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2024-03-19 23:25:56 -04:00
|
|
|
// startDeathMusic(1.0, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Music hasn't started yet.
|
|
|
|
switch (PlayStatePlaylist.campaignId)
|
|
|
|
{
|
|
|
|
// TODO: Make the behavior for playing Jeff's voicelines generic or un-hardcoded.
|
|
|
|
// This will simplify the class and make it easier for mods to add death quotes.
|
|
|
|
case 'week7':
|
|
|
|
if (boyfriend.getCurrentAnimation().startsWith('firstDeath') && boyfriend.isAnimationFinished() && !playingJeffQuote)
|
|
|
|
{
|
|
|
|
playingJeffQuote = true;
|
|
|
|
playJeffQuote();
|
|
|
|
// Start music at lower volume
|
|
|
|
startDeathMusic(0.2, false);
|
|
|
|
boyfriend.playAnimation('deathLoop' + animationSuffix);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// Start music at normal volume once the initial death animation finishes.
|
|
|
|
if (boyfriend.getCurrentAnimation().startsWith('firstDeath') && boyfriend.isAnimationFinished())
|
|
|
|
{
|
|
|
|
startDeathMusic(1.0, false);
|
|
|
|
boyfriend.playAnimation('deathLoop' + animationSuffix);
|
|
|
|
}
|
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-02 18:08:49 -04:00
|
|
|
// Start death music before firstDeath gets replaced
|
|
|
|
super.update(elapsed);
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do behavior which occurs when you confirm and move to restart the level.
|
|
|
|
*/
|
|
|
|
function confirmDeath():Void
|
|
|
|
{
|
|
|
|
if (!isEnding)
|
|
|
|
{
|
|
|
|
isEnding = true;
|
|
|
|
startDeathMusic(1.0, true); // isEnding changes this function's behavior.
|
|
|
|
|
2024-03-27 01:40:22 -04:00
|
|
|
if (PlayState.instance.isMinimalMode || boyfriend == null) {}
|
2024-03-19 23:25:56 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
boyfriend.playAnimation('deathConfirm' + animationSuffix, true);
|
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
// After the animation finishes...
|
2023-05-17 16:42:58 -04:00
|
|
|
new FlxTimer().start(0.7, function(tmr:FlxTimer) {
|
2023-01-22 22:25:45 -05:00
|
|
|
// ...fade out the graphics. Then after that happens...
|
2023-05-17 16:42:58 -04:00
|
|
|
FlxG.camera.fade(FlxColor.BLACK, 2, false, function() {
|
2023-06-01 18:52:58 -04:00
|
|
|
// ...close the GameOverSubState.
|
2023-01-22 22:25:45 -05:00
|
|
|
FlxG.camera.fade(FlxColor.BLACK, 1, true, null, true);
|
2023-06-06 17:38:31 -04:00
|
|
|
PlayState.instance.needsReset = true;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2024-03-27 01:40:22 -04:00
|
|
|
if (PlayState.instance.isMinimalMode || boyfriend == null) {}
|
2024-03-19 23:25:56 -04:00
|
|
|
else
|
2024-03-16 00:55:57 -04:00
|
|
|
{
|
2024-03-19 23:25:56 -04:00
|
|
|
// Readd Boyfriend to the stage.
|
2024-03-16 00:55:57 -04:00
|
|
|
boyfriend.isDead = false;
|
|
|
|
remove(boyfriend);
|
|
|
|
PlayState.instance.currentStage.addCharacter(boyfriend, BF);
|
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2024-03-01 08:13:06 -05:00
|
|
|
// Snap reset the camera which may have changed because of the player character data.
|
|
|
|
resetCameraZoom();
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
// Close the substate.
|
|
|
|
close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-16 00:55:57 -04:00
|
|
|
public override function dispatchEvent(event:ScriptEvent):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
super.dispatchEvent(event);
|
|
|
|
|
|
|
|
ScriptEventDispatcher.callEvent(boyfriend, event);
|
|
|
|
}
|
|
|
|
|
2024-02-18 03:02:36 -05:00
|
|
|
/**
|
|
|
|
* Rather than hardcoding stuff, we look for the presence of a music file
|
|
|
|
* with the given suffix, and strip it down until we find one that's valid.
|
|
|
|
*/
|
|
|
|
function resolveMusicPath(suffix:String, starting:Bool = false, ending:Bool = false):Null<String>
|
|
|
|
{
|
2024-03-16 00:55:57 -04:00
|
|
|
var basePath:String = 'gameplay/gameover/gameOver';
|
|
|
|
if (ending) basePath += 'End';
|
|
|
|
else if (starting) basePath += 'Start';
|
2024-02-18 03:02:36 -05:00
|
|
|
|
2024-03-16 00:55:57 -04:00
|
|
|
var musicPath:String = Paths.music(basePath + suffix);
|
2024-02-18 03:02:36 -05:00
|
|
|
while (!Assets.exists(musicPath) && suffix.length > 0)
|
|
|
|
{
|
|
|
|
suffix = suffix.split('-').slice(0, -1).join('-');
|
|
|
|
musicPath = Paths.music(basePath + suffix);
|
|
|
|
}
|
|
|
|
if (!Assets.exists(musicPath)) return null;
|
|
|
|
trace('Resolved music path: ' + musicPath);
|
|
|
|
return musicPath;
|
|
|
|
}
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
/**
|
|
|
|
* Starts the death music at the appropriate volume.
|
2024-03-16 00:55:57 -04:00
|
|
|
* @param startingVolume The initial volume for the music.
|
|
|
|
* @param force Whether or not to force the music to restart.
|
2023-01-22 22:25:45 -05:00
|
|
|
*/
|
2024-02-18 03:02:36 -05:00
|
|
|
public function startDeathMusic(startingVolume:Float = 1, force:Bool = false):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2024-03-16 00:55:57 -04:00
|
|
|
var musicPath:Null<String> = resolveMusicPath(musicSuffix, isStarting, isEnding);
|
|
|
|
var onComplete:() -> Void = () -> {};
|
|
|
|
|
2024-02-18 03:02:36 -05:00
|
|
|
if (isStarting)
|
|
|
|
{
|
|
|
|
if (musicPath == null)
|
|
|
|
{
|
2024-03-16 00:55:57 -04:00
|
|
|
// Looked for starting music and didn't find it. Use middle music instead.
|
2024-02-18 03:02:36 -05:00
|
|
|
isStarting = false;
|
|
|
|
musicPath = resolveMusicPath(musicSuffix, isStarting, isEnding);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onComplete = function() {
|
2024-03-16 00:55:57 -04:00
|
|
|
isStarting = true;
|
2024-02-18 03:02:36 -05:00
|
|
|
// We need to force to ensure that the non-starting music plays.
|
|
|
|
startDeathMusic(1.0, true);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (musicPath == null)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2024-03-16 00:55:57 -04:00
|
|
|
FlxG.log.warn('[GAMEOVER] Could not find game over music at path ($musicPath)!');
|
2024-02-18 03:02:36 -05:00
|
|
|
return;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
2024-02-18 03:02:36 -05:00
|
|
|
else if (gameOverMusic == null || !gameOverMusic.playing || force)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2024-02-18 03:02:36 -05:00
|
|
|
if (gameOverMusic != null) gameOverMusic.stop();
|
2024-03-16 00:55:57 -04:00
|
|
|
|
2024-02-18 03:02:36 -05:00
|
|
|
gameOverMusic = FunkinSound.load(musicPath);
|
2024-03-16 00:55:57 -04:00
|
|
|
if (gameOverMusic == null) return;
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
gameOverMusic.volume = startingVolume;
|
2024-02-18 03:02:36 -05:00
|
|
|
gameOverMusic.looped = !(isEnding || isStarting);
|
|
|
|
gameOverMusic.onComplete = onComplete;
|
2023-01-22 22:25:45 -05:00
|
|
|
gameOverMusic.play();
|
|
|
|
}
|
2024-02-18 03:02:36 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
@:privateAccess
|
|
|
|
trace('Music already playing! ${gameOverMusic?._label}');
|
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Play the sound effect that occurs when
|
|
|
|
* boyfriend's testicles get utterly annihilated.
|
|
|
|
*/
|
2024-03-16 00:55:57 -04:00
|
|
|
public static function playBlueBalledSFX():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-06-02 15:56:40 -04:00
|
|
|
blueballed = true;
|
2024-02-15 17:25:28 -05:00
|
|
|
if (Assets.exists(Paths.sound('gameplay/gameover/fnf_loss_sfx' + blueBallSuffix)))
|
|
|
|
{
|
2024-03-23 17:50:48 -04:00
|
|
|
FunkinSound.playOnce(Paths.sound('gameplay/gameover/fnf_loss_sfx' + blueBallSuffix));
|
2024-02-15 17:25:28 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlxG.log.error('Missing blue ball sound effect: ' + Paths.sound('gameplay/gameover/fnf_loss_sfx' + blueBallSuffix));
|
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var playingJeffQuote:Bool = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Week 7-specific hardcoded behavior, to play a custom death quote.
|
|
|
|
* TODO: Make this a module somehow.
|
|
|
|
*/
|
2024-03-16 00:55:57 -04:00
|
|
|
function playJeffQuote():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
var randomCensor:Array<Int> = [];
|
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
if (!Preferences.naughtyness) randomCensor = [1, 3, 8, 13, 17, 21];
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2024-03-23 17:50:48 -04:00
|
|
|
FunkinSound.playOnce(Paths.sound('jeffGameover/jeffGameover-' + FlxG.random.int(1, 25, randomCensor)), function() {
|
2023-01-22 22:25:45 -05:00
|
|
|
// Once the quote ends, fade in the game over music.
|
|
|
|
if (!isEnding && gameOverMusic != null)
|
|
|
|
{
|
|
|
|
gameOverMusic.fadeIn(4, 0.2, 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2024-01-17 23:14:28 -05:00
|
|
|
|
2024-03-16 00:55:57 -04:00
|
|
|
public override function destroy():Void
|
2024-02-18 03:02:36 -05:00
|
|
|
{
|
|
|
|
super.destroy();
|
2024-03-16 00:55:57 -04:00
|
|
|
if (gameOverMusic != null)
|
|
|
|
{
|
|
|
|
gameOverMusic.stop();
|
|
|
|
gameOverMusic = null;
|
|
|
|
}
|
|
|
|
blueballed = false;
|
2024-02-18 03:02:36 -05:00
|
|
|
instance = null;
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:14:28 -05:00
|
|
|
public override function toString():String
|
|
|
|
{
|
2024-03-16 00:55:57 -04:00
|
|
|
return 'GameOverSubState';
|
2024-01-17 23:14:28 -05:00
|
|
|
}
|
2020-10-27 06:35:23 -04:00
|
|
|
}
|
2023-12-19 01:27:58 -05:00
|
|
|
|
2024-03-16 00:55:57 -04:00
|
|
|
/**
|
|
|
|
* Parameters used to instantiate a GameOverSubState.
|
|
|
|
*/
|
2023-12-19 01:27:58 -05:00
|
|
|
typedef GameOverParams =
|
|
|
|
{
|
|
|
|
var isChartingMode:Bool;
|
2023-12-19 01:57:39 -05:00
|
|
|
var transparent:Bool;
|
2023-12-19 01:27:58 -05:00
|
|
|
}
|