Endscreen formatieren

This commit is contained in:
Mats Pape 2022-01-25 11:42:39 +01:00
parent af010b5bd8
commit 98bcfec0fd
10 changed files with 29 additions and 26 deletions

View File

@ -158,9 +158,9 @@ public class FormatingClass {
public void endScreenFormating(Pane endScreen, Pane pause, Label endScreenHeadline, Label currentScoreEndscreenLabel) { public void endScreenFormating(Pane endScreen, Pane pause, Label endScreenHeadline, Label currentScoreEndscreenLabel) {
/*Endscreen-Pane formatieren*/ /*Endscreen-Pane formatieren*/
endScreen.setPrefSize(400, 500); endScreen.setPrefSize(400, 500);
pause.setLayoutX(200); endScreen.setLayoutX(200);
pause.setLayoutY(100); endScreen.setLayoutY(100);
pause.setStyle("-fx-background-color: #DED894; " + endScreen.setStyle("-fx-background-color: #DED894; " +
"-fx-border-width: 5px;" + "-fx-border-width: 5px;" +
"-fx-border-color: #543847;" + "-fx-border-color: #543847;" +
"-fx-border-radius: 15px;" + "-fx-border-radius: 15px;" +
@ -175,7 +175,7 @@ public class FormatingClass {
"-fx-font-weight: bold;" + "-fx-font-weight: bold;" +
"-fx-alignment: center;"); "-fx-alignment: center;");
currentScoreEndscreenLabel.setPrefSize(250,50); currentScoreEndscreenLabel.setPrefSize(300,50);
currentScoreEndscreenLabel.setLayoutX(75); currentScoreEndscreenLabel.setLayoutX(75);
currentScoreEndscreenLabel.setLayoutY(100); currentScoreEndscreenLabel.setLayoutY(100);
currentScoreEndscreenLabel.setStyle("-fx-background-color: #DED894; " + currentScoreEndscreenLabel.setStyle("-fx-background-color: #DED894; " +

View File

@ -23,6 +23,8 @@ import java.util.ArrayList;
public class HappyBirdMain extends Application { public class HappyBirdMain extends Application {
private int birdPositionMovedBy = 0; private int birdPositionMovedBy = 0;
private int collectedPoints; private int collectedPoints;
private int playerhighscore;
private boolean openEndScreen = false;
/* Formatierungsklasse */ /* Formatierungsklasse */
private final FormatingClass formatingClass = new FormatingClass(); private final FormatingClass formatingClass = new FormatingClass();
@ -70,8 +72,8 @@ public class HappyBirdMain extends Application {
private final Button backButtonPause = new Button("ZURÜCK"); private final Button backButtonPause = new Button("ZURÜCK");
private final Button background1 = new Button(); private final Button background1 = new Button();
private final Button background2 = new Button(); private final Button background2 = new Button();
private final Button backMenuButton = new Button(); private final Button backMenuButton = new Button("HAUPTMENÜ");
private final Button restartGameButton = new Button(); private final Button restartGameButton = new Button("NEU STARTEN");
private final Button personalHighscoresButton = new Button ("YOUR SCORES"); private final Button personalHighscoresButton = new Button ("YOUR SCORES");
private final Button backEndscreenButton = new Button("ZURÜCK"); private final Button backEndscreenButton = new Button("ZURÜCK");
@ -121,6 +123,7 @@ public class HappyBirdMain extends Application {
/*ArrayList, in der alle Rechtecke/ Pipes gespeichert werden*/ /*ArrayList, in der alle Rechtecke/ Pipes gespeichert werden*/
private final ArrayList<Rectangle> pipesArrayList = new ArrayList<Rectangle>(); private final ArrayList<Rectangle> pipesArrayList = new ArrayList<Rectangle>();
private final ArrayList<Rectangle> pipesToRemove = new ArrayList<Rectangle>();
/*Timeline, auf der sich die Pipes und der Vogel abspielen*/ /*Timeline, auf der sich die Pipes und der Vogel abspielen*/
private Timeline timeline; private Timeline timeline;
@ -337,7 +340,7 @@ public class HappyBirdMain extends Application {
*/ */
public void generateGameScreen() { public void generateGameScreen() {
menuScreenRunning = false; menuScreenRunning = false;
int playerhighscore = getPlayerHighscore(); playerhighscore = getPlayerHighscore();
highscoreLabel.setText("HIGHSCORE: " + playerhighscore); highscoreLabel.setText("HIGHSCORE: " + playerhighscore);
/*Headline-Label umbenennen*/ /*Headline-Label umbenennen*/
nameLabel.setText("KÜRZEL: " + acronym.getText()); nameLabel.setText("KÜRZEL: " + acronym.getText());
@ -433,11 +436,18 @@ public class HappyBirdMain extends Application {
collisionChecker = new AnimationTimer() { collisionChecker = new AnimationTimer() {
@Override @Override
public void handle(long timestamp) { public void handle(long timestamp) {
if (!openEndScreen) {
for (Rectangle rectangle : pipesArrayList) { for (Rectangle rectangle : pipesArrayList) {
if(rectangle != null){ if (rectangle != null) {
checkCollision(happyBird,rectangle); checkCollision(happyBird, rectangle);
} }
} }
for (Rectangle rectangle : pipesToRemove) {
pipesArrayList.remove(rectangle);
}
} else {
generateEndScreen();
}
} }
}; };
@ -464,12 +474,16 @@ public class HappyBirdMain extends Application {
/*Pausieren der Timeline, sodass keine neuen Pipes spawnen*/ /*Pausieren der Timeline, sodass keine neuen Pipes spawnen*/
timeline.stop(); timeline.stop();
gameRunning = false; gameRunning = false;
openEndScreen = true;
} }
if(happyBird.getBoundsInParent().getMaxX() > pipe.getBoundsInParent().getMaxX()) { if(happyBird.getBoundsInParent().getMaxX() > pipe.getBoundsInParent().getMaxX()) {
collectedPoints++; collectedPoints++;
int pointstoset = collectedPoints / 2; int pointsToSet = collectedPoints / 2;
currentScoreLabel.setText("SCORE: " + pointstoset); currentScoreLabel.setText("SCORE: " + pointsToSet);
pipesArrayList.remove(pipe); if (pointsToSet > playerhighscore) {
highscoreLabel.setText("HIGHSCORE: " + pointsToSet);
}
pipesToRemove.add(pipe);
} }
} }
@ -986,12 +1000,13 @@ public class HappyBirdMain extends Application {
currentScoreLabel.setVisible(false); currentScoreLabel.setVisible(false);
/**/ /**/
endScreen.setVisible(true);
endScreen.getChildren().add(endScreenHeadline); endScreen.getChildren().add(endScreenHeadline);
endScreenHeadline.setVisible(true); endScreenHeadline.setVisible(true);
endScreen.getChildren().add(currentScoreEndscreenLabel); endScreen.getChildren().add(currentScoreEndscreenLabel);
currentScoreEndscreenLabel.setText("YOUR SCORE: " + collectedPoints / 2);
currentScoreEndscreenLabel.setVisible(true); currentScoreEndscreenLabel.setVisible(true);
/* Buttons einfügen */ /* Buttons einfügen */
@ -1012,18 +1027,6 @@ public class HappyBirdMain extends Application {
//AB HIER MÜLL //AB HIER MÜLL
/*Überschrift einblenden - Text auf Game Over setzen */
headline.setVisible(true);
headline.setText("GAME OVER");
/*startGameButton anzeigen, Text zu "neu Starten" ändern und positionieren*/
startGameButton.setVisible(true);
startGameButton.setText("NEU STARTEN");
/*Button fürs Hauptmenü einblenden und positionieren*/
menuButton.setVisible(true);
/*Button für persönliche Highscores einblenden und positionieren*/
personalHighscoresButton.setVisible(true);
//personalHighscoresButton.setLayoutX();
//personalHighscoresButton.setLayoutY();
} }