Game Development Reference
In-Depth Information
Add the following line to the WorldController class:
public float scoreVisual;
Next, make the following changes to the same class:
private void initLevel () {
score = 0;
scoreVisual = score;
level = new Level(Constants.LEVEL_01);
cameraHelper.setTarget(level.bunnyHead);
}
public void update (float deltaTime) {
...
level.mountains.updateScrollPosition
(cameraHelper.getPosition());
if (livesVisual> lives)
livesVisual = Math.max(lives, livesVisual - 1 * deltaTime);
if (scoreVisual< score)
scoreVisual = Math.min(score, scoreVisual
+ 250 * deltaTime);
}
We introduced the new variable scoreVisual , which serves the same purpose as
livesVisual does to control the progress of the score animation.
Additionally, make the following changes to the WorldRenderer class:
private void renderGuiScore (SpriteBatch batch) {
float x = -15;
float y = -15;
float offsetX = 50;
float offsetY = 50;
if (worldController.scoreVisual<worldController.score) {
long shakeAlpha = System.currentTimeMillis() % 360;
float shakeDist = 1.5f;
offsetX += MathUtils.sinDeg(shakeAlpha * 2.2f) * shakeDist;
offsetY += MathUtils.sinDeg(shakeAlpha * 2.9f) * shakeDist;
}
batch.draw(Assets.instance.goldCoin.goldCoin, x, y, offsetX,
offsetY, 100, 100, 0.35f, -0.35f, 0);
Assets.instance.fonts.defaultBig.draw(batch,
"" + (int)worldController.scoreVisual,
x + 75, y + 37);
}
 
Search WWH ::




Custom Search