From ae409399cfbc4f2ac20c3cde59d19aa80da14c14 Mon Sep 17 00:00:00 2001 From: ZIRTR0X <76250995+ZIRTR0X@users.noreply.github.com> Date: Mon, 17 Jan 2022 23:03:16 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20classe=20cr=C3=A9ature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + code/src/controller/MapController.java | 1 - code/src/model/Creature.java | 39 +++++++++++++++++++++ code/src/model/GameLoop.java | 47 ++++++++++++++------------ code/src/model/Time.java | 39 ++++++++++----------- 5 files changed, 83 insertions(+), 44 deletions(-) create mode 100644 code/src/model/Creature.java diff --git a/.gitignore b/.gitignore index 8f73520..cd60232 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +code/out/ diff --git a/code/src/controller/MapController.java b/code/src/controller/MapController.java index 30c2e1a..771b956 100644 --- a/code/src/controller/MapController.java +++ b/code/src/controller/MapController.java @@ -9,7 +9,6 @@ import model.Case; import model.Map; public class MapController implements Initializable { - private final Map map = new Map(32,30); private final Image b = new Image("/image/terrain/chemin.png"); private final Image a = new Image("/image/terrain/herbe.png"); diff --git a/code/src/model/Creature.java b/code/src/model/Creature.java new file mode 100644 index 0000000..ca32713 --- /dev/null +++ b/code/src/model/Creature.java @@ -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; + } +} diff --git a/code/src/model/GameLoop.java b/code/src/model/GameLoop.java index 224b598..6d6ed16 100644 --- a/code/src/model/GameLoop.java +++ b/code/src/model/GameLoop.java @@ -4,33 +4,36 @@ public class GameLoop { private Thread timer; public void start() { + System.out.println("GameLoop.start()"); timer = new Thread("timer") { public void run() { - final double FPS = 60; - final double DELAY = 1000000000 / FPS; - long lastTime = System.nanoTime(); - long timer = 0; - double delta = 0; - long currentTime; - int frames = 0; - while (true) { - currentTime = System.nanoTime(); - delta += (currentTime - lastTime) / DELAY; - timer += currentTime - lastTime; - lastTime = currentTime; - if (delta >= 1) { - //update(); // fonction qui sera update - - frames++; - delta--; - } - if (timer >= 1000000000) { - timer = 0; - System.out.println("FPS: " + frames); - frames = 0; + int nbMinutes = 1; + int i = 0; + while(true) { + if(i == 0) { + //action + System.out.println("Timer = " + i); + i = 10 * nbMinutes; + try { + timer.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }else{ + System.out.println("Timer = " + i); + i--; + try { + timer.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } } + } } + + }; + timer.start(); } } diff --git a/code/src/model/Time.java b/code/src/model/Time.java index 9375e99..e08f63d 100644 --- a/code/src/model/Time.java +++ b/code/src/model/Time.java @@ -6,30 +6,27 @@ public class Time { public void start() { timer = new Thread("timer") { public void run() { - final double FPS = 60; - final double DELAY = 1000000000 / FPS; - long lastTime = System.nanoTime(); - long timer = 0; - double delta = 0; - long currentTime; - int frames = 0; - while (true) { - currentTime = System.nanoTime(); - delta += (currentTime - lastTime) / DELAY; - timer += currentTime - lastTime; - lastTime = currentTime; - if (delta >= 1) { - //update(); // fonction qui sera update - frames++; - delta--; - } - if (timer >= 1000000000) { - timer = 0; - System.out.println("FPS: " + frames); - frames = 0; + int nbMinutes = 1; + int i = 0; + while(true) { + if(i == 0) { + //action + System.out.println("Timer = " + i); + i = 60 * nbMinutes; + }else{ + System.out.println("Timer = " + i); + i--; + try { + timer.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } } + } } + + }; }