diff --git a/src/main/java/PingPong/GamePanel.java b/src/main/java/PingPong/GamePanel.java index 040cb36..0a9304a 100644 --- a/src/main/java/PingPong/GamePanel.java +++ b/src/main/java/PingPong/GamePanel.java @@ -38,16 +38,32 @@ public class GamePanel extends JPanel implements Runnable { gameThread.start(); } + public void checkCollision() { + } public void run() { + long lastTime = System.nanoTime(); + double amountOfTicks = 60.0; + double nanoseconds = 1000000000 / amountOfTicks; + double delta = 0; + while (true) { + long now = System.nanoTime(); + delta += (now - lastTime) / nanoseconds; + lastTime = now; + if (delta >= 1) { + move(); + checkCollision(); + repaint(); + delta--; + } - + } } public void draw(Graphics g) { @@ -57,8 +73,9 @@ public class GamePanel extends JPanel implements Runnable { ball.draw(g); } + public void move() { - + paddle_1.move(); paddle_2.move(); ball.move(); diff --git a/target/classes/PingPong/GamePanel$AL.class b/target/classes/PingPong/GamePanel$AL.class index 3715fad..fb0c399 100644 Binary files a/target/classes/PingPong/GamePanel$AL.class and b/target/classes/PingPong/GamePanel$AL.class differ diff --git a/target/classes/PingPong/GamePanel.class b/target/classes/PingPong/GamePanel.class index a08c5bf..b5a0ce9 100644 Binary files a/target/classes/PingPong/GamePanel.class and b/target/classes/PingPong/GamePanel.class differ