PongWithFrames/src/Game.java

55 lines
1.1 KiB
Java

public class Game {
Ball ball;
// blob
// Delta time: siehe https://en.wikipedia.org/wiki/Delta_timing
private long dt;
private long lastT;
private Player leftPlayer;
private Player rightPlayer;
public Game() {
leftPlayer = new Player();
rightPlayer = new Player();
ball = new Ball();
ball.setSize(ball.xSize, ball.ySize);
leftPlayer.setSize(0, leftPlayer.ySize);
leftPlayer.setTitle("left Player");
rightPlayer.setSize(0, rightPlayer.ySize);
rightPlayer.setTitle("right Player");
ball.setLocation(ball.getPos('x', dt), ball.getPos('y', dt));
lastT = System.nanoTime(); // delta time
while (true) {
dt = System.nanoTime() - lastT; // delta time
lastT = System.nanoTime(); // delta time
leftPlayer.setLocation(0, leftPlayer.getPos(dt, ball.leftUp, ball.leftDown));
rightPlayer.setLocation(1785, rightPlayer.getPos(dt, ball.rightUp, ball.rightDown));
ball.setLocation(ball.getPos('x', dt), ball.getPos('y', dt));
// ball.leftPlayer.setLocation(10, 700);
// ball.xPos++;
// System.out.println(ball.leftDown + " " + ball.leftUp);
}
}
}