Funkin/source/FreeplayState.hx

216 lines
4.5 KiB
Haxe
Raw Normal View History

2020-10-21 14:05:27 -04:00
package;
import flash.text.TextField;
2020-10-21 14:05:27 -04:00
import flixel.FlxG;
import flixel.FlxSprite;
2020-10-25 16:51:06 -04:00
import flixel.addons.display.FlxGridOverlay;
2020-10-31 23:22:49 -04:00
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.math.FlxMath;
2020-10-21 14:05:27 -04:00
import flixel.text.FlxText;
import flixel.util.FlxColor;
import htmlparser.HtmlDocument;
import lime.utils.Assets;
2020-10-21 14:05:27 -04:00
class FreeplayState extends MusicBeatState
{
2020-10-31 23:31:31 -04:00
var songs:Array<String> = ["Bopeebo", "Dadbattle", "Fresh", "Tutorial"];
2020-10-21 14:05:27 -04:00
var selector:FlxText;
var curSelected:Int = 0;
2020-11-06 05:21:29 -05:00
var curDifficulty:Int = 1;
2020-10-21 14:05:27 -04:00
var scoreText:FlxText;
2020-11-06 05:31:33 -05:00
var diffText:FlxText;
var lerpScore:Int = 0;
var intendedScore:Int = 0;
2020-10-31 23:22:49 -04:00
private var grpSongs:FlxTypedGroup<Alphabet>;
2020-10-21 14:05:27 -04:00
override function create()
{
if (FlxG.sound.music != null)
{
if (!FlxG.sound.music.playing)
FlxG.sound.playMusic('assets/music/freakyMenu' + TitleState.soundExt);
}
2020-11-01 02:58:20 -05:00
2020-11-01 18:20:13 -05:00
var isDebug:Bool = false;
#if debug
isDebug = true;
#end
if (StoryMenuState.weekUnlocked[1] || isDebug)
2020-10-31 23:31:31 -04:00
{
songs.push('Spookeez');
songs.push('South');
}
2020-10-21 14:05:27 -04:00
// LOAD MUSIC
// LOAD CHARACTERS
2020-10-31 23:22:49 -04:00
var bg:FlxSprite = new FlxSprite().loadGraphic(AssetPaths.menuBGBlue__png);
2020-10-25 16:51:06 -04:00
add(bg);
2020-10-31 23:22:49 -04:00
grpSongs = new FlxTypedGroup<Alphabet>();
add(grpSongs);
2020-10-21 14:05:27 -04:00
for (i in 0...songs.length)
{
2020-10-28 05:26:33 -04:00
var songText:Alphabet = new Alphabet(0, (70 * i) + 30, songs[i], true, false);
2020-10-31 23:22:49 -04:00
songText.isMenuItem = true;
songText.targetY = i;
grpSongs.add(songText);
// songText.x += 40;
2020-10-28 05:26:33 -04:00
// DONT PUT X IN THE FIRST PARAMETER OF new ALPHABET() !!
2020-10-27 04:31:21 -04:00
// songText.screenCenter(X);
2020-10-21 14:05:27 -04:00
}
scoreText = new FlxText(FlxG.width * 0.7, 5, 0, "", 32);
// scoreText.autoSize = false;
scoreText.setFormat("assets/fonts/vcr.ttf", 32, FlxColor.WHITE, RIGHT);
// scoreText.alignment = RIGHT;
2020-11-06 05:31:33 -05:00
var scoreBG:FlxSprite = new FlxSprite(scoreText.x - 6, 0).makeGraphic(Std.int(FlxG.width * 0.35), 66, 0xFF000000);
scoreBG.alpha = 0.6;
add(scoreBG);
2020-11-06 05:31:33 -05:00
diffText = new FlxText(scoreText.x, scoreText.y + 36, 0, "", 24);
diffText.font = scoreText.font;
add(diffText);
add(scoreText);
2020-10-31 23:22:49 -04:00
changeSelection();
2020-11-06 05:21:29 -05:00
changeDiff();
2020-10-31 23:22:49 -04:00
// FlxG.sound.playMusic('assets/music/title' + TitleState.soundExt, 0);
// FlxG.sound.music.fadeIn(2, 0, 0.8);
2020-10-21 14:05:27 -04:00
selector = new FlxText();
2020-10-28 05:26:33 -04:00
2020-10-25 16:51:06 -04:00
selector.size = 40;
2020-10-21 14:05:27 -04:00
selector.text = ">";
2020-10-31 23:22:49 -04:00
// add(selector);
2020-10-21 14:05:27 -04:00
2020-10-25 16:51:06 -04:00
var swag:Alphabet = new Alphabet(1, 0, "swag");
// JUST DOIN THIS SHIT FOR TESTING!!!
/*
var md:String = Markdown.markdownToHtml(Assets.getText('CHANGELOG.md'));
var texFel:TextField = new TextField();
texFel.width = FlxG.width;
texFel.height = FlxG.height;
// texFel.
texFel.htmlText = md;
FlxG.stage.addChild(texFel);
// scoreText.textField.htmlText = md;
trace(md);
*/
2020-10-21 14:05:27 -04:00
super.create();
}
override function update(elapsed:Float)
{
2020-10-28 04:24:56 -04:00
super.update(elapsed);
lerpScore = Math.floor(FlxMath.lerp(lerpScore, intendedScore, 0.4));
scoreText.text = "PERSONAL BEST:" + lerpScore;
2020-10-28 04:24:56 -04:00
var upP = controls.UP_P;
var downP = controls.DOWN_P;
var accepted = controls.ACCEPT;
if (upP)
2020-10-21 14:05:27 -04:00
{
2020-10-31 23:22:49 -04:00
changeSelection(-1);
2020-10-21 14:05:27 -04:00
}
2020-10-28 04:24:56 -04:00
if (downP)
2020-10-21 14:05:27 -04:00
{
2020-10-31 23:22:49 -04:00
changeSelection(1);
}
2020-11-06 05:31:33 -05:00
if (controls.LEFT_P)
changeDiff(-1);
if (controls.RIGHT_P)
changeDiff(1);
2020-11-01 00:34:17 -04:00
if (controls.BACK)
{
2020-11-01 00:55:00 -04:00
FlxG.switchState(new MainMenuState());
2020-11-01 00:34:17 -04:00
}
2020-10-31 23:22:49 -04:00
if (accepted)
{
2020-11-06 05:31:33 -05:00
var poop:String = Highscore.formatSong(songs[curSelected].toLowerCase(), curDifficulty);
PlayState.SONG = Song.loadFromJson(poop, songs[curSelected].toLowerCase());
2020-10-31 23:22:49 -04:00
PlayState.isStoryMode = false;
FlxG.switchState(new PlayState());
if (FlxG.sound.music != null)
FlxG.sound.music.stop();
2020-10-21 14:05:27 -04:00
}
2020-10-31 23:22:49 -04:00
}
2020-11-06 05:21:29 -05:00
function changeDiff(change:Int = 0)
{
curDifficulty += change;
if (curDifficulty < 0)
curDifficulty = 2;
if (curDifficulty > 2)
curDifficulty = 0;
2020-11-06 05:31:33 -05:00
intendedScore = Highscore.getScore(songs[curSelected], curDifficulty);
switch (curDifficulty)
{
case 0:
diffText.text = "EASY";
case 1:
diffText.text = 'NORMAL';
case 2:
diffText.text = "HARD";
}
2020-11-06 05:21:29 -05:00
}
2020-10-31 23:22:49 -04:00
function changeSelection(change:Int = 0)
{
NGio.logEvent('Fresh');
2020-10-31 23:22:49 -04:00
curSelected += change;
2020-10-21 14:05:27 -04:00
if (curSelected < 0)
curSelected = songs.length - 1;
if (curSelected >= songs.length)
curSelected = 0;
2020-10-31 23:22:49 -04:00
// selector.y = (70 * curSelected) + 30;
2020-10-21 14:05:27 -04:00
2020-11-06 05:31:33 -05:00
intendedScore = Highscore.getScore(songs[curSelected], curDifficulty);
// lerpScore = 0;
2020-10-31 23:22:49 -04:00
var bullShit:Int = 0;
for (item in grpSongs.members)
2020-10-21 19:33:43 -04:00
{
2020-10-31 23:22:49 -04:00
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-21 19:33:43 -04:00
}
2020-10-21 14:05:27 -04:00
}
}