PauseScreen aufrufen
This commit is contained in:
parent
d51c97c989
commit
9c028dd79e
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2
Happy_Bird/.idea/.name
generated
2
Happy_Bird/.idea/.name
generated
@ -1 +1 @@
|
||||
HappyBird.java
|
||||
HappyBirdMain.java
|
Binary file not shown.
Binary file not shown.
@ -7,13 +7,10 @@
|
||||
|
||||
<StackPane prefHeight="800.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.happy_bird.HappyBird" back >
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<ImageView>
|
||||
<image>
|
||||
<Image url="@pics/Background.png"></Image>
|
||||
</image>
|
||||
</ImageView>
|
||||
|
||||
>>>>>>> 5db5b6bb195a2b7d1296e7d3f9b98d6c75dba2c2
|
||||
</StackPane>
|
||||
|
Binary file not shown.
21
Happy_Bird/src/main/java/com/example/happy_bird/Bird.java
Normal file
21
Happy_Bird/src/main/java/com/example/happy_bird/Bird.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.example.happy_bird;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.ImageObserver;
|
||||
|
||||
public class Bird extends SpielObjekt {
|
||||
|
||||
public Bird(int xWert, int yWert) {
|
||||
super(xWert, yWert);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Graphics2D g, ImageObserver obs) {
|
||||
|
||||
}
|
||||
}
|
@ -1,11 +1,6 @@
|
||||
package com.example.happy_bird;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
@ -13,11 +8,12 @@ import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.image.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.text.TextAlignment;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HappyBirdMain extends Application {
|
||||
@ -31,6 +27,7 @@ public class HappyBirdMain extends Application {
|
||||
private Label soundLabel = new Label("SOUND");
|
||||
private Label currentScoreLabel = new Label("SCORE");
|
||||
private Label highscoreLabel = new Label("HIGHSCORE");
|
||||
private Label pauseMenu = new Label("Pause");
|
||||
private Label labels[] = {nameLabel, acronymLabel, soundLabel, currentScoreLabel, highscoreLabel};
|
||||
private Label headlineLabels[] = {headline};
|
||||
|
||||
@ -39,8 +36,10 @@ public class HappyBirdMain extends Application {
|
||||
private Button settingsButton = new Button("EINSTELLUNGEN");
|
||||
private Button startGameButton = new Button("SPIEL STARTEN");
|
||||
private Button menuButton = new Button("ZURÜCK");
|
||||
private Button pauseButton = new Button("PAUSE");
|
||||
private Button continueButton = new Button("WEITERSPIELEN");
|
||||
|
||||
private Button[] buttons = {startButton, highscoresButton, settingsButton, startGameButton, menuButton};
|
||||
private Button[] buttons = {startButton, highscoresButton, settingsButton, startGameButton, menuButton, pauseButton, continueButton};
|
||||
|
||||
private TextField name = new TextField();
|
||||
private TextField acronym = new TextField();
|
||||
@ -54,6 +53,10 @@ public class HappyBirdMain extends Application {
|
||||
private Image upperPipe = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeOben.png", 86, 300, false, false);
|
||||
private Image lowerPipe = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeUnten.png", 86, 300, false, false);
|
||||
|
||||
private Pane pause = new Pane();
|
||||
|
||||
private boolean gameRuns;
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -66,6 +69,39 @@ public class HappyBirdMain extends Application {
|
||||
stage.setTitle("Happy Bird");
|
||||
stage.setScene(scene);
|
||||
|
||||
generateMenueScene();
|
||||
|
||||
gameRuns = false;
|
||||
|
||||
/**ClickEvents:*/
|
||||
startButton.setOnAction(event -> {
|
||||
startButtonClick();
|
||||
});
|
||||
|
||||
settingsButton.setOnAction(event -> {
|
||||
settingsButtonClick();
|
||||
});
|
||||
|
||||
highscoresButton.setOnAction(event -> {
|
||||
highscoresButtonClick();
|
||||
});
|
||||
|
||||
menuButton.setOnAction(event -> {
|
||||
menuButtonClick();
|
||||
});
|
||||
|
||||
startGameButton.setOnAction(event -> {
|
||||
gameRuns = true;
|
||||
startGameButtonClick();
|
||||
});
|
||||
|
||||
|
||||
|
||||
stage.show();
|
||||
}
|
||||
|
||||
|
||||
public void generateMenueScene() {
|
||||
/**Bild für Hintergrund erstellen:*/
|
||||
Image image = new Image("file:src/main/resources/com/example/happy_bird/pics/Background.png");
|
||||
|
||||
@ -85,6 +121,12 @@ public class HappyBirdMain extends Application {
|
||||
|
||||
|
||||
/**Labels erstellen:*/
|
||||
//nameLabel = new Label("NAME");
|
||||
//acronymLabel = new Label("KÜRZEL");
|
||||
//headline = new Label("HAPPY BIRD");
|
||||
//soundLabel = new Label("SOUND");
|
||||
//currentScoreLabel = new Label("SCORE");
|
||||
//highscoreLabel = new Label("HIGHSCORE");
|
||||
|
||||
|
||||
/**Labels in Arrays speichern:*/
|
||||
@ -112,7 +154,11 @@ public class HappyBirdMain extends Application {
|
||||
|
||||
|
||||
/**Buttons erstellen:*/
|
||||
|
||||
//startButton = new Button("START");
|
||||
//highscoresButton = new Button("HIGHSCORES");
|
||||
//settingsButton = new Button("EINSTELLUNGEN");
|
||||
//startGameButton = new Button("SPIEL STARTEN");
|
||||
//menuButton = new Button("ZURÜCK");
|
||||
|
||||
/**Buttons in Array speichern:*/
|
||||
|
||||
@ -136,10 +182,14 @@ public class HappyBirdMain extends Application {
|
||||
/**startGameButton unsichtbar*/
|
||||
startGameButton.setVisible(false);
|
||||
|
||||
/**continueButton unsichtbar*/
|
||||
continueButton.setVisible(false);
|
||||
|
||||
|
||||
|
||||
/**Textfelder erstellen:*/
|
||||
|
||||
//name = new TextField();
|
||||
//acronym = new TextField();
|
||||
|
||||
/**Textfelder in Array speichern:*/
|
||||
|
||||
@ -158,31 +208,71 @@ public class HappyBirdMain extends Application {
|
||||
|
||||
|
||||
/**SoundSlider erstellen:*/
|
||||
|
||||
//soundSlider = new Slider();
|
||||
|
||||
/**SoundSlicer anpassen:*/
|
||||
soundSliderFormating(soundSlider, pane);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generiert den GameScreen durch Ausblenden und
|
||||
* Sichtbarmachen der richtigen Buttons, Labels, ...
|
||||
*/
|
||||
public void generateGameScreen() {
|
||||
/**Headline-Label umbenennen*/
|
||||
nameLabel.setText("NAME: " + acronym.getText());
|
||||
|
||||
/**ClickEvents:*/
|
||||
startButton.setOnAction(event -> {
|
||||
startButtonClick();
|
||||
});
|
||||
/**Textfelder ausblenden*/
|
||||
for(TextField feld : inputFields) {
|
||||
feld.setVisible(false);
|
||||
}
|
||||
|
||||
settingsButton.setOnAction(event -> {
|
||||
settingsButtonClick();
|
||||
});
|
||||
/**Labels ausblenden*/
|
||||
for (Label label : labels )
|
||||
{
|
||||
label.setVisible(false);
|
||||
}
|
||||
headline.setVisible(false);
|
||||
|
||||
highscoresButton.setOnAction(event -> {
|
||||
highscoresButtonClick();
|
||||
});
|
||||
/**nameLabel, currentScoreLabel und highscoreLabel positionieren und sichtbar machen*/
|
||||
nameLabel.setLayoutX(10);
|
||||
nameLabel.setLayoutY(10);
|
||||
nameLabel.setVisible(true);
|
||||
|
||||
menuButton.setOnAction(event -> {
|
||||
menuButtonClick();
|
||||
});
|
||||
currentScoreLabel.setLayoutX(540);
|
||||
currentScoreLabel.setLayoutY(10);
|
||||
currentScoreLabel.setVisible(true);
|
||||
|
||||
stage.show();
|
||||
highscoreLabel.setLayoutX(540);
|
||||
highscoreLabel.setLayoutY(70);
|
||||
highscoreLabel.setVisible(true);
|
||||
|
||||
/**Übrige Buttons ausblenden*/
|
||||
startGameButton.setVisible(false);
|
||||
menuButton.setVisible(false);
|
||||
|
||||
/**Pause-Button positionieren und sichtbar machen*/
|
||||
pauseButton.setLayoutX(575);
|
||||
pauseButton.setLayoutY(625);
|
||||
pauseButton.setVisible(true);
|
||||
|
||||
/**Vogel hinzufügen, bisher nur als Bild*/
|
||||
ImageView birdView = new ImageView(bird);
|
||||
pane.getChildren().add(birdView);
|
||||
birdView.setLayoutY(325);
|
||||
birdView.setLayoutX(50);
|
||||
|
||||
/**Pipes oben, unten hinzufügen, bisher nur als Bild*/
|
||||
ImageView upperPipeView = new ImageView(upperPipe);
|
||||
pane.getChildren().add(upperPipeView);
|
||||
upperPipeView.setLayoutX(400);
|
||||
upperPipeView.setLayoutY(0);
|
||||
|
||||
ImageView lowerPipeView = new ImageView(lowerPipe);
|
||||
pane.getChildren().add(lowerPipeView);
|
||||
lowerPipeView.setLayoutX(400);
|
||||
lowerPipeView.setLayoutY(430);
|
||||
}
|
||||
|
||||
/***
|
||||
@ -288,6 +378,20 @@ public class HappyBirdMain extends Application {
|
||||
slider.setVisible(false);
|
||||
}
|
||||
|
||||
/***
|
||||
* Formatiert den PauseScreen
|
||||
*/
|
||||
public void pauseScreenFormating() {
|
||||
pause.setLayoutX(200);
|
||||
pause.setLayoutY(100);
|
||||
pause.setPrefSize(400, 500);
|
||||
pause.setStyle("-fx-background-color: #DED894; " +
|
||||
"-fx-border-width: 5px;" +
|
||||
"-fx-border-color: #543847;" +
|
||||
"-fx-border-radius: 15px;" +
|
||||
"-fx-background-radius: 20px;");
|
||||
}
|
||||
|
||||
/***
|
||||
* Hauptmenü wird ausgeblendet, Nameneingabe folgt
|
||||
*/
|
||||
@ -367,40 +471,68 @@ public class HappyBirdMain extends Application {
|
||||
* Startet Spiel nach Namenseingabe
|
||||
*/
|
||||
public void startGameButtonClick() {
|
||||
nameLabel.setText("NAME: " + acronym.getText());
|
||||
for(TextField feld : inputFields) {
|
||||
feld.setVisible(false);
|
||||
}
|
||||
for (Label label : labels )
|
||||
{
|
||||
label.setVisible(false);
|
||||
}
|
||||
startGameButton.setVisible(false);
|
||||
menuButton.setVisible(false);
|
||||
headline.setVisible(false);
|
||||
ImageView birdView = new ImageView(bird);
|
||||
pane.getChildren().add(birdView);
|
||||
birdView.setLayoutY(325);
|
||||
birdView.setLayoutX(50);
|
||||
nameLabel.setLayoutX(10);
|
||||
nameLabel.setLayoutY(10);
|
||||
nameLabel.setVisible(true);
|
||||
generateGameScreen();
|
||||
|
||||
ImageView upperPipeView = new ImageView(upperPipe);
|
||||
pane.getChildren().add(upperPipeView);
|
||||
upperPipeView.setLayoutX(400);
|
||||
upperPipeView.setLayoutY(0);
|
||||
|
||||
ImageView lowerPipeView = new ImageView(lowerPipe);
|
||||
pane.getChildren().add(lowerPipeView);
|
||||
lowerPipeView.setLayoutX(400);
|
||||
lowerPipeView.setLayoutY(430);
|
||||
/**Klick auf den Pause-Button, um das Pause-Menü aufzurufen*/
|
||||
pauseButton.setOnAction(event -> {
|
||||
//
|
||||
if(gameRuns) {
|
||||
gameRuns = false;
|
||||
} else {
|
||||
gameRuns = true;
|
||||
}
|
||||
pauseButtonClick(gameRuns);
|
||||
});
|
||||
|
||||
currentScoreLabel.setLayoutX(540);
|
||||
currentScoreLabel.setLayoutY(10);
|
||||
currentScoreLabel.setVisible(true);
|
||||
highscoreLabel.setLayoutX(540);
|
||||
highscoreLabel.setLayoutY(70);
|
||||
highscoreLabel.setVisible(true);
|
||||
/**ESC-Tast drücken, um das Pause-Menü aufzurufen*/
|
||||
scene.setOnKeyPressed(e -> {
|
||||
if(e.getCode() == KeyCode.ESCAPE) {
|
||||
if(gameRuns) {
|
||||
gameRuns = false;
|
||||
pauseButtonClick(false);
|
||||
} else {
|
||||
gameRuns = true;
|
||||
pauseButtonClick(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/***
|
||||
* Ruft das Pause-Menü im Spiel auf oder blendet es wieder aus
|
||||
*/
|
||||
public void pauseButtonClick(Boolean gameRuns) {
|
||||
pauseScreenFormating();
|
||||
|
||||
/**PauseScreen aufrufen, wenn das Spiel läuft, sonst wieder ausblenden*/
|
||||
if(gameRuns) {
|
||||
/**PauseScreen ausblenden*/
|
||||
pause.setVisible(true);
|
||||
pauseButton.setVisible(false);
|
||||
highscoresButton.setVisible(true);
|
||||
settingsButton.setVisible(true);
|
||||
highscoresButton.setLayoutX(100);
|
||||
settingsButton.setLayoutX(100);
|
||||
|
||||
/**Zum PauseScreen hinzufügen*/
|
||||
pause.getChildren().add(settingsButton);
|
||||
pause.getChildren().add(highscoresButton);
|
||||
pane.getChildren().add(pause);
|
||||
} else {
|
||||
/**PauseScreen aufrufen/ sichtbar machen*/
|
||||
pause.setVisible(false);
|
||||
|
||||
pauseButton.setVisible(true);
|
||||
highscoresButton.setVisible(false);
|
||||
settingsButton.setVisible(false);
|
||||
highscoresButton.setLayoutX(300);
|
||||
settingsButton.setLayoutX(300);
|
||||
|
||||
/**Vom PauseScreen entfernen*/
|
||||
pause.getChildren().remove(settingsButton);
|
||||
pause.getChildren().remove(highscoresButton);
|
||||
pane.getChildren().remove(pause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,10 @@
|
||||
|
||||
<StackPane prefHeight="800.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.happy_bird.HappyBird" back >
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<ImageView>
|
||||
<image>
|
||||
<Image url="@pics/Background.png"></Image>
|
||||
</image>
|
||||
</ImageView>
|
||||
|
||||
>>>>>>> 5db5b6bb195a2b7d1296e7d3f9b98d6c75dba2c2
|
||||
</StackPane>
|
||||
|
Loading…
Reference in New Issue
Block a user