From 6b076faaf7bf3f46176092375c9981329b99c81d Mon Sep 17 00:00:00 2001
From: Cameron Taylor <cameron.taylor.ninja@gmail.com>
Date: Tue, 27 Oct 2020 03:35:23 -0700
Subject: [PATCH] LOSS SCREEN WIP

---
 source/AnimationDebug.hx   |  2 +-
 source/Boyfriend.hx        | 13 +++++++++++
 source/FreeplayState.hx    |  2 +-
 source/GameOverState.hx    | 48 +++++++++++++++++++++++++++-----------
 source/GameOverSubstate.hx | 47 +++++++++++++++++++++++++++++++++++++
 source/Main.hx             |  2 +-
 source/PauseSubState.hx    |  8 ++++++-
 source/PlayState.hx        | 19 +++++++++++----
 source/TitleState.hx       |  3 ++-
 9 files changed, 120 insertions(+), 24 deletions(-)
 create mode 100644 source/GameOverSubstate.hx

diff --git a/source/AnimationDebug.hx b/source/AnimationDebug.hx
index ae3ca510e..1cf4021a3 100644
--- a/source/AnimationDebug.hx
+++ b/source/AnimationDebug.hx
@@ -21,7 +21,7 @@ class AnimationDebug extends FlxState
 	var dumbTexts:FlxTypedGroup<FlxText>;
 	var animList:Array<String> = [];
 	var curAnim:Int = 0;
-	var isDad:Bool = true;
+	var isDad:Bool = false;
 	var daAnim:String = 'spooky';
 	var camFollow:FlxObject;
 
diff --git a/source/Boyfriend.hx b/source/Boyfriend.hx
index 4796b8549..483f4d0e6 100644
--- a/source/Boyfriend.hx
+++ b/source/Boyfriend.hx
@@ -26,6 +26,10 @@ class Boyfriend extends Character
 		animation.addByPrefix('singRIGHTmiss', 'BF NOTE RIGHT MISS', 24, false);
 		animation.addByPrefix('singDOWNmiss', 'BF NOTE DOWN MISS', 24, false);
 		animation.addByPrefix('hey', 'BF HEY', 24, false);
+
+		animation.addByPrefix('firstDeath', "BF dies", 24, false);
+		animation.addByPrefix('deathLoop', "BF Dead Loop", 24, true);
+		animation.addByPrefix('deathConfirm', "BF Dead confirm", 24, false);
 		playAnim('idle');
 
 		antialiasing = true;
@@ -40,6 +44,9 @@ class Boyfriend extends Character
 		addOffset("singLEFTmiss", 12, 24);
 		addOffset("singDOWNmiss", -11, -19);
 		addOffset("hey", 7, 4);
+		addOffset('firstDeath', 37, 11);
+		addOffset('deathLoop', 37, 5);
+		addOffset('deathConfirm', 37, 69);
 	}
 
 	override function update(elapsed:Float)
@@ -48,6 +55,12 @@ class Boyfriend extends Character
 		{
 			playAnim('idle', true, false, 10);
 		}
+
+		if (animation.curAnim.name == 'firstDeath' && animation.curAnim.finished)
+		{
+			playAnim('deathLoop');
+		}
+
 		super.update(elapsed);
 	}
 }
diff --git a/source/FreeplayState.hx b/source/FreeplayState.hx
index e10db5261..05b22123f 100644
--- a/source/FreeplayState.hx
+++ b/source/FreeplayState.hx
@@ -7,7 +7,7 @@ import flixel.text.FlxText;
 
 class FreeplayState extends MusicBeatState
 {
-	var songs:Array<String> = ["Bopeebo", "Dadbattle", "Fresh", "Tutorial\nlol"];
+	var songs:Array<String> = ["Bopeebo", "Dadbattle", "Fresh", "Tutorial", "Spookeez"];
 
 	var selector:FlxText;
 	var curSelected:Int = 0;
diff --git a/source/GameOverState.hx b/source/GameOverState.hx
index d3de48311..064325478 100644
--- a/source/GameOverState.hx
+++ b/source/GameOverState.hx
@@ -10,26 +10,44 @@ import flixel.tweens.FlxTween;
 
 class GameOverState extends FlxTransitionableState
 {
+	var bfX:Float = 0;
+	var bfY:Float = 0;
+
+	public function new(x:Float, y:Float)
+	{
+		super();
+
+		bfX = x;
+		bfY = y;
+	}
+
 	override function create()
 	{
-		var loser:FlxSprite = new FlxSprite(100, 100);
-		var loseTex = FlxAtlasFrames.fromSparrow(AssetPaths.lose__png, AssetPaths.lose__xml);
-		loser.frames = loseTex;
-		loser.animation.addByPrefix('lose', 'lose', 24, false);
-		loser.animation.play('lose');
-		add(loser);
+		/* var loser:FlxSprite = new FlxSprite(100, 100);
+			var loseTex = FlxAtlasFrames.fromSparrow(AssetPaths.lose__png, AssetPaths.lose__xml);
+			loser.frames = loseTex;
+			loser.animation.addByPrefix('lose', 'lose', 24, false);
+			loser.animation.play('lose');
+			// add(loser); */
 
-		var restart:FlxSprite = new FlxSprite(500, 50).loadGraphic(AssetPaths.restart__png);
-		restart.setGraphicSize(Std.int(restart.width * 0.6));
-		restart.updateHitbox();
-		restart.alpha = 0;
-		restart.antialiasing = true;
-		add(restart);
+		var bf:Boyfriend = new Boyfriend(bfX, bfY);
+		// bf.scrollFactor.set();
+		add(bf);
+		bf.playAnim('firstDeath');
+
+		FlxG.camera.follow(bf, LOCKON, 0.001);
+		/* 
+			var restart:FlxSprite = new FlxSprite(500, 50).loadGraphic(AssetPaths.restart__png);
+			restart.setGraphicSize(Std.int(restart.width * 0.6));
+			restart.updateHitbox();
+			restart.alpha = 0;
+			restart.antialiasing = true;
+			// add(restart); */
 
 		FlxG.sound.music.fadeOut(2, FlxG.sound.music.volume * 0.6);
 
-		FlxTween.tween(restart, {alpha: 1}, 1, {ease: FlxEase.quartInOut});
-		FlxTween.tween(restart, {y: restart.y + 40}, 7, {ease: FlxEase.quartInOut, type: PINGPONG});
+		// FlxTween.tween(restart, {alpha: 1}, 1, {ease: FlxEase.quartInOut});
+		// FlxTween.tween(restart, {y: restart.y + 40}, 7, {ease: FlxEase.quartInOut, type: PINGPONG});
 
 		super.create();
 	}
@@ -48,6 +66,8 @@ class GameOverState extends FlxTransitionableState
 				pressed = true;
 		}
 
+		pressed = false;
+
 		if (pressed && !fading)
 		{
 			fading = true;
diff --git a/source/GameOverSubstate.hx b/source/GameOverSubstate.hx
new file mode 100644
index 000000000..5028fb036
--- /dev/null
+++ b/source/GameOverSubstate.hx
@@ -0,0 +1,47 @@
+package;
+
+import flixel.FlxG;
+import flixel.FlxObject;
+import flixel.FlxSubState;
+import flixel.math.FlxPoint;
+
+class GameOverSubstate extends FlxSubState
+{
+	var bf:Boyfriend;
+	var camFollow:FlxObject;
+
+	public function new(x:Float, y:Float)
+	{
+		super();
+
+		bf = new Boyfriend(x, y);
+		add(bf);
+
+		camFollow = new FlxObject(bf.getGraphicMidpoint().x, bf.getGraphicMidpoint().y, 1, 1);
+		add(camFollow);
+
+		FlxG.sound.play('assets/sounds/fnf_loss_sfx' + TitleState.soundExt);
+
+		// FlxG.camera.followLerp = 1;
+		// FlxG.camera.focusOn(FlxPoint.get(FlxG.width / 2, FlxG.height / 2));
+		FlxG.camera.scroll.set();
+		FlxG.camera.target = null;
+
+		bf.playAnim('firstDeath');
+	}
+
+	override function update(elapsed:Float)
+	{
+		super.update(elapsed);
+
+		if (bf.animation.curAnim.name == 'firstDeath' && bf.animation.curAnim.curFrame == 12)
+		{
+			FlxG.camera.follow(camFollow, LOCKON, 0.01);
+		}
+
+		if (bf.animation.curAnim.name == 'firstDeath' && bf.animation.curAnim.finished)
+		{
+			FlxG.sound.playMusic('assets/music/gameOver' + TitleState.soundExt);
+		}
+	}
+}
diff --git a/source/Main.hx b/source/Main.hx
index 13376db44..e2e0f4dee 100644
--- a/source/Main.hx
+++ b/source/Main.hx
@@ -9,7 +9,7 @@ class Main extends Sprite
 	public function new()
 	{
 		super();
-		addChild(new FlxGame(0, 0, TitleState));
+		addChild(new FlxGame(0, 0, FreeplayState));
 
 		#if !mobile
 		addChild(new FPS(10, 3, 0xFFFFFF));
diff --git a/source/PauseSubState.hx b/source/PauseSubState.hx
index a4a1278dc..dbf232b6d 100644
--- a/source/PauseSubState.hx
+++ b/source/PauseSubState.hx
@@ -9,7 +9,7 @@ import flixel.util.FlxColor;
 
 class PauseSubState extends FlxSubState
 {
-	public function new()
+	public function new(x:Float, y:Float)
 	{
 		super();
 		var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
@@ -17,6 +17,12 @@ class PauseSubState extends FlxSubState
 		bg.scrollFactor.set();
 		add(bg);
 
+		var bf:Boyfriend = new Boyfriend(x, y);
+		bf.scrollFactor.set();
+		// add(bf);
+
+		bf.playAnim('firstDeath');
+
 		bg.cameras = [FlxG.cameras.list[1]];
 	}
 
diff --git a/source/PlayState.hx b/source/PlayState.hx
index 48df0fea6..5e3846652 100644
--- a/source/PlayState.hx
+++ b/source/PlayState.hx
@@ -526,7 +526,7 @@ class PlayState extends MusicBeatState
 			persistentDraw = true;
 			paused = true;
 
-			openSubState(new PauseSubState());
+			openSubState(new PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
 		}
 
 		if (FlxG.keys.justPressed.ESCAPE)
@@ -548,7 +548,7 @@ class PlayState extends MusicBeatState
 		/* if (FlxG.keys.justPressed.NINE)
 			FlxG.switchState(new Charting()); */
 		if (FlxG.keys.justPressed.EIGHT)
-			FlxG.switchState(new AnimationDebug(SONG.player2));
+			FlxG.switchState(new AnimationDebug(SONG.player1));
 
 		if (startingSong)
 		{
@@ -667,7 +667,17 @@ class PlayState extends MusicBeatState
 		if (health <= 0)
 		{
 			boyfriend.stunned = true;
-			FlxG.switchState(new GameOverState());
+
+			persistentUpdate = false;
+			persistentDraw = false;
+			paused = true;
+
+			vocals.stop();
+			FlxG.sound.music.stop();
+
+			openSubState(new GameOverSubstate(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
+
+			// FlxG.switchState(new GameOverState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
 		}
 
 		if (unspawnNotes[0] != null)
@@ -744,9 +754,8 @@ class PlayState extends MusicBeatState
 	private function popUpScore(strumtime:Float):Void
 	{
 		var noteDiff:Float = Math.abs(strumtime - Conductor.songPosition);
-
 		// boyfriend.playAnim('hey');
-		// vocals.volume = 1;
+		vocals.volume = 1;
 
 		var placement:String = Std.string(combo);
 		// var placement:String = sectionScores[1][curSection] + '/' + sectionScores[0][curSection];
diff --git a/source/TitleState.hx b/source/TitleState.hx
index 5c5ed9413..c1124ab4c 100644
--- a/source/TitleState.hx
+++ b/source/TitleState.hx
@@ -130,7 +130,7 @@ class TitleState extends MusicBeatState
 
 			new FlxTimer().start(2, function(tmr:FlxTimer)
 			{
-				FlxG.switchState(new PlayState());
+				FlxG.switchState(new FreeplayState());
 			});
 			FlxG.sound.play('assets/music/titleShoot' + TitleState.soundExt, 0.7);
 		}
@@ -232,6 +232,7 @@ class TitleState extends MusicBeatState
 		{
 			FlxG.camera.flash(FlxColor.WHITE, 4);
 			remove(credGroup);
+			skippedIntro = true;
 		}
 	}
 }