Skip to content

Commit 8f11c52

Browse files
committed
Added game menu
1 parent 9ad633d commit 8f11c52

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

src/main/java/com/dinosaur/dinosaurexploder/view/DinosaurGUI.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
package com.dinosaur.dinosaurexploder.view;
22

33
import com.almasb.fxgl.app.GameSettings;
4+
import com.almasb.fxgl.app.scene.FXGLMenu;
5+
import com.almasb.fxgl.app.scene.SceneFactory;
6+
import javafx.scene.Scene;
47

58
public class DinosaurGUI {
9+
public static final int WIDTH = 550;
10+
public static final int HEIGHT = 750;
11+
612
public void initSettings(GameSettings settings) {
7-
settings.setWidth(550);
8-
settings.setHeight(750);
13+
settings.setWidth(WIDTH);
14+
settings.setHeight(HEIGHT);
915
settings.setTitle("Dinosaur Exploder");
16+
settings.setMainMenuEnabled(true);
17+
18+
// Custom main menu
19+
settings.setSceneFactory(new SceneFactory() {
20+
@Override
21+
public FXGLMenu newMainMenu() {
22+
return new DinosaurMenu();
23+
}
24+
});
25+
26+
1027
settings.setVersion("1.0");
1128
settings.setTicksPerSecond(60); // check info : settings.setProfilingEnabled(true);
1229
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.dinosaur.dinosaurexploder.view;
2+
3+
import com.almasb.fxgl.app.scene.FXGLMenu;
4+
import com.almasb.fxgl.app.scene.MenuType;
5+
import com.almasb.fxgl.dsl.FXGL;
6+
import com.almasb.fxgl.ui.FontType;
7+
import javafx.scene.Node;
8+
import javafx.scene.control.Button;
9+
import javafx.scene.layout.Pane;
10+
import javafx.scene.layout.StackPane;
11+
import javafx.scene.paint.Color;
12+
import javafx.scene.shape.Rectangle;
13+
14+
public class DinosaurMenu extends FXGLMenu {
15+
16+
public DinosaurMenu() {
17+
super(MenuType.MAIN_MENU);
18+
19+
var bg = new Rectangle(getAppWidth(), getAppHeight(), Color.BLACK);
20+
21+
var title = FXGL.getUIFactoryService().newText("Dinosaur Exploder", Color.LIME, FontType.MONO, 35);
22+
var startButton = new Button("Start Game");
23+
var quitButton = new Button("Quit");
24+
25+
startButton.setMinSize(200, 100);
26+
quitButton.setMinSize(200, 100);
27+
28+
title.setTranslateY(100);
29+
title.setTranslateX(getAppWidth() / 2 - 175);
30+
31+
startButton.setTranslateY(350);
32+
startButton.setTranslateX(getAppWidth() / 2 - 100);
33+
startButton.setStyle("-fx-font-size:20");
34+
35+
quitButton.setTranslateY(490);
36+
quitButton.setTranslateX(getAppWidth() / 2 - 100);
37+
quitButton.setStyle("-fx-font-size:20");
38+
39+
startButton.setOnAction(event -> fireNewGame());
40+
quitButton.setOnAction(event -> fireExit());
41+
42+
getContentRoot().getChildren().addAll(
43+
bg, title, startButton, quitButton
44+
);
45+
}
46+
47+
}

0 commit comments

Comments
 (0)