Files
FNF-i486-Engine/source/GameOverSubstate.hx
JordanSantiagoYT ee6b9a05e6 oops
fixed 2 oversights
2024-08-22 00:26:54 -04:00

185 lines
4.8 KiB
Haxe

package;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSubState;
import flixel.math.FlxMath;
import flixel.math.FlxPoint;
import flixel.util.FlxColor;
import flixel.util.FlxTimer;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import Character.Boyfriend;
using StringTools;
class GameOverSubstate extends MusicBeatSubstate
{
public var boyfriend:Boyfriend;
var camFollow:FlxPoint;
var camFollowPos:FlxObject;
var updateCamera:Bool = false;
var playingDeathSound:Bool = false;
var stageSuffix:String = "";
public static var characterName:String = 'bf-dead';
public static var deathSoundName:String = 'fnf_loss_sfx';
public static var loopSoundName:String = 'gameOver';
public static var endSoundName:String = 'gameOverEnd';
public static var instance:GameOverSubstate;
public static function resetVariables() {
characterName = 'bf-dead';
deathSoundName = 'fnf_loss_sfx';
loopSoundName = 'gameOver';
endSoundName = 'gameOverEnd';
var _song = PlayState.SONG;
if(_song != null)
{
if(_song.gameOverChar != null && _song.gameOverChar.trim().length > 0) characterName = _song.gameOverChar;
if(_song.gameOverSound != null && _song.gameOverSound.trim().length > 0) deathSoundName = _song.gameOverSound;
if(_song.gameOverLoop != null && _song.gameOverLoop.trim().length > 0) loopSoundName = _song.gameOverLoop;
if(_song.gameOverEnd != null && _song.gameOverEnd.trim().length > 0) endSoundName = _song.gameOverEnd;
}
}
var charX:Float = 0;
var charY:Float = 0;
override function create()
{
instance = this;
PlayState.instance.callOnLuas('onGameOverStart', []);
super.create();
}
public function new(x:Float, y:Float)
{
super();
PlayState.instance.setOnLuas('inGameOver', true);
Conductor.songPosition = 0;
boyfriend = new Boyfriend(x, y, characterName);
boyfriend.x += boyfriend.positionArray[0];
boyfriend.y += boyfriend.positionArray[1];
add(boyfriend);
camFollow = new FlxPoint(boyfriend.getGraphicMidpoint().x, boyfriend.getGraphicMidpoint().y);
FlxG.sound.play(Paths.sound(deathSoundName));
FlxG.camera.scroll.set();
FlxG.camera.target = null;
boyfriend.playAnim('firstDeath');
camFollowPos = new FlxObject(0, 0, 1, 1);
camFollowPos.setPosition(FlxG.camera.scroll.x + (FlxG.camera.width / 2), FlxG.camera.scroll.y + (FlxG.camera.height / 2));
add(camFollowPos);
}
var isFollowingAlready:Bool = false;
override function update(elapsed:Float)
{
super.update(elapsed);
PlayState.instance.callOnLuas('onUpdate', [elapsed]);
if(updateCamera) {
var lerpVal:Float = CoolUtil.boundTo(elapsed * 0.6, 0, 1);
camFollowPos.setPosition(FlxMath.lerp(camFollowPos.x, camFollow.x, lerpVal), FlxMath.lerp(camFollowPos.y, camFollow.y, lerpVal));
}
if (controls.ACCEPT)
{
endBullshit();
}
if (controls.BACK)
{
FlxG.sound.music.stop();
PlayState.deathCounter = 0;
PlayState.seenCutscene = false;
PlayState.chartingMode = false;
WeekData.loadTheFirstEnabledMod();
if (PlayState.isStoryMode)
FlxG.switchState(StoryMenuState.new);
else
FlxG.switchState(FreeplayState.new);
FlxG.sound.playMusic(Paths.music('freakyMenu-' + ClientPrefs.daMenuMusic));
PlayState.instance.callOnLuas('onGameOverConfirm', [false]);
}
if (boyfriend.animation.curAnim != null && boyfriend.animation.curAnim.name == 'firstDeath')
{
if(boyfriend.animation.curAnim.curFrame >= 12 && !isFollowingAlready)
{
FlxG.camera.follow(camFollowPos, LOCKON, 1);
updateCamera = true;
isFollowingAlready = true;
}
if (boyfriend.animation.curAnim.finished && !playingDeathSound)
{
if (PlayState.SONG.stage == 'tank')
{
playingDeathSound = true;
coolStartDeath(0.2);
var exclude:Array<Int> = [];
//if(!ClientPrefs.cursing) exclude = [1, 3, 8, 13, 17, 21];
FlxG.sound.play(Paths.sound('jeffGameover/jeffGameover-' + FlxG.random.int(1, 25, exclude)), 1, false, null, true, function() {
if(!isEnding)
{
FlxG.sound.music.fadeIn(0.2, 1, 4);
}
});
}
else
{
coolStartDeath();
}
boyfriend.startedDeath = true;
}
}
if (FlxG.sound.music.playing)
{
Conductor.songPosition = FlxG.sound.music.time;
}
PlayState.instance.callOnLuas('onUpdatePost', [elapsed]);
}
var isEnding:Bool = false;
function coolStartDeath(?volume:Float = 1):Void
{
FlxG.sound.playMusic(Paths.music(loopSoundName), volume);
}
function endBullshit():Void
{
if (!isEnding)
{
isEnding = true;
boyfriend.playAnim('deathConfirm', true);
FlxG.sound.music.stop();
FlxG.sound.play(Paths.music(endSoundName));
new FlxTimer().start(0.7, function(tmr:FlxTimer)
{
FlxG.camera.fade(FlxColor.BLACK, 2, false, function()
{
FlxG.resetState();
});
});
PlayState.instance.callOnLuas('onGameOverConfirm', [true]);
}
}
}