diff --git a/src/Q3.java b/src/Q3.java index 3fac7aa49ae91039292520cec22e918549ac879d..1b94540981d53919f97171a4c18979a99acc0ba4 100644 --- a/src/Q3.java +++ b/src/Q3.java @@ -30,6 +30,11 @@ public class Q3 extends AbstractGame { private double playerX = PLAYER_POSITION.x; private double playerY = PLAYER_POSITION.y; + // (c) If the player comes within 20 pixels of the ball, we say the player catches the ball and you should + // print to the console "Great job!". Remember, the Euclidean distance between points (x1; y1) and + // (x2; y2) is given by: d_12 = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)) + private static final double SCORE_DISTANCE = 20; + public static void main(String[] args) { new Q3().run(); } @@ -50,6 +55,11 @@ public class Q3 extends AbstractGame { playerY += STEP_SIZE; } + // (d) + if (new Point(playerX, playerY).distanceTo(BALL_POSITION) <= SCORE_DISTANCE) { + System.out.println("Great job!"); + } + playerImage.draw(playerX, playerY); ballImage.draw(BALL_POSITION.x, BALL_POSITION.y); }