1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-09-03 20:28:04 +00:00
Funkin/source/funkin/play/notes/NoteSplash.hx

70 lines
2 KiB
Haxe
Raw Permalink Normal View History

2023-06-22 05:41:01 +00:00
package funkin.play.notes;
2025-02-24 18:45:03 +00:00
import funkin.play.notes.notestyle.NoteStyle;
2023-06-22 05:41:01 +00:00
import flixel.graphics.frames.FlxFramesCollection;
import flixel.FlxG;
import flixel.FlxSprite;
class NoteSplash extends FlxSprite
{
public var splashFramerate:Int = 24;
public var splashFramerateVariance:Int = 2;
2023-06-22 05:41:01 +00:00
static var frameCollection:FlxFramesCollection;
2025-02-24 18:45:03 +00:00
public function new(noteStyle:NoteStyle)
2023-06-22 05:41:01 +00:00
{
super(0, 0);
2025-02-24 18:45:03 +00:00
setupSplashGraphic(noteStyle);
2023-06-22 05:41:01 +00:00
2025-03-03 02:44:41 +00:00
this.animation.onFinish.add(this.onAnimationFinished);
2023-06-22 05:41:01 +00:00
}
/**
* Add ALL the animations to this sprite. We will recycle and reuse the FlxSprite multiple times.
*/
2025-02-24 18:45:03 +00:00
function setupSplashGraphic(noteStyle:NoteStyle):Void
2023-06-22 05:41:01 +00:00
{
2025-02-24 18:45:03 +00:00
if (frames == null) noteStyle.buildSplashSprite(this);
2023-06-22 05:41:01 +00:00
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
{
2025-02-24 22:11:13 +00:00
if (variant == null)
2023-06-22 05:41:01 +00:00
{
2025-02-24 22:11:13 +00:00
var animationAmount:Int = this.animation.getAnimationList().filter(function(anim) return anim.name.startsWith('splash${direction.nameUpper}')).length
- 1;
variant = FlxG.random.int(0, animationAmount);
2023-06-22 05:41:01 +00:00
}
2025-02-24 22:11:13 +00:00
// splashUP0, splashUP1, splashRIGHT0, etc.
2025-03-12 01:06:28 +00:00
// the animations are processed via `NoteStyle.fetchSplashAnimationData()` in this format
2025-02-24 22:11:13 +00:00
this.playAnimation('splash${direction.nameUpper}${variant}');
if (animation.curAnim == null) return;
2023-06-22 05:41:01 +00:00
// Vary the speed of the animation a bit.
animation.curAnim.frameRate = splashFramerate + FlxG.random.int(-splashFramerateVariance, splashFramerateVariance);
2023-06-22 05:41:01 +00:00
// 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();
}
}