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

finish Q4b

parent 8982a525
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,10 @@ public class Q4 extends AbstractGame { ...@@ -40,6 +40,10 @@ public class Q4 extends AbstractGame {
private double playerDirectionX = 0, private double playerDirectionX = 0,
playerDirectionY = 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 * 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 * @param Dest destination for the player to move to
...@@ -64,6 +68,9 @@ public class Q4 extends AbstractGame { ...@@ -64,6 +68,9 @@ public class Q4 extends AbstractGame {
if (input.wasPressed(Keys.ENTER)) { if (input.wasPressed(Keys.ENTER)) {
// (a) // (a)
this.setPlayerDirectionTo(BALL_POSITION); 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) { if (new Point(playerX, playerY).distanceTo(BALL_POSITION) <= SCORE_DISTANCE) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment