From 74c71e7246d31064bc86c10650a9e85e9a4dc7ae Mon Sep 17 00:00:00 2001 From: fdai4616 Date: Wed, 8 Feb 2023 20:43:07 +0100 Subject: [PATCH] update --- src/main/java/PingPong/GamePanel.java | 21 +++++++++++++++++++-- target/classes/PingPong/GamePanel$AL.class | Bin 731 -> 731 bytes target/classes/PingPong/GamePanel.class | Bin 2119 -> 2818 bytes 3 files changed, 19 insertions(+), 2 deletions(-) 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 3715fadec8a8da8adb96e1535625f31d4610ea35..fb0c3990f47de49b6bb3eaff7afeb3a93692a1d4 100644 GIT binary patch delta 27 icmcc3dYg5FH4|g-WE-Xk&M*dUhHwTkhKR{?nd|^-j|R#B delta 27 icmcc3dYg5FH4~%#WE-XkPA3L#24@B_2A9cmnd|^(_Xc_Z diff --git a/target/classes/PingPong/GamePanel.class b/target/classes/PingPong/GamePanel.class index a08c5bf7e5fee999c6a9b12c7d3b138a184f8422..b5a0ce9db11d0429828a4d21b9b4e7f9e3a1ab51 100644 GIT binary patch literal 2818 zcmZuz*;f;16#oqg2I2?_A_BH`!D6_0z{e6>RCUW`^?%ey`?=HW)eE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