-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameThread.java
More file actions
42 lines (35 loc) · 1.04 KB
/
GameThread.java
File metadata and controls
42 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Created by SPARK on 2016-01-26.
*/
public class GameThread extends Thread {
private Breakout game;
public GameThread(Breakout game) {
this.game = game;
}
public static int score = 0;
public void run() { // make sure game gets updated.
// Initiate
System.out.println("Initiated.");
game.isRunning = true;
game.isPaused = false;
game.lastUpdate = System.nanoTime();
// Game Loop
while (game.isRunning) {
try {
//System.out.println("loop");
if (game.isPaused) {
game.lastUpdate = System.nanoTime();
Thread.sleep(1);
} else {
game.tick();
game.lastUpdate = System.nanoTime();
Thread.sleep( (long) (1000/game.FPS));
}
} catch (Exception e) {
e.printStackTrace();
}
}
// Exit
System.out.println("Exited the Game Loop");
}
}