From 5aafeda1108147ad8cfbd6dbdaabd82651092a3a Mon Sep 17 00:00:00 2001 From: yangxvlin <1768528843@qq.com> Date: Wed, 31 Mar 2021 23:01:17 +1100 Subject: [PATCH] copy from Q4 --- src/Q5.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/Q5.java diff --git a/src/Q5.java b/src/Q5.java new file mode 100644 index 0000000..da17687 --- /dev/null +++ b/src/Q5.java @@ -0,0 +1,57 @@ +import bagel.*; +import bagel.util.Point; + +import java.text.DecimalFormat; + +/** + * Xulin Yang, 904904 + * + * @create 2021-03-31 22:59 + * description: + **/ + +public class Q5 extends AbstractGame { + private static final String PLAYER_IMAGE = "res/player.png"; + + private static final Point PLAYER_POSITION = new Point(200, 350); + + private final Image playerImage = new Image(PLAYER_IMAGE); + + private static final double STEP_SIZE = 20; + + 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); + + private static DecimalFormat df = new DecimalFormat("0.00"); + + private double playerDirectionX = 0, + playerDirectionY = 0; + public void setPlayerDirectionTo(Point Dest){ + double Len = new Point(playerX, playerY).distanceTo(Dest); + playerDirectionX = (Dest.x - playerX)/Len; + playerDirectionY = (Dest.y - playerY)/Len; + } + + public static void main(String[] args) { + new Q5().run(); + } + + @Override + protected void update(Input input) { + if (input.wasPressed(Keys.ESCAPE)) { + System.out.println("closed"); + Window.close(); + } else { + if (input.wasPressed(Keys.ENTER)) { + + } + } + + playerImage.draw(playerX, playerY); + } +} -- GitLab