a few little FreeplayScore tidying perhaps

This commit is contained in:
Cameron Taylor
2025-07-17 04:28:52 +08:00
committed by Hundrec
parent 4c5aa9743e
commit 949f409cff
+18 -26
View File
@@ -11,28 +11,16 @@ class FreeplayScore extends FlxTypedSpriteGroup<ScoreNum>
function set_scoreShit(val):Int
{
if (group == null || group.members == null) return val;
var loopNum:Int = group.members.length - 1;
var dumbNumb = Std.parseInt(Std.string(val));
if (dumbNumb == null) dumbNumb = 0;
var prevNum:ScoreNum;
var dumbNumb:Int = Std.parseInt(Std.string(val)) ?? 0;
dumbNumb = Std.int(Math.min(dumbNumb, Math.pow(10, group.members.length) - 1));
var loopNum:Int = group.members.length - 1;
while (dumbNumb > 0)
{
group.members[loopNum].digit = dumbNumb % 10;
// 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!
dumbNumb = Math.floor(dumbNumb / 10);
loopNum--;
}
@@ -71,6 +59,11 @@ class FreeplayScore extends FlxTypedSpriteGroup<ScoreNum>
}
}
/**
* ScoreNum is the number graphic that is used for the completion percentage.
* It handles offsetting / positioning of the numbers so they look a bit nicer placed
* NOTE: this is actually a bit similar to the ResultScore class, should perhaps tidy the logic up?
*/
@:nullSafety
class ScoreNum extends FlxSprite
{
@@ -106,18 +99,10 @@ class ScoreNum extends FlxSprite
return val;
}
public var baseY:Float = 0;
public var baseX:Float = 0;
var numToString:Array<String> = ["ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"];
public function new(x:Float, y:Float, ?initDigit:Int = 0, ?styleData:FreeplayStyle)
{
super(x, y);
baseY = y;
baseX = x;
if (styleData == null)
{
frames = Paths.getSparrowAtlas('digital_numbers');
@@ -129,15 +114,22 @@ class ScoreNum extends FlxSprite
for (i in 0...10)
{
var stringNum:String = numToString[i];
animation.addByPrefix(stringNum, '$stringNum DIGITAL', 24, false);
animation.addByPrefix(getIntToString(i), '${getIntToString(i)} DIGITAL', 24, false);
}
this.digit = initDigit ?? 0;
animation.play(numToString[digit], true);
animation.play(getIntToString(digit), true);
setGraphicSize(Std.int(width * 0.4));
updateHitbox();
}
final numToString:Array<String> = ["ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"];
function getIntToString(number:Int):String
{
if (numToString[number] == null) return numToString[0];
return numToString[number];
}
}