package funkin.menus; #if desktop import funkin.system.Discord.DiscordClient; import sys.thread.Thread; #end import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxState; import flixel.addons.display.FlxGridOverlay; import flixel.addons.transition.FlxTransitionSprite.GraphicTransTileDiamond; import flixel.addons.transition.FlxTransitionableState; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxAtlasFrames; import flixel.group.FlxGroup; import flixel.input.gamepad.FlxGamepad; import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.system.FlxSound; import flixel.system.ui.FlxSoundTray; import flixel.text.FlxText; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; import flixel.util.FlxColor; import flixel.util.FlxTimer; import funkin.system.Conductor; import lime.app.Application; import openfl.Assets; import funkin.ui.Alphabet; using StringTools; class TitleState extends MusicBeatState { static var initialized:Bool = false; var blackScreen:FlxSprite; var textGroup:FlxGroup; var ngSpr:FlxSprite; var curWacky:Array = []; var wackyImage:FlxSprite; override public function create():Void { curWacky = FlxG.random.getObject(getIntroTextShit()); FlxTransitionableState.skipNextTransIn = true; super.create(); startIntro(); #if desktop DiscordClient.initialize(); Application.current.onExit.add (function (exitCode) { DiscordClient.shutdown(); }); #end } var logoBl:FlxSprite; var gfDance:FlxSprite; var danceLeft:Bool = false; var titleText:FlxSprite; function startIntro() { if (!initialized) { FlxG.sound.playMusic(Paths.music('freakyMenu'), 0); FlxG.sound.music.fadeIn(4, 0, 0.7); } Conductor.changeBPM(102); persistentUpdate = true; var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK); add(bg); logoBl = new FlxSprite(-150, -100); logoBl.frames = Paths.getSparrowAtlas('logoBumpin'); logoBl.antialiasing = true; logoBl.animation.addByPrefix('bump', 'logo bumpin', 24); logoBl.animation.play('bump'); logoBl.updateHitbox(); gfDance = new FlxSprite(FlxG.width * 0.4, FlxG.height * 0.07); gfDance.frames = Paths.getSparrowAtlas('gfDanceTitle'); gfDance.animation.addByIndices('danceLeft', 'gfDance', [30, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], "", 24, false); gfDance.animation.addByIndices('danceRight', 'gfDance', [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], "", 24, false); gfDance.antialiasing = true; add(gfDance); add(logoBl); titleText = new FlxSprite(100, FlxG.height * 0.8); titleText.frames = Paths.getSparrowAtlas('titleEnter'); titleText.animation.addByPrefix('idle', "Press Enter to Begin", 24); titleText.animation.addByPrefix('press', "ENTER PRESSED", 24); titleText.antialiasing = true; titleText.animation.play('idle'); titleText.updateHitbox(); add(titleText); textGroup = new FlxGroup(); blackScreen = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK); add(blackScreen); ngSpr = new FlxSprite(0, FlxG.height * 0.52).loadGraphic(Paths.image('newgrounds_logo')); add(ngSpr); ngSpr.visible = false; ngSpr.setGraphicSize(Std.int(ngSpr.width * 0.8)); ngSpr.updateHitbox(); ngSpr.screenCenter(X); ngSpr.antialiasing = true; FlxG.mouse.visible = false; if (initialized) skipIntro(); else initialized = true; } function getIntroTextShit():Array> { var fullText:String = Assets.getText(Paths.txt('titlescreen/introText')); var firstArray:Array = fullText.split('\n'); var swagGoodArray:Array> = []; for (i in firstArray) { swagGoodArray.push(i.split('--')); } return swagGoodArray; } var transitioning:Bool = false; override function update(elapsed:Float) { if (FlxG.sound.music != null) Conductor.songPosition = FlxG.sound.music.time; if (FlxG.keys.justPressed.F) FlxG.fullscreen = !FlxG.fullscreen; var pressedEnter:Bool = FlxG.keys.justPressed.ENTER; #if mobile for (touch in FlxG.touches.list) { if (touch.justPressed) { pressedEnter = true; } } #end var gamepad:FlxGamepad = FlxG.gamepads.lastActive; if (gamepad != null) { if (gamepad.justPressed.START) pressedEnter = true; #if switch if (gamepad.justPressed.B) pressedEnter = true; #end } if (pressedEnter && !transitioning && skippedIntro) { titleText.animation.play('press'); FlxG.camera.flash(FlxColor.WHITE, 1); FlxG.sound.play(Paths.sound('confirmMenu'), 0.7); transitioning = true; // FlxG.sound.music.stop(); new FlxTimer().start(2, function(tmr:FlxTimer) { FlxG.switchState(new MainMenuState()); }); } if (pressedEnter && !skippedIntro) skipIntro(); super.update(elapsed); } function createCoolText(textArray:Array) { for (i=>text in textArray) { if (text == "" || text == null) continue; var money:Alphabet = new Alphabet(0, (i * 60) + 200, text, true, false); money.screenCenter(X); textGroup.add(money); } } function addMoreText(text:String) { var coolText:Alphabet = new Alphabet(0, (textGroup.length * 60) + 200, text, true, false); coolText.screenCenter(X); textGroup.add(coolText); } function deleteCoolText() { while (textGroup.members.length > 0) textGroup.remove(textGroup.members[0], true); } override function beatHit() { super.beatHit(); logoBl.animation.play('bump'); danceLeft = !danceLeft; if (danceLeft) gfDance.animation.play('danceRight'); else gfDance.animation.play('danceLeft'); #if TITLESCREEN_XML #else switch (curBeat) { case 1: createCoolText(['ninjamuffin99', 'phantomArcade', 'kawaisprite', 'evilsk8er']); case 3: addMoreText('present'); case 4: deleteCoolText(); case 5: createCoolText(['In association', 'with']); case 7: addMoreText('newgrounds'); ngSpr.visible = true; case 8: deleteCoolText(); ngSpr.visible = false; case 9: createCoolText([curWacky[0]]); case 11: addMoreText(curWacky[1]); case 12: deleteCoolText(); case 13: addMoreText('Friday'); case 14: addMoreText('Night'); case 15: addMoreText('Funkin'); case 16: skipIntro(); } #end } var skippedIntro:Bool = false; function skipIntro():Void { if (!skippedIntro) { remove(ngSpr); FlxG.camera.flash(FlxColor.WHITE, 4); remove(blackScreen); blackScreen.destroy(); skippedIntro = true; } } }