-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameFrame.java
55 lines (42 loc) · 1.16 KB
/
GameFrame.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
import javax.swing.JFrame;
public class GameFrame extends JFrame {
private static GameFrame gameFrame;
public final int WIDTH = 1280;
public final int HEIGHT = 720;
private Thread renderThread;
private boolean running;
private GameCanvas minecraftCanvas;
private InputListener inputListener;
private Game game;
private GameFrame() {
super("Minecraft");
this.running = false;
this.minecraftCanvas = new GameCanvas();
this.inputListener = new InputListener(minecraftCanvas);
minecraftCanvas.addKeyListener(inputListener);
minecraftCanvas.addMouseListener(inputListener);
setSize(WIDTH, HEIGHT);
setResizable(false);
add(minecraftCanvas);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public Game getGame() {
return game;
}
private void start() {
running = true;
game = new Game();
setVisible(true);
renderThread = new Thread(minecraftCanvas);
renderThread.start();
}
public static GameFrame getInstance() {
if (gameFrame == null) {
gameFrame = new GameFrame();
}
return gameFrame;
}
public static void main(String[] args) {
getInstance().start();
}
}