Skip to content

Commit

Permalink
Merge pull request #105 from PrethamMuthappa/main
Browse files Browse the repository at this point in the history
Added improvements to Main menu & Movements
  • Loading branch information
jvondermarck authored Apr 17, 2024
2 parents 4faff3c + c297a46 commit dccd630
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 0 additions & 47 deletions dinosaur-exploder.iml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public void initInput() {
onKey(KeyCode.RIGHT, () -> player.getComponent(PlayerComponent.class).moveRight());

onKeyDown(KeyCode.SPACE,() -> player.getComponent(PlayerComponent.class).shoot());

onKey(KeyCode.W, () -> player.getComponent(PlayerComponent.class).moveUp());
onKey(KeyCode.S, () -> player.getComponent(PlayerComponent.class).moveDown());
onKey(KeyCode.A, () -> player.getComponent(PlayerComponent.class).moveLeft());
onKey(KeyCode.D, () -> player.getComponent(PlayerComponent.class).moveRight());

}
/**
* Summary :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.almasb.fxgl.app.scene.FXGLMenu;
import com.almasb.fxgl.app.scene.SceneFactory;

import java.io.FileNotFoundException;

public class DinosaurGUI {
public static final int WIDTH = 550;
public static final int HEIGHT = 750;
Expand Down
142 changes: 71 additions & 71 deletions src/main/java/com/dinosaur/dinosaurexploder/view/DinosaurMenu.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
package com.dinosaur.dinosaurexploder.view;

import static com.almasb.fxgl.dsl.FXGL.getLocalizationService;
import static com.almasb.fxgl.dsl.FXGL.getSettings;

import java.util.Arrays;
import java.util.Locale;
import com.almasb.fxgl.app.scene.FXGLMenu;
import com.almasb.fxgl.app.scene.MenuType;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.localization.Language;
import com.almasb.fxgl.ui.FXGLChoiceBox;
import com.almasb.fxgl.ui.FontType;
import com.dinosaur.dinosaurexploder.DinosaurApp;
import com.dinosaur.dinosaurexploder.model.GameConstants;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.util.StringConverter;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class DinosaurMenu extends FXGLMenu {

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

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

var title = FXGL.getUIFactoryService().newText(GameConstants.GAME_NAME, Color.LIME, FontType.MONO, 35);
title.setTranslateY(100);
title.setTranslateX(getAppWidth() / 2 - 175);

DinosaurApp.initLanguages();
drawControls(mainMenuSound, bg, title);
}

private void drawControls(MediaPlayer mainMenuSound, Rectangle bg, Text title) {
getContentRoot().getChildren().removeAll(getContentRoot().getChildren());

var startButton = new Button(getLocalizationService().getLocalizedString("Menu.1"));
var quitButton = new Button(getLocalizationService().getLocalizedString("Menu.2"));
var chooseLanguage = new FXGLChoiceBox<Language>(FXCollections.observableArrayList(GameConstants.AVAILABLE_LANGUAGES));


startButton.setMinSize(200, 100);
quitButton.setMinSize(200, 100);

startButton.setTranslateY(350);
startButton.setTranslateX(getAppWidth() / 2 - 100);
startButton.setStyle("-fx-font-size:20");

quitButton.setTranslateY(490);
quitButton.setTranslateX(getAppWidth() / 2 - 100);
quitButton.setStyle("-fx-font-size:20");

chooseLanguage.setTranslateY(700);
chooseLanguage.setTranslateX(getAppWidth() / 2 - 100);
chooseLanguage.setValue(getLocalizationService().getSelectedLanguage());
quitButton.setStyle("-fx-font-size:20");
chooseLanguage.setConverter(new StringConverter<Language>() {

@Override
public String toString(Language language) {
return getLocalizationService().getLocalizedString(language.getName());
}

@Override
public Language fromString(String text) {
throw new UnsupportedOperationException();
}
});

startButton.setOnAction(event -> {
fireNewGame();
mainMenuSound.stop();
});

quitButton.setOnAction(event -> fireExit());

chooseLanguage.setOnAction(event -> {
getLocalizationService().setSelectedLanguage(chooseLanguage.getValue());
drawControls(mainMenuSound, bg, title);
});

getContentRoot().getChildren().addAll(bg, title, startButton, quitButton, chooseLanguage);
}
}
var title = FXGL.getUIFactoryService().newText(GameConstants.GAME_NAME, Color.LIME, FontType.MONO, 35);
var startButton = new Button("Start Game");
var quitButton = new Button("Quit");
try {


FileInputStream fileInputStream = new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png");
FileInputStream mutemusic_button = new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/silent.png");

// image for dino in main menu
Image image = new Image(fileInputStream);
ImageView imageView = new ImageView(image);
imageView.setFitHeight(250);
imageView.setFitWidth(200);
imageView.setX(200);
imageView.setY(190);
imageView.setPreserveRatio(true);

//adding image to manually mute music

Image mute = new Image(mutemusic_button);
ImageView imageView_mute = new ImageView(mute);
imageView_mute.setFitHeight(40);
imageView_mute.setFitWidth(50);
imageView_mute.setX(490);
imageView_mute.setY(20);
imageView_mute.setPreserveRatio(true);

startButton.setMinSize(50, 50);
quitButton.setMinSize(140, 50);

title.setTranslateY(100);
title.setTranslateX(getAppWidth() / 2 - 145);

startButton.setTranslateY(400);
startButton.setTranslateX(getAppWidth() / 2 - 50);
startButton.setStyle("-fx-font-size:20");

quitButton.setTranslateY(500);
quitButton.setTranslateX(getAppWidth() / 2 - 50);
quitButton.setStyle("-fx-font-size:20");

startButton.setOnAction(event -> {
fireNewGame();
mainMenuSound.stop();
});

imageView_mute.setOnMouseClicked(mouseEvent -> {
mainMenuSound.stop();
});

imageView_mute.setOnMousePressed(mouseEvent -> {
mainMenuSound.stop();
});
quitButton.setOnAction(event -> fireExit());

getContentRoot().getChildren().addAll(
bg, title, startButton, quitButton, imageView, imageView_mute
);
}
catch (FileNotFoundException e){
System.out.println("File not found" + e.getMessage());
}
}

}
18 changes: 12 additions & 6 deletions src/main/java/com/dinosaur/dinosaurexploder/view/PauseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ public PauseMenu() {
btnQuitGame.enable();
btnControls.enable();
}),
new OptionsButton(getLocalizationService().getLocalizedString("Pause.5")),
new OptionsButton(getLocalizationService().getLocalizedString("Pause.6")),
new OptionsButton(getLocalizationService().getLocalizedString("Pause.7")),
new OptionsButton(getLocalizationService().getLocalizedString("Pause.8")),
new OptionsButton(getLocalizationService().getLocalizedString("Pause.9")),
new OptionsButton(getLocalizationService().getLocalizedString("Pause.10")));
new OptionsButton("↑ / W : Move spaceship up"),
new OptionsButton("↓ / S : Move spaceship down"),
new OptionsButton("→ / D : Move spaceship right"),
new OptionsButton("← / A : Move spaceship left"),
new OptionsButton("ESC: Pause the game"),
new OptionsButton("SPACE: Shoot"));
new OptionsButton(getLocalizationService().getLocalizedString("Pause.5"));
new OptionsButton(getLocalizationService().getLocalizedString("Pause.6"));
new OptionsButton(getLocalizationService().getLocalizedString("Pause.7"));
new OptionsButton(getLocalizationService().getLocalizedString("Pause.8"));
new OptionsButton(getLocalizationService().getLocalizedString("Pause.9"));
new OptionsButton(getLocalizationService().getLocalizedString("Pause.10"));

controlsBox.setTranslateX(300);
controlsBox.setTranslateY(getAppWidth() / 2);
Expand Down
Binary file added src/main/resources/assets/textures/dinomenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/assets/textures/silent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dccd630

Please sign in to comment.