2023-11-07 04:04:22 -05:00
|
|
|
package funkin.ui.freeplay;
|
2023-08-23 05:33:52 -04:00
|
|
|
|
|
|
|
import flixel.group.FlxSpriteGroup;
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.util.FlxTimer;
|
|
|
|
|
|
|
|
class FreeplayFlames extends FlxSpriteGroup
|
|
|
|
{
|
|
|
|
var flameX(default, set):Float = 917;
|
|
|
|
var flameY(default, set):Float = 103;
|
|
|
|
var flameSpreadX(default, set):Float = 29;
|
|
|
|
var flameSpreadY(default, set):Float = 6;
|
|
|
|
|
|
|
|
public var flameCount(default, set):Int = 0;
|
|
|
|
|
|
|
|
var flameTimer:Float = 0.25;
|
|
|
|
|
|
|
|
public function new(x:Float, y:Float)
|
|
|
|
{
|
|
|
|
super(x, y);
|
|
|
|
|
|
|
|
for (i in 0...5)
|
|
|
|
{
|
|
|
|
var flame:FlxSprite = new FlxSprite(flameX + (flameSpreadX * i), flameY + (flameSpreadY * i));
|
|
|
|
flame.frames = Paths.getSparrowAtlas("freeplay/freeplayFlame");
|
2024-02-22 18:55:24 -05:00
|
|
|
flame.animation.addByPrefix("flame", "fire loop full instance 1", FlxG.random.int(23, 25), false);
|
2023-08-23 05:33:52 -04:00
|
|
|
flame.animation.play("flame");
|
|
|
|
flame.visible = false;
|
|
|
|
flameCount = 0;
|
|
|
|
|
|
|
|
// sets the loop... maybe better way to do this lol!
|
|
|
|
flame.animation.finishCallback = function(_) {
|
|
|
|
flame.animation.play("flame", true, false, 2);
|
|
|
|
};
|
|
|
|
add(flame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var properPositions:Bool = false;
|
|
|
|
|
|
|
|
override public function update(elapsed:Float):Void
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
// doesn't work in create()/new() for some reason
|
|
|
|
// so putting it here bwah!
|
|
|
|
if (!properPositions)
|
|
|
|
{
|
|
|
|
setFlamePositions();
|
|
|
|
properPositions = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-11 01:05:51 -04:00
|
|
|
var timers:Array<FlxTimer> = [];
|
|
|
|
|
2023-08-23 05:33:52 -04:00
|
|
|
function set_flameCount(value:Int):Int
|
|
|
|
{
|
2024-05-11 01:05:51 -04:00
|
|
|
// Stop all existing timers.
|
|
|
|
// This fixes a bug where quickly switching difficulties would show flames.
|
|
|
|
for (timer in timers)
|
|
|
|
{
|
|
|
|
timer.active = false;
|
|
|
|
timer.destroy();
|
|
|
|
timers.remove(timer);
|
|
|
|
}
|
|
|
|
|
2023-08-23 05:33:52 -04:00
|
|
|
this.flameCount = value;
|
|
|
|
var visibleCount:Int = 0;
|
|
|
|
for (i in 0...5)
|
|
|
|
{
|
|
|
|
if (members[i] == null) continue;
|
|
|
|
var flame:FlxSprite = members[i];
|
|
|
|
if (i < flameCount)
|
|
|
|
{
|
|
|
|
if (!flame.visible)
|
|
|
|
{
|
2024-05-11 01:05:51 -04:00
|
|
|
var nextTimer:FlxTimer = new FlxTimer().start(flameTimer * visibleCount, function(currentTimer:FlxTimer) {
|
|
|
|
if (i >= this.flameCount)
|
|
|
|
{
|
|
|
|
trace('EARLY EXIT');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
timers.remove(currentTimer);
|
2023-08-23 05:33:52 -04:00
|
|
|
flame.animation.play("flame", true);
|
|
|
|
flame.visible = true;
|
|
|
|
});
|
2024-05-11 01:05:51 -04:00
|
|
|
timers.push(nextTimer);
|
|
|
|
|
2023-08-23 05:33:52 -04:00
|
|
|
visibleCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flame.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.flameCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setFlamePositions()
|
|
|
|
{
|
|
|
|
for (i in 0...5)
|
|
|
|
{
|
|
|
|
var flame:FlxSprite = members[i];
|
|
|
|
flame.x = flameX + (flameSpreadX * i);
|
|
|
|
flame.y = flameY + (flameSpreadY * i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_flameX(value:Float):Float
|
|
|
|
{
|
|
|
|
this.flameX = value;
|
|
|
|
setFlamePositions();
|
|
|
|
return this.flameX;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_flameY(value:Float):Float
|
|
|
|
{
|
|
|
|
this.flameY = value;
|
|
|
|
setFlamePositions();
|
|
|
|
return this.flameY;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_flameSpreadX(value:Float):Float
|
|
|
|
{
|
|
|
|
this.flameSpreadX = value;
|
|
|
|
setFlamePositions();
|
|
|
|
return this.flameSpreadX;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_flameSpreadY(value:Float):Float
|
|
|
|
{
|
|
|
|
this.flameSpreadY = value;
|
|
|
|
setFlamePositions();
|
|
|
|
return this.flameSpreadY;
|
|
|
|
}
|
|
|
|
}
|