Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
PrethamMuthappa authored Apr 14, 2024
2 parents 7ecc87b + 4faff3c commit 17d1399
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 16 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -70,7 +70,7 @@
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.dinosaur.dinosaurexploder/com.dinosaur.dinosaurexploder.HelloApplication
<mainClass>com.dinosaur.dinosaurexploder/com.dinosaur.dinosaurexploder.DinosaurApp
</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/dinosaur/dinosaurexploder/DinosaurApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.localization.Language;
import com.dinosaur.dinosaurexploder.controller.DinosaurController;
import com.dinosaur.dinosaurexploder.model.EntityType;
import com.dinosaur.dinosaurexploder.model.GameEntityFactory;
Expand All @@ -14,6 +15,9 @@
import javafx.scene.input.KeyCode;

import static com.almasb.fxgl.dsl.FXGL.*;

import java.util.Locale;
import java.util.ResourceBundle;
/**
* Summary :
* The Factory handles the DinosaurApp,Physics,Settings and Input of all entities in the game
Expand Down Expand Up @@ -69,4 +73,19 @@ public static void main(String[] args) {
launch(args);

}

@Override
protected void onPreInit() {
initLanguages();
}

public static void initLanguages() {
// Init languages
getLocalizationService().addLanguageData(Language.ENGLISH, ResourceBundle.getBundle("assets.properties.texts", Locale.ENGLISH));
getLocalizationService().addLanguageData(Language.GERMAN, ResourceBundle.getBundle("assets.properties.texts", Locale.GERMAN));

// Set first entry as default
getLocalizationService().selectedLanguageProperty().unbind();
getLocalizationService().setSelectedLanguage(Language.ENGLISH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

import static com.almasb.fxgl.dsl.FXGL.*;
import static com.almasb.fxgl.dsl.FXGLForKtKt.spawn;
import static javafx.util.Duration.seconds;
Expand Down Expand Up @@ -118,7 +117,7 @@ public void initPhysics() {
* To detect whether the player lives are empty or not
*/
public void gameOver(){
getDialogService().showConfirmationBox("Game Over. Play Again?", yes ->{
getDialogService().showConfirmationBox(getLocalizationService().getLocalizedString("Game.2"), yes ->{
if (yes){
getGameController().startNewGame();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package com.dinosaur.dinosaurexploder.model;

import java.util.List;

import com.almasb.fxgl.localization.Language;

/**
*
* This holds every constant in the the PROJECT
Expand Down Expand Up @@ -33,4 +38,7 @@ public class GameConstants {

public static final String GAME_NAME = "Dinosaur Exploder";

public static final List<Language> AVAILABLE_LANGUAGES = List.of(Language.ENGLISH, Language.GERMAN );


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dinosaur.dinosaurexploder.model;

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

import com.almasb.fxgl.entity.component.Component;
import javafx.scene.Node;
import javafx.scene.image.Image;
Expand All @@ -17,7 +19,7 @@ public class LifeComponent extends Component implements Life {
final private Image heart = new Image(GameConstants.HEART_IMAGEPATH);
Integer life = 3;
// Declaring Lives Text
Text lifeText = new Text("Lives");
Text lifeText = new Text(getLocalizationService().getLocalizedString("Game.5"));

// Declaring 3 Hearts
ImageView test1 = new ImageView(heart);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.dinosaur.dinosaurexploder.model;


import java.io.*;
import static com.almasb.fxgl.dsl.FXGL.getLocalizationService;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.almasb.fxgl.entity.component.Component;
import javafx.scene.image.Image;
Expand Down Expand Up @@ -50,8 +56,8 @@ public void onUpdate(double ptf) {
entity.getViewComponent().clearChildren();
GridPane gridPane = new GridPane();
gridPane.setHgap(10);
Text scoreText = new Text("Score: " + score.toString());
Text highScoreText = new Text("HighScore: " + highScore.getHigh().toString());
Text scoreText = new Text(getLocalizationService().getLocalizedString("Game.3") + score.toString());
Text highScoreText = new Text(getLocalizationService().getLocalizedString("Game.4") + highScore.getHigh().toString());
Image image = new Image(GameConstants.GREENDINO_IMAGEPATH,25,20,false, false);
ImageView imageView = new ImageView();
imageView.setImage(image);
Expand Down Expand Up @@ -99,6 +105,4 @@ public void incrementScore(int i){
e.printStackTrace();
}}
}


}
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
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;
Expand All @@ -28,6 +40,7 @@ public DinosaurMenu() throws FileNotFoundException {

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


var title = FXGL.getUIFactoryService().newText(GameConstants.GAME_NAME, Color.LIME, FontType.MONO, 35);
var startButton = new Button("Start Game");
var quitButton = new Button("Quit");
Expand Down Expand Up @@ -86,4 +99,63 @@ public DinosaurMenu() throws FileNotFoundException {
);
}

}
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);
}
}
20 changes: 16 additions & 4 deletions src/main/java/com/dinosaur/dinosaurexploder/view/PauseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import static com.almasb.fxgl.dsl.FXGL.*;

import static com.almasb.fxgl.dsl.FXGL.getLocalizationService;
import static com.almasb.fxgl.dsl.FXGLForKtKt.getUIFactoryService;

import com.dinosaur.dinosaurexploder.DinosaurApp;
import com.dinosaur.dinosaurexploder.model.GameConstants;

public class PauseMenu extends FXGLMenu {
public PauseMenu() {
super(MenuType.GAME_MENU);
DinosaurApp.initLanguages();


PauseButton btnBack = new PauseButton("Back",() -> fireResume());
PauseButton btnBack = new PauseButton(getLocalizationService().getLocalizedString("Pause.1"),() -> fireResume());

PauseButton btnQuitGame = new PauseButton("Quit Game",() -> fireExitToMainMenu());
PauseButton btnQuitGame = new PauseButton(getLocalizationService().getLocalizedString("Pause.2"),() -> fireExitToMainMenu());

ControlButton btnControls = new ControlButton("Controls");
ControlButton btnControls = new ControlButton(getLocalizationService().getLocalizedString("Pause.3"));

btnControls.setControlAction(() -> {

Expand All @@ -33,7 +39,7 @@ public PauseMenu() {
var controlsBox = new VBox(15);

controlsBox.getChildren().addAll(
new PauseButton("Back", () -> {
new PauseButton(getLocalizationService().getLocalizedString("Pause.4"), () -> {
controlsBox.getChildren().removeAll(controlsBox.getChildren());
removeChild(bg);
btnBack.enable();
Expand All @@ -46,6 +52,12 @@ public PauseMenu() {
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
30 changes: 30 additions & 0 deletions src/main/resources/assets/properties/texts_de.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Menu
Menu.1=Spiel starten
Menu.2=Beenden

# Game
Game.1=Punkte
Game.2=Game Over. Nochmal spielen?
Game.3=Punkte:
Game.4=Höchste Punktzahl:
Game.5=Leben

# Pause
Pause.1=Zurück
Pause.2=Spiel beenden
Pause.3=Steuerung
Pause.4=Zurück
Pause.5=\u2191: Raumschiff nach oben bewegen
Pause.6=\u2193: Raumschiff nach unten bewegen
Pause.7=\u2192: Raumschiff nach rechts bewegen
Pause.8=\u2190: Raumschiff nach links bewegen
Pause.9=ESC: Spiel pausieren
Pause.10=LEERTASTE: Schießen

# Languages
ENGLISH=Englisch
GERMAN=Deutsch

# Dialog
dialog.yes = JA
dialog.no = NEIN
26 changes: 26 additions & 0 deletions src/main/resources/assets/properties/texts_en.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Menu
Menu.1=Start Game
Menu.2=Quit

# Game
Game.1=Score
Game.2=Game Over. Play Again?
Game.3=Score:
Game.4=HighScore:
Game.5=Lives

# Pause
Pause.1=Back
Pause.2=Quit Game
Pause.3=Controls
Pause.4=Back
Pause.5=\u2191: Move spaceship up
Pause.6=\u2193: Move spaceship down
Pause.7=\u2192: Move spaceship right
Pause.8=\u2190: Move spaceship left
Pause.9=ESC: Pause the game
PAUSE.10=SPACE: Shoot

# Languages
ENGLISH=English
GERMAN=German

0 comments on commit 17d1399

Please sign in to comment.