77 lines
2.1 KiB
Haxe
77 lines
2.1 KiB
Haxe
package funkin.play.notes;
|
|
|
|
import funkin.play.notes.notestyle.NoteStyle;
|
|
import flixel.graphics.frames.FlxFramesCollection;
|
|
import flixel.FlxG;
|
|
import flixel.FlxSprite;
|
|
|
|
class NoteSplash extends FlxSprite
|
|
{
|
|
static final ALPHA:Float = 0.6;
|
|
static final FRAMERATE_DEFAULT:Int = 24;
|
|
static final FRAMERATE_VARIANCE:Int = 2;
|
|
|
|
static var frameCollection:FlxFramesCollection;
|
|
|
|
public static function preloadFrames():Void
|
|
{
|
|
frameCollection = Paths.getSparrowAtlas('noteSplashes');
|
|
frameCollection.parent.persist = true;
|
|
}
|
|
|
|
public function new(noteStyle:NoteStyle)
|
|
{
|
|
super(0, 0);
|
|
|
|
setupSplashGraphic(noteStyle);
|
|
|
|
this.alpha = ALPHA;
|
|
this.animation.finishCallback = this.onAnimationFinished;
|
|
}
|
|
|
|
/**
|
|
* Add ALL the animations to this sprite. We will recycle and reuse the FlxSprite multiple times.
|
|
*/
|
|
function setupSplashGraphic(noteStyle:NoteStyle):Void
|
|
{
|
|
if (frames == null) noteStyle.buildSplashSprite(this);
|
|
|
|
if (this.animation.getAnimationList().length < 8)
|
|
{
|
|
trace('WARNING: NoteSplash failed to initialize all animations.');
|
|
}
|
|
}
|
|
|
|
public function playAnimation(name:String, force:Bool = false, reversed:Bool = false, startFrame:Int = 0):Void
|
|
{
|
|
this.animation.play(name, force, reversed, startFrame);
|
|
}
|
|
|
|
public function play(direction:NoteDirection, variant:Int = null):Void
|
|
{
|
|
if (variant == null)
|
|
{
|
|
var animationAmount:Int = this.animation.getAnimationList().filter(function(anim) return anim.name.startsWith('splash${direction.nameUpper}')).length
|
|
- 1;
|
|
variant = FlxG.random.int(0, animationAmount);
|
|
}
|
|
|
|
// splashUP0, splashUP1, splashRIGHT0, etc.
|
|
this.playAnimation('splash${direction.nameUpper}${variant}');
|
|
|
|
if (animation.curAnim == null) return;
|
|
|
|
// Vary the speed of the animation a bit.
|
|
animation.curAnim.frameRate = FRAMERATE_DEFAULT + FlxG.random.int(-FRAMERATE_VARIANCE, FRAMERATE_VARIANCE);
|
|
|
|
// Center the animation on the note splash.
|
|
offset.set(width * 0.3, height * 0.3);
|
|
}
|
|
|
|
public function onAnimationFinished(animationName:String):Void
|
|
{
|
|
// *lightning* *zap* *crackle*
|
|
this.kill();
|
|
}
|
|
}
|