diff --git a/src/Q5.java b/src/Q5.java index f9942f90ab1526f183e232c9546e4867d545c73b..bee9bc69913e387ac0775a8b8457b19ae3442f3b 100644 --- a/src/Q5.java +++ b/src/Q5.java @@ -45,6 +45,10 @@ public class Q5 extends AbstractGame { // (b) When the player is within 20 pixels of the ball, the ball should move to another random position. + // (c) Keep track of the player's score, which starts at 0 and increases by 1 every time the player catches + // the ball. Draw this score (using Font) at the top-left of the window. + private int score = 0; + public static void main(String[] args) { new Q5().run(); } @@ -66,7 +70,12 @@ public class Q5 extends AbstractGame { // (b) if (new Point(playerX, playerY).distanceTo(ball.getPosition()) <= SCORE_DISTANCE) { ball.resetPosition(); + + // (c) + score++; } + // (c) + font.drawString("Score: " + score, FONT_POSITION.x, FONT_POSITION.y); } playerImage.draw(playerX, playerY);