1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-05 06:14:36 +00:00
Funkin/source/FreeplayState.hx

104 lines
2.2 KiB
Haxe
Raw Normal View History

2020-10-21 18:05:27 +00:00
package;
import flixel.FlxG;
import flixel.FlxSprite;
2020-10-25 20:51:06 +00:00
import flixel.addons.display.FlxGridOverlay;
2020-10-21 18:05:27 +00:00
import flixel.text.FlxText;
2020-10-26 23:06:42 +00:00
#if switch
import openfl.events.GameInputEvent;
import openfl.ui.GameInput;
import openfl.ui.GameInputDevice;
import openfl.ui.GameInputControl;
#end
2020-10-21 18:05:27 +00:00
class FreeplayState extends MusicBeatState
{
2020-10-30 23:47:19 +00:00
var songs:Array<String> = ["Bopeebo", "Dadbattle", "Fresh", "Tutorial", "Spookeez", "South", "Monster"];
2020-10-21 18:05:27 +00:00
var selector:FlxText;
var curSelected:Int = 0;
override function create()
{
// LOAD MUSIC
// LOAD CHARACTERS
2020-10-25 20:51:06 +00:00
var bg:FlxSprite = FlxGridOverlay.create(20, 20);
add(bg);
2020-10-21 18:05:27 +00:00
for (i in 0...songs.length)
{
2020-10-30 23:47:19 +00:00
var songText:Alphabet = new Alphabet(0, (70 * i) + 30, songs[i], true, false);
2020-10-21 18:05:27 +00:00
add(songText);
2020-10-30 23:47:19 +00:00
songText.x += 40;
// DONT PUT X IN THE FIRST PARAMETER OF new ALPHABET() !!
// songText.screenCenter(X);
2020-10-21 18:05:27 +00:00
}
2020-10-30 23:47:19 +00:00
FlxG.sound.playMusic('assets/music/title' + TitleState.soundExt, 0);
FlxG.sound.music.fadeIn(2, 0, 0.8);
2020-10-21 18:05:27 +00:00
selector = new FlxText();
2020-10-30 23:47:19 +00:00
2020-10-25 20:51:06 +00:00
selector.size = 40;
2020-10-21 18:05:27 +00:00
selector.text = ">";
add(selector);
2020-10-25 20:51:06 +00:00
var swag:Alphabet = new Alphabet(1, 0, "swag");
2020-10-21 18:05:27 +00:00
super.create();
}
override function update(elapsed:Float)
{
2020-10-30 23:47:19 +00:00
super.update(elapsed);
var upP = controls.UP_P;
var downP = controls.DOWN_P;
var accepted = controls.ACCEPT;
if (upP)
2020-10-21 18:05:27 +00:00
{
curSelected -= 1;
}
2020-10-30 23:47:19 +00:00
if (downP)
2020-10-21 18:05:27 +00:00
{
curSelected += 1;
}
2020-10-26 23:06:42 +00: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 18:05:27 +00:00
if (curSelected < 0)
curSelected = songs.length - 1;
if (curSelected >= songs.length)
curSelected = 0;
2020-10-25 20:51:06 +00:00
selector.y = (70 * curSelected) + 30;
2020-10-21 18:05:27 +00:00
2020-10-30 23:47:19 +00:00
if (accepted)
2020-10-21 23:33:43 +00:00
{
PlayState.SONG = Song.loadFromJson(songs[curSelected].toLowerCase());
FlxG.switchState(new PlayState());
2020-10-30 23:47:19 +00:00
FlxG.sound.music.stop();
2020-10-21 23:33:43 +00:00
}
2020-10-26 23:06:42 +00:00
#if switch
2020-10-30 23:39:13 +00:00
if (gamepad.anyJustPressed(["B"])) //"B" is swapped with "A" on Switch
2020-10-26 23:06:42 +00:00
{
PlayState.SONG = Song.loadFromJson(songs[curSelected].toLowerCase());
FlxG.switchState(new PlayState());
2020-10-30 23:47:19 +00:00
FlxG.sound.music.stop();
2020-10-26 23:06:42 +00:00
}
#end
2020-10-21 18:05:27 +00:00
}
}