diff --git a/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin b/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin index b256089..b978099 100644 Binary files a/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin and b/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin differ diff --git a/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.lock b/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.lock index f653249..b039b63 100644 Binary files a/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.lock and b/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.lock differ diff --git a/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.bin b/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.bin index b4b154e..82340d4 100644 Binary files a/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.bin and b/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.bin differ diff --git a/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.lock b/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.lock index 54bfb98..574589e 100644 Binary files a/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.lock and b/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.lock differ diff --git a/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 8d9d088..7cd3b4b 100644 Binary files a/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/Happy_Bird/build/classes/java/main/com/example/happy_bird/HappyBirdMain.class b/Happy_Bird/build/classes/java/main/com/example/happy_bird/HappyBirdMain.class index f76937b..7c96fe4 100644 Binary files a/Happy_Bird/build/classes/java/main/com/example/happy_bird/HappyBirdMain.class and b/Happy_Bird/build/classes/java/main/com/example/happy_bird/HappyBirdMain.class differ diff --git a/Happy_Bird/build/classes/java/main/module-info.class b/Happy_Bird/build/classes/java/main/module-info.class index c6bee7e..9ac6a58 100644 Binary files a/Happy_Bird/build/classes/java/main/module-info.class and b/Happy_Bird/build/classes/java/main/module-info.class differ diff --git a/Happy_Bird/build/libs/Happy_Bird-1.0-SNAPSHOT.jar b/Happy_Bird/build/libs/Happy_Bird-1.0-SNAPSHOT.jar index dc7b7c1..6816fde 100644 Binary files a/Happy_Bird/build/libs/Happy_Bird-1.0-SNAPSHOT.jar and b/Happy_Bird/build/libs/Happy_Bird-1.0-SNAPSHOT.jar differ diff --git a/Happy_Bird/build/resources/main/com/example/happy_bird/pics/PipeBottom.png b/Happy_Bird/build/resources/main/com/example/happy_bird/pics/PipeBottom.png new file mode 100644 index 0000000..1db255a Binary files /dev/null and b/Happy_Bird/build/resources/main/com/example/happy_bird/pics/PipeBottom.png differ diff --git a/Happy_Bird/build/resources/main/com/example/happy_bird/pics/PipeTop.png b/Happy_Bird/build/resources/main/com/example/happy_bird/pics/PipeTop.png new file mode 100644 index 0000000..83b7271 Binary files /dev/null and b/Happy_Bird/build/resources/main/com/example/happy_bird/pics/PipeTop.png differ diff --git a/Happy_Bird/build/tmp/compileJava/previous-compilation-data.bin b/Happy_Bird/build/tmp/compileJava/previous-compilation-data.bin index 01de109..2eead97 100644 Binary files a/Happy_Bird/build/tmp/compileJava/previous-compilation-data.bin and b/Happy_Bird/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/Happy_Bird/src/main/java/com/example/happy_bird/FormatingClass.java b/Happy_Bird/src/main/java/com/example/happy_bird/FormatingClass.java index 11bbb9e..12b356d 100644 --- a/Happy_Bird/src/main/java/com/example/happy_bird/FormatingClass.java +++ b/Happy_Bird/src/main/java/com/example/happy_bird/FormatingClass.java @@ -236,4 +236,9 @@ public class FormatingClass { pane.getChildren().add(backgroundButtons[i]); } } + + + public void menueScreenFormating(Label[] labels, Button[] buttons) { + + } } diff --git a/Happy_Bird/src/main/java/com/example/happy_bird/GameObject.java b/Happy_Bird/src/main/java/com/example/happy_bird/GameObject.java index 0594ba0..6e36e87 100644 --- a/Happy_Bird/src/main/java/com/example/happy_bird/GameObject.java +++ b/Happy_Bird/src/main/java/com/example/happy_bird/GameObject.java @@ -1,34 +1,40 @@ package com.example.happy_bird; -import java.awt.*; -import java.util.Random; -public class GameObject { - int x, y, width, height; - Rectangle topPipe, bottomPipe; - int distance = 105; - boolean isPassedOn = false; +import javafx.scene.Node; - // Objekt Initialisierung +public abstract class GameObject extends Node { + protected int xKoord; + protected int yKoord; + protected int width; + protected int height; + protected boolean isPassedOn = false; + + /*** + * Konstruktor GameObject + * Variablen werden zugewiesen + * @param x x-Position + * @param y y-Position + * @param width Breite + * @param height Höhe + */ public GameObject(int x, int y, int width, int height) { - this.x = x; - this.y = y; + this.xKoord = x; + this.yKoord = y; this.width = width; this.height = height; - topPipe = new Rectangle(x, y, width, height); - bottomPipe = new Rectangle(x, height + distance, width, height); } - // Auf Anfangs Position setzen - public void resetToNewPosition(int newX) { - topPipe.x = newX; - bottomPipe.x = newX; - x = newX; - topPipe.y = -(new Random().nextInt(140) + 100); - bottomPipe.y = topPipe.y + height + distance; - isPassedOn = false; - } + public abstract void setImage(); + + /*** + * Setzt ein Object auf eine neue Position + * param newX neue x-Position + */ + public abstract void resetToNewPosition(int newX); + + /* // Prüfung ob Rectangle true oder false ist public boolean intersect(Rectangle rectangle) { return rectangle.intersects(topPipe) || rectangle.intersects(bottomPipe); @@ -36,13 +42,13 @@ public class GameObject { // Röhren Counter → Check, wenn Röhre durchflogen ist public boolean passedOn(Rectangle rectangle) { - return rectangle.x > x + width && !isPassedOn; + return rectangle.x > xKoord + width && !isPassedOn; } // Bei Bewegung der X Koordinate werden Röhren generiert public void moveX(int dx) { - x -= dx; + xKoord -= dx; topPipe.x -= dx; bottomPipe.x -= dx; - } -} \ No newline at end of file + }*/ +} diff --git a/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java b/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java index 001b3b9..a77cde5 100644 --- a/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java +++ b/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java @@ -1,16 +1,28 @@ package com.example.happy_bird; +import javafx.animation.*; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; import javafx.scene.layout.*; +import javafx.scene.paint.ImagePattern; import javafx.stage.Stage; +import javafx.scene.shape.*; +import javafx.util.Duration; +//import java.awt.*; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLOutput; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; public class HappyBirdMain extends Application { /* Formatierungsklasse */ @@ -85,8 +97,8 @@ public class HappyBirdMain extends Application { /*Bilder*/ private final Image bird = new Image("file:src/main/resources/com/example/happy_bird/pics/bird.png", 50, 35, false, false); - private final Image upperPipe = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeOben.png", 86, 300, false, false); - private final Image lowerPipe = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeUnten.png", 86, 300, false, false); + private final Image pipeTop = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeTop.png"); + private final Image pipeBottom = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeBottom.png"); /*Variablen für den Spielverlauf*/ //menuScreenRunning: das Hauptmenü ist aufgerufen @@ -94,16 +106,26 @@ public class HappyBirdMain extends Application { //gameRunning: das Spiel läuft/ GameScreen ist aufgerufen private boolean gameRunning; + + private TranslateTransition top; + private TranslateTransition bottom; + + private Timeline timeline; + private final ArrayList transitions = new ArrayList();; + public static void main(String[] args) { + + launch(args); + + } @Override public void start(Stage stage) { - stage.setTitle("Happy Bird"); stage.setScene(scene); - generateMenueScene(); + generateMenueScreen(); /*ClickEvents:*/ startButton.setOnAction(event -> startButtonClick()); @@ -119,11 +141,81 @@ public class HappyBirdMain extends Application { startGameButtonClick(); }); + stage.show(); } + /*** + * Erstellt zwei Pipes als Rectangle und fügt ihnen eine Animation über eine Transition hinzu + * @return pipes zwei Rectangles + */ + public Rectangle[] createPipes() { - public void generateMenueScene() { + /* y-Koordinate für die Pipes + * -300, da die obere Pipe 500px hoch ist */ + int y = (int) (Math.random() * (200))-300; + + /* Pipe oben; spawnt bei x=900 -> 100 Pixel neben Bild */ + Rectangle topPipe = new Rectangle(900, y, 91, 500); + + /* Pipe unten; spawnt auf der gleichen Höhe wie obere Pipe + * +400, da y-Koord die untere linke Ecke ist + * +250, der Abstand zwischen oberer Pipe und unterer Pipe */ + Rectangle bottomPipe = new Rectangle(900, y + 400 + 250, 91, 500); + + /* oberer Pipe ein Hintergrundbild geben */ + Image img = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeTop.png"); + topPipe.setFill(new ImagePattern(pipeTop)); + + /* unterer Pipe ein Hintergrundbild geben */ + img = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeBottom.png"); + bottomPipe.setFill(new ImagePattern(pipeBottom)); + + /* neue Animationen über TranslateTransitions */ + top = new TranslateTransition(); + bottom = new TranslateTransition(); + + /* top-Transition die obere Pipe hinzufügen */ + top.setNode(topPipe); + + /* die Pipe braucht 7 Sekunden, bis sie von rechts nach links gelaufen ist */ + top.setDuration(Duration.seconds(7)); + + /* Pipe läuft 1100px nach links */ + top.setToX(-1100); + + /* nach Erreichen des linken Randes, wird topPipe von Pane entfernt */ + top.setOnFinished(e -> { + pane.getChildren().remove(topPipe); + }); + + + /* top-Transition die untere Pipe hinzufügen */ + bottom.setNode(bottomPipe); + + /* die Pipe braucht 7 Sekunden, bis sie von rechts nach links gelaufen ist */ + bottom.setDuration(Duration.seconds(7)); + + /* Pipe läuft 1100px nach links */ + bottom.setToX(-1100); + + /* nach Erreichen des linken Randes, wird topPipe von Pane entfernt */ + bottom.setOnFinished(e -> { + pane.getChildren().remove(bottomPipe); + }); + + /* Array für die Pipes */ + Rectangle[] pipes = {topPipe, bottomPipe}; + + /* Transitions in ArrayList speichern, um sie nachher stoppen zu können */ + transitions.add(top); + transitions.add(bottom); + + return pipes; + } + + + public void generateMenueScreen() { dataQuery(); menuScreenRunning = true; @@ -204,8 +296,9 @@ public class HappyBirdMain extends Application { yPositionInputFields += 150; } - /*SoundSlicer anpassen:*/ + /*SoundSlider anpassen:*/ formatingClass.soundSliderFormating(soundSlider, pane); + } /** @@ -260,7 +353,7 @@ public class HappyBirdMain extends Application { birdView.setLayoutY(325); birdView.setLayoutX(50); - /*Pipes oben, unten hinzufügen, bisher nur als Bild*/ + /*Pipes oben, unten hinzufügen, bisher nur als Bild ImageView upperPipeView = new ImageView(upperPipe); pane.getChildren().add(upperPipeView); upperPipeView.setLayoutX(400); @@ -269,7 +362,27 @@ public class HappyBirdMain extends Application { ImageView lowerPipeView = new ImageView(lowerPipe); pane.getChildren().add(lowerPipeView); lowerPipeView.setLayoutX(400); - lowerPipeView.setLayoutY(430); + lowerPipeView.setLayoutY(430);*/ + + + /*Timeline: alle 2 Sekunden spawnt eine neue Pipe am rechten Rand*/ + timeline = new Timeline(new KeyFrame(Duration.seconds(2), e ->{ + /*Pipes erstellen*/ + Rectangle[] pipesTopBottom = createPipes(); + + /*Pipes der Pane hinzufügen*/ + for(Rectangle pipe : pipesTopBottom) { + pane.getChildren().add(pipe); + } + + /*Transitions abspielen*/ + top.play(); + bottom.play(); + })); + + timeline.setCycleCount(Animation.INDEFINITE); + + timeline.play(); } /*** @@ -474,7 +587,6 @@ public class HappyBirdMain extends Application { } else { System.out.println("Name oder Kürzel falsch!"); } - } /*** @@ -552,10 +664,20 @@ public class HappyBirdMain extends Application { menuButtonPause.setOnAction(event -> { menuButtonPauseClick(); - generateMenueScene(); + generateMenueScreen(); }); settingsButtonPause.setOnAction(event -> settingsButtonPauseClick()); + + /*Pausieren der Transitions/ Pipes*/ + for(Transition transition : transitions) { + transition.pause(); + System.out.println(transition.toString()); + } + + /*Pausieren der Timeline, sodass keine neuen Pipes spawnen*/ + timeline.pause(); + } else { /*pauseButton einblenden*/ pauseButton.setVisible(true); @@ -568,6 +690,14 @@ public class HappyBirdMain extends Application { /*pause von pane entfernen*/ pane.getChildren().remove(pause); + + /*Wiederabspielen der Transitions/ Pipes*/ + for(Transition transition : transitions) { + transition.play(); + } + + /*Wiederabspielen der Timeline, sodass neue Pipes spawnen*/ + timeline.play(); } } @@ -845,6 +975,6 @@ public class HappyBirdMain extends Application { */ private void backMenuButtonClick() { pane.getChildren().remove(endScreen); - generateMenueScene(); + generateMenueScreen(); } } \ No newline at end of file diff --git a/Happy_Bird/src/main/java/com/example/happy_bird/Pipes.java b/Happy_Bird/src/main/java/com/example/happy_bird/Pipes.java new file mode 100644 index 0000000..28ef7dc --- /dev/null +++ b/Happy_Bird/src/main/java/com/example/happy_bird/Pipes.java @@ -0,0 +1,110 @@ +package com.example.happy_bird; + +import javafx.animation.AnimationTimer; +import javafx.animation.Transition; +import javafx.animation.TranslateTransition; +import javafx.scene.Node; +import javafx.scene.image.Image; +import javafx.scene.layout.Pane; +import javafx.scene.paint.ImagePattern; +import javafx.scene.shape.Rectangle; +import javafx.animation.TranslateTransition; +import javafx.util.Duration; + +public class Pipes extends Rectangle { + private int y; + private Rectangle topPipe; + private Rectangle bottomPipe; + private int distanceBeweenPipes = 250; + private boolean isPassedOn = false; + /*** + * Konstruktor GameObject + * Variablen werden zugewiesen + * param x x-Position + * param y y-Position + * param width Breite + * param height Höhe + */ + public Pipes(){ + + } + + + public Rectangle[] createPipes(Transition top, Transition bottom, Pane pane) { + int y = (int) (Math.random() * (200))-300; + Rectangle topPipe = new Rectangle(1000, y, 91, 500); + Rectangle bottomPipe = new Rectangle(1000, y + 400 + 250, 91, 500); + + + Image img = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeTop.png"); + topPipe.setFill(new ImagePattern(img)); + + img = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeBottom.png"); + bottomPipe.setFill(new ImagePattern(img)); + + top = new TranslateTransition(); + bottom = new TranslateTransition(); + + ((TranslateTransition) top).setNode(topPipe); + ((TranslateTransition) top).setDuration(Duration.seconds(5)); + ((TranslateTransition) top).setToX(-1200); + top.setOnFinished(e -> { + pane.getChildren().remove(topPipe); + }); + + ((TranslateTransition) bottom).setNode(bottomPipe); + ((TranslateTransition) bottom).setDuration(Duration.seconds(5)); + ((TranslateTransition) bottom).setToX(-1200); + bottom.setOnFinished(e -> { + pane.getChildren().remove(bottomPipe); + }); + + Rectangle[] pipes = {topPipe, bottomPipe}; + return pipes; + } + + public void destroy(Pane pane) { + + pane.getChildren().remove(topPipe); + pane.getChildren().remove(bottomPipe); + } + + /*** + * Setzt für die beiden Rechtecke der Pipes das Hintergrundbild + */ + public void setImage() { + Image img = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeTop.png"); + topPipe.setFill(new ImagePattern(img)); + + img = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeBottom.png"); + bottomPipe.setFill(new ImagePattern(img)); + } + + /*** + * Setzt ein Object auf eine neue Position + * param newX neue x-Position + */ + public void resetToNewPosition(int newX) { + topPipe.setX(newX); + bottomPipe.setX(newX); + //xKoord = newX; + } + + /* + // Prüfung ob Rectangle true oder false ist + public boolean intersect(Rectangle rectangle) { + return rectangle.intersects(topPipe) || rectangle.intersects(bottomPipe); + } + + // Röhren Counter → Check, wenn Röhre durchflogen ist + public boolean passedOn(Rectangle rectangle) { + return rectangle.x > xKoord + width && !isPassedOn; + } + + // Bei Bewegung der X Koordinate werden Röhren generiert + public void moveX(int dx) { + xKoord -= dx; + topPipe.x -= dx; + bottomPipe.x -= dx; + }*/ +} \ No newline at end of file diff --git a/Happy_Bird/src/main/resources/com/example/happy_bird/pics/PipeBottom.png b/Happy_Bird/src/main/resources/com/example/happy_bird/pics/PipeBottom.png new file mode 100644 index 0000000..1db255a Binary files /dev/null and b/Happy_Bird/src/main/resources/com/example/happy_bird/pics/PipeBottom.png differ diff --git a/Happy_Bird/src/main/resources/com/example/happy_bird/pics/PipeTop.png b/Happy_Bird/src/main/resources/com/example/happy_bird/pics/PipeTop.png new file mode 100644 index 0000000..83b7271 Binary files /dev/null and b/Happy_Bird/src/main/resources/com/example/happy_bird/pics/PipeTop.png differ