-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGame.java
More file actions
62 lines (51 loc) · 1.58 KB
/
Copy pathGame.java
File metadata and controls
62 lines (51 loc) · 1.58 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.Stage;
import Controller.Controller;
import Model.Scene.SceneManager;
/**
* Main class of the game.
*
*/
public class Game extends Application {
private int screenWidth = 960;
private int screenHeight = 640;
/**
* Main, launch the function start of javafx
* @param args Arguments of the command line
*/
public static void main(String[] args) {
launch(args);
}
/**
* Main function of the game, init all the element of javafx and lauch the game's loop.
*/
public void start(Stage stage) {
stage.setTitle("Andromeda");
Group root = new Group();
Scene scene = new Scene(root);
stage.setScene(scene);
Canvas canvas = new Canvas(screenWidth , screenHeight);
root.getChildren().add( canvas );
GraphicsContext gc = canvas.getGraphicsContext2D();
final SceneManager sceneManager = new SceneManager(gc, screenWidth , screenHeight);
final Controller controller = new Controller(scene, sceneManager);
/** Game loop **/
new AnimationTimer(){
long prevNanoTime = System.nanoTime();
public void handle(long currentNanoTime){
double delta = (currentNanoTime - prevNanoTime) / 1000000;
if (!sceneManager.tick(delta)) {
System.exit(0);
}
controller.tick();
prevNanoTime = currentNanoTime;
}
}.start();
stage.show();
}
}