From 312757188609ea46c5909e9cc04f83ffe4f20ea8 Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Tue, 30 Dec 2014 01:17:05 -0500 Subject: [PATCH] Smoother health bar changes. Also merged GameScore update calls into a single method. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/GameScore.java | 34 ++++++++++++++++++++------- src/itdelatrisu/opsu/states/Game.java | 10 +++----- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/itdelatrisu/opsu/GameScore.java b/src/itdelatrisu/opsu/GameScore.java index 19cba2fd..14545d2f 100644 --- a/src/itdelatrisu/opsu/GameScore.java +++ b/src/itdelatrisu/opsu/GameScore.java @@ -174,6 +174,11 @@ public class GameScore { */ private float health; + /** + * Displayed health (for animation, slightly behind health). + */ + private float healthDisplay; + /** * Beatmap HPDrainRate value. (0:easy ~ 10:hard) */ @@ -228,6 +233,7 @@ public class GameScore { score = 0; scoreDisplay = 0; health = 100f; + healthDisplay = 100f; hitResultCount = new int[HIT_MAX]; hitResultList = new LinkedList(); objectCount = 0; @@ -533,7 +539,7 @@ public class GameScore { if (!breakPeriod) { // scorebar - float healthRatio = health / 100f; + float healthRatio = healthDisplay / 100f; if (firstObject) { // gradually move ki before map begins if (firstObjectTime >= 1500 && trackPosition < firstObjectTime - 500) healthRatio = (float) trackPosition / (firstObjectTime - 500); @@ -762,22 +768,32 @@ public class GameScore { } /** - * Updates the score display based on a delta value. + * Updates the score, health, and combo burst displays based on a delta value. * @param delta the delta interval since the last call */ - public void updateScoreDisplay(int delta) { + public void updateDisplays(int delta) { + // score display if (scoreDisplay < score) { scoreDisplay += (score - scoreDisplay) * delta / 50 + 1; if (scoreDisplay > score) scoreDisplay = score; } - } - /** - * Updates combo burst data based on a delta value. - * @param delta the delta interval since the last call - */ - public void updateComboBurst(int delta) { + // health display + if (healthDisplay != health) { + float shift = delta / 15f; + if (healthDisplay < health) { + healthDisplay += shift; + if (healthDisplay > health) + healthDisplay = health; + } else { + healthDisplay -= shift; + if (healthDisplay < health) + healthDisplay = health; + } + } + + // combo burst if (comboBurstIndex > -1 && Options.isComboBurstEnabled()) { int leftX = 0; int rightX = width - comboBurstImages[comboBurstIndex].getWidth(); diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java index 514e5557..6a25da3d 100644 --- a/src/itdelatrisu/opsu/states/Game.java +++ b/src/itdelatrisu/opsu/states/Game.java @@ -490,7 +490,7 @@ public class Game extends BasicGameState { } } - score.updateScoreDisplay(delta); + score.updateDisplays(delta); // map complete! if (objectIndex >= osu.objects.length) { @@ -517,10 +517,8 @@ public class Game extends BasicGameState { } // song beginning - if (objectIndex == 0) { - if (trackPosition < osu.objects[0].getTime()) - return; // nothing to do here - } + if (objectIndex == 0 && trackPosition < osu.objects[0].getTime()) + return; // nothing to do here // break periods if (osu.breaks != null && breakIndex < osu.breaks.size()) { @@ -554,8 +552,6 @@ public class Game extends BasicGameState { game.enterState(Opsu.STATE_GAMEPAUSEMENU); } - score.updateComboBurst(delta); - // drain health score.changeHealth(delta * -1 * GameScore.HP_DRAIN_MULTIPLIER); if (!score.isAlive()) {