Funkin/source/funkin/GameOverSubstate.hx

193 lines
4 KiB
Haxe
Raw Normal View History

package funkin;
2020-10-27 06:35:23 -04:00
import flixel.FlxObject;
import flixel.FlxSubState;
import flixel.math.FlxPoint;
import flixel.system.FlxSound;
2020-10-28 03:03:32 -04:00
import flixel.util.FlxColor;
import flixel.util.FlxTimer;
import haxe.display.Display;
import funkin.ui.PreferencesMenu;
import funkin.play.PlayState;
2020-10-27 06:35:23 -04:00
2020-10-28 05:26:33 -04:00
class GameOverSubstate extends MusicBeatSubstate
2020-10-27 06:35:23 -04:00
{
var bf:Boyfriend;
var camFollow:FlxObject;
2021-01-30 07:16:51 -05:00
var stageSuffix:String = "";
2021-03-18 14:15:54 -04:00
var randomGameover:Int = 1;
2020-11-01 04:55:02 -05:00
var gameOverMusic:FlxSound;
2020-10-27 06:35:23 -04:00
public function new(x:Float, y:Float)
{
gameOverMusic = new FlxSound();
FlxG.sound.list.add(gameOverMusic);
2022-02-23 16:49:54 -05:00
var daStage = PlayState.curStageId;
2021-01-30 07:16:51 -05:00
var daBf:String = '';
switch (daStage)
{
case 'school' | 'schoolEvil':
2021-02-02 05:46:17 -05:00
stageSuffix = '-pixel';
daBf = 'bf-pixel-dead';
2021-01-30 07:16:51 -05:00
default:
daBf = 'bf';
}
var daSong = PlayState.SONG.song.toLowerCase();
switch (daSong)
{
case 'stress':
daBf = 'bf-holding-gf-dead';
}
2020-10-27 06:35:23 -04:00
super();
2020-10-28 05:26:33 -04:00
Conductor.songPosition = 0;
2021-01-30 07:16:51 -05:00
bf = new Boyfriend(x, y, daBf);
2020-10-27 06:35:23 -04:00
add(bf);
camFollow = new FlxObject(bf.getGraphicMidpoint().x, bf.getGraphicMidpoint().y, 1, 1);
add(camFollow);
2021-02-08 16:34:48 -05:00
FlxG.sound.play(Paths.sound('fnf_loss_sfx' + stageSuffix));
// Conductor.changeBPM(100);
2020-10-27 06:35:23 -04:00
2021-09-22 15:33:30 -04:00
switch (PlayState.SONG.player1)
{
case 'pico':
stageSuffix = 'Pico';
}
2020-10-27 06:35:23 -04:00
// FlxG.camera.followLerp = 1;
// FlxG.camera.focusOn(FlxPoint.get(FlxG.width / 2, FlxG.height / 2));
// commented out for now
2020-10-27 06:35:23 -04:00
FlxG.camera.scroll.set();
FlxG.camera.target = null;
bf.playAnim('firstDeath');
2021-03-18 14:15:54 -04:00
2021-04-09 11:38:09 -04:00
var randomCensor:Array<Int> = [];
if (PreferencesMenu.getPref('censor-naughty'))
randomCensor = [1, 3, 8, 13, 17, 21];
randomGameover = FlxG.random.int(1, 25, randomCensor);
2020-10-27 06:35:23 -04:00
}
2021-03-18 14:15:54 -04:00
var playingDeathSound:Bool = false;
2020-10-27 06:35:23 -04:00
override function update(elapsed:Float)
{
2021-04-19 13:11:30 -04:00
// makes the lerp non-dependant on the framerate
2021-05-06 08:08:51 -04:00
// FlxG.camera.followLerp = CoolUtil.camLerpShit(0.01);
2021-04-19 13:11:30 -04:00
2020-10-27 06:35:23 -04:00
super.update(elapsed);
2021-08-22 10:37:06 -04:00
if (FlxG.onMobile)
{
var touch = FlxG.touches.getFirst();
if (touch != null)
{
if (touch.overlaps(bf))
endBullshit();
}
}
2020-11-01 02:58:20 -05:00
if (controls.ACCEPT)
2020-10-28 03:03:32 -04:00
{
endBullshit();
}
2020-11-01 02:58:20 -05:00
if (controls.BACK)
{
2021-04-09 16:37:54 -04:00
PlayState.deathCounter = 0;
PlayState.seenCutscene = false;
// FlxG.sound.music.stop();
gameOverMusic.stop();
2020-11-01 02:58:20 -05:00
if (PlayState.isStoryMode)
FlxG.switchState(new StoryMenuState());
else
FlxG.switchState(new FreeplayState());
}
2020-10-27 06:35:23 -04:00
if (bf.animation.curAnim.name == 'firstDeath' && bf.animation.curAnim.curFrame == 12)
{
2021-05-06 08:08:51 -04:00
FlxG.camera.follow(camFollow, LOCKON, 0.01);
2020-10-27 06:35:23 -04:00
}
2021-03-18 14:15:54 -04:00
switch (PlayState.storyWeek)
2020-10-27 06:35:23 -04:00
{
2021-03-18 14:15:54 -04:00
case 7:
if (bf.animation.curAnim.name == 'firstDeath' && bf.animation.curAnim.finished && !playingDeathSound)
{
playingDeathSound = true;
2021-04-18 05:25:44 -04:00
bf.startedDeath = true;
coolStartDeath(0.2);
2021-03-18 14:15:54 -04:00
FlxG.sound.play(Paths.sound('jeffGameover/jeffGameover-' + randomGameover), 1, false, null, true, function()
{
if (!isEnding)
{
gameOverMusic.fadeIn(4, 0.2, 1);
}
// FlxG.sound.music.fadeIn(4, 0.2, 1);
2021-03-18 14:15:54 -04:00
});
}
default:
if (bf.animation.curAnim.name == 'firstDeath' && bf.animation.curAnim.finished)
{
bf.startedDeath = true;
coolStartDeath();
}
2020-10-27 06:35:23 -04:00
}
2020-10-28 05:26:33 -04:00
if (gameOverMusic.playing)
2020-10-28 05:26:33 -04:00
{
Conductor.songPosition = gameOverMusic.time;
2020-10-28 05:26:33 -04:00
}
}
2021-04-18 05:25:44 -04:00
private function coolStartDeath(?vol:Float = 1):Void
2021-03-18 14:15:54 -04:00
{
if (!isEnding)
{
gameOverMusic.loadEmbedded(Paths.music('gameOver' + stageSuffix));
gameOverMusic.volume = vol;
gameOverMusic.play();
}
// FlxG.sound.playMusic();
2020-10-27 06:35:23 -04:00
}
2020-10-28 03:03:32 -04:00
var isEnding:Bool = false;
function endBullshit():Void
{
if (!isEnding)
{
isEnding = true;
bf.playAnim('deathConfirm', true);
gameOverMusic.stop();
// FlxG.sound.music.stop();
2021-02-08 16:34:48 -05:00
FlxG.sound.play(Paths.music('gameOverEnd' + stageSuffix));
2020-10-28 03:03:32 -04:00
new FlxTimer().start(0.7, function(tmr:FlxTimer)
{
FlxG.camera.fade(FlxColor.BLACK, 2, false, function()
{
FlxG.camera.fade(FlxColor.BLACK, 1, true, null, true);
PlayState.needsReset = true;
close();
// LoadingState.loadAndSwitchState(new PlayState());
2020-10-28 03:03:32 -04:00
});
});
}
}
2020-10-27 06:35:23 -04:00
}