|
| 1 | +package substates; |
| 2 | + |
| 3 | +import archipelago.APPlayState; |
| 4 | +import objects.GameOverVideoSprite; |
| 5 | +import backend.WeekData; |
| 6 | + |
| 7 | +import objects.Character; |
| 8 | +import flixel.FlxObject; |
| 9 | +import flixel.FlxSubState; |
| 10 | +import flixel.math.FlxPoint; |
| 11 | + |
| 12 | +import states.StoryMenuState; |
| 13 | +import states.FreeplayState; |
| 14 | + |
| 15 | +//It has its own folder cuz it was made for something much bigger. |
| 16 | +//im just too lazy to move it. |
| 17 | +//-sans |
| 18 | +import undertale.UnderTextParser; |
| 19 | + |
| 20 | +class APGameOverSubstate extends MusicBeatSubstate |
| 21 | +{ |
| 22 | + public var boyfriend:Character; |
| 23 | + var camFollow:FlxObject; |
| 24 | + |
| 25 | + var stagePostfix:String = ""; |
| 26 | + |
| 27 | + public static var characterName:String = 'bf-dead'; |
| 28 | + public static var deathSoundName:String = 'fnf_loss_sfx'; |
| 29 | + public static var loopSoundName:String = 'gameOver'; |
| 30 | + public static var endSoundName:String = 'gameOverEnd'; |
| 31 | + public static var deathDelay:Float = 0; |
| 32 | + |
| 33 | + public static var deathbysquare:FlxSprite; |
| 34 | + public static var causeofdeath:UnderTextParser; |
| 35 | + |
| 36 | + public static var video:Null<GameOverVideoSprite> = null; |
| 37 | + public static var isVideo:Bool = false; |
| 38 | + |
| 39 | + public static var instance:APGameOverSubstate; |
| 40 | + public function new() { |
| 41 | + super(); |
| 42 | + } |
| 43 | + |
| 44 | + public static function resetVariables() { |
| 45 | + characterName = 'bf-dead'; |
| 46 | + deathSoundName = 'fnf_loss_sfx'; |
| 47 | + loopSoundName = 'gameOver'; |
| 48 | + endSoundName = 'gameOverEnd'; |
| 49 | + deathDelay = 0; |
| 50 | + |
| 51 | + video = null; |
| 52 | + isVideo = false; |
| 53 | + |
| 54 | + var _song = PlayState.SONG; |
| 55 | + if(_song != null) |
| 56 | + { |
| 57 | + if(_song.gameOverChar != null && _song.gameOverChar.trim().length > 0) characterName = _song.gameOverChar; |
| 58 | + if(_song.gameOverSound != null && _song.gameOverSound.trim().length > 0) deathSoundName = _song.gameOverSound; |
| 59 | + if(_song.gameOverLoop != null && _song.gameOverLoop.trim().length > 0) loopSoundName = _song.gameOverLoop; |
| 60 | + if(_song.gameOverEnd != null && _song.gameOverEnd.trim().length > 0) endSoundName = _song.gameOverEnd; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + var charX:Float = 0; |
| 65 | + var charY:Float = 0; |
| 66 | + |
| 67 | + var overlay:FlxSprite; |
| 68 | + var overlayConfirmOffsets:FlxPoint = FlxPoint.get(); |
| 69 | + override function create() |
| 70 | + { |
| 71 | + instance = this; |
| 72 | + |
| 73 | + FlxG.camera.bgColor = 0xFF000000; // to fix mods that like to change its color (looking at you, 17bucks) |
| 74 | + |
| 75 | + if (Std.is(PlayState.instance, APPlayState) && APPlayState.deathByLink) |
| 76 | + { |
| 77 | + APPlayState.deathByLink = false; |
| 78 | + APPlayState.deathLinkPacket = null; |
| 79 | + } |
| 80 | + |
| 81 | + Conductor.songPosition = 0; |
| 82 | + |
| 83 | + if(boyfriend == null) |
| 84 | + { |
| 85 | + boyfriend = new Character(0, 0, 'bf-dead', true); |
| 86 | + boyfriend.x += boyfriend.positionArray[0]; |
| 87 | + boyfriend.y += boyfriend.positionArray[1]; |
| 88 | + } |
| 89 | + boyfriend.skipDance = true; |
| 90 | + add(boyfriend); |
| 91 | + |
| 92 | + FlxG.sound.play(Paths.sound(deathSoundName)); |
| 93 | + FlxG.camera.scroll.set(); |
| 94 | + FlxG.camera.target = null; |
| 95 | + |
| 96 | + boyfriend.playAnim('firstDeath'); |
| 97 | + |
| 98 | + camFollow = new FlxObject(0, 0, 1, 1); |
| 99 | + camFollow.setPosition(boyfriend.getGraphicMidpoint().x + boyfriend.cameraPosition[0], boyfriend.getGraphicMidpoint().y + boyfriend.cameraPosition[1]); |
| 100 | + FlxG.camera.focusOn(new FlxPoint(FlxG.camera.scroll.x + (FlxG.camera.width / 2), FlxG.camera.scroll.y + (FlxG.camera.height / 2))); |
| 101 | + FlxG.camera.follow(camFollow, LOCKON, 0.01); |
| 102 | + add(camFollow); |
| 103 | + |
| 104 | + PlayState.instance?.setOnScripts('inGameOver', true); |
| 105 | + PlayState.instance?.callOnScripts('onGameOverStart', []); |
| 106 | + FlxG.sound.music.loadEmbedded(Paths.music(loopSoundName), true); |
| 107 | + |
| 108 | + if(characterName == 'pico-dead') |
| 109 | + { |
| 110 | + overlay = new FlxSprite(boyfriend.x + 205, boyfriend.y - 80); |
| 111 | + overlay.frames = Paths.getSparrowAtlas('Pico_Death_Retry'); |
| 112 | + overlay.animation.addByPrefix('deathLoop', 'Retry Text Loop', 24, true); |
| 113 | + overlay.animation.addByPrefix('deathConfirm', 'Retry Text Confirm', 24, false); |
| 114 | + overlay.antialiasing = ClientPrefs.data.antialiasing; |
| 115 | + overlayConfirmOffsets.set(250, 200); |
| 116 | + overlay.visible = false; |
| 117 | + add(overlay); |
| 118 | + |
| 119 | + boyfriend.animation.callback = function(name:String, frameNumber:Int, frameIndex:Int) |
| 120 | + { |
| 121 | + switch(name) |
| 122 | + { |
| 123 | + case 'firstDeath': |
| 124 | + if(frameNumber >= 36 - 1) |
| 125 | + { |
| 126 | + overlay.visible = true; |
| 127 | + overlay.animation.play('deathLoop'); |
| 128 | + boyfriend.animation.callback = null; |
| 129 | + } |
| 130 | + default: |
| 131 | + boyfriend.animation.callback = null; |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + if(PlayState.instance?.gf != null && PlayState.instance?.gf.curCharacter == 'nene') |
| 136 | + { |
| 137 | + var neneKnife:FlxSprite = new FlxSprite(boyfriend.x - 450, boyfriend.y - 250); |
| 138 | + neneKnife.frames = Paths.getSparrowAtlas('NeneKnifeToss'); |
| 139 | + neneKnife.animation.addByPrefix('anim', 'knife toss', 24, false); |
| 140 | + neneKnife.antialiasing = ClientPrefs.data.antialiasing; |
| 141 | + neneKnife.animation.finishCallback = function(_) |
| 142 | + { |
| 143 | + remove(neneKnife); |
| 144 | + neneKnife.destroy(); |
| 145 | + } |
| 146 | + insert(0, neneKnife); |
| 147 | + neneKnife.animation.play('anim', true); |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + deathbysquare = new FlxSprite().makeGraphic(500, 300, 0xFFFFFFFF); |
| 152 | + deathbysquare.scrollFactor.set(); |
| 153 | + deathbysquare.x += 800; |
| 154 | + deathbysquare.y -= 100; |
| 155 | + deathbysquare.alpha = 0.3; |
| 156 | + add(deathbysquare); |
| 157 | + |
| 158 | + var alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; |
| 159 | + causeofdeath = new UnderTextParser(deathbysquare.x, deathbysquare.y + 125, Std.int(deathbysquare.width), "", 32); |
| 160 | + causeofdeath.scrollFactor.set(); |
| 161 | + causeofdeath.font = Paths.font("fnf1.ttf"); |
| 162 | + causeofdeath.color = 0xFFFFFFFF; |
| 163 | + for (letter in alphabet) { |
| 164 | + causeofdeath.soundOnChars.set(letter, FlxG.sound.load(Paths.sound('ut/uifont'), 1)); |
| 165 | + causeofdeath.soundOnChars.set(letter.toUpperCase(), FlxG.sound.load(Paths.sound('ut/uifont'), 1)); |
| 166 | + } |
| 167 | + add(causeofdeath); |
| 168 | + |
| 169 | + super.create(); |
| 170 | + } |
| 171 | + |
| 172 | + override function update(elapsed:Float) |
| 173 | + { |
| 174 | + super.update(elapsed); |
| 175 | + |
| 176 | + PlayState.instance?.callOnScripts('onUpdate', [elapsed]); |
| 177 | + |
| 178 | + var justPlayedLoop:Bool = false; |
| 179 | + if (!boyfriend.isAnimationNull() && boyfriend.getAnimationName() == 'firstDeath' && boyfriend.isAnimationFinished()) |
| 180 | + { |
| 181 | + boyfriend.playAnim('deathLoop'); |
| 182 | + if(overlay != null && overlay.animation.exists('deathLoop')) |
| 183 | + { |
| 184 | + overlay.visible = true; |
| 185 | + overlay.animation.play('deathLoop'); |
| 186 | + } |
| 187 | + justPlayedLoop = true; |
| 188 | + } |
| 189 | + |
| 190 | + if(!isEnding) |
| 191 | + { |
| 192 | + if (controls.ACCEPT) |
| 193 | + { |
| 194 | + endBullshit(); |
| 195 | + } |
| 196 | + else if (controls.BACK) |
| 197 | + { |
| 198 | + #if DISCORD_ALLOWED DiscordClient.resetClientID(); #end |
| 199 | + FlxG.camera.visible = false; |
| 200 | + FlxG.sound.music.stop(); |
| 201 | + |
| 202 | + Mods.loadTopMod(); |
| 203 | + MusicBeatState.switchState(new FreeplayState()); |
| 204 | + |
| 205 | + FlxG.sound.playMusic(Paths.music('freakyMenu')); |
| 206 | + PlayState.instance?.callOnScripts('onGameOverConfirm', [false]); |
| 207 | + } |
| 208 | + else if (justPlayedLoop) coolStartDeath(); |
| 209 | + |
| 210 | + if (FlxG.sound.music.playing) |
| 211 | + { |
| 212 | + Conductor.songPosition = FlxG.sound.music.time; |
| 213 | + } |
| 214 | + } |
| 215 | + PlayState.instance?.callOnScripts('onUpdatePost', [elapsed]); |
| 216 | + } |
| 217 | + |
| 218 | + var isEnding:Bool = false; |
| 219 | + function coolStartDeath(?volume:Float = 1):Void |
| 220 | + { |
| 221 | + FlxG.sound.music.play(true); |
| 222 | + FlxG.sound.music.volume = volume; |
| 223 | + causeofdeath.resetText(COD.getCOD()); |
| 224 | + causeofdeath.start(0.05, true); |
| 225 | + } |
| 226 | + |
| 227 | + function endBullshit():Void |
| 228 | + { |
| 229 | + if (!isEnding) |
| 230 | + { |
| 231 | + isEnding = true; |
| 232 | + if(boyfriend.hasAnimation('deathConfirm')) |
| 233 | + boyfriend.playAnim('deathConfirm', true); |
| 234 | + else if(boyfriend.hasAnimation('deathLoop')) |
| 235 | + boyfriend.playAnim('deathLoop', true); |
| 236 | + |
| 237 | + if(overlay != null && overlay.animation.exists('deathConfirm')) |
| 238 | + { |
| 239 | + overlay.visible = true; |
| 240 | + overlay.animation.play('deathConfirm'); |
| 241 | + overlay.offset.set(overlayConfirmOffsets.x, overlayConfirmOffsets.y); |
| 242 | + } |
| 243 | + FlxG.sound.music.stop(); |
| 244 | + FlxG.sound.play(Paths.music(endSoundName)); |
| 245 | + new FlxTimer().start(0.7, function(tmr:FlxTimer) |
| 246 | + { |
| 247 | + FlxG.camera.fade(FlxColor.BLACK, 2, false, function() |
| 248 | + { |
| 249 | + MusicBeatState.resetState(); |
| 250 | + }); |
| 251 | + }); |
| 252 | + PlayState.instance?.callOnScripts('onGameOverConfirm', [true]); |
| 253 | + } |
| 254 | + } |
| 255 | + |
| 256 | + override function destroy() |
| 257 | + { |
| 258 | + instance = null; |
| 259 | + super.destroy(); |
| 260 | + } |
| 261 | +} |
0 commit comments