Skip to content

Commit

Permalink
Animated the score display.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <[email protected]>
  • Loading branch information
itdelatrisu committed Jul 3, 2014
1 parent f195ffb commit 0b471fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/itdelatrisu/opsu/GameScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public OsuHitObjectResult(int time, int result, float x, float y, Color color) {
*/
private long score;

/**
* Displayed game score (for animation, slightly behind score).
*/
private long scoreDisplay;

/**
* Current health bar percentage.
*/
Expand Down Expand Up @@ -249,6 +254,7 @@ public GameScore(int width, int height) {
*/
public void clear() {
score = 0;
scoreDisplay = 0;
health = 100f;
hitResultCount = new int[HIT_MAX];
hitResultList = new LinkedList<OsuHitObjectResult>();
Expand Down Expand Up @@ -432,7 +438,7 @@ private void drawSymbolString(String str, int x, int y, float scale, boolean rig
*/
public void drawGameElements(Graphics g, int mapLength, boolean breakPeriod, boolean firstObject) {
// score
drawSymbolString(String.format("%08d", score),
drawSymbolString(String.format("%08d", scoreDisplay),
width - 2, 0, 1.0f, true);

// score percentage
Expand Down Expand Up @@ -670,8 +676,21 @@ else if (hit300ratio >= 60f)
return GRADE_D;
}

/**
* Updates the score display based on a delta value.
* @param delta the delta interval since the last call
*/
public void updateScoreDisplay(int delta) {
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) {
if (comboBurstIndex > -1 && Options.isComboBurstEnabled()) {
Expand Down
6 changes: 4 additions & 2 deletions src/itdelatrisu/opsu/states/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ else if (!container.hasFocus()) {
return;
}

score.updateScoreDisplay(delta);

// map complete!
if (objectIndex >= osu.objects.length) {
game.enterState(Opsu.STATE_GAMERANKING, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
Expand Down Expand Up @@ -558,6 +560,8 @@ else if (!container.hasFocus()) {
game.enterState(Opsu.STATE_GAMEPAUSEMENU);
}

score.updateComboBurst(delta);

// drain health
score.changeHealth(delta / -200f);
if (!score.isAlive()) {
Expand All @@ -566,8 +570,6 @@ else if (!container.hasFocus()) {
game.enterState(Opsu.STATE_GAMEPAUSEMENU);
}

score.updateComboBurst(delta);

// update objects (loop in unlikely event of any skipped indexes)
while (objectIndex < osu.objects.length && trackPosition > osu.objects[objectIndex].time) {
OsuHitObject hitObject = osu.objects[objectIndex];
Expand Down

0 comments on commit 0b471fa

Please sign in to comment.