Funkin/source/FreeplayState.hx

93 lines
1.8 KiB
Haxe
Raw Normal View History

2020-10-21 14:05:27 -04:00
package;
import flixel.FlxG;
import flixel.FlxSprite;
2020-10-25 16:51:06 -04:00
import flixel.addons.display.FlxGridOverlay;
2020-10-21 14:05:27 -04:00
import flixel.text.FlxText;
2020-10-26 19:06:42 -04:00
#if switch
import openfl.events.GameInputEvent;
import openfl.ui.GameInput;
import openfl.ui.GameInputDevice;
import openfl.ui.GameInputControl;
#end
2020-10-21 14:05:27 -04:00
class FreeplayState extends MusicBeatState
{
var songs:Array<String> = ["Bopeebo", "Dadbattle", "Fresh", "Tutorial\nlol"];
2020-10-21 14:05:27 -04:00
var selector:FlxText;
var curSelected:Int = 0;
override function create()
{
// LOAD MUSIC
// LOAD CHARACTERS
2020-10-25 16:51:06 -04:00
var bg:FlxSprite = FlxGridOverlay.create(20, 20);
add(bg);
2020-10-21 14:05:27 -04:00
for (i in 0...songs.length)
{
2020-10-25 16:51:06 -04:00
var songText:Alphabet = new Alphabet(40, (70 * i) + 30, songs[i]);
2020-10-21 14:05:27 -04:00
add(songText);
}
selector = new FlxText();
2020-10-25 16:51:06 -04:00
selector.size = 40;
2020-10-21 14:05:27 -04:00
selector.text = ">";
add(selector);
2020-10-25 16:51:06 -04:00
var swag:Alphabet = new Alphabet(1, 0, "swag");
2020-10-21 14:05:27 -04:00
super.create();
}
override function update(elapsed:Float)
{
if (FlxG.keys.justPressed.UP)
{
curSelected -= 1;
}
if (FlxG.keys.justPressed.DOWN)
{
curSelected += 1;
}
2020-10-26 19:06:42 -04:00
#if switch
if (gamepad.anyJustPressed(["UP", "DPAD_UP", "LEFT_STICK_DIGITAL_UP"]))
{
curSelected -= 1;
}
if (gamepad.anyJustPressed(["DOWN", "DPAD_DOWN", "LEFT_STICK_DIGITAL_DOWN"]))
{
curSelected += 1;
}
#end
2020-10-21 14:05:27 -04:00
if (curSelected < 0)
curSelected = songs.length - 1;
if (curSelected >= songs.length)
curSelected = 0;
2020-10-25 16:51:06 -04:00
selector.y = (70 * curSelected) + 30;
2020-10-21 14:05:27 -04:00
2020-10-21 19:33:43 -04:00
if (FlxG.keys.justPressed.ENTER)
{
PlayState.SONG = Song.loadFromJson(songs[curSelected].toLowerCase());
FlxG.switchState(new PlayState());
}
2020-10-26 19:06:42 -04:00
#if switch
if (gamepad.anyJustPressed(["B"])) //"B" is swapped with "A" on Switch
{
PlayState.SONG = Song.loadFromJson(songs[curSelected].toLowerCase());
FlxG.switchState(new PlayState());
}
#end
2020-10-21 14:05:27 -04:00
super.update(elapsed);
}
}