Move ball speed boost check to Brick's hit() method

This commit is contained in:
BlueNutterfly 2018-11-12 18:19:19 +04:00
parent 1ee5a5a36c
commit e1c7fbb53f
2 changed files with 9 additions and 3 deletions

View File

@ -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;

View File

@ -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);