import bagel.DrawOptions; import bagel.Font; import bagel.Image; import bagel.util.Point; /** * Player Code for SWEN20003 Project 1, Semester 2, 2022 * <p> * Manage world info. * Manage player life. * Player move. * Draw player. * * @JIAXI3 */ public class Player { private final static Image FaceLeftImage = new Image("res/faeLeft.png"); private final static Image FaceRightImage = new Image("res/faeRight.png"); private static final int Life = 100; private static Image Img; private final Font LifeFont = new Font("res/frostbite.ttf", 30); private final DrawOptions LifeHighColor = new DrawOptions(); private final DrawOptions LifeMidColor = new DrawOptions(); private final DrawOptions LifeLowColor = new DrawOptions(); public int X = 0; public int Y = 0; public int WORLD_TOP = 0; public int WORLD_LEFT = 0; public int WORLD_BOTTOM = 0; public int WORLD_RIGHT = 0; public Player() { /*Init player image*/ Img = FaceRightImage; /*Init life color*/ LifeHighColor.setBlendColour(0, 0.8, 0.2); LifeMidColor.setBlendColour(0.9, 0.6, 0); LifeLowColor.setBlendColour(1, 0, 0); } public Point GetPos() { return new Point(X, Y); } public void MoveUp() { /*Player moves up in world, step = 2*/ if (Y > (WORLD_TOP + 2)) { Y -= 2; } } public void MoveDown() { /*Player moves down in world, step = 2*/ if (Y < (WORLD_BOTTOM - 2)) { Y += 2; } } public void MoveLeft() { /*Player moves left in world, step = 2*/ if (X > (WORLD_LEFT + 2)) { X -= 2; } } public void MoveRight() { /*Player moves right in world, step = 2*/ if (X < (WORLD_RIGHT - 2)) { X += 2; } } public void Update() { /*Show play image*/ Img.drawFromTopLeft(X, Y); /*Show life text*/ if (Life >= 65) { LifeFont.drawString(Life + "%", 20, 25, LifeHighColor); } else if (Life >= 35) { LifeFont.drawString(Life + "%", 20, 25, LifeMidColor); } else { LifeFont.drawString(Life + "%", 20, 25, LifeLowColor); } } public void ToLeft() { /*Changing user orientation to left*/ Img = FaceLeftImage; } public void ToRight() { /*Changing user orientation to right*/ Img = FaceRightImage; } }