1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-25 06:36:43 +00:00
Funkin/source/funkin/play/notes/NoteHoldCover.hx

135 lines
3.4 KiB
Haxe
Raw Normal View History

2023-07-04 20:38:10 +00:00
package funkin.play.notes;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import funkin.play.notes.NoteDirection;
import flixel.graphics.frames.FlxFramesCollection;
2023-07-10 22:14:34 +00:00
import funkin.util.assets.FlxAnimationUtil;
2023-07-04 20:38:10 +00:00
import flixel.FlxG;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.FlxSprite;
class NoteHoldCover extends FlxTypedSpriteGroup<FlxSprite>
{
static final FRAMERATE_DEFAULT:Int = 24;
2023-07-10 22:14:34 +00:00
static var glowFrames:FlxFramesCollection;
2023-07-04 20:38:10 +00:00
2023-07-06 02:11:58 +00:00
public var holdNote:SustainTrail;
2023-07-04 20:38:10 +00:00
var glow:FlxSprite;
var sparks:FlxSprite;
public function new()
{
super(0, 0);
setup();
}
2023-07-06 02:11:58 +00:00
public static function preloadFrames():Void
{
2023-07-10 22:14:34 +00:00
glowFrames = null;
for (direction in Strumline.DIRECTIONS)
{
var directionName = direction.colorName.toTitleCase();
var atlas:FlxFramesCollection = Paths.getSparrowAtlas('holdCover${directionName}');
atlas.parent.persist = true;
if (glowFrames != null)
{
glowFrames = FlxAnimationUtil.combineFramesCollections(glowFrames, atlas);
}
else
{
glowFrames = atlas;
}
}
2023-07-06 02:11:58 +00:00
}
2023-07-04 20:38:10 +00:00
/**
* Add ALL the animations to this sprite. We will recycle and reuse the FlxSprite multiple times.
*/
function setup():Void
{
glow = new FlxSprite();
add(glow);
if (glowFrames == null) preloadFrames();
glow.frames = glowFrames;
2023-07-10 22:14:34 +00:00
for (direction in Strumline.DIRECTIONS)
{
var directionName = direction.colorName.toTitleCase();
glow.animation.addByPrefix('holdCoverStart$directionName', 'holdCoverStart${directionName}0', FRAMERATE_DEFAULT, false, false, false);
glow.animation.addByPrefix('holdCover$directionName', 'holdCover${directionName}0', FRAMERATE_DEFAULT, true, false, false);
glow.animation.addByPrefix('holdCoverEnd$directionName', 'holdCoverEnd${directionName}0', FRAMERATE_DEFAULT, false, false, false);
}
2023-07-04 20:38:10 +00:00
glow.animation.finishCallback = this.onAnimationFinished;
2023-07-10 22:14:34 +00:00
if (glow.animation.getAnimationList().length < 3 * 4)
2023-07-04 20:38:10 +00:00
{
trace('WARNING: NoteHoldCover failed to initialize all animations.');
}
}
2023-07-06 02:11:58 +00:00
public override function update(elapsed):Void
2023-07-04 20:38:10 +00:00
{
2023-07-06 02:11:58 +00:00
super.update(elapsed);
2023-07-04 20:38:10 +00:00
}
2023-07-06 02:11:58 +00:00
public function playStart():Void
2023-07-04 20:38:10 +00:00
{
2023-07-10 22:14:34 +00:00
var direction:NoteDirection = holdNote.noteDirection;
glow.animation.play('holdCoverStart${direction.colorName.toTitleCase()}');
2023-07-06 02:11:58 +00:00
}
public function playContinue():Void
{
2023-07-10 22:14:34 +00:00
var direction:NoteDirection = holdNote.noteDirection;
glow.animation.play('holdCover${direction.colorName.toTitleCase()}');
2023-07-04 20:38:10 +00:00
}
2023-07-06 02:11:58 +00:00
public function playEnd():Void
2023-07-04 20:38:10 +00:00
{
2023-07-10 22:14:34 +00:00
var direction:NoteDirection = holdNote.noteDirection;
glow.animation.play('holdCoverEnd${direction.colorName.toTitleCase()}');
2023-07-04 20:38:10 +00:00
}
public override function kill():Void
{
super.kill();
this.visible = false;
if (glow != null) glow.visible = false;
if (sparks != null) sparks.visible = false;
}
public override function revive():Void
{
super.revive();
this.visible = true;
this.alpha = 1.0;
if (glow != null) glow.visible = true;
if (sparks != null) sparks.visible = true;
}
2023-07-04 20:38:10 +00:00
public function onAnimationFinished(animationName:String):Void
{
2023-07-06 02:11:58 +00:00
if (animationName.startsWith('holdCoverStart'))
{
playContinue();
}
2023-07-04 20:38:10 +00:00
if (animationName.startsWith('holdCoverEnd'))
{
// *lightning* *zap* *crackle*
2023-07-06 02:11:58 +00:00
this.visible = false;
2023-07-04 20:38:10 +00:00
this.kill();
}
}
}