From 823ae066cab3cc1eb85d04e6ae7ae438850f060d Mon Sep 17 00:00:00 2001 From: Chaowen Zeng <chaowenz@student.unimelb.edu.au> Date: Sun, 16 May 2021 22:56:11 +1000 Subject: [PATCH] Update src/Player.java, src/Sandwich.java, src/Zombie.java files --- src/Player.java | 35 +++++++++++++++++++++++++++++++++++ src/Sandwich.java | 30 ++++++++++++++++++++++++++++++ src/Zombie.java | 30 ++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/Player.java create mode 100644 src/Sandwich.java create mode 100644 src/Zombie.java diff --git a/src/Player.java b/src/Player.java new file mode 100644 index 0000000..e75ce25 --- /dev/null +++ b/src/Player.java @@ -0,0 +1,35 @@ +import bagel.Image; +import bagel.util.Point; +/** + * a movable entity: player + */ +public class Player{ + /** + * the player's image displayed in the window + */ + private final Image image; + /** + * render position of the player in the window + */ + private Point pos; + /** + * Player's current energy value + */ + private int energy; + /** + * constructor + * @param x abscissa + * @param y ordinate + */ + public Player(double x, double y,int energy) { + this.image = new Image("res/images/player.png"); + this.pos = new Point(x,y); + this.energy = energy; + } + /** + * draw player on the background + */ + public void draw() { + image.drawFromTopLeft(pos.x, pos.y); + } +} diff --git a/src/Sandwich.java b/src/Sandwich.java new file mode 100644 index 0000000..fbcbf98 --- /dev/null +++ b/src/Sandwich.java @@ -0,0 +1,30 @@ +import bagel.Image; +import bagel.util.Point; +/** + * a stationary entity: sandwich + */ +public class Sandwich{ + /** + * the sandwich's image displayed in the window + */ + private Image image; + /** + * a Point object representing the position of the sandwich + */ + private Point pos; + /** + * constructor + * @param x abscissa + * @param y ordinate + */ + public Sandwich(double x, double y){ + this.image = new Image("res/images/sandwich.png"); + this.pos = new Point(x,y); + } + /** + * draw sandwich on the background + */ + public void draw() { + image.drawFromTopLeft(pos.x, pos.y); + } +} diff --git a/src/Zombie.java b/src/Zombie.java new file mode 100644 index 0000000..98dc3ce --- /dev/null +++ b/src/Zombie.java @@ -0,0 +1,30 @@ +import bagel.Image; +import bagel.util.Point; +/** + * a stationary entity: zombie + */ +public class Zombie{ + /** + * the zombie's image displayed in the window + */ + private Image image; + /** + * a Point object representing the position of the zombie + */ + private Point pos; + /** + * constructor + * @param x abscissa + * @param y ordinate + */ + public Zombie(double x, double y){ + this.image = new Image("res/images/zombie.png"); + this.pos = new Point(x,y); + } + /** + * draw zombie on the background + */ + public void draw() { + image.drawFromTopLeft(pos.x, pos.y); + } +} -- GitLab