1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-26 23:16:46 +00:00
Funkin/source/funkin/play/components/TallyCounter.hx

101 lines
2.3 KiB
Haxe
Raw Normal View History

package funkin.play.components;
2022-09-22 08:09:06 +00:00
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import flixel.math.FlxMath;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
2024-04-02 01:59:53 +00:00
import flixel.text.FlxText.FlxTextAlign;
import funkin.util.MathUtil;
2022-09-22 08:09:06 +00:00
/**
* Numerical counters used next to each judgement in the Results screen.
2022-09-22 08:09:06 +00:00
*/
class TallyCounter extends FlxTypedSpriteGroup<FlxSprite>
{
public var curNumber:Float = 0;
public var neededNumber:Int = 0;
2024-04-02 01:59:53 +00:00
public var flavour:Int = 0xFFFFFFFF;
2024-04-02 01:59:53 +00:00
public var align:FlxTextAlign = FlxTextAlign.LEFT;
public function new(x:Float, y:Float, neededNumber:Int = 0, ?flavour:Int = 0xFFFFFFFF, align:FlxTextAlign = FlxTextAlign.LEFT)
{
super(x, y);
2024-04-02 01:59:53 +00:00
this.align = align;
this.flavour = flavour;
this.neededNumber = neededNumber;
2024-04-02 01:59:53 +00:00
if (curNumber == neededNumber) drawNumbers();
}
var tmr:Float = 0;
override function update(elapsed:Float)
{
super.update(elapsed);
if (curNumber < neededNumber) drawNumbers();
}
function drawNumbers()
{
var seperatedScore:Array<Int> = [];
var tempCombo:Int = Math.round(curNumber);
2024-04-02 01:59:53 +00:00
var fullNumberDigits:Int = Std.int(Math.max(1, Math.ceil(MathUtil.logBase(10, neededNumber))));
while (tempCombo != 0)
{
seperatedScore.push(tempCombo % 10);
tempCombo = Math.floor(tempCombo / 10);
}
if (seperatedScore.length == 0) seperatedScore.push(0);
seperatedScore.reverse();
for (ind => num in seperatedScore)
{
if (ind >= members.length)
{
2024-04-02 01:59:53 +00:00
var xPos = ind * (43 * this.scale.x);
if (this.align == FlxTextAlign.RIGHT)
{
xPos -= (fullNumberDigits * (43 * this.scale.x));
}
var numb:TallyNumber = new TallyNumber(xPos, 0, num);
numb.scale.set(this.scale.x, this.scale.y);
add(numb);
numb.color = flavour;
}
else
{
members[ind].animation.play(Std.string(num));
members[ind].color = flavour;
}
}
}
2022-09-22 08:09:06 +00:00
}
class TallyNumber extends FlxSprite
{
public function new(x:Float, y:Float, digit:Int)
{
super(x, y);
2022-09-22 08:09:06 +00:00
frames = Paths.getSparrowAtlas("resultScreen/tallieNumber");
2022-09-22 08:09:06 +00:00
for (i in 0...10)
animation.addByPrefix(Std.string(i), i + " small", 24, false);
2022-09-22 08:09:06 +00:00
animation.play(Std.string(digit));
updateHitbox();
}
2022-09-22 08:09:06 +00:00
}