Création classe créature

main
ZIRTR0X 3 years ago
parent 22ae223909
commit ae409399cf

1
.gitignore vendored

@ -22,3 +22,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
code/out/

@ -9,7 +9,6 @@ import model.Case;
import model.Map; import model.Map;
public class MapController implements Initializable { public class MapController implements Initializable {
private final Map map = new Map(32,30); private final Map map = new Map(32,30);
private final Image b = new Image("/image/terrain/chemin.png"); private final Image b = new Image("/image/terrain/chemin.png");
private final Image a = new Image("/image/terrain/herbe.png"); private final Image a = new Image("/image/terrain/herbe.png");

@ -0,0 +1,39 @@
package model;
public class Creature {
int idCreature;
String image;
int coordX;
int coordY;
public Creature(int idCreature, String image, int coordX, int coordY) {
this.idCreature = idCreature;
this.image = image;
this.coordX = coordX;
this.coordY = coordY;
}
public int getIdCreature() {
return idCreature;
}
public String getImage() {
return image;
}
public int getCoordX() {
return coordX;
}
public int getCoordY() {
return coordY;
}
public void setCoordX(int coordX) {
this.coordX = coordX;
}
public void setCoordY(int coordY) {
this.coordY = coordY;
}
}

@ -4,33 +4,36 @@ public class GameLoop {
private Thread timer; private Thread timer;
public void start() { public void start() {
System.out.println("GameLoop.start()");
timer = new Thread("timer") { timer = new Thread("timer") {
public void run() { public void run() {
final double FPS = 60; int nbMinutes = 1;
final double DELAY = 1000000000 / FPS; int i = 0;
long lastTime = System.nanoTime(); while(true) {
long timer = 0; if(i == 0) {
double delta = 0; //action
long currentTime; System.out.println("Timer = " + i);
int frames = 0; i = 10 * nbMinutes;
while (true) { try {
currentTime = System.nanoTime(); timer.sleep(1000);
delta += (currentTime - lastTime) / DELAY; } catch (InterruptedException e) {
timer += currentTime - lastTime; e.printStackTrace();
lastTime = currentTime; }
if (delta >= 1) { }else{
//update(); // fonction qui sera update System.out.println("Timer = " + i);
i--;
frames++; try {
delta--; timer.sleep(1000);
} } catch (InterruptedException e) {
if (timer >= 1000000000) { e.printStackTrace();
timer = 0; }
System.out.println("FPS: " + frames);
frames = 0;
} }
} }
} }
}; };
timer.start();
} }
} }

@ -6,30 +6,27 @@ public class Time {
public void start() { public void start() {
timer = new Thread("timer") { timer = new Thread("timer") {
public void run() { public void run() {
final double FPS = 60; int nbMinutes = 1;
final double DELAY = 1000000000 / FPS; int i = 0;
long lastTime = System.nanoTime(); while(true) {
long timer = 0; if(i == 0) {
double delta = 0; //action
long currentTime; System.out.println("Timer = " + i);
int frames = 0; i = 60 * nbMinutes;
while (true) { }else{
currentTime = System.nanoTime(); System.out.println("Timer = " + i);
delta += (currentTime - lastTime) / DELAY; i--;
timer += currentTime - lastTime; try {
lastTime = currentTime; timer.sleep(1000);
if (delta >= 1) { } catch (InterruptedException e) {
//update(); // fonction qui sera update e.printStackTrace();
frames++; }
delta--;
}
if (timer >= 1000000000) {
timer = 0;
System.out.println("FPS: " + frames);
frames = 0;
} }
} }
} }
}; };
} }

Loading…
Cancel
Save