Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 1 #4

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions source/objects/HealthIcon.hx
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
The reason for all my changes here is so that icons can be more configurable out of the box, without having to change a thing from base source.
Yes, users can already make winning icons, but this supports a built in override, which I think is neat.

This also just seems like a good practice for icons anyway. As it provides a way to create really wacky icons by abusing the height value.

-- saturn-volv
*/

package objects;

class HealthIcon extends FlxSprite
Expand All @@ -24,6 +33,18 @@ class HealthIcon extends FlxSprite
setPosition(sprTracker.x + sprTracker.width + 12, sprTracker.y - 30);
}

private var iconSize:Int = 0;
/**
* An index which decides which frame of the icon to use.
*/
@:isVar public var iconIndex(get, set):Int;
public function get_iconIndex() {
return iconIndex = animation?.curAnim.curFrame ?? 0;
}
public function set_iconIndex(i:Int):Int {
return iconIndex = animation.curAnim.curFrame = (i % iconSize);
}

private var iconOffsets:Array<Float> = [0, 0];
public function changeIcon(char:String, ?allowGPU:Bool = true) {
if(this.char != char) {
Expand All @@ -32,12 +53,15 @@ class HealthIcon extends FlxSprite
if(!Paths.fileExists('images/' + name + '.png', IMAGE)) name = 'icons/icon-face'; //Prevents crash from missing icon

var graphic = Paths.image(name, allowGPU);
loadGraphic(graphic, true, Math.floor(graphic.width / 2), Math.floor(graphic.height));
iconOffsets[0] = (width - 150) / 2;
iconOffsets[1] = (height - 150) / 2;
iconSize = Math.floor(graphic.width / graphic.height);
loadGraphic(graphic, true, Math.floor(graphic.width / iconSize), Math.floor(graphic.height));
iconOffsets[0] = (width - 150) / iconSize;
iconOffsets[1] = (height - 150) / iconSize;
updateHitbox();

animation.add(char, [0, 1], 0, false, isPlayer);
animation.add(char,
[for(i in 0...iconSize) i], // Creates an array from 0 of iconSize in length;
0, false, isPlayer);
animation.play(char);
this.char = char;

Expand Down
4 changes: 2 additions & 2 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1843,8 +1843,8 @@ class PlayState extends MusicBeatState
var newPercent:Null<Float> = FlxMath.remapToRange(FlxMath.bound(healthBar.valueFunction(), healthBar.bounds.min, healthBar.bounds.max), healthBar.bounds.min, healthBar.bounds.max, 0, 100);
healthBar.percent = (newPercent != null ? newPercent : 0);

iconP1.animation.curAnim.curFrame = (healthBar.percent < 20) ? 1 : 0; //If health is under 20%, change player icon to frame 1 (losing icon), otherwise, frame 0 (normal)
iconP2.animation.curAnim.curFrame = (healthBar.percent > 80) ? 1 : 0; //If health is over 80%, change opponent icon to frame 1 (losing icon), otherwise, frame 0 (normal)
iconP1.iconIndex = (healthBar.percent < 20) ? 1 : 0; //If health is under 20%, change player icon to frame 1 (losing icon), otherwise, frame 0 (normal)
iconP2.iconIndex = (healthBar.percent > 80) ? 1 : 0; //If health is over 80%, change opponent icon to frame 1 (losing icon), otherwise, frame 0 (normal)
return health;
}

Expand Down
Loading