Skip to content
Snippets Groups Projects
Commit 8b11a552 authored by Yixin Cai's avatar Yixin Cai
Browse files

Initial commit

parent 1bcf9fe5
No related branches found
No related tags found
No related merge requests found
<?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
......@@ -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);
}
......
......@@ -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();
......
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);
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment