From a6c390f10e8702c108188a544a596b214c0c3184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Sun, 6 Jul 2025 14:43:00 +0200 Subject: [PATCH] making health updating auto more optimised than doing it each frame --- source/funkin/game/PlayState.hx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index e3349016..699ccb52 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -247,12 +247,12 @@ class PlayState extends MusicBeatState /** * Current health. Goes from 0 to maxHealth (defaults to 2) */ - public var health:Float = 1; + public var health(default, set):Float = 1; /** * Maximum health the player can have. Defaults to 2. */ - @:isVar public var maxHealth(get, set):Float = Flags.DEFAULT_MAX_HEALTH; + public var maxHealth(default, set):Float = Flags.DEFAULT_MAX_HEALTH; /** * Current combo. */ @@ -556,13 +556,13 @@ class PlayState extends MusicBeatState curRating = event.rating; } - private inline function get_maxHealth() - return this.maxHealth; - private function set_maxHealth(v:Float) { - if (healthBar != null && healthBar.max == this.maxHealth) { - healthBar.setRange(healthBar.min, v); - } - return this.maxHealth = v; + private inline function set_health(v:Float) + return health = FlxMath.bound(v, 0, maxHealth); + private inline function set_maxHealth(v:Float) { + if (healthBar != null && healthBar.max == maxHealth) healthBar.setRange(healthBar.min, v); + maxHealth = v; + health = health; // running the setter - Nex + return maxHealth; } private inline function get_curStage() @@ -1283,8 +1283,6 @@ class PlayState extends MusicBeatState iconP1.x = center - iconOffset; iconP2.x = center - (iconP2.width - iconOffset); - health = FlxMath.bound(health, 0, maxHealth); - iconP1.health = healthBarPercent / 100; iconP2.health = 1 - (healthBarPercent / 100); }