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;
|
|
|
|
import flixel.FlxG;
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
|
|
|
|
class NoteHoldCover extends FlxTypedSpriteGroup<FlxSprite>
|
|
|
|
{
|
|
|
|
static final FRAMERATE_DEFAULT:Int = 24;
|
|
|
|
|
|
|
|
static var glowFrames:FlxAtlasFrames;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
glowFrames = Paths.getSparrowAtlas('holdCoverRed');
|
|
|
|
glowFrames.parent.persist = true;
|
|
|
|
}
|
|
|
|
|
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-06 02:11:58 +00:00
|
|
|
glow.animation.addByPrefix('holdCoverStartRed', 'holdCoverStartRed0', FRAMERATE_DEFAULT, false, false, false);
|
2023-07-04 20:38:10 +00:00
|
|
|
glow.animation.addByPrefix('holdCoverRed', 'holdCoverRed0', FRAMERATE_DEFAULT, true, false, false);
|
2023-07-06 02:11:58 +00:00
|
|
|
glow.animation.addByPrefix('holdCoverEndRed', 'holdCoverEndRed0', FRAMERATE_DEFAULT, false, false, false);
|
2023-07-04 20:38:10 +00:00
|
|
|
|
|
|
|
glow.animation.finishCallback = this.onAnimationFinished;
|
|
|
|
|
2023-07-08 05:03:46 +00:00
|
|
|
if (glow.animation.getAnimationList().length < 3)
|
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-08 05:03:46 +00:00
|
|
|
if ((!holdNote.alive || holdNote.missedNote) && !glow.animation.curAnim.name.startsWith('holdCoverEnd'))
|
2023-07-06 02:11:58 +00:00
|
|
|
{
|
2023-07-08 05:03:46 +00:00
|
|
|
// If alive is false, the hold note was held to completion.
|
|
|
|
// If missedNote is true, the hold note was "dropped".
|
|
|
|
|
|
|
|
playEnd();
|
2023-07-06 02:11:58 +00:00
|
|
|
}
|
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-08 05:03:46 +00:00
|
|
|
// glow.animation.play('holdCoverStart${noteDirection.colorName.toTitleCase()}');
|
2023-07-06 02:11:58 +00:00
|
|
|
glow.animation.play('holdCoverStartRed');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function playContinue():Void
|
|
|
|
{
|
2023-07-08 05:03:46 +00:00
|
|
|
// glow.animation.play('holdCover${noteDirection.colorName.toTitleCase()}');
|
2023-07-04 20:38:10 +00:00
|
|
|
glow.animation.play('holdCoverRed');
|
|
|
|
}
|
|
|
|
|
2023-07-06 02:11:58 +00:00
|
|
|
public function playEnd():Void
|
2023-07-04 20:38:10 +00:00
|
|
|
{
|
2023-07-08 05:03:46 +00:00
|
|
|
// glow.animation.play('holdCoverEnd${noteDirection.colorName.toTitleCase()}');
|
2023-07-04 20:38:10 +00:00
|
|
|
glow.animation.play('holdCoverEndRed');
|
|
|
|
}
|
|
|
|
|
2023-07-08 05:03:46 +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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|