diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..27c5aa3ec32d5edf70e0edc6d077aeffe5f64816 Binary files /dev/null and b/.DS_Store differ diff --git a/bagel.iml b/bagel.iml new file mode 100644 index 0000000000000000000000000000000000000000..1d041d2ad70f907af5c709c8f6702db639b211c5 --- /dev/null +++ b/bagel.iml @@ -0,0 +1,26 @@ +<?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/pom.xml b/pom.xml new file mode 100755 index 0000000000000000000000000000000000000000..c51fbeb6edb5f5974c1fb74356f6ef57a90b4965 --- /dev/null +++ b/pom.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>au.edu.unimelb.cis</groupId> + <artifactId>bagel</artifactId> + <version>0.1-SNAPSHOT</version> + <packaging>jar</packaging> + + <build> + <sourceDirectory>src/</sourceDirectory> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>14</source> + <target>14</target> + </configuration> + </plugin> + </plugins> + </build> + + <properties> + <maven.compiler.source>14</maven.compiler.source> + <maven.compiler.target>14</maven.compiler.target> + </properties> + + <dependencies> + <dependency> + <groupId>io.github.eleanor-em</groupId> + <artifactId>bagel</artifactId> + <version>1.9.3</version> + </dependency> + </dependencies> +</project> diff --git a/res/.DS_Store b/res/.DS_Store new file mode 100755 index 0000000000000000000000000000000000000000..65708cf219869fe648620ae045d86560a1e625a5 Binary files /dev/null and b/res/.DS_Store differ diff --git a/res/IO/.DS_Store b/res/IO/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/res/IO/.DS_Store differ diff --git a/res/IO/environment.csv b/res/IO/environment.csv new file mode 100755 index 0000000000000000000000000000000000000000..34433464a67b782b64b56ef3d04904a00c63c7ab --- /dev/null +++ b/res/IO/environment.csv @@ -0,0 +1,3 @@ +Player,650,100,2 +Zombie,300,200 +Sandwich,500,400 \ No newline at end of file diff --git a/res/font/DejaVuSans-Bold.ttf b/res/font/DejaVuSans-Bold.ttf new file mode 100755 index 0000000000000000000000000000000000000000..c0d8e5e462df7f268efba09f6931e37daad151e1 Binary files /dev/null and b/res/font/DejaVuSans-Bold.ttf differ diff --git a/res/images/background.png b/res/images/background.png new file mode 100755 index 0000000000000000000000000000000000000000..a6601996a24eebf1b568ad8e05d2e137a030b52e Binary files /dev/null and b/res/images/background.png differ diff --git a/res/images/player.png b/res/images/player.png new file mode 100755 index 0000000000000000000000000000000000000000..103a2ff1c64ccd5bf18b9ef8b2ca444dbdf204d1 Binary files /dev/null and b/res/images/player.png differ diff --git a/res/images/sandwich.png b/res/images/sandwich.png new file mode 100755 index 0000000000000000000000000000000000000000..87e12ec3db6704914262fd359822407fb9ecd172 Binary files /dev/null and b/res/images/sandwich.png differ diff --git a/res/images/zombie.png b/res/images/zombie.png new file mode 100755 index 0000000000000000000000000000000000000000..41519c41828d76f5cdfbd9493025d3867347d926 Binary files /dev/null and b/res/images/zombie.png differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100755 index 0000000000000000000000000000000000000000..24957dce42144cc115095b85bb08b4dcbdca5642 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/Background.java b/src/Background.java new file mode 100644 index 0000000000000000000000000000000000000000..4d46fee0a7cd7c7695f5ee1520a14ad0a79edaef --- /dev/null +++ b/src/Background.java @@ -0,0 +1,13 @@ +import bagel.*; + +public class Background{ + Image image; + + public Background(String image) { + this.image = new Image(image); + } + + public void drawBackground(){ + image.drawFromTopLeft(0,0); + } +} \ No newline at end of file diff --git a/src/Entity.java b/src/Entity.java new file mode 100644 index 0000000000000000000000000000000000000000..200dd1f7bf749dcf400ef77e9e799d36f3d42260 --- /dev/null +++ b/src/Entity.java @@ -0,0 +1,43 @@ +import bagel.*; +import java.lang.Math; +import java.security.PrivateKey; + +public class Entity { + private double PositionX; + private double PositionY; + private final Image image; + + public Entity(double PositionX, double PositionY, String image ){ + this.image = new Image(image); + this.PositionX = PositionX; + this.PositionY = PositionY; + }; + + public void drawEntity(){ + this.image.draw(this.getPositionX(), this.getPositionY()); + } + + public double getPositionX(){ + return this.PositionX; + } + + public double getPositionY(){ + return this.PositionY; + } + + public void setPositionX(double x){ + this.PositionX = x; + } + + public void setPositionY(double y){ + this.PositionY = y; + } + + public double distanceFrom(Entity ohterEntity){ + double dx = this.getPositionX() - ohterEntity.getPositionX(); + double dy = this.getPositionY() - ohterEntity.getPositionY(); + return Math.sqrt(dx*dx + dy*dy); + } + + +} diff --git a/src/Player.java b/src/Player.java new file mode 100644 index 0000000000000000000000000000000000000000..7eaaf477bd062765d8904c81e33f8bcfbc1f771d --- /dev/null +++ b/src/Player.java @@ -0,0 +1,34 @@ +public class Player extends Entity { + private int energyLevel; + + private static final int stepSize = 10; + + + public Player(double PositionX, double PositionY, String image, int energyLevel) { + super(PositionX, PositionY, image); + this.energyLevel = energyLevel; + } + + public int getEnergyLevel() { + return this.energyLevel; + } + + public void setEnergyLevel(int energyLeve){ + this.energyLevel = energyLeve; + } + + public boolean meet(Entity entity){ + if(this.distanceFrom(entity) < 50){ + return true; + } + return false; + } + + public void moveTo(Entity entity){ + double xd = (entity.getPositionX() - this.getPositionX())/this.distanceFrom(entity); + double yd = (entity.getPositionY() - this.getPositionY())/this.distanceFrom(entity); + + this.setPositionX(this.getPositionX() + xd*this.stepSize); + this.setPositionY(this.getPositionY() + yd*this.stepSize); + } +} diff --git a/src/Sandwich.java b/src/Sandwich.java new file mode 100644 index 0000000000000000000000000000000000000000..fcb05ec74f106f088a9c29d92a5bf2d56cf09a49 --- /dev/null +++ b/src/Sandwich.java @@ -0,0 +1,5 @@ +public class Sandwich extends Entity { + public Sandwich(double PositionX, double PositionY, String image) { + super(PositionX, PositionY, image); + } +} diff --git a/src/ShadowTreasure.java b/src/ShadowTreasure.java new file mode 100755 index 0000000000000000000000000000000000000000..49d585910dac11aac04dc9fed6fda5327e6e879a --- /dev/null +++ b/src/ShadowTreasure.java @@ -0,0 +1,118 @@ +import bagel.*; +import org.lwjgl.system.CallbackI; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.text.DecimalFormat; + + +/** + * An example Bagel game. + */ +public class ShadowTreasure extends AbstractGame { + + // for rounding double number; use this to print the location of the player + private static DecimalFormat df = new DecimalFormat("0.00"); + + + // + private Player player; + private Zambie zambie; + private Sandwich sandwich; + private Background background; + private int countFrame = 0; + private Font font; + + public static void printInfo(double x, double y, int e) { + System.out.println(df.format(x) + "," + df.format(y) + "," + e); + } + + public ShadowTreasure() throws IOException { + + this.loadEnvironment("test/test2/environment.csv"); + // Add code to initialize other attributes as needed + } + + /** + * Load from input file + */ + private void loadEnvironment(String filename){ + // Code here to read from the file and set up the environment + try(BufferedReader file = new BufferedReader(new FileReader(filename))){ + String[] newLine = file.readLine().split(","); + + 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); + + this.background.drawBackground(); + this.player.drawEntity(); + this.zambie.drawEntity(); + this.sandwich.drawEntity(); + this.font.drawString("energy:" + player.getEnergyLevel(), 20, 760); + + }catch(IOException e){ + e.printStackTrace(); + } + + } + + /** + * Performs a state update. + */ + @Override + public void update(Input input) { + // Logic to update the game, as per specification must go here + this.background.drawBackground(); + this.player.drawEntity(); + this.zambie.drawEntity(); + if(this.sandwich != null) { + this.sandwich.drawEntity(); + } + this.font.drawString("energy:" + this.player.getEnergyLevel(), 20, 760); + + if( this.countFrame == 10){ + if( this.player.meet(this.zambie)){ + this.player.setEnergyLevel(this.player.getEnergyLevel() - 3); + printInfo(this.player.getPositionX(), this.player.getPositionY(), this.player.getEnergyLevel()); + System.exit(0); + }else if(this.sandwich != null && this.player.meet(this.sandwich)){ + this.player.setEnergyLevel(this.player.getEnergyLevel() + 5); + printInfo(this.player.getPositionX(), this.player.getPositionY(), this.player.getEnergyLevel()); + this.sandwich = null; + }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; + } + + + /** + * The entry point for the program. + */ + public static void main(String[] args) throws IOException { + + ShadowTreasure game = new ShadowTreasure(); + game.run(); + } +} diff --git a/src/Zambie.java b/src/Zambie.java new file mode 100644 index 0000000000000000000000000000000000000000..acd2c5e75b216f8ad31cecf68a68bab84bd80c61 --- /dev/null +++ b/src/Zambie.java @@ -0,0 +1,6 @@ +public class Zambie extends Entity { + public Zambie(double PositionX, double PositionY, String image) { + super(PositionX, PositionY, image); + } + +} diff --git a/target/.DS_Store b/target/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..daa3c980a9253b52a4f9f3e6d72ff3d39475d129 Binary files /dev/null and b/target/.DS_Store differ diff --git a/target/bagel-0.1-SNAPSHOT.jar b/target/bagel-0.1-SNAPSHOT.jar new file mode 100755 index 0000000000000000000000000000000000000000..7971ca9e1c1ad59e287794ee370250934dd0f6ec Binary files /dev/null and b/target/bagel-0.1-SNAPSHOT.jar differ diff --git a/target/classes/Background.class b/target/classes/Background.class new file mode 100644 index 0000000000000000000000000000000000000000..cc202651e5f172d28530858fab6434003dae04b0 Binary files /dev/null and b/target/classes/Background.class differ diff --git a/target/classes/Entity.class b/target/classes/Entity.class new file mode 100644 index 0000000000000000000000000000000000000000..0593a96e3f682768673d7483d4405b0a94ee700d Binary files /dev/null and b/target/classes/Entity.class differ diff --git a/target/classes/Player.class b/target/classes/Player.class new file mode 100644 index 0000000000000000000000000000000000000000..b78f0708ae93a3a7284e2163fc0811647d19ff1c Binary files /dev/null and b/target/classes/Player.class differ diff --git a/target/classes/Sandwich.class b/target/classes/Sandwich.class new file mode 100644 index 0000000000000000000000000000000000000000..f964c0920a1e9bc0714924ef29c1d82c546cecab Binary files /dev/null and b/target/classes/Sandwich.class differ diff --git a/target/classes/ShadowTreasure.class b/target/classes/ShadowTreasure.class new file mode 100644 index 0000000000000000000000000000000000000000..96aa8e62c8adb17c79a59856cf8752099af8acfd Binary files /dev/null and b/target/classes/ShadowTreasure.class differ diff --git a/target/classes/Zambie.class b/target/classes/Zambie.class new file mode 100644 index 0000000000000000000000000000000000000000..b7081f98a57fdaa606c8297188f9bb77d95c30cf Binary files /dev/null and b/target/classes/Zambie.class differ diff --git a/target/generated-sources/.DS_Store b/target/generated-sources/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4c6e644aff5d4f04fdfface9cc0755dfec577280 Binary files /dev/null and b/target/generated-sources/.DS_Store differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100755 index 0000000000000000000000000000000000000000..f50533bad05a26dbc0891a8c413e57c7bfd9d17d --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Thu Mar 18 12:46:42 AEDT 2021 +groupId=au.edu.unimelb.cis +artifactId=bagel +version=0.1-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100755 index 0000000000000000000000000000000000000000..253ae07e82b3e0fff072cc239eba9ee9d4c51140 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,5 @@ +ShadowTreasure.class +Zombie.class +Sandwich.class +Record.class +Player.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100755 index 0000000000000000000000000000000000000000..cde17032e59ef7d58ce0e5e35b62db883326bf25 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,5 @@ +/Users/nid1/Desktop/ShadowTreasure/project1/src/Zombie.java +/Users/nid1/Desktop/ShadowTreasure/project1/src/Sandwich.java +/Users/nid1/Desktop/ShadowTreasure/project1/src/Record.java +/Users/nid1/Desktop/ShadowTreasure/project1/src/ShadowTreasure.java +/Users/nid1/Desktop/ShadowTreasure/project1/src/Player.java diff --git a/test/.DS_Store b/test/.DS_Store new file mode 100755 index 0000000000000000000000000000000000000000..a5bf6284b2fb01b340101d164e5d2d6afa263d49 Binary files /dev/null and b/test/.DS_Store differ diff --git a/test/test1/environment.csv b/test/test1/environment.csv new file mode 100755 index 0000000000000000000000000000000000000000..34433464a67b782b64b56ef3d04904a00c63c7ab --- /dev/null +++ b/test/test1/environment.csv @@ -0,0 +1,3 @@ +Player,650,100,2 +Zombie,300,200 +Sandwich,500,400 \ No newline at end of file diff --git a/test/test1/output.csv b/test/test1/output.csv new file mode 100644 index 0000000000000000000000000000000000000000..331f2949d096b29343572835ee807a617e1e88de --- /dev/null +++ b/test/test1/output.csv @@ -0,0 +1,53 @@ +650.00,100.00,2 +645.53,108.94,2 +641.06,117.89,2 +636.58,126.83,2 +632.11,135.78,2 +627.64,144.72,2 +623.17,153.67,2 +618.70,162.61,2 +614.22,171.55,2 +609.75,180.50,2 +605.28,189.44,2 +600.81,198.39,2 +596.33,207.33,2 +591.86,216.28,2 +587.39,225.22,2 +582.92,234.16,2 +578.45,243.11,2 +573.97,252.05,2 +569.50,261.00,2 +565.03,269.94,2 +560.56,278.89,2 +556.09,287.83,2 +551.61,296.77,2 +547.14,305.72,2 +542.67,314.66,2 +538.20,323.61,2 +533.72,332.55,2 +529.25,341.50,2 +524.78,350.44,2 +520.31,359.38,7 +512.21,353.52,7 +504.10,347.66,7 +496.00,341.80,7 +487.90,335.94,7 +479.80,330.08,7 +471.70,324.21,7 +463.59,318.35,7 +455.49,312.49,7 +447.39,306.63,7 +439.29,300.77,7 +431.19,294.91,7 +423.08,289.05,7 +414.98,283.18,7 +406.88,277.32,7 +398.78,271.46,7 +390.68,265.60,7 +382.57,259.74,7 +374.47,253.88,7 +366.37,248.02,7 +358.27,242.15,7 +350.17,236.29,7 +342.06,230.43,7 +333.96,224.57,4 diff --git a/test/test2/environment.csv b/test/test2/environment.csv new file mode 100755 index 0000000000000000000000000000000000000000..52b5d638b191e77b95ccbbf9c9e6d430333dd896 --- /dev/null +++ b/test/test2/environment.csv @@ -0,0 +1,3 @@ +Player,650,100,3 +Zombie,500,500 +Sandwich,300,200 \ No newline at end of file diff --git a/test/test2/output.csv b/test/test2/output.csv new file mode 100644 index 0000000000000000000000000000000000000000..85bdc5c3a6f2228b4c3a76410bbe6a043b63634e --- /dev/null +++ b/test/test2/output.csv @@ -0,0 +1,39 @@ +650.00,100.00,3 +646.49,109.36,3 +642.98,118.73,3 +639.47,128.09,3 +635.96,137.45,3 +632.44,146.82,3 +628.93,156.18,3 +625.42,165.54,3 +621.91,174.91,3 +618.40,184.27,3 +614.89,193.63,3 +611.38,203.00,3 +607.87,212.36,3 +604.35,221.72,3 +600.84,231.09,3 +597.33,240.45,3 +593.82,249.81,3 +590.31,259.18,3 +586.80,268.54,3 +583.29,277.90,3 +579.78,287.27,3 +576.26,296.63,3 +572.75,305.99,3 +569.24,315.36,3 +565.73,324.72,3 +562.22,334.08,3 +558.71,343.45,3 +555.20,352.81,3 +551.69,362.17,3 +548.17,371.54,3 +544.66,380.90,3 +541.15,390.26,3 +537.64,399.63,3 +534.13,408.99,3 +530.62,418.35,3 +527.11,427.72,3 +523.60,437.08,3 +520.08,446.44,3 +516.57,455.81,0