From b9c755319d4a2eda9b6cf07d72f99fe516c45e16 Mon Sep 17 00:00:00 2001
From: yangxvlin <1768528843@qq.com>
Date: Wed, 31 Mar 2021 22:55:17 +1100
Subject: [PATCH] copy from Q3

---
 src/Q4.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 src/Q4.java

diff --git a/src/Q4.java b/src/Q4.java
new file mode 100644
index 0000000..bf68e52
--- /dev/null
+++ b/src/Q4.java
@@ -0,0 +1,50 @@
+import bagel.*;
+import bagel.util.Point;
+
+/**
+ * Xulin Yang, 904904
+ *
+ * @create 2021-03-31 22:53
+ * description:
+ **/
+
+public class Q4 extends AbstractGame {
+    private static final String PLAYER_IMAGE = "res/player.png";
+    private static final String BALL_IMAGE = "res/ball.png";
+    private static final Point PLAYER_POSITION = new Point(200, 350);
+    private static final Point BALL_POSITION = new Point(650, 180);
+
+    private final Image playerImage = new Image(PLAYER_IMAGE);
+    private final Image ballImage = new Image(BALL_IMAGE);
+
+    private static final double STEP_SIZE = 2;
+
+    private double playerX = 10; // PLAYER_POSITION.x;
+    private double playerY = PLAYER_POSITION.y;
+
+    private static final double SCORE_DISTANCE = 20;
+
+    private final Font font = new Font("res/conformable.otf", 24);
+    private static final Point FONT_POSITION = new Point(32, 32);
+
+
+    public static void main(String[] args) {
+        new Q4().run();
+    }
+
+    @Override
+    protected void update(Input input) {
+        if (input.wasPressed(Keys.ESCAPE)) {
+            System.out.println("closed");
+            Window.close();
+        }
+
+        if (new Point(playerX, playerY).distanceTo(BALL_POSITION) <= SCORE_DISTANCE) {
+            // System.out.println("Great job!");
+            font.drawString("Great job!", FONT_POSITION.x, FONT_POSITION.y);
+        }
+
+        playerImage.draw(playerX, playerY);
+        ballImage.draw(BALL_POSITION.x, BALL_POSITION.y);
+    }
+}
-- 
GitLab