diff --git a/core/src/com/me/brickbuster/BrickBuster.java b/core/src/com/me/brickbuster/BrickBuster.java index ca6a188..107874d 100644 --- a/core/src/com/me/brickbuster/BrickBuster.java +++ b/core/src/com/me/brickbuster/BrickBuster.java @@ -37,7 +37,7 @@ public class BrickBuster extends ApplicationAdapter { private ArrayList bricks; private ArrayList powerUps; - private boolean shieldActive = false; + private int shieldCount = 0; @Override public void create () { @@ -88,10 +88,10 @@ public class BrickBuster extends ApplicationAdapter { } paddle.render(sr); - if (shieldActive) { + if (getShieldCount() > 0) { sr.begin(ShapeRenderer.ShapeType.Filled); sr.setColor(Color.SALMON); - sr.rect(0, 0, WIDTH, SHIELD_HEIGHT); + sr.rect(0, 0, WIDTH, getShieldCount() * SHIELD_HEIGHT); sr.end(); } @@ -157,12 +157,18 @@ public class BrickBuster extends ApplicationAdapter { return null; } - public void setShieldActive(boolean shieldActive) { - this.shieldActive = shieldActive; + public int getShieldCount() { + return shieldCount; } - public boolean isShieldActive() { - return shieldActive; + public void addShield() { + shieldCount++; + paddle.setY(paddle.getY() + SHIELD_HEIGHT); + } + + public void removeShield() { + shieldCount--; + paddle.setY(paddle.getY() - SHIELD_HEIGHT); } public ArrayList getBalls() { diff --git a/core/src/com/me/brickbuster/entity/Ball.java b/core/src/com/me/brickbuster/entity/Ball.java index 94437f3..2f0449f 100644 --- a/core/src/com/me/brickbuster/entity/Ball.java +++ b/core/src/com/me/brickbuster/entity/Ball.java @@ -26,7 +26,7 @@ public class Ball extends Entity { private boolean isDead = false; public Ball(BrickBuster brickBuster) { - super(brickBuster,BrickBuster.WIDTH/2, Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS); + super(brickBuster,BrickBuster.WIDTH/2, brickBuster.getPaddle().getY() + Paddle.PADDLE_HEIGHT + RADIUS); this.speed = getBrickBuster().getBricks().size() > BLOCKS_FOR_BOOST? DEFAULT_SPEED : BOOST_SPEED; } @@ -48,10 +48,12 @@ public class Ball extends Entity { } } + BrickBuster game = getBrickBuster(); + Vector2 new_pos = getPos().cpy().add(direction.cpy().scl(speed * dt)); boolean brickCollision = false; - Iterator brickIterator = getBrickBuster().getBricks().iterator(); + Iterator brickIterator = game.getBricks().iterator(); while (!brickCollision && brickIterator.hasNext()) { Brick brick = brickIterator.next(); Vector2[] vertices = brick.getVertices(); @@ -76,20 +78,21 @@ public class Ball extends Entity { Utils.reflect(direction, BrickBuster.VERTICAL_EDGE); } else if (new_pos.y + RADIUS > BrickBuster.HEIGHT) { Utils.reflect(direction, BrickBuster.HORIZONTAL_EDGE); - } else if (new_pos.y - RADIUS < BrickBuster.SHIELD_HEIGHT && getBrickBuster().isShieldActive()) { + } else if (game.getShieldCount() > 0 + && new_pos.y - RADIUS < BrickBuster.SHIELD_HEIGHT * game.getShieldCount()) { Utils.reflect(direction, BrickBuster.HORIZONTAL_EDGE); - getBrickBuster().setShieldActive(false); + game.removeShield(); } else if (new_pos.y + RADIUS < 0) { isDead = true; return; - } else if (direction.y < 0 && new_pos.y <= Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS) { - Pair paddle = getBrickBuster().getPaddle().getTopEdge(); + } else if (direction.y < 0 && new_pos.y <= game.getPaddle().getY() + Paddle.PADDLE_HEIGHT + RADIUS) { + Pair paddle = game.getPaddle().getTopEdge(); Vector2 lineDir = paddle.getValue().sub(paddle.getKey()); Vector2 nearest = Utils.nearestPoint(paddle.getKey().cpy(), lineDir, new_pos.cpy()); if (nearest.dst(new_pos.x, new_pos.y) <= RADIUS) { paddleCollision(); - if (getBrickBuster().getPaddle().isSticky()) { + if (game.getPaddle().isSticky()) { return; } } @@ -120,7 +123,7 @@ public class Ball extends Entity { Paddle paddle = getBrickBuster().getPaddle(); if (paddle.isSticky()) { isStuck = true; - setY(Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS); + setY(paddle.getY() + Paddle.PADDLE_HEIGHT + RADIUS); return; } direction = paddleReflectAngle(); diff --git a/core/src/com/me/brickbuster/entity/Paddle.java b/core/src/com/me/brickbuster/entity/Paddle.java index f4ada06..a452df9 100644 --- a/core/src/com/me/brickbuster/entity/Paddle.java +++ b/core/src/com/me/brickbuster/entity/Paddle.java @@ -17,8 +17,8 @@ public class Paddle extends Entity { public static final int PADDLE_Y = 15; public static final int PADDLE_SPEED = 375; - private boolean sticky = false; private int width = DEFAULT_WIDTH; + private boolean sticky = false; public Paddle(BrickBuster brickBuster) { super(brickBuster, BrickBuster.WIDTH / 2, PADDLE_Y); @@ -73,6 +73,10 @@ public class Paddle extends Entity { return width; } + public void setWidth(int width) { + this.width = width; + } + public boolean isSticky() { return sticky; } @@ -81,7 +85,7 @@ public class Paddle extends Entity { this.sticky = sticky; } - public void setWidth(int width) { - this.width = width; - } + + + } diff --git a/core/src/com/me/brickbuster/entity/powerup/ShieldPowerUp.java b/core/src/com/me/brickbuster/entity/powerup/ShieldPowerUp.java index eaf7697..cf4fc4b 100644 --- a/core/src/com/me/brickbuster/entity/powerup/ShieldPowerUp.java +++ b/core/src/com/me/brickbuster/entity/powerup/ShieldPowerUp.java @@ -12,7 +12,7 @@ public class ShieldPowerUp extends PowerUp { @Override public void activate() { - getBrickBuster().setShieldActive(true); + getBrickBuster().addShield(); } }