diff --git a/bagel.iml b/bagel.iml deleted file mode 100644 index 1d041d2ad70f907af5c709c8f6702db639b211c5..0000000000000000000000000000000000000000 --- a/bagel.iml +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_14"> - <output url="file://$MODULE_DIR$/target/classes" /> - <output-test url="file://$MODULE_DIR$/target/test-classes" /> - <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> - <excludeFolder url="file://$MODULE_DIR$/target" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - <orderEntry type="library" name="Maven: io.github.eleanor-em:bagel:1.9.3" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-assimp:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-glfw:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-openal:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-opengl:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-stb:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl:natives-macos:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-assimp:natives-macos:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-glfw:natives-macos:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-openal:natives-macos:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-opengl:natives-macos:3.2.2" level="project" /> - <orderEntry type="library" name="Maven: org.lwjgl:lwjgl-stb:natives-macos:3.2.2" level="project" /> - </component> -</module> \ No newline at end of file diff --git a/src/Background.java b/src/Background.java index 4d46fee0a7cd7c7695f5ee1520a14ad0a79edaef..e28637bddf6eb5767ed5495dd0ae73821dc3e67f 100644 --- a/src/Background.java +++ b/src/Background.java @@ -7,6 +7,7 @@ public class Background{ this.image = new Image(image); } + // to draw the background of game public void drawBackground(){ image.drawFromTopLeft(0,0); } diff --git a/src/Entity.java b/src/Entity.java index 200dd1f7bf749dcf400ef77e9e799d36f3d42260..c74ef037d676a2d5050be60996e27608af1d5d03 100644 --- a/src/Entity.java +++ b/src/Entity.java @@ -7,32 +7,35 @@ public class Entity { private double PositionY; private final Image image; + // set up entity public Entity(double PositionX, double PositionY, String image ){ this.image = new Image(image); this.PositionX = PositionX; this.PositionY = PositionY; }; + // to draw the entity in game public void drawEntity(){ this.image.draw(this.getPositionX(), this.getPositionY()); } + // get position public double getPositionX(){ return this.PositionX; } - public double getPositionY(){ return this.PositionY; } + // set up position public void setPositionX(double x){ this.PositionX = x; } - public void setPositionY(double y){ this.PositionY = y; } + // calculate the distance between two entity public double distanceFrom(Entity ohterEntity){ double dx = this.getPositionX() - ohterEntity.getPositionX(); double dy = this.getPositionY() - ohterEntity.getPositionY(); diff --git a/src/Player.java b/src/Player.java index 7eaaf477bd062765d8904c81e33f8bcfbc1f771d..8c0d83caeac3af7ed5f7ddcd71fbc238cfe15338 100644 --- a/src/Player.java +++ b/src/Player.java @@ -1,22 +1,24 @@ public class Player extends Entity { private int energyLevel; - private static final int stepSize = 10; - + // set up the player public Player(double PositionX, double PositionY, String image, int energyLevel) { super(PositionX, PositionY, image); this.energyLevel = energyLevel; } + // get energy level from player public int getEnergyLevel() { return this.energyLevel; } + // set energy level public void setEnergyLevel(int energyLeve){ this.energyLevel = energyLeve; } + // check meet to other entity public boolean meet(Entity entity){ if(this.distanceFrom(entity) < 50){ return true; @@ -24,6 +26,7 @@ public class Player extends Entity { return false; } + // move to other entity public void moveTo(Entity entity){ double xd = (entity.getPositionX() - this.getPositionX())/this.distanceFrom(entity); double yd = (entity.getPositionY() - this.getPositionY())/this.distanceFrom(entity); diff --git a/src/ShadowTreasure.java b/src/ShadowTreasure.java index 49d585910dac11aac04dc9fed6fda5327e6e879a..7c76be22ae4a3396b6b580ebe740ec273a33a367 100755 --- a/src/ShadowTreasure.java +++ b/src/ShadowTreasure.java @@ -16,7 +16,7 @@ public class ShadowTreasure extends AbstractGame { private static DecimalFormat df = new DecimalFormat("0.00"); - // + // Set up the attributes for game private Player player; private Zambie zambie; private Sandwich sandwich; @@ -42,20 +42,16 @@ public class ShadowTreasure extends AbstractGame { try(BufferedReader file = new BufferedReader(new FileReader(filename))){ String[] newLine = file.readLine().split(","); + //read each row from file and set up the entities and background this.player = new Player(Double.parseDouble(newLine[1]),Double.parseDouble(newLine[2]), "res/images/player.png", Integer.parseInt(newLine[3])); - newLine = file.readLine().split(","); - this.zambie = new Zambie(Double.parseDouble(newLine[1]),Double.parseDouble(newLine[2]), "res/images/zombie.png"); - newLine = file.readLine().split(","); - this.sandwich = new Sandwich(Double.parseDouble(newLine[1]),Double.parseDouble(newLine[2]), "res/images/sandwich.png"); - this.background = new Background("res/images/background.png"); - this.font = new Font( "res/font/DejaVuSans-Bold.ttf",20); + // draw the attributes and energy level this.background.drawBackground(); this.player.drawEntity(); this.zambie.drawEntity(); @@ -74,6 +70,8 @@ public class ShadowTreasure extends AbstractGame { @Override public void update(Input input) { // Logic to update the game, as per specification must go here + + // draw the attributes and energy level this.background.drawBackground(); this.player.drawEntity(); this.zambie.drawEntity(); @@ -82,6 +80,7 @@ public class ShadowTreasure extends AbstractGame { } this.font.drawString("energy:" + this.player.getEnergyLevel(), 20, 760); + // follow the interaction logic and update energy in each tick, than output the location and energy level if( this.countFrame == 10){ if( this.player.meet(this.zambie)){ this.player.setEnergyLevel(this.player.getEnergyLevel() - 3); @@ -94,13 +93,11 @@ public class ShadowTreasure extends AbstractGame { }else{ printInfo(this.player.getPositionX(), this.player.getPositionY(), this.player.getEnergyLevel()); } - if( this.player.getEnergyLevel() >= 3){ this.player.moveTo(this.zambie); }else{ this.player.moveTo(this.sandwich); } - this.countFrame = 0; } this.countFrame += 1;