Skip to content

Commit dccd630

Browse files
authored
Merge pull request #105 from PrethamMuthappa/main
Added improvements to Main menu & Movements
2 parents 4faff3c + c297a46 commit dccd630

File tree

8 files changed

+92
-125
lines changed

8 files changed

+92
-125
lines changed

β€Ž.idea/misc.xmlβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ždinosaur-exploder.imlβ€Ž

Lines changed: 0 additions & 47 deletions
This file was deleted.

β€Žsrc/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.javaβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public void initInput() {
5353
onKey(KeyCode.RIGHT, () -> player.getComponent(PlayerComponent.class).moveRight());
5454

5555
onKeyDown(KeyCode.SPACE,() -> player.getComponent(PlayerComponent.class).shoot());
56+
57+
onKey(KeyCode.W, () -> player.getComponent(PlayerComponent.class).moveUp());
58+
onKey(KeyCode.S, () -> player.getComponent(PlayerComponent.class).moveDown());
59+
onKey(KeyCode.A, () -> player.getComponent(PlayerComponent.class).moveLeft());
60+
onKey(KeyCode.D, () -> player.getComponent(PlayerComponent.class).moveRight());
61+
5662
}
5763
/**
5864
* Summary :

β€Žsrc/main/java/com/dinosaur/dinosaurexploder/view/DinosaurGUI.javaβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.almasb.fxgl.app.scene.FXGLMenu;
55
import com.almasb.fxgl.app.scene.SceneFactory;
66

7+
import java.io.FileNotFoundException;
8+
79
public class DinosaurGUI {
810
public static final int WIDTH = 550;
911
public static final int HEIGHT = 750;
Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
package com.dinosaur.dinosaurexploder.view;
22

3-
import static com.almasb.fxgl.dsl.FXGL.getLocalizationService;
4-
import static com.almasb.fxgl.dsl.FXGL.getSettings;
5-
6-
import java.util.Arrays;
7-
import java.util.Locale;
83
import com.almasb.fxgl.app.scene.FXGLMenu;
94
import com.almasb.fxgl.app.scene.MenuType;
105
import com.almasb.fxgl.dsl.FXGL;
11-
import com.almasb.fxgl.localization.Language;
12-
import com.almasb.fxgl.ui.FXGLChoiceBox;
136
import com.almasb.fxgl.ui.FontType;
14-
import com.dinosaur.dinosaurexploder.DinosaurApp;
157
import com.dinosaur.dinosaurexploder.model.GameConstants;
16-
import javafx.collections.FXCollections;
17-
import javafx.collections.ObservableList;
188
import javafx.scene.control.Button;
9+
import javafx.scene.image.Image;
10+
import javafx.scene.image.ImageView;
1911
import javafx.scene.media.Media;
2012
import javafx.scene.media.MediaPlayer;
2113
import javafx.scene.paint.Color;
2214
import javafx.scene.shape.Rectangle;
23-
import javafx.scene.text.Text;
24-
import javafx.util.StringConverter;
15+
16+
import java.io.FileInputStream;
17+
import java.io.FileNotFoundException;
2518

2619
public class DinosaurMenu extends FXGLMenu {
2720

@@ -35,62 +28,69 @@ public DinosaurMenu() {
3528

3629
var bg = new Rectangle(getAppWidth(), getAppHeight(), Color.BLACK);
3730

38-
var title = FXGL.getUIFactoryService().newText(GameConstants.GAME_NAME, Color.LIME, FontType.MONO, 35);
39-
title.setTranslateY(100);
40-
title.setTranslateX(getAppWidth() / 2 - 175);
41-
42-
DinosaurApp.initLanguages();
43-
drawControls(mainMenuSound, bg, title);
44-
}
45-
46-
private void drawControls(MediaPlayer mainMenuSound, Rectangle bg, Text title) {
47-
getContentRoot().getChildren().removeAll(getContentRoot().getChildren());
48-
49-
var startButton = new Button(getLocalizationService().getLocalizedString("Menu.1"));
50-
var quitButton = new Button(getLocalizationService().getLocalizedString("Menu.2"));
51-
var chooseLanguage = new FXGLChoiceBox<Language>(FXCollections.observableArrayList(GameConstants.AVAILABLE_LANGUAGES));
52-
53-
54-
startButton.setMinSize(200, 100);
55-
quitButton.setMinSize(200, 100);
56-
57-
startButton.setTranslateY(350);
58-
startButton.setTranslateX(getAppWidth() / 2 - 100);
59-
startButton.setStyle("-fx-font-size:20");
60-
61-
quitButton.setTranslateY(490);
62-
quitButton.setTranslateX(getAppWidth() / 2 - 100);
63-
quitButton.setStyle("-fx-font-size:20");
64-
65-
chooseLanguage.setTranslateY(700);
66-
chooseLanguage.setTranslateX(getAppWidth() / 2 - 100);
67-
chooseLanguage.setValue(getLocalizationService().getSelectedLanguage());
68-
quitButton.setStyle("-fx-font-size:20");
69-
chooseLanguage.setConverter(new StringConverter<Language>() {
70-
71-
@Override
72-
public String toString(Language language) {
73-
return getLocalizationService().getLocalizedString(language.getName());
74-
}
75-
76-
@Override
77-
public Language fromString(String text) {
78-
throw new UnsupportedOperationException();
79-
}
80-
});
81-
82-
startButton.setOnAction(event -> {
83-
fireNewGame();
84-
mainMenuSound.stop();
85-
});
86-
87-
quitButton.setOnAction(event -> fireExit());
88-
89-
chooseLanguage.setOnAction(event -> {
90-
getLocalizationService().setSelectedLanguage(chooseLanguage.getValue());
91-
drawControls(mainMenuSound, bg, title);
92-
});
93-
94-
getContentRoot().getChildren().addAll(bg, title, startButton, quitButton, chooseLanguage);
95-
}
96-
}
31+
var title = FXGL.getUIFactoryService().newText(GameConstants.GAME_NAME, Color.LIME, FontType.MONO, 35);
32+
var startButton = new Button("Start Game");
33+
var quitButton = new Button("Quit");
34+
try {
35+
36+
37+
FileInputStream fileInputStream = new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png");
38+
FileInputStream mutemusic_button = new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/silent.png");
39+
40+
// image for dino in main menu
41+
Image image = new Image(fileInputStream);
42+
ImageView imageView = new ImageView(image);
43+
imageView.setFitHeight(250);
44+
imageView.setFitWidth(200);
45+
imageView.setX(200);
46+
imageView.setY(190);
47+
imageView.setPreserveRatio(true);
48+
49+
//adding image to manually mute music
50+
51+
Image mute = new Image(mutemusic_button);
52+
ImageView imageView_mute = new ImageView(mute);
53+
imageView_mute.setFitHeight(40);
54+
imageView_mute.setFitWidth(50);
55+
imageView_mute.setX(490);
56+
imageView_mute.setY(20);
57+
imageView_mute.setPreserveRatio(true);
58+
59+
startButton.setMinSize(50, 50);
60+
quitButton.setMinSize(140, 50);
61+
62+
title.setTranslateY(100);
63+
title.setTranslateX(getAppWidth() / 2 - 145);
64+
65+
startButton.setTranslateY(400);
66+
startButton.setTranslateX(getAppWidth() / 2 - 50);
67+
startButton.setStyle("-fx-font-size:20");
68+
69+
quitButton.setTranslateY(500);
70+
quitButton.setTranslateX(getAppWidth() / 2 - 50);
71+
quitButton.setStyle("-fx-font-size:20");
72+
73+
startButton.setOnAction(event -> {
74+
fireNewGame();
75+
mainMenuSound.stop();
76+
});
77+
78+
imageView_mute.setOnMouseClicked(mouseEvent -> {
79+
mainMenuSound.stop();
80+
});
81+
82+
imageView_mute.setOnMousePressed(mouseEvent -> {
83+
mainMenuSound.stop();
84+
});
85+
quitButton.setOnAction(event -> fireExit());
86+
87+
getContentRoot().getChildren().addAll(
88+
bg, title, startButton, quitButton, imageView, imageView_mute
89+
);
90+
}
91+
catch (FileNotFoundException e){
92+
System.out.println("File not found" + e.getMessage());
93+
}
94+
}
95+
96+
}

β€Žsrc/main/java/com/dinosaur/dinosaurexploder/view/PauseMenu.javaβ€Ž

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ public PauseMenu() {
4646
btnQuitGame.enable();
4747
btnControls.enable();
4848
}),
49-
new OptionsButton(getLocalizationService().getLocalizedString("Pause.5")),
50-
new OptionsButton(getLocalizationService().getLocalizedString("Pause.6")),
51-
new OptionsButton(getLocalizationService().getLocalizedString("Pause.7")),
52-
new OptionsButton(getLocalizationService().getLocalizedString("Pause.8")),
53-
new OptionsButton(getLocalizationService().getLocalizedString("Pause.9")),
54-
new OptionsButton(getLocalizationService().getLocalizedString("Pause.10")));
49+
new OptionsButton("↑ / W : Move spaceship up"),
50+
new OptionsButton("↓ / S : Move spaceship down"),
51+
new OptionsButton("β†’ / D : Move spaceship right"),
52+
new OptionsButton("← / A : Move spaceship left"),
53+
new OptionsButton("ESC: Pause the game"),
54+
new OptionsButton("SPACE: Shoot"));
55+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.5"));
56+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.6"));
57+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.7"));
58+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.8"));
59+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.9"));
60+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.10"));
5561

5662
controlsBox.setTranslateX(300);
5763
controlsBox.setTranslateY(getAppWidth() / 2);
244 KB
Loading
20.9 KB
Loading

0 commit comments

Comments
Β (0)