From b20cb27f828a57e7b6676782245ce94fe707220e Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 23 Aug 2023 05:33:52 -0400 Subject: [PATCH] hue shifting in progress --- assets | 2 +- hmm.json | 2 +- .../funkin/freeplayStuff/DifficultyStars.hx | 112 ++++++++++++++++ source/funkin/freeplayStuff/FreeplayFlames.hx | 120 ++++++++++++++++++ source/funkin/shaderslmfao/HSVShader.hx | 44 +++++++ 5 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 source/funkin/freeplayStuff/DifficultyStars.hx create mode 100644 source/funkin/freeplayStuff/FreeplayFlames.hx create mode 100644 source/funkin/shaderslmfao/HSVShader.hx diff --git a/assets b/assets index bc7e486ba..cb481d798 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit bc7e486ba4cf52e55893daa951e58b37059b0adb +Subproject commit cb481d79891707029a7f10975ce0d392c56f244a diff --git a/hmm.json b/hmm.json index 85c83ea6d..bb2832ba8 100644 --- a/hmm.json +++ b/hmm.json @@ -32,7 +32,7 @@ "name": "flxanimate", "type": "git", "dir": null, - "ref": "a913635", + "ref": "37fd4ed45011063a38fdfe9bb6091671b3ac6c17", "url": "https://github.com/ninjamuffin99/flxanimate" }, { diff --git a/source/funkin/freeplayStuff/DifficultyStars.hx b/source/funkin/freeplayStuff/DifficultyStars.hx new file mode 100644 index 000000000..3078f0e9a --- /dev/null +++ b/source/funkin/freeplayStuff/DifficultyStars.hx @@ -0,0 +1,112 @@ +package funkin.freeplayStuff; + +import flixel.group.FlxSpriteGroup; +import funkin.graphics.adobeanimate.FlxAtlasSprite; +import funkin.shaderslmfao.HSVShader; + +class DifficultyStars extends FlxSpriteGroup +{ + /** + * Internal handler var for difficulty... ranges from 0... to 15 + * 0 is 1 star... 15 is 0 stars! + */ + var curDifficulty(default, set):Int = 0; + + /** + * Range between 0 and 15 + */ + public var difficulty(default, set):Int = 1; + + var stars:FlxAtlasSprite; + + var flames:FreeplayFlames; + + var hsvShader:HSVShader; + + public function new(x:Float, y:Float) + { + super(x, y); + + hsvShader = new HSVShader(); + + flames = new FreeplayFlames(0, 0); + add(flames); + + stars = new FlxAtlasSprite(0, 0, Paths.animateAtlas("freeplay/freeplayStars")); + stars.anim.play("diff stars"); + add(stars); + + stars.shader = hsvShader; + + for (memb in flames.members) + memb.shader = hsvShader; + + FlxG.debugger.addTrackerProfile(new TrackerProfile(HSVShader, ["hue", "saturation", "value"])); + FlxG.debugger.track(hsvShader); + + FlxG.debugger.addTrackerProfile(new TrackerProfile(DifficultyStars, ["difficulty"])); + FlxG.debugger.track(this); + } + + override function update(elapsed:Float):Void + { + super.update(elapsed); + + // "loops" the current animation + // for clarity, the animation file looks like + // frame : stars + // 0-99: 1 star + // 100-199: 2 stars + // ...... + // 1300-1499: 15 stars + // 1500 : 0 stars + if (curDifficulty < 15 && stars.anim.curFrame >= (curDifficulty + 1) * 100) + { + stars.anim.play("diff stars", true, false, curDifficulty * 100); + } + } + + function set_difficulty(value:Int):Int + { + difficulty = value; + + if (difficulty <= 0) + { + difficulty = 0; + curDifficulty = 15; + } + else if (difficulty <= 15) + { + difficulty = value; + curDifficulty = difficulty - 1; + } + else + { + difficulty = 15; + curDifficulty = difficulty - 1; + } + + if (difficulty > 10) flames.flameCount = difficulty - 10; + else + flames.flameCount = 0; + + return difficulty; + } + + function set_curDifficulty(value:Int):Int + { + curDifficulty = value; + if (curDifficulty == 15) + { + stars.anim.play("diff stars", true, false, 1500); + stars.anim.pause(); + } + else + { + stars.anim.curFrame = Std.int(curDifficulty * 100); + stars.anim.play("diff stars", true, false, curDifficulty * 100); + } + + return curDifficulty; + } +} diff --git a/source/funkin/freeplayStuff/FreeplayFlames.hx b/source/funkin/freeplayStuff/FreeplayFlames.hx new file mode 100644 index 000000000..cf606bdb8 --- /dev/null +++ b/source/funkin/freeplayStuff/FreeplayFlames.hx @@ -0,0 +1,120 @@ +package funkin.freeplayStuff; + +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"); + flame.animation.addByPrefix("flame", "fire loop", FlxG.random.int(23, 25), false); + 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); + } + + FlxG.debugger.addTrackerProfile(new TrackerProfile(FreeplayFlames, ["flameTimer"])); + FlxG.debugger.track(this); + } + + 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; + } + } + + function set_flameCount(value:Int):Int + { + 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) + { + new FlxTimer().start(flameTimer * visibleCount, function(_) { + flame.animation.play("flame", true); + flame.visible = true; + }); + 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; + } +} diff --git a/source/funkin/shaderslmfao/HSVShader.hx b/source/funkin/shaderslmfao/HSVShader.hx new file mode 100644 index 000000000..066a49c96 --- /dev/null +++ b/source/funkin/shaderslmfao/HSVShader.hx @@ -0,0 +1,44 @@ +package funkin.shaderslmfao; + +import flixel.addons.display.FlxRuntimeShader; +import funkin.Paths; +import openfl.utils.Assets; + +class HSVShader extends FlxRuntimeShader +{ + public var hue(default, set):Float; + public var saturation(default, set):Float; + public var value(default, set):Float; + + public function new() + { + super(Assets.getText(Paths.frag('hsv'))); + hue = 1; + saturation = 1; + value = 1; + } + + function set_hue(value:Float):Float + { + this.setFloat('hue', value); + this.hue = value; + + return this.hue; + } + + function set_saturation(value:Float):Float + { + this.setFloat('sat', value); + this.saturation = value; + + return this.saturation; + } + + function set_value(value:Float):Float + { + this.setFloat('val', value); + this.value = value; + + return this.value; + } +}