Skip to content
Snippets Groups Projects
Commit 7e034174 authored by MEDEDJI Setondji's avatar MEDEDJI Setondji :speech_balloon:
Browse files

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/engine/Kernel.java
#	src/main/java/engine/physic/PhysicEngine.java
#	src/main/java/pong/PongApp.java
parents 54a05305 4f3658a3
No related branches found
No related tags found
No related merge requests found
Pipeline #23109 failed
...@@ -40,8 +40,9 @@ public class GraphicEngine extends JFrame implements Engine { ...@@ -40,8 +40,9 @@ public class GraphicEngine extends JFrame implements Engine {
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
repaint();
revalidate();
} }
......
...@@ -78,4 +78,7 @@ public interface Entity { ...@@ -78,4 +78,7 @@ public interface Entity {
*/ */
public void halt(); public void halt();
int getWidth();
int getHeight();
} }
...@@ -97,4 +97,14 @@ public class Movable implements Entity { ...@@ -97,4 +97,14 @@ public class Movable implements Entity {
} }
} }
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
} }
...@@ -68,4 +68,14 @@ public class NotMovable implements Entity { ...@@ -68,4 +68,14 @@ public class NotMovable implements Entity {
} }
@Override
public int getWidth() {
return 0;
}
@Override
public int getHeight() {
return 0;
}
} }
...@@ -9,6 +9,8 @@ import java.util.HashMap; ...@@ -9,6 +9,8 @@ import java.util.HashMap;
public class PhysicEngine implements Engine { public class PhysicEngine implements Engine {
public HashMap<PongObject, Entity> pongObjectEntityHashMap = new HashMap<>(); public HashMap<PongObject, Entity> pongObjectEntityHashMap = new HashMap<>();
private HashMap<Coordinates2D, PongObject> positions = new HashMap<>();
public PhysicEngine(){ public PhysicEngine(){
for (PongObject pongObject: Kernel.gameObjects) { for (PongObject pongObject: Kernel.gameObjects) {
Coordinates2D speed = new Coordinates2D(0, 0); Coordinates2D speed = new Coordinates2D(0, 0);
...@@ -17,20 +19,21 @@ public class PhysicEngine implements Engine { ...@@ -17,20 +19,21 @@ public class PhysicEngine implements Engine {
} }
//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()));
/*if(pongObject.getName().equals("Left racket")){ positions.put(pongObject.getPosition(), pongObject);
pongObjectEntityHashMap.put(pongObject, new Movable(1, pongObject.getPosition(), new Coordinates2D(0,1), new Coordinates2D(0, 0), pongObject.getWidth(), pongObject.getHeight()));
}
if(pongObject.getName().equals("Right racket")){
pongObjectEntityHashMap.put(pongObject, new Movable(1, pongObject.getPosition(), new Coordinates2D(0,1), new Coordinates2D(0, 0), pongObject.getWidth(), pongObject.getHeight()));
}*/
} }
} }
@Override @Override
public void update(){ public void update(){
for (PongObject pongObject: Kernel.gameObjects) { for (PongObject pongObject: Kernel.gameObjects) {
pongObjectEntityHashMap.get(pongObject).updatePosition(); // Updating of the associated movable position pongObjectEntityHashMap.get(pongObject).updatePosition(); // Updating of the associated movable position
//checkCollision();
pongObject.setPosition(pongObjectEntityHashMap.get(pongObject).getPosition()); // Updating of the pong object position pongObject.setPosition(pongObjectEntityHashMap.get(pongObject).getPosition()); // Updating of the pong object position
} }
} }
public void checkCollision(Entity firstObject, Entity secondObject){
//TODO: check collision between two objects
}
} }
...@@ -5,8 +5,6 @@ import engine.Kernel; ...@@ -5,8 +5,6 @@ import engine.Kernel;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
public class PongApp { public class PongApp {
...@@ -32,15 +30,14 @@ public class PongApp { ...@@ -32,15 +30,14 @@ public class PongApp {
Kernel kernel = new Kernel("Pong", width, height, components); Kernel kernel = new Kernel("Pong", width, height, components);
//kernel.setGameObject(components); //kernel.setGameObject(components);
Timer timer = new Timer();
int delay = 0; // Délai initial avant la première exécution (en millisecondes)
int interval = 1; // Intervalle entre les exécutions (en millisecondes)
timer.schedule(new TimerTask() { while(true){
@Override try {
public void run() {
kernel.update(); kernel.update();
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
}, delay, interval);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment