Gravitation & Velocity Jump Fix &

Pipe anpassen
This commit is contained in:
Gregor Bickmann 2022-02-10 08:32:00 +01:00
parent e21b4c0f2d
commit 0f2352e003
10 changed files with 15 additions and 6 deletions

View File

@ -9,6 +9,7 @@ import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.scene.paint.ImagePattern; import javafx.scene.paint.ImagePattern;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -21,7 +22,6 @@ import java.sql.ResultSet;
import java.util.ArrayList; import java.util.ArrayList;
public class HappyBirdMain extends Application { public class HappyBirdMain extends Application {
Thread thread;
private float velocity = 0f; private float velocity = 0f;
private float gravity = 0.25f; private float gravity = 0.25f;
@ -103,8 +103,7 @@ public class HappyBirdMain extends Application {
private final Slider soundSliderPause = new Slider(); private final Slider soundSliderPause = new Slider();
/*Bilder*/ /*Bilder*/
private final Image bird = new Image("file:src/main/resources/com/example/happy_bird/pics/bird.png", private final Image bird = new Image("file:src/main/resources/com/example/happy_bird/pics/bird.png");
45, 30, false, false);
private final Image pipeTop = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeTop.png"); 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"); private final Image pipeBottom = new Image("file:src/main/resources/com/example/happy_bird/pics/PipeBottom.png");
@ -412,7 +411,7 @@ public class HappyBirdMain extends Application {
/*Timeline: alle 2 Sekunden spawnt eine neue Pipe am rechten Rand*/ /*Timeline: alle 2 Sekunden spawnt eine neue Pipe am rechten Rand*/
timeline = new Timeline(new KeyFrame(Duration.seconds(2), e ->{ timeline = new Timeline(new KeyFrame(Duration.seconds(1.5), e ->{
/*Pipes erstellen*/ /*Pipes erstellen*/
Rectangle[] pipesTopBottom = createPipes(); Rectangle[] pipesTopBottom = createPipes();
@ -696,6 +695,17 @@ public class HappyBirdMain extends Application {
} }
} }
public void keyPressed(KeyEvent e) {
scene.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.W) {
moveBirdUp();
}
if (event.getCode() == KeyCode.S) {
moveBirdDown();
}
});
};
/*** /***
* Startet Spiel nach Namenseingabe * Startet Spiel nach Namenseingabe
*/ */
@ -740,7 +750,6 @@ public class HappyBirdMain extends Application {
moveBirdDown(); moveBirdDown();
}*/ }*/
if (event.getCode() == KeyCode.W) { if (event.getCode() == KeyCode.W) {
moveBirdUp(); moveBirdUp();
} }
@ -1191,7 +1200,7 @@ public class HappyBirdMain extends Application {
} }
private void moveBirdUp() { private void moveBirdUp() {
velocity = (float) -1.5; velocity = (float) -4.5;
var pos = velocity += gravity; var pos = velocity += gravity;
birdPositionMovedBy += pos; birdPositionMovedBy += pos;
happyBird.setLayoutY(birdPositionMovedBy); happyBird.setLayoutY(birdPositionMovedBy);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 65 KiB