|
@ -38,16 +38,32 @@ public class GamePanel extends JPanel implements Runnable { |
|
|
gameThread.start(); |
|
|
gameThread.start(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void checkCollision() { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void run() { |
|
|
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) { |
|
|
public void draw(Graphics g) { |
|
@ -57,6 +73,7 @@ public class GamePanel extends JPanel implements Runnable { |
|
|
ball.draw(g); |
|
|
ball.draw(g); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void move() { |
|
|
public void move() { |
|
|
|
|
|
|
|
|
paddle_1.move(); |
|
|
paddle_1.move(); |
|
|