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;
|
2023-07-02 15:34:07 -04:00
|
|
|
import flixel.sound.FlxSound;
|
2023-05-17 16:42:58 -04:00
|
|
|
import funkin.ui.story.StoryMenuState;
|
2020-10-28 03:03:32 -04:00
|
|
|
import flixel.util.FlxColor;
|
|
|
|
import flixel.util.FlxTimer;
|
2022-04-18 20:39:41 -04:00
|
|
|
import funkin.modding.events.ScriptEvent;
|
|
|
|
import funkin.modding.events.ScriptEventDispatcher;
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.play.PlayState;
|
2022-04-18 20:39:41 -04:00
|
|
|
import funkin.play.character.BaseCharacter;
|
2022-04-18 19:36:09 -04:00
|
|
|
import funkin.ui.PreferencesMenu;
|
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.
|
|
|
|
*/
|
2023-06-01 18:52:58 -04:00
|
|
|
class GameOverSubState extends MusicBeatSubState
|
2020-10-27 06:35:23 -04: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.
|
|
|
|
*/
|
|
|
|
public static var animationSuffix:String = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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`.
|
|
|
|
*/
|
|
|
|
public static var musicSuffix:String = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Which alternate "blue ball" sound effect to use.
|
|
|
|
*/
|
|
|
|
public static var blueBallSuffix:String = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The boyfriend character.
|
|
|
|
*/
|
|
|
|
var boyfriend:BaseCharacter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The invisible object in the scene which the camera focuses on.
|
|
|
|
*/
|
|
|
|
var cameraFollowPoint:FlxObject;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The music playing in the background of the state.
|
|
|
|
*/
|
|
|
|
var gameOverMusic:FlxSound = new FlxSound();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the player has confirmed and prepared to restart the level.
|
|
|
|
* This means the animation and transition have already started.
|
|
|
|
*/
|
|
|
|
var isEnding:Bool = false;
|
|
|
|
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the game over configuration to the default.
|
|
|
|
*/
|
|
|
|
public static function reset()
|
|
|
|
{
|
|
|
|
animationSuffix = "";
|
|
|
|
musicSuffix = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
override public function create()
|
|
|
|
{
|
|
|
|
super.create();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set up the visuals
|
|
|
|
//
|
|
|
|
|
|
|
|
// Add a black background to the screen.
|
|
|
|
// We make this transparent so that we can see the stage underneath during debugging.
|
|
|
|
var bg = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
|
|
|
|
bg.alpha = 0.25;
|
|
|
|
bg.scrollFactor.set();
|
|
|
|
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.
|
|
|
|
boyfriend = PlayState.instance.currentStage.getBoyfriend(true);
|
|
|
|
boyfriend.isDead = true;
|
|
|
|
add(boyfriend);
|
|
|
|
boyfriend.resetCharacter();
|
2023-05-31 03:03:10 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
// Assign a camera follow point to the boyfriend's position.
|
|
|
|
cameraFollowPoint = new FlxObject(PlayState.instance.cameraFollowPoint.x, PlayState.instance.cameraFollowPoint.y, 1, 1);
|
|
|
|
cameraFollowPoint.x = boyfriend.getGraphicMidpoint().x;
|
|
|
|
cameraFollowPoint.y = boyfriend.getGraphicMidpoint().y;
|
|
|
|
add(cameraFollowPoint);
|
|
|
|
|
|
|
|
FlxG.camera.target = null;
|
|
|
|
FlxG.camera.follow(cameraFollowPoint, LOCKON, 0.01);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set up the audio
|
|
|
|
//
|
|
|
|
|
|
|
|
// Prepare the game over music.
|
|
|
|
FlxG.sound.list.add(gameOverMusic);
|
|
|
|
gameOverMusic.stop();
|
|
|
|
|
|
|
|
// The conductor now represents the BPM of the game over music.
|
2023-07-26 20:03:31 -04:00
|
|
|
Conductor.update(0);
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
2023-06-01 00:31:32 -04:00
|
|
|
var hasStartedAnimation:Bool = false;
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
2023-06-01 00:31:32 -04:00
|
|
|
if (!hasStartedAnimation)
|
|
|
|
{
|
|
|
|
hasStartedAnimation = true;
|
|
|
|
|
2023-06-15 03:48:52 -04:00
|
|
|
if (boyfriend.hasAnimation('fakeoutDeath') && FlxG.random.bool((1 / 4096) * 100))
|
2023-06-01 00:31:32 -04:00
|
|
|
{
|
|
|
|
boyfriend.playAnimation('fakeoutDeath', true, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boyfriend.playAnimation('firstDeath', true, true);
|
|
|
|
// Play the "blue balled" sound. May play a variant if one has been assigned.
|
|
|
|
playBlueBalledSFX();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
//
|
|
|
|
// Handle user inputs.
|
|
|
|
//
|
|
|
|
|
|
|
|
// MOBILE ONLY: Restart the level when tapping Boyfriend.
|
|
|
|
if (FlxG.onMobile)
|
|
|
|
{
|
|
|
|
var touch = FlxG.touches.getFirst();
|
|
|
|
if (touch != null)
|
|
|
|
{
|
|
|
|
if (touch.overlaps(boyfriend))
|
|
|
|
{
|
|
|
|
confirmDeath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// KEYBOARD ONLY: Restart the level when pressing the assigned key.
|
2023-06-02 15:56:40 -04:00
|
|
|
if (controls.ACCEPT && blueballed)
|
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.
|
|
|
|
if (controls.BACK)
|
|
|
|
{
|
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...
|
2023-01-22 22:25:45 -05:00
|
|
|
gameOverMusic.stop();
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
if (PlayStatePlaylist.isStoryMode) FlxG.switchState(new StoryMenuState());
|
2023-01-22 22:25:45 -05:00
|
|
|
else
|
|
|
|
FlxG.switchState(new FreeplayState());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gameOverMusic.playing)
|
|
|
|
{
|
|
|
|
// Match the conductor to the music.
|
|
|
|
// This enables the stepHit and beatHit events.
|
2023-07-26 20:03:31 -04:00
|
|
|
Conductor.update(gameOverMusic.time);
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Music hasn't started yet.
|
2023-06-06 17:38:31 -04:00
|
|
|
switch (PlayStatePlaylist.campaignId)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
// 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.
|
2023-06-06 17:38:31 -04:00
|
|
|
case "week7":
|
2023-01-22 22:25:45 -05:00
|
|
|
if (boyfriend.getCurrentAnimation().startsWith('firstDeath') && boyfriend.isAnimationFinished() && !playingJeffQuote)
|
|
|
|
{
|
|
|
|
playingJeffQuote = true;
|
|
|
|
playJeffQuote();
|
|
|
|
// Start music at lower volume
|
|
|
|
startDeathMusic(0.2, false);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// Start music at normal volume once the initial death animation finishes.
|
|
|
|
if (boyfriend.getCurrentAnimation().startsWith('firstDeath') && boyfriend.isAnimationFinished())
|
|
|
|
{
|
|
|
|
startDeathMusic(1.0, false);
|
2023-08-02 18:08:49 -04:00
|
|
|
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.
|
|
|
|
|
|
|
|
boyfriend.playAnimation('deathConfirm' + animationSuffix, true);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
// Readd Boyfriend to the stage.
|
|
|
|
boyfriend.isDead = false;
|
|
|
|
remove(boyfriend);
|
|
|
|
PlayState.instance.currentStage.addCharacter(boyfriend, BF);
|
|
|
|
|
|
|
|
// Close the substate.
|
|
|
|
close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-16 17:37:56 -04:00
|
|
|
public override function dispatchEvent(event:ScriptEvent)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
super.dispatchEvent(event);
|
|
|
|
|
|
|
|
ScriptEventDispatcher.callEvent(boyfriend, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the death music at the appropriate volume.
|
2023-06-08 16:30:45 -04:00
|
|
|
* @param startingVolume
|
2023-01-22 22:25:45 -05:00
|
|
|
*/
|
|
|
|
function startDeathMusic(?startingVolume:Float = 1, ?force:Bool = false):Void
|
|
|
|
{
|
|
|
|
var musicPath = Paths.music('gameOver' + musicSuffix);
|
|
|
|
if (isEnding)
|
|
|
|
{
|
|
|
|
musicPath = Paths.music('gameOverEnd' + musicSuffix);
|
|
|
|
}
|
|
|
|
if (!gameOverMusic.playing || force)
|
|
|
|
{
|
|
|
|
gameOverMusic.loadEmbedded(musicPath);
|
|
|
|
gameOverMusic.volume = startingVolume;
|
|
|
|
gameOverMusic.play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-04 01:19:08 -04:00
|
|
|
static var blueballed:Bool = false;
|
2023-06-02 15:56:40 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
/**
|
|
|
|
* Play the sound effect that occurs when
|
|
|
|
* boyfriend's testicles get utterly annihilated.
|
|
|
|
*/
|
2023-06-01 00:31:32 -04:00
|
|
|
public static function playBlueBalledSFX()
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-06-02 15:56:40 -04:00
|
|
|
blueballed = true;
|
2023-01-22 22:25:45 -05:00
|
|
|
FlxG.sound.play(Paths.sound('fnf_loss_sfx' + blueBallSuffix));
|
|
|
|
}
|
|
|
|
|
|
|
|
var playingJeffQuote:Bool = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Week 7-specific hardcoded behavior, to play a custom death quote.
|
|
|
|
* TODO: Make this a module somehow.
|
|
|
|
*/
|
|
|
|
function playJeffQuote()
|
|
|
|
{
|
|
|
|
var randomCensor:Array<Int> = [];
|
|
|
|
|
|
|
|
if (PreferencesMenu.getPref('censor-naughty')) randomCensor = [1, 3, 8, 13, 17, 21];
|
|
|
|
|
2023-05-17 16:42:58 -04:00
|
|
|
FlxG.sound.play(Paths.sound('jeffGameover/jeffGameover-' + FlxG.random.int(1, 25, randomCensor)), 1, false, null, true, 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-10-27 06:35:23 -04:00
|
|
|
}
|