intro messages
This commit is contained in:
148
source/MainMenuState.hx
Normal file
148
source/MainMenuState.hx
Normal file
@ -0,0 +1,148 @@
|
||||
package;
|
||||
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxObject;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.effects.FlxFlicker;
|
||||
import flixel.graphics.frames.FlxAtlasFrames;
|
||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||
import flixel.tweens.FlxEase;
|
||||
import flixel.tweens.FlxTween;
|
||||
|
||||
class MainMenuState extends MusicBeatState
|
||||
{
|
||||
var curSelected:Int = 0;
|
||||
|
||||
var menuItems:FlxTypedGroup<FlxSprite>;
|
||||
|
||||
var optionShit:Array<String> = ['story mode', 'freeplay', 'donate'];
|
||||
|
||||
var magenta:FlxSprite;
|
||||
var camFollow:FlxObject;
|
||||
|
||||
override function create()
|
||||
{
|
||||
persistentUpdate = persistentDraw = true;
|
||||
|
||||
var bg:FlxSprite = new FlxSprite(-80).loadGraphic(AssetPaths.menuBG__png);
|
||||
bg.scrollFactor.x = 0;
|
||||
bg.scrollFactor.y = 0.18;
|
||||
bg.setGraphicSize(Std.int(bg.width * 1.1));
|
||||
bg.updateHitbox();
|
||||
bg.screenCenter();
|
||||
bg.antialiasing = true;
|
||||
add(bg);
|
||||
|
||||
camFollow = new FlxObject(0, 0, 1, 1);
|
||||
add(camFollow);
|
||||
|
||||
magenta = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, 0xFFF44688);
|
||||
magenta.visible = false;
|
||||
add(magenta);
|
||||
magenta.scrollFactor.set();
|
||||
|
||||
menuItems = new FlxTypedGroup<FlxSprite>();
|
||||
add(menuItems);
|
||||
|
||||
var tex = FlxAtlasFrames.fromSparrow(AssetPaths.FNF_main_menu_assets__png, AssetPaths.FNF_main_menu_assets__xml);
|
||||
|
||||
for (i in 0...optionShit.length)
|
||||
{
|
||||
var menuItem:FlxSprite = new FlxSprite(0, 60 + (i * 160));
|
||||
menuItem.frames = tex;
|
||||
menuItem.animation.addByPrefix('idle', optionShit[i] + " basic", 24);
|
||||
menuItem.animation.addByPrefix('selected', optionShit[i] + " white", 24);
|
||||
menuItem.animation.play('idle');
|
||||
menuItem.ID = i;
|
||||
menuItem.screenCenter(X);
|
||||
menuItems.add(menuItem);
|
||||
menuItem.scrollFactor.set();
|
||||
menuItem.antialiasing = true;
|
||||
}
|
||||
|
||||
FlxG.camera.follow(camFollow, null, 0.06);
|
||||
|
||||
changeItem();
|
||||
|
||||
super.create();
|
||||
}
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
if (controls.UP_P)
|
||||
changeItem(-1);
|
||||
if (controls.DOWN_P)
|
||||
changeItem(1);
|
||||
|
||||
super.update(elapsed);
|
||||
|
||||
if (controls.ACCEPT)
|
||||
{
|
||||
if (optionShit[curSelected] == 'donate')
|
||||
{
|
||||
FlxG.openURL('https://ninja-muffin24.itch.io/funkin');
|
||||
}
|
||||
else
|
||||
{
|
||||
FlxFlicker.flicker(magenta, 0, 0.40);
|
||||
|
||||
menuItems.forEach(function(spr:FlxSprite)
|
||||
{
|
||||
if (curSelected != spr.ID)
|
||||
{
|
||||
FlxTween.tween(spr, {alpha: 0}, 0.4, {
|
||||
ease: FlxEase.quadOut,
|
||||
onComplete: function(twn:FlxTween)
|
||||
{
|
||||
spr.kill();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
FlxFlicker.flicker(spr, 1, 0.06, false, false, function(flick:FlxFlicker)
|
||||
{
|
||||
var daChoice:String = optionShit[curSelected];
|
||||
|
||||
switch (daChoice)
|
||||
{
|
||||
case 'story mode':
|
||||
FlxG.switchState(new StoryMenuState());
|
||||
case 'freeplay':
|
||||
FlxG.switchState(new FreeplayState());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
menuItems.forEach(function(spr:FlxSprite)
|
||||
{
|
||||
spr.screenCenter(X);
|
||||
});
|
||||
}
|
||||
|
||||
function changeItem(huh:Int = 0)
|
||||
{
|
||||
curSelected += huh;
|
||||
|
||||
if (curSelected >= menuItems.length)
|
||||
curSelected = 0;
|
||||
if (curSelected < 0)
|
||||
curSelected = menuItems.length - 1;
|
||||
|
||||
menuItems.forEach(function(spr:FlxSprite)
|
||||
{
|
||||
spr.animation.play('idle');
|
||||
|
||||
if (spr.ID == curSelected)
|
||||
{
|
||||
spr.animation.play('selected');
|
||||
camFollow.setPosition(spr.getGraphicMidpoint().x, spr.getGraphicMidpoint().y);
|
||||
}
|
||||
|
||||
spr.updateHitbox();
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user