1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-14 02:42:55 +00:00
Funkin/source/funkin/ComboCounter.hx

141 lines
2.9 KiB
Haxe
Raw Normal View History

package funkin;
2021-07-15 00:32:09 +00:00
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
2021-07-15 22:45:25 +00:00
import flixel.util.FlxTimer;
2021-07-15 00:32:09 +00:00
class ComboCounter extends FlxTypedSpriteGroup<FlxSprite>
{
var effectStuff:FlxSprite;
var wasComboSetup:Bool = false;
var daCombo:Int = 0;
var grpNumbers:FlxTypedGroup<ComboNumber>;
2021-07-15 22:45:25 +00:00
var onScreenTime:Float = 0;
2021-07-15 00:32:09 +00:00
public function new(x:Float, y:Float, daCombo:Int = 0)
{
super(x, y);
this.daCombo = daCombo;
effectStuff = new FlxSprite(0, 0);
effectStuff.frames = Paths.getSparrowAtlas('noteCombo');
effectStuff.animation.addByPrefix('funny', 'NOTE COMBO animation', 24, false);
effectStuff.animation.play('funny');
effectStuff.antialiasing = true;
effectStuff.animation.finishCallback = function(nameThing)
{
kill();
};
add(effectStuff);
grpNumbers = new FlxTypedGroup<ComboNumber>();
// add(grpNumbers);
}
2021-07-15 22:22:15 +00:00
public function forceFinish():Void
{
2021-07-15 22:45:25 +00:00
if (onScreenTime < 0.9)
{
new FlxTimer().start((Conductor.crochet / 1000) * 0.25, function(tmr)
{
forceFinish();
});
}
else
effectStuff.animation.play('funny', true, false, 18);
2021-07-15 22:22:15 +00:00
}
2021-07-15 00:32:09 +00:00
override function update(elapsed:Float)
{
2021-07-15 22:45:25 +00:00
onScreenTime += elapsed;
2021-07-15 22:22:15 +00:00
if (effectStuff.animation.curAnim.curFrame == 17)
effectStuff.animation.pause();
2021-07-15 00:32:09 +00:00
if (effectStuff.animation.curAnim.curFrame == 2 && !wasComboSetup)
{
setupCombo(daCombo);
}
if (effectStuff.animation.curAnim.curFrame == 18)
{
grpNumbers.forEach(function(spr:ComboNumber)
{
spr.animation.reset();
});
}
if (effectStuff.animation.curAnim.curFrame == 20)
{
grpNumbers.forEach(function(spr:ComboNumber)
{
spr.kill();
});
}
super.update(elapsed);
}
function setupCombo(daCombo:Int)
{
FlxG.sound.play(Paths.sound('comboSound'));
wasComboSetup = true;
var loopNum:Int = 0;
while (daCombo > 0)
{
var comboNumber:ComboNumber = new ComboNumber(420 - (130 * loopNum), 44 * loopNum, daCombo % 10);
grpNumbers.add(comboNumber);
add(comboNumber);
loopNum += 1;
daCombo = Math.floor(daCombo / 10);
}
// var comboNumber:ComboNumber = new ComboNumber(420, 0, 0);
// add to both, in the group just for ez organize/accessing
// grpNumbers.add(comboNumber);
// add(comboNumber);
// var comboNumber2:ComboNumber = new ComboNumber(420 - 134, 44, 0);
// grpNumbers.add(comboNumber2);
// add(comboNumber2);
}
}
class ComboNumber extends FlxSprite
{
public function new(x:Float, y:Float, digit:Int)
{
super(x - 20, y);
var stringNum:String = Std.string(digit);
frames = Paths.getSparrowAtlas('noteComboNumbers');
animation.addByPrefix(stringNum, stringNum, 24, false);
animation.play(stringNum);
antialiasing = true;
updateHitbox();
}
var shiftedX:Bool = false;
override function update(elapsed:Float)
{
if (animation.curAnim.curFrame == 2 && !shiftedX)
{
shiftedX = true;
x += 20;
}
super.update(elapsed);
}
}