Smoother health bar changes.

Also merged GameScore update calls into a single method.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2014-12-30 01:17:05 -05:00
parent b0649541eb
commit 3127571886
2 changed files with 28 additions and 16 deletions

View File

@ -174,6 +174,11 @@ public class GameScore {
*/ */
private float health; private float health;
/**
* Displayed health (for animation, slightly behind health).
*/
private float healthDisplay;
/** /**
* Beatmap HPDrainRate value. (0:easy ~ 10:hard) * Beatmap HPDrainRate value. (0:easy ~ 10:hard)
*/ */
@ -228,6 +233,7 @@ public class GameScore {
score = 0; score = 0;
scoreDisplay = 0; scoreDisplay = 0;
health = 100f; health = 100f;
healthDisplay = 100f;
hitResultCount = new int[HIT_MAX]; hitResultCount = new int[HIT_MAX];
hitResultList = new LinkedList<OsuHitObjectResult>(); hitResultList = new LinkedList<OsuHitObjectResult>();
objectCount = 0; objectCount = 0;
@ -533,7 +539,7 @@ public class GameScore {
if (!breakPeriod) { if (!breakPeriod) {
// scorebar // scorebar
float healthRatio = health / 100f; float healthRatio = healthDisplay / 100f;
if (firstObject) { // gradually move ki before map begins if (firstObject) { // gradually move ki before map begins
if (firstObjectTime >= 1500 && trackPosition < firstObjectTime - 500) if (firstObjectTime >= 1500 && trackPosition < firstObjectTime - 500)
healthRatio = (float) 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 * @param delta the delta interval since the last call
*/ */
public void updateScoreDisplay(int delta) { public void updateDisplays(int delta) {
// score display
if (scoreDisplay < score) { if (scoreDisplay < score) {
scoreDisplay += (score - scoreDisplay) * delta / 50 + 1; scoreDisplay += (score - scoreDisplay) * delta / 50 + 1;
if (scoreDisplay > score) if (scoreDisplay > score)
scoreDisplay = score; scoreDisplay = score;
} }
}
/** // health display
* Updates combo burst data based on a delta value. if (healthDisplay != health) {
* @param delta the delta interval since the last call float shift = delta / 15f;
*/ if (healthDisplay < health) {
public void updateComboBurst(int delta) { healthDisplay += shift;
if (healthDisplay > health)
healthDisplay = health;
} else {
healthDisplay -= shift;
if (healthDisplay < health)
healthDisplay = health;
}
}
// combo burst
if (comboBurstIndex > -1 && Options.isComboBurstEnabled()) { if (comboBurstIndex > -1 && Options.isComboBurstEnabled()) {
int leftX = 0; int leftX = 0;
int rightX = width - comboBurstImages[comboBurstIndex].getWidth(); int rightX = width - comboBurstImages[comboBurstIndex].getWidth();

View File

@ -490,7 +490,7 @@ public class Game extends BasicGameState {
} }
} }
score.updateScoreDisplay(delta); score.updateDisplays(delta);
// map complete! // map complete!
if (objectIndex >= osu.objects.length) { if (objectIndex >= osu.objects.length) {
@ -517,10 +517,8 @@ public class Game extends BasicGameState {
} }
// song beginning // song beginning
if (objectIndex == 0) { if (objectIndex == 0 && trackPosition < osu.objects[0].getTime())
if (trackPosition < osu.objects[0].getTime()) return; // nothing to do here
return; // nothing to do here
}
// break periods // break periods
if (osu.breaks != null && breakIndex < osu.breaks.size()) { if (osu.breaks != null && breakIndex < osu.breaks.size()) {
@ -554,8 +552,6 @@ public class Game extends BasicGameState {
game.enterState(Opsu.STATE_GAMEPAUSEMENU); game.enterState(Opsu.STATE_GAMEPAUSEMENU);
} }
score.updateComboBurst(delta);
// drain health // drain health
score.changeHealth(delta * -1 * GameScore.HP_DRAIN_MULTIPLIER); score.changeHealth(delta * -1 * GameScore.HP_DRAIN_MULTIPLIER);
if (!score.isAlive()) { if (!score.isAlive()) {