From ff9bafece42c853832ddef73abb30c0f284a3628 Mon Sep 17 00:00:00 2001 From: yangxvlin <1768528843@qq.com> Date: Wed, 31 Mar 2021 22:58:27 +1100 Subject: [PATCH] finish Q4b --- src/Q4.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Q4.java b/src/Q4.java index a55c0be..d188375 100644 --- a/src/Q4.java +++ b/src/Q4.java @@ -40,6 +40,10 @@ public class Q4 extends AbstractGame { private double playerDirectionX = 0, playerDirectionY = 0; + // (b) Moving in direction (xd; yd) by one step: + // add STEP_SIZE * xd to x1; + // add STEP_SIZE * yd to y1; + /** * calculate the direction for the player based on the input point w.r.t. player's location * @param Dest destination for the player to move to @@ -64,6 +68,9 @@ public class Q4 extends AbstractGame { if (input.wasPressed(Keys.ENTER)) { // (a) this.setPlayerDirectionTo(BALL_POSITION); + // (b) + playerX += STEP_SIZE * this.playerDirectionX; + playerY += STEP_SIZE * this.playerDirectionY; } if (new Point(playerX, playerY).distanceTo(BALL_POSITION) <= SCORE_DISTANCE) { -- GitLab