diff --git a/src/Q5.java b/src/Q5.java index 2646c64fc0017d95e2d1956443c15231d3b5f92c..f9942f90ab1526f183e232c9546e4867d545c73b 100644 --- a/src/Q5.java +++ b/src/Q5.java @@ -43,6 +43,8 @@ public class Q5 extends AbstractGame { // see Ball.java private Ball ball = new Ball(); + // (b) When the player is within 20 pixels of the ball, the ball should move to another random position. + public static void main(String[] args) { new Q5().run(); } @@ -60,6 +62,11 @@ public class Q5 extends AbstractGame { playerY += STEP_SIZE * this.playerDirectionY; System.out.println(df.format(playerX) + "," + df.format(playerY)); } + + // (b) + if (new Point(playerX, playerY).distanceTo(ball.getPosition()) <= SCORE_DISTANCE) { + ball.resetPosition(); + } } playerImage.draw(playerX, playerY);