1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-10 08:44:47 +00:00
Funkin/source/funkin/freeplayStuff/FreeplayScore.hx

127 lines
2.4 KiB
Haxe
Raw Normal View History

package funkin.freeplayStuff;
2021-12-06 05:13:11 +00:00
import flixel.FlxSprite;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
class FreeplayScore extends FlxTypedSpriteGroup<ScoreNum>
{
2021-12-06 05:41:10 +00:00
public var scoreShit(default, set):Int = 0;
function set_scoreShit(val):Int
{
if (group == null || group.members == null)
return val;
2021-12-06 05:41:10 +00:00
var loopNum:Int = group.members.length - 1;
var dumbNumb = Std.parseInt(Std.string(val));
2021-12-06 06:45:45 +00:00
var prevNum:ScoreNum;
2021-12-06 05:41:10 +00:00
while (dumbNumb > 0)
{
group.members[loopNum].digit = dumbNumb % 10;
2021-12-06 06:45:45 +00:00
// var funnyNum = group.members[loopNum];
// prevNum = group.members[loopNum + 1];
// if (prevNum != null)
// {
// funnyNum.x = prevNum.x - (funnyNum.width * 0.7);
// }
// funnyNum.y = (funnyNum.baseY - (funnyNum.height / 2)) + 73;
// funnyNum.x = (funnyNum.baseX - (funnyNum.width / 2)) + 450; // this plus value is hand picked lol!
2021-12-06 05:41:10 +00:00
dumbNumb = Math.floor(dumbNumb / 10);
loopNum--;
}
while (loopNum > 0)
{
group.members[loopNum].digit = 0;
loopNum--;
}
return val;
}
2021-12-06 05:13:11 +00:00
public function new(x:Float, y:Float, scoreShit:Int = 100)
{
super(x, y);
for (i in 0...7)
{
2022-12-16 22:10:22 +00:00
add(new ScoreNum(x + (45 * i), y, 0));
2021-12-06 05:13:11 +00:00
}
2021-12-06 05:41:10 +00:00
this.scoreShit = scoreShit;
2021-12-06 05:13:11 +00:00
}
public function updateScore(scoreNew:Int)
{
2021-12-06 05:41:10 +00:00
scoreShit = scoreNew;
2021-12-06 05:13:11 +00:00
}
}
class ScoreNum extends FlxSprite
{
public var digit(default, set):Int = 0;
function set_digit(val):Int
{
2022-12-14 17:25:12 +00:00
if (animation.curAnim != null && animation.curAnim.name != numToString[val])
2021-12-06 05:41:10 +00:00
{
2022-12-14 17:25:12 +00:00
animation.play(numToString[val], true, false, 0);
2021-12-06 06:45:45 +00:00
updateHitbox();
switch (val)
{
2022-12-14 17:25:12 +00:00
case 1:
offset.x -= 15;
case 5:
// set offsets
// offset.x += 0;
// offset.y += 10;
case 7:
// offset.y += 6;
case 4:
// offset.y += 5;
case 9:
// offset.y += 5;
default:
centerOffsets(false);
}
2021-12-06 05:41:10 +00:00
}
2021-12-06 05:13:11 +00:00
return val;
}
2021-12-06 06:45:45 +00:00
public var baseY:Float = 0;
public var baseX:Float = 0;
2022-12-14 17:25:12 +00:00
var numToString:Array<String> = ["ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"];
2021-12-06 05:13:11 +00:00
public function new(x:Float, y:Float, ?initDigit:Int = 0)
{
super(x, y);
2021-12-06 06:45:45 +00:00
baseY = y;
baseX = x;
2022-12-14 17:25:12 +00:00
frames = Paths.getSparrowAtlas('digital_numbers');
2021-12-06 05:13:11 +00:00
for (i in 0...10)
{
2022-12-14 17:25:12 +00:00
var stringNum:String = numToString[i];
2021-12-06 05:13:11 +00:00
animation.addByPrefix(stringNum, stringNum, 24, false);
}
this.digit = initDigit;
2022-12-14 17:25:12 +00:00
animation.play(numToString[digit], true);
2021-12-06 05:13:11 +00:00
antialiasing = true;
2022-12-16 22:10:22 +00:00
setGraphicSize(Std.int(width * 0.4));
2021-12-06 05:13:11 +00:00
updateHitbox();
}
}