1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-11 16:05:02 +00:00
Funkin/source/funkin/ui/MenuItem.hx

63 lines
1.5 KiB
Haxe
Raw Normal View History

package funkin.ui;
2020-10-30 21:18:26 +00:00
import flixel.FlxSprite;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.group.FlxSpriteGroup;
2020-10-30 21:55:20 +00:00
import flixel.math.FlxMath;
import funkin.util.MathUtil;
2021-03-02 03:35:27 +00:00
import flixel.util.FlxColor;
2020-10-30 21:18:26 +00:00
class MenuItem extends FlxSpriteGroup
{
public var targetY:Float = 0;
public var week:FlxSprite;
public var flashingInt:Int = 0;
public function new(x:Float, y:Float, weekNum:Int = 0, weekType:WeekType)
{
super(x, y);
var weekStr:String = switch (weekType)
{
case WEEK:
"week";
case WEEKEND:
"weekend";
}
week = new FlxSprite().loadGraphic(Paths.image('storymenu/' + weekStr + weekNum));
add(week);
}
var isFlashing:Bool = false;
public function startFlashing():Void
{
isFlashing = true;
}
// if it runs at 60fps, fake framerate will be 6
// if it runs at 144 fps, fake framerate will be like 14, and will update the graphic every 0.016666 * 3 seconds still???
// so it runs basically every so many seconds, not dependant on framerate??
// I'm still learning how math works thanks whoever is reading this lol
var fakeFramerate:Int = Math.round((1 / FlxG.elapsed) / 10);
override function update(elapsed:Float)
{
super.update(elapsed);
y = MathUtil.coolLerp(y, (targetY * 120) + 480, 0.17);
if (isFlashing) flashingInt += 1;
if (flashingInt % fakeFramerate >= Math.floor(fakeFramerate / 2)) week.color = 0xFF33ffff;
else
week.color = FlxColor.WHITE;
}
2020-10-30 21:18:26 +00:00
}
2022-08-25 05:35:47 +00:00
enum abstract WeekType(String) to String
{
var WEEK;
var WEEKEND;
2022-08-25 05:35:47 +00:00
}