diff --git a/app/src/main/java/jonathan/balljumper/classes/Ball.java b/app/src/main/java/jonathan/balljumper/classes/Ball.java index 744631c..f3f44e5 100644 --- a/app/src/main/java/jonathan/balljumper/classes/Ball.java +++ b/app/src/main/java/jonathan/balljumper/classes/Ball.java @@ -10,12 +10,17 @@ */ public class Ball extends Sprite { + private final int animationSizeMax = 6; + private float radius; private float velocity, startVelocity; private float gravity; private float deltaX, deltaY; private int jumpBoost; + private boolean isAnimationRunning; + private float animationSize; + private Paint paint; public Ball(float x, float y, float radius, float velocity, float gravity, float speed, int color) { @@ -35,7 +40,13 @@ } public void draw(Canvas canvas) { - canvas.drawOval(getLeft(), getTop(), getRight(), getBottom(), paint); + canvas.drawOval( + getLeft() - animationSize / 2, + getTop() + animationSize * 2, + getRight() + animationSize / 2, + getBottom() - animationSize, + paint + ); } /** @@ -46,6 +57,8 @@ jumpBoost = (int)speed; // Give the ball a boost. velocity = this.startVelocity; // Reset velocity } + + isAnimationRunning = true; } public void move() { @@ -71,6 +84,17 @@ this.deltaY = y - this.deltaY; this.deltaX = x - this.deltaX; + + if (isAnimationRunning) { + animationSize += velocity * 2; + if (animationSize >= animationSizeMax) { + isAnimationRunning = false; + } + } else if (animationSize > 0) { + animationSize -= velocity * 2; + if (animationSize < 0) animationSize = 0; + } + } public boolean intersects(float x, float y, float w, float h) {