From e1c7fbb53fe38e5e95f6db95d792dcddac611fd6 Mon Sep 17 00:00:00 2001 From: BlueNutterfly Date: Mon, 12 Nov 2018 18:19:19 +0400 Subject: [PATCH] Move ball speed boost check to Brick's hit() method --- core/src/com/me/brickbuster/entity/Ball.java | 6 +++--- core/src/com/me/brickbuster/entity/Brick.java | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/com/me/brickbuster/entity/Ball.java b/core/src/com/me/brickbuster/entity/Ball.java index 44d91ff..fad8bed 100644 --- a/core/src/com/me/brickbuster/entity/Ball.java +++ b/core/src/com/me/brickbuster/entity/Ball.java @@ -63,9 +63,6 @@ public class Ball extends Entity { if (nearest.dst(new_pos.x, new_pos.y) <= RADIUS) { brickIterator.remove(); brick.hit(); - if (getBrickBuster().getBricks().size() <= BLOCKS_FOR_BOOST) { - speed = BOOST_SPEED; - } Utils.reflect(direction, segment.nor()); brickCollision = true; break; @@ -126,6 +123,9 @@ public class Ball extends Entity { direction = paddleReflectAngle(); } + public void setSpeed(float speed) { + this.speed = speed; + } public boolean isStuck() { return isStuck; diff --git a/core/src/com/me/brickbuster/entity/Brick.java b/core/src/com/me/brickbuster/entity/Brick.java index 29e3fa0..7bd4af3 100644 --- a/core/src/com/me/brickbuster/entity/Brick.java +++ b/core/src/com/me/brickbuster/entity/Brick.java @@ -40,6 +40,12 @@ public class Brick extends Entity { } public boolean hit() { + if (getBrickBuster().getBricks().size()-1 <= Ball.BLOCKS_FOR_BOOST) { + for (Ball ball : getBrickBuster().getBalls()) { + ball.setSpeed(Ball.BOOST_SPEED); + } + } + if (powerUpType != null) { try { PowerUp powerUp = powerUpType.getConstructor(BrickBuster.class, Brick.class).newInstance(getBrickBuster(), this);