diff --git a/app/src/main/java/brickbreaker/Ball.java b/app/src/main/java/brickbreaker/Ball.java index 42c5006a9cd1d31edebf8d38b079063dd8ff25dc..24987c141fc926c744d30a45f809c873f3930943 100644 --- a/app/src/main/java/brickbreaker/Ball.java +++ b/app/src/main/java/brickbreaker/Ball.java @@ -11,7 +11,7 @@ package brickbreaker; public class Ball { private Vector position; private Vector direction; - private int radius; + public int radius; public Ball(int posX, int posY, int dirX, int dirY, int radius) { this.position = new Vector(posX, posY); diff --git a/app/src/main/java/brickbreaker/GamePanel.java b/app/src/main/java/brickbreaker/GamePanel.java index 4601626cc6cc7361210093b66144843f5598a138..2bc524fdf8e3170927d7ef005a75c12031873aa9 100644 --- a/app/src/main/java/brickbreaker/GamePanel.java +++ b/app/src/main/java/brickbreaker/GamePanel.java @@ -31,7 +31,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener { public GamePanel() { this.balls.add(new Ball(350, 450, 1, -1, 20)); // Adjust the initial ball position and direction - this.balls.add(new Ball(380, 420, -1, 1, 20)); + this.balls.add(new Ball(380, 420, -1, 1, 50)); this.totalBricks = rows * columns; map = new GameMapBuilder(rows, columns); @@ -58,7 +58,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener { graphics.fillRect(691, 0, 3, 592); graphics.setColor(Color.blue); - graphics.fillRect(paddle, 550, 100, 12); + graphics.fillRect(paddle, 550, 100, 20); graphics.setColor(Color.RED); // ball color Iterator<Ball> ballsIterator = balls.iterator(); @@ -67,7 +67,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener { Ball ball = ballsIterator.next(); Vector ballPosition = ball.getPosition(); - if (ballPosition.y > 570) { + if (ballPosition.y > 560) { ballsIterator.remove(); continue; } else { @@ -75,7 +75,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener { } graphics.setColor(Color.RED); // ball color - graphics.fillOval(ballPosition.x, ballPosition.y, 20, 20); + graphics.fillOval(ballPosition.x, ballPosition.y, ball.radius, ball.radius); } graphics.setColor(Color.black); @@ -86,6 +86,10 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener { Color color = new Color(0XFF6464); gameOver(graphics, "You Won", color); } + + if (balls.isEmpty()) { + gameOver(graphics, "Game Over", Color.BLACK); + } } @@ -106,7 +110,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener { Vector ballPosition = ball.getPosition(); Vector ballDirection = ball.getDirection(); - if (new Rectangle(ballPosition.x, ballPosition.y, 20, 20).intersects(new Rectangle(paddle, 550, 100, 8))) { + if (new Rectangle(ballPosition.x, ballPosition.y, ball.radius, ball.radius).intersects(new Rectangle(paddle, 550, 100, 8))) { ballDirection.y = -ballDirection.y; ball.setDirection(ballDirection.x, ballDirection.y); } @@ -120,7 +124,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener { int brickHeight = map.brickHeight; Rectangle brickRect = new Rectangle(brickX, brickY, brickWidth, brickHeight); - Rectangle ballRect = new Rectangle(ballPosition.x, ballPosition.y, 20, 20); + Rectangle ballRect = new Rectangle(ballPosition.x, ballPosition.y, ball.radius, ball.radius); if (ballRect.intersects(brickRect)) {