Funkin/source/TitleState.hx

98 lines
2.8 KiB
Haxe
Raw Normal View History

2020-10-05 14:24:51 -04:00
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.addons.display.FlxGridOverlay;
import flixel.addons.transition.FlxTransitionSprite.GraphicTransTileDiamond;
import flixel.addons.transition.FlxTransitionableState;
import flixel.addons.transition.TransitionData;
import flixel.graphics.FlxGraphic;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import flixel.util.FlxTimer;
class TitleState extends FlxTransitionableState
{
static var initialized:Bool = false;
2020-10-06 21:56:14 -04:00
static public var soundExt:String = ".mp3";
2020-10-05 14:24:51 -04:00
override public function create():Void
{
2020-10-06 21:56:14 -04:00
#if (!web)
TitleState.soundExt = '.ogg';
#end
2020-10-05 14:24:51 -04:00
super.create();
if (!initialized)
{
var diamond:FlxGraphic = FlxGraphic.fromClass(GraphicTransTileDiamond);
diamond.persist = true;
diamond.destroyOnNoUse = false;
FlxTransitionableState.defaultTransIn = new TransitionData(FADE, FlxColor.BLACK, 2, new FlxPoint(0, -1), {asset: diamond, width: 32, height: 32},
new FlxRect(0, 0, FlxG.width, FlxG.height));
FlxTransitionableState.defaultTransOut = new TransitionData(FADE, FlxColor.BLACK, 1.3, new FlxPoint(0, 1),
{asset: diamond, width: 32, height: 32}, new FlxRect(0, 0, FlxG.width, FlxG.height));
initialized = true;
FlxTransitionableState.defaultTransIn.tileData = {asset: diamond, width: 32, height: 32};
FlxTransitionableState.defaultTransOut.tileData = {asset: diamond, width: 32, height: 32};
transIn = FlxTransitionableState.defaultTransIn;
transOut = FlxTransitionableState.defaultTransOut;
}
persistentUpdate = true;
2020-10-05 18:29:59 -04:00
var bg:FlxSprite = new FlxSprite().loadGraphic(AssetPaths.stageback__png);
bg.antialiasing = true;
bg.setGraphicSize(Std.int(bg.width * 0.6));
bg.updateHitbox();
2020-10-05 14:24:51 -04:00
add(bg);
var logoBl:FlxSprite = new FlxSprite().loadGraphic(AssetPaths.logo__png);
logoBl.screenCenter();
logoBl.color = FlxColor.BLACK;
add(logoBl);
var logo:FlxSprite = new FlxSprite().loadGraphic(AssetPaths.logo__png);
logo.screenCenter();
2020-10-05 18:29:59 -04:00
logo.antialiasing = true;
2020-10-05 14:24:51 -04:00
add(logo);
FlxTween.tween(logoBl, {y: logoBl.y + 50}, 0.6, {ease: FlxEase.quadInOut, type: PINGPONG});
FlxTween.tween(logo, {y: logoBl.y + 50}, 0.6, {ease: FlxEase.quadInOut, type: PINGPONG, startDelay: 0.1});
2020-10-06 21:56:14 -04:00
FlxG.sound.playMusic('assets/music/title' + TitleState.soundExt, 0, false);
2020-10-05 14:24:51 -04:00
FlxG.sound.music.fadeIn(4, 0, 0.7);
}
var transitioning:Bool = false;
override function update(elapsed:Float)
{
if (FlxG.keys.justPressed.ENTER && !transitioning)
{
2020-10-05 14:33:56 -04:00
FlxG.camera.flash(FlxColor.WHITE, 1);
2020-10-05 14:24:51 -04:00
transitioning = true;
FlxG.sound.music.stop();
new FlxTimer().start(2, function(tmr:FlxTimer)
{
FlxG.switchState(new PlayState());
});
2020-10-06 21:56:14 -04:00
FlxG.sound.play('assets/music/titleShoot' + TitleState.soundExt, 0.7);
2020-10-05 14:24:51 -04:00
}
super.update(elapsed);
}
}