Funkin/source/PauseSubState.hx

129 lines
2.6 KiB
Haxe
Raw Normal View History

2020-10-09 17:24:20 -04:00
package;
2020-10-21 20:22:12 -04:00
import Controls.Control;
2020-10-09 17:24:20 -04:00
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxSubState;
2021-02-12 01:20:20 -05:00
import flixel.addons.transition.FlxTransitionableState;
2020-11-17 20:50:09 -05:00
import flixel.group.FlxGroup.FlxTypedGroup;
2020-10-21 20:22:12 -04:00
import flixel.input.keyboard.FlxKey;
2020-11-20 07:21:04 -05:00
import flixel.system.FlxSound;
2020-10-09 17:24:20 -04:00
import flixel.util.FlxColor;
2020-11-17 20:50:09 -05:00
class PauseSubState extends MusicBeatSubstate
2020-10-09 17:24:20 -04:00
{
2020-11-17 20:50:09 -05:00
var grpMenuShit:FlxTypedGroup<Alphabet>;
var menuItems:Array<String> = ['Resume', 'Restart Song', 'Exit to menu'];
var curSelected:Int = 0;
2020-11-20 07:21:04 -05:00
var pauseMusic:FlxSound;
2020-10-27 06:35:23 -04:00
public function new(x:Float, y:Float)
2020-10-09 17:24:20 -04:00
{
super();
2020-11-20 07:21:04 -05:00
2021-02-08 16:34:48 -05:00
pauseMusic = new FlxSound().loadEmbedded(Paths.music('breakfast'), true, true);
2020-11-20 07:21:04 -05:00
pauseMusic.volume = 0;
pauseMusic.play(false, FlxG.random.int(0, Std.int(pauseMusic.length / 2)));
FlxG.sound.list.add(pauseMusic);
2020-10-09 17:24:20 -04:00
var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
bg.alpha = 0.6;
bg.scrollFactor.set();
add(bg);
2020-11-17 20:50:09 -05:00
grpMenuShit = new FlxTypedGroup<Alphabet>();
add(grpMenuShit);
for (i in 0...menuItems.length)
{
var songText:Alphabet = new Alphabet(0, (70 * i) + 30, menuItems[i], true, false);
songText.isMenuItem = true;
songText.targetY = i;
grpMenuShit.add(songText);
}
2020-10-27 06:35:23 -04:00
2020-11-17 20:50:09 -05:00
changeSelection();
2020-10-27 06:35:23 -04:00
2021-03-13 21:11:56 -05:00
// cameras = [FlxG.cameras.list[FlxG.cameras.list.length - 1]];
2020-10-09 17:24:20 -04:00
}
override function update(elapsed:Float)
{
2020-11-20 07:21:04 -05:00
if (pauseMusic.volume < 0.5)
pauseMusic.volume += 0.01 * elapsed;
2020-10-09 17:24:20 -04:00
super.update(elapsed);
2021-03-13 21:11:56 -05:00
var upP = controls.UI_UP_P;
var downP = controls.UI_DOWN_P;
2020-11-17 20:50:09 -05:00
var accepted = controls.ACCEPT;
if (upP)
{
changeSelection(-1);
}
if (downP)
{
changeSelection(1);
}
if (accepted)
{
var daSelected:String = menuItems[curSelected];
switch (daSelected)
{
case "Resume":
close();
2020-11-17 21:20:27 -05:00
case "Restart Song":
FlxG.resetState();
2020-11-17 20:50:09 -05:00
case "Exit to menu":
FlxG.switchState(new MainMenuState());
}
}
2020-10-21 20:22:12 -04:00
if (FlxG.keys.justPressed.J)
{
2020-11-17 20:50:09 -05:00
// for reference later!
// PlayerSettings.player1.controls.replaceBinding(Control.LEFT, Keys, FlxKey.J, null);
2020-10-21 20:22:12 -04:00
}
2020-11-17 20:50:09 -05:00
}
2020-11-20 07:21:04 -05:00
override function destroy()
{
pauseMusic.destroy();
super.destroy();
}
2020-11-17 20:50:09 -05:00
function changeSelection(change:Int = 0):Void
{
curSelected += change;
2020-10-21 20:22:12 -04:00
2020-11-17 20:50:09 -05:00
if (curSelected < 0)
curSelected = menuItems.length - 1;
if (curSelected >= menuItems.length)
curSelected = 0;
var bullShit:Int = 0;
for (item in grpMenuShit.members)
{
item.targetY = bullShit - curSelected;
bullShit++;
item.alpha = 0.6;
// item.setGraphicSize(Std.int(item.width * 0.8));
if (item.targetY == 0)
{
item.alpha = 1;
// item.setGraphicSize(Std.int(item.width));
}
}
2020-10-09 17:24:20 -04:00
}
}