Skip to content
Snippets Groups Projects
Commit 1d0708a2 authored by yangxvlin's avatar yangxvlin
Browse files

finish Q5b

parent 829119be
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment