Skip to content
Snippets Groups Projects
Commit f8b38808 authored by bosskkev's avatar bosskkev
Browse files

Correction bug vitesse. Modification de la boucle while(true) et augmentation...

Correction bug vitesse. Modification de la boucle while(true) et augmentation de la vitesse dans PhysicEngine
parent 1e192e67
No related branches found
No related tags found
No related merge requests found
Pipeline #23745 failed
...@@ -18,7 +18,7 @@ public class PhysicEngine implements Engine { ...@@ -18,7 +18,7 @@ public class PhysicEngine implements Engine {
for (PongObject pongObject: Kernel.gameObjects) { for (PongObject pongObject: Kernel.gameObjects) {
Coordinates2D speed = new Coordinates2D(0, 0); Coordinates2D speed = new Coordinates2D(0, 0);
if(pongObject.getName().equals("Ball")){ if(pongObject.getName().equals("Ball")){
speed = new Coordinates2D(1, 1); speed = new Coordinates2D(2, 2);
} }
//Coordinates2D speed = new Coordinates2D(random.nextInt(2) - 1, random.nextInt(2) - 1); //Coordinates2D speed = new Coordinates2D(random.nextInt(2) - 1, random.nextInt(2) - 1);
pongObjectEntityHashMap.put(pongObject, new Movable(1, pongObject.getPosition(), speed, new Coordinates2D(0, 0), pongObject.getWidth(), pongObject.getHeight())); pongObjectEntityHashMap.put(pongObject, new Movable(1, pongObject.getPosition(), speed, new Coordinates2D(0, 0), pongObject.getWidth(), pongObject.getHeight()));
......
...@@ -35,14 +35,27 @@ public class PongApp { ...@@ -35,14 +35,27 @@ public class PongApp {
//kernel.setGameObject(components); //kernel.setGameObject(components);
final long MIN_INTERVAL_TIME = 10; // Minimum time between two iterations
long lastIterationTime = System.currentTimeMillis(); //Initialize the last iteration time
while (true) { while (true) {
try {
kernel.update();
Thread.sleep(1); kernel.update(); // Updating the kernel and the game state
long elapsedTime = System.currentTimeMillis() - lastIterationTime;
// If the elapsed time is less than the minimum interval
if (elapsedTime < MIN_INTERVAL_TIME) {
try {
Thread.sleep(MIN_INTERVAL_TIME - elapsedTime); // Wait until the minimum interval is reached
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
lastIterationTime = System.currentTimeMillis(); // Update the last iteration time with the current time
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment