From 0856194abd0b708ecd07785d7ccca62e02b797c3 Mon Sep 17 00:00:00 2001
From: yangxvlin <1768528843@qq.com>
Date: Wed, 31 Mar 2021 22:51:05 +1100
Subject: [PATCH] finish Q3b

---
 src/Q3.java | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/Q3.java b/src/Q3.java
index 9db0cbd..3fac7aa 100644
--- a/src/Q3.java
+++ b/src/Q3.java
@@ -22,13 +22,35 @@ public class Q3 extends AbstractGame {
     private final Image playerImage = new Image(PLAYER_IMAGE);
     private final Image ballImage = new Image(BALL_IMAGE);
 
+    // (b) The player should be able to move left, right, up, and down, using the respective arrow keys at a
+    //constant step size (in pixels per frame). Try different values for the step size (a constant named as
+    //STEP SIZE), starting at 1.
+    private static final double STEP_SIZE = 1;
+
+    private double playerX = PLAYER_POSITION.x;
+    private double playerY = PLAYER_POSITION.y;
+
     public static void main(String[] args) {
         new Q3().run();
     }
 
     @Override
     protected void update(Input input) {
-        playerImage.draw(PLAYER_POSITION.x, PLAYER_POSITION.y);
+        // (b)
+        if (input.isDown(Keys.LEFT)) {
+            playerX -= STEP_SIZE;
+        }
+        if (input.isDown(Keys.RIGHT)) {
+            playerX += STEP_SIZE;
+        }
+        if (input.isDown(Keys.UP)) {
+            playerY -= STEP_SIZE;
+        }
+        if (input.isDown(Keys.DOWN)) {
+            playerY += STEP_SIZE;
+        }
+
+        playerImage.draw(playerX, playerY);
         ballImage.draw(BALL_POSITION.x, BALL_POSITION.y);
     }
 }
-- 
GitLab