1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-04 22:04:29 +00:00
Funkin/source/TitleState.hx

404 lines
10 KiB
Haxe
Raw Normal View History

2020-10-05 18:24:51 +00:00
package;
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.addons.transition.TransitionData;
import flixel.graphics.FlxGraphic;
2020-11-01 19:16:22 +00:00
import flixel.graphics.frames.FlxAtlasFrames;
2020-10-21 06:23:39 +00:00
import flixel.group.FlxGroup;
2020-10-09 07:29:00 +00:00
import flixel.input.gamepad.FlxGamepad;
2020-10-05 18:24:51 +00:00
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
2020-11-07 21:59:25 +00:00
import flixel.system.FlxSound;
import flixel.system.ui.FlxSoundTray;
2020-10-21 06:23:39 +00:00
import flixel.text.FlxText;
2020-10-05 18:24:51 +00:00
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import flixel.util.FlxTimer;
import io.newgrounds.NG;
import lime.app.Application;
2021-01-25 03:42:51 +00:00
import openfl.Assets;
2021-01-04 23:56:30 +00:00
import polymod.Polymod;
2020-10-05 18:24:51 +00:00
using StringTools;
2020-10-21 06:23:39 +00:00
class TitleState extends MusicBeatState
2020-10-05 18:24:51 +00:00
{
static var initialized:Bool = false;
2020-10-07 01:56:14 +00:00
static public var soundExt:String = ".mp3";
2020-10-05 18:24:51 +00:00
2020-10-21 06:23:39 +00:00
var blackScreen:FlxSprite;
var credGroup:FlxGroup;
2020-10-30 23:47:19 +00:00
var credTextShit:Alphabet;
var textGroup:FlxGroup;
2020-11-01 01:11:14 +00:00
var ngSpr:FlxSprite;
var curWacky:Array<String> = [];
2020-10-21 06:23:39 +00:00
2020-11-02 22:40:12 +00:00
var wackyImage:FlxSprite;
2020-10-05 18:24:51 +00:00
override public function create():Void
{
2021-01-25 03:42:51 +00:00
Polymod.init({modRoot: "mods", dirs: ['introMod']});
2021-01-04 23:56:30 +00:00
2020-10-07 01:56:14 +00:00
#if (!web)
TitleState.soundExt = '.ogg';
#end
2020-10-30 23:47:19 +00:00
PlayerSettings.init();
2020-11-16 20:29:18 +00:00
curWacky = FlxG.random.getObject(getIntroTextShit());
2020-11-01 01:11:14 +00:00
2020-10-30 23:47:19 +00:00
// DEBUG BULLSHIT
2020-10-05 18:24:51 +00:00
super.create();
2020-12-16 03:00:22 +00:00
NGio.noLogin(APIStuff.API);
2020-12-04 17:57:09 +00:00
#if ng
2020-11-01 19:16:22 +00:00
var ng:NGio = new NGio(APIStuff.API, APIStuff.EncKey);
2020-12-04 17:46:03 +00:00
trace('NEWGROUNDS LOL');
2020-11-01 19:16:22 +00:00
#end
2020-11-07 02:17:27 +00:00
FlxG.save.bind('funkin', 'ninjamuffin99');
Highscore.load();
if (FlxG.save.data.weekUnlocked != null)
{
2020-12-27 10:57:45 +00:00
// FIX LATER!!!
// WEEK UNLOCK PROGRESSION!!
// StoryMenuState.weekUnlocked = FlxG.save.data.weekUnlocked;
2020-11-07 02:17:27 +00:00
2020-12-11 09:15:24 +00:00
if (StoryMenuState.weekUnlocked.length < 4)
2020-12-11 13:49:06 +00:00
StoryMenuState.weekUnlocked.insert(0, true);
// QUICK PATCH OOPS!
if (!StoryMenuState.weekUnlocked[0])
StoryMenuState.weekUnlocked[0] = true;
2020-11-07 02:17:27 +00:00
}
2020-12-27 02:46:22 +00:00
#if FREEPLAY
FlxG.switchState(new FreeplayState());
#elseif CHARTING
2020-12-21 22:20:57 +00:00
FlxG.switchState(new ChartingState());
2020-10-30 23:47:19 +00:00
#else
startIntro();
#end
}
2020-11-01 19:16:22 +00:00
var logoBl:FlxSprite;
var gfDance:FlxSprite;
var danceLeft:Bool = false;
var titleText:FlxSprite;
2020-10-30 23:47:19 +00:00
function startIntro()
{
2020-10-05 18:24:51 +00:00
if (!initialized)
{
var diamond:FlxGraphic = FlxGraphic.fromClass(GraphicTransTileDiamond);
diamond.persist = true;
diamond.destroyOnNoUse = false;
2020-11-01 01:11:14 +00:00
FlxTransitionableState.defaultTransIn = new TransitionData(FADE, FlxColor.BLACK, 1, new FlxPoint(0, -1), {asset: diamond, width: 32, height: 32},
2021-01-20 09:11:55 +00:00
new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4));
2020-11-01 01:11:14 +00:00
FlxTransitionableState.defaultTransOut = new TransitionData(FADE, FlxColor.BLACK, 0.7, new FlxPoint(0, 1),
2021-01-20 09:11:55 +00:00
{asset: diamond, width: 32, height: 32}, new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4));
2020-10-05 18:24:51 +00:00
transIn = FlxTransitionableState.defaultTransIn;
transOut = FlxTransitionableState.defaultTransOut;
2020-11-01 01:11:14 +00:00
2021-01-17 04:15:29 +00:00
// HAD TO MODIFY SOME BACKEND SHIT
// IF THIS PR IS HERE IF ITS ACCEPTED UR GOOD TO GO
// https://github.com/HaxeFlixel/flixel-addons/pull/348
2020-11-11 10:00:13 +00:00
// var music:FlxSound = new FlxSound();
// music.loadStream('assets/music/freakyMenu' + TitleState.soundExt);
// FlxG.sound.list.add(music);
// music.play();
2020-11-01 01:11:14 +00:00
FlxG.sound.playMusic('assets/music/freakyMenu' + TitleState.soundExt, 0);
FlxG.sound.music.fadeIn(4, 0, 0.7);
2020-10-05 18:24:51 +00:00
}
2020-11-01 19:16:22 +00:00
Conductor.changeBPM(102);
2020-10-05 18:24:51 +00:00
persistentUpdate = true;
2020-11-01 19:16:22 +00:00
var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
// bg.antialiasing = true;
// bg.setGraphicSize(Std.int(bg.width * 0.6));
// bg.updateHitbox();
2020-10-05 18:24:51 +00:00
add(bg);
2020-11-01 19:16:22 +00:00
logoBl = new FlxSprite(-150, -100);
2021-01-04 23:56:30 +00:00
logoBl.frames = FlxAtlasFrames.fromSparrow('assets/images/logoBumpin.png', 'assets/images/logoBumpin.xml');
2020-11-01 19:16:22 +00:00
logoBl.antialiasing = true;
logoBl.animation.addByPrefix('bump', 'logo bumpin', 24);
logoBl.animation.play('bump');
logoBl.updateHitbox();
// logoBl.screenCenter();
// logoBl.color = FlxColor.BLACK;
gfDance = new FlxSprite(FlxG.width * 0.4, FlxG.height * 0.07);
2021-01-04 23:56:30 +00:00
gfDance.frames = FlxAtlasFrames.fromSparrow('assets/images/gfDanceTitle.png', 'assets/images/gfDanceTitle.xml');
2020-11-01 19:16:22 +00:00
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);
2020-10-05 18:24:51 +00:00
add(logoBl);
2020-11-01 19:16:22 +00:00
titleText = new FlxSprite(100, FlxG.height * 0.8);
2021-01-04 23:56:30 +00:00
titleText.frames = FlxAtlasFrames.fromSparrow('assets/images/titleEnter.png', 'assets/images/titleEnter.xml');
2020-11-01 19:16:22 +00:00
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();
// titleText.screenCenter(X);
add(titleText);
2021-01-04 23:56:30 +00:00
var logo:FlxSprite = new FlxSprite().loadGraphic('assets/images/logo.png');
2020-10-05 18:24:51 +00:00
logo.screenCenter();
2020-10-05 22:29:59 +00:00
logo.antialiasing = true;
2020-11-01 19:16:22 +00:00
// add(logo);
2020-10-05 18:24:51 +00:00
2020-11-01 19:16:22 +00:00
// FlxTween.tween(logoBl, {y: logoBl.y + 50}, 0.6, {ease: FlxEase.quadInOut, type: PINGPONG});
// FlxTween.tween(logo, {y: logoBl.y + 50}, 0.6, {ease: FlxEase.quadInOut, type: PINGPONG, startDelay: 0.1});
2020-10-05 18:24:51 +00:00
2020-10-21 06:23:39 +00:00
credGroup = new FlxGroup();
add(credGroup);
2020-10-30 23:47:19 +00:00
textGroup = new FlxGroup();
2020-10-21 06:23:39 +00:00
blackScreen = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
credGroup.add(blackScreen);
2020-10-30 23:47:19 +00:00
credTextShit = new Alphabet(0, 0, "ninjamuffin99\nPhantomArcade\nkawaisprite\nevilsk8er", true);
2020-10-21 06:23:39 +00:00
credTextShit.screenCenter();
2020-10-30 23:47:19 +00:00
// credTextShit.alignment = CENTER;
2020-10-21 06:23:39 +00:00
credTextShit.visible = false;
2021-01-04 23:56:30 +00:00
ngSpr = new FlxSprite(0, FlxG.height * 0.52).loadGraphic('assets/images/newgrounds_logo.png');
2020-11-01 01:11:14 +00:00
add(ngSpr);
ngSpr.visible = false;
ngSpr.setGraphicSize(Std.int(ngSpr.width * 0.8));
ngSpr.updateHitbox();
ngSpr.screenCenter(X);
ngSpr.antialiasing = true;
2020-10-21 06:23:39 +00:00
2020-11-01 01:11:14 +00:00
FlxTween.tween(credTextShit, {y: credTextShit.y + 20}, 2.9, {ease: FlxEase.quadInOut, type: PINGPONG});
2020-10-21 06:23:39 +00:00
2020-11-01 19:16:22 +00:00
FlxG.mouse.visible = false;
2020-11-01 01:11:14 +00:00
if (initialized)
skipIntro();
else
initialized = true;
2020-10-05 18:24:51 +00:00
2020-11-01 01:11:14 +00:00
// credGroup.add(credTextShit);
2020-10-05 18:24:51 +00:00
}
2020-11-16 20:29:18 +00:00
function getIntroTextShit():Array<Array<String>>
{
var fullText:String = Assets.getText('assets/data/introText.txt');
var firstArray:Array<String> = fullText.split('\n');
var swagGoodArray:Array<Array<String>> = [];
for (i in firstArray)
{
swagGoodArray.push(i.split('--'));
}
return swagGoodArray;
}
2020-10-05 18:24:51 +00:00
var transitioning:Bool = false;
override function update(elapsed:Float)
{
2020-10-21 06:23:39 +00:00
Conductor.songPosition = FlxG.sound.music.time;
2020-11-07 02:17:27 +00:00
// FlxG.watch.addQuick('amp', FlxG.sound.music.amplitude);
if (FlxG.keys.justPressed.F)
{
FlxG.fullscreen = !FlxG.fullscreen;
}
2020-10-21 06:23:39 +00:00
2020-10-09 07:29:00 +00:00
var pressedEnter:Bool = FlxG.keys.justPressed.ENTER;
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;
if (gamepad != null)
{
if (gamepad.justPressed.START)
pressedEnter = true;
2020-11-03 09:12:13 +00:00
#if switch
if (gamepad.justPressed.B)
pressedEnter = true;
#end
2020-10-09 07:29:00 +00:00
}
2020-10-21 18:05:27 +00:00
if (pressedEnter && !transitioning && skippedIntro)
2020-10-05 18:24:51 +00:00
{
2020-11-02 20:31:28 +00:00
#if !switch
2020-11-01 19:16:22 +00:00
NGio.unlockMedal(60960);
2020-11-07 02:17:27 +00:00
// If it's Friday according to da clock
if (Date.now().getDay() == 5)
NGio.unlockMedal(61034);
2020-11-02 20:31:28 +00:00
#end
2020-11-02 23:37:55 +00:00
2020-11-01 19:16:22 +00:00
titleText.animation.play('press');
2020-10-05 18:33:56 +00:00
FlxG.camera.flash(FlxColor.WHITE, 1);
2020-11-01 01:11:14 +00:00
FlxG.sound.play('assets/sounds/confirmMenu' + TitleState.soundExt, 0.7);
2020-10-05 18:33:56 +00:00
2020-10-05 18:24:51 +00:00
transitioning = true;
2020-11-01 01:11:14 +00:00
// FlxG.sound.music.stop();
2020-10-05 18:24:51 +00:00
new FlxTimer().start(2, function(tmr:FlxTimer)
{
// Check if version is outdated
var version:String = "v" + Application.current.meta.get('version');
if (version.trim() != NGio.GAME_VER.trim() && !OutdatedSubState.leftState)
{
trace('OLD VERSION!');
FlxG.switchState(new OutdatedSubState());
}
else
{
FlxG.switchState(new MainMenuState());
}
2020-10-05 18:24:51 +00:00
});
2020-11-01 01:11:14 +00:00
// FlxG.sound.play('assets/music/titleShoot' + TitleState.soundExt, 0.7);
}
if (pressedEnter && !skippedIntro)
{
skipIntro();
2020-10-05 18:24:51 +00:00
}
super.update(elapsed);
}
2020-10-21 06:23:39 +00:00
2020-10-30 23:47:19 +00:00
function createCoolText(textArray:Array<String>)
{
for (i in 0...textArray.length)
{
var money:Alphabet = new Alphabet(0, 0, textArray[i], true, false);
money.screenCenter(X);
money.y += (i * 60) + 200;
credGroup.add(money);
textGroup.add(money);
}
}
function addMoreText(text:String)
{
var coolText:Alphabet = new Alphabet(0, 0, text, true, false);
coolText.screenCenter(X);
coolText.y += (textGroup.length * 60) + 200;
credGroup.add(coolText);
textGroup.add(coolText);
}
function deleteCoolText()
{
while (textGroup.members.length > 0)
{
credGroup.remove(textGroup.members[0], true);
textGroup.remove(textGroup.members[0], true);
}
}
2020-10-21 06:23:39 +00:00
override function beatHit()
{
super.beatHit();
2020-11-01 19:16:22 +00:00
logoBl.animation.play('bump');
danceLeft = !danceLeft;
if (danceLeft)
gfDance.animation.play('danceRight');
else
gfDance.animation.play('danceLeft');
2020-10-21 06:23:39 +00:00
FlxG.log.add(curBeat);
switch (curBeat)
{
case 1:
2020-10-30 23:47:19 +00:00
createCoolText(['ninjamuffin99', 'phantomArcade', 'kawaisprite', 'evilsk8er']);
// credTextShit.visible = true;
2020-10-21 06:23:39 +00:00
case 3:
2020-10-30 23:47:19 +00:00
addMoreText('present');
// credTextShit.text += '\npresent...';
// credTextShit.addText();
2020-10-21 06:23:39 +00:00
case 4:
2020-10-30 23:47:19 +00:00
deleteCoolText();
// credTextShit.visible = false;
// credTextShit.text = 'In association \nwith';
// credTextShit.screenCenter();
2020-10-21 06:23:39 +00:00
case 5:
2020-10-30 23:47:19 +00:00
createCoolText(['In association', 'with']);
2020-10-21 06:23:39 +00:00
case 7:
2020-10-30 23:47:19 +00:00
addMoreText('newgrounds');
2020-11-01 01:11:14 +00:00
ngSpr.visible = true;
2020-10-30 23:47:19 +00:00
// credTextShit.text += '\nNewgrounds';
2020-10-21 06:23:39 +00:00
case 8:
2020-10-30 23:47:19 +00:00
deleteCoolText();
2020-11-01 01:11:14 +00:00
ngSpr.visible = false;
2020-10-30 23:47:19 +00:00
// credTextShit.visible = false;
// credTextShit.text = 'Shoutouts Tom Fulp';
// credTextShit.screenCenter();
2020-10-21 06:23:39 +00:00
case 9:
2020-11-01 01:11:14 +00:00
createCoolText([curWacky[0]]);
2020-10-30 23:47:19 +00:00
// credTextShit.visible = true;
2020-10-21 06:23:39 +00:00
case 11:
2020-11-01 01:11:14 +00:00
addMoreText(curWacky[1]);
2020-10-30 23:47:19 +00:00
// credTextShit.text += '\nlmao';
2020-10-21 06:23:39 +00:00
case 12:
2020-10-30 23:47:19 +00:00
deleteCoolText();
// credTextShit.visible = false;
// credTextShit.text = "Friday";
// credTextShit.screenCenter();
2020-10-21 06:23:39 +00:00
case 13:
2020-10-30 23:47:19 +00:00
addMoreText('Friday');
// credTextShit.visible = true;
2020-10-21 06:23:39 +00:00
case 14:
2020-10-30 23:47:19 +00:00
addMoreText('Night');
// credTextShit.text += '\nNight';
2020-10-21 06:23:39 +00:00
case 15:
2020-10-30 23:47:19 +00:00
addMoreText('Funkin'); // credTextShit.text += '\nFunkin';
2020-10-21 06:23:39 +00:00
case 16:
2020-10-21 18:05:27 +00:00
skipIntro();
}
}
var skippedIntro:Bool = false;
function skipIntro():Void
{
if (!skippedIntro)
{
2020-11-01 01:11:14 +00:00
remove(ngSpr);
2020-10-21 18:05:27 +00:00
FlxG.camera.flash(FlxColor.WHITE, 4);
remove(credGroup);
2020-10-30 23:47:19 +00:00
skippedIntro = true;
2020-10-21 06:23:39 +00:00
}
}
2020-10-05 18:24:51 +00:00
}