Movement über Keys einbauen (W/S)
This commit is contained in:
parent
46bf46f92c
commit
b5daf848c4
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.
@ -21,6 +21,7 @@ import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HappyBirdMain extends Application {
|
||||
private int currentBirdPosition = 0;
|
||||
/* Formatierungsklasse */
|
||||
private final FormatingClass formatingClass = new FormatingClass();
|
||||
|
||||
@ -160,8 +161,8 @@ public class HappyBirdMain extends Application {
|
||||
*/
|
||||
public Rectangle createBird() {
|
||||
/* Startposition des Birds */
|
||||
int y = 325;
|
||||
int x = 50;
|
||||
int y = 325;
|
||||
|
||||
/* Erstellen eines Rechtecks mit der passenden Größe */
|
||||
Rectangle happyBird = new Rectangle(x,y,45,30);
|
||||
@ -649,7 +650,7 @@ public class HappyBirdMain extends Application {
|
||||
{
|
||||
generateGameScreen();
|
||||
System.out.println(gameRunning);
|
||||
|
||||
pauseButton.setDefaultButton(false);
|
||||
|
||||
/*Klick auf den Pause-Button, um das Pause-Menü aufzurufen*/
|
||||
pauseButton.setOnAction(event -> {
|
||||
@ -666,6 +667,19 @@ public class HappyBirdMain extends Application {
|
||||
gameRunning = !gameRunning;
|
||||
}
|
||||
});
|
||||
|
||||
currentBirdPosition = 0;
|
||||
scene.setOnKeyPressed(event -> {
|
||||
if (event.getCode() == KeyCode.S) {
|
||||
moveBirdDown();
|
||||
System.out.println(currentBirdPosition);
|
||||
}
|
||||
if (event.getCode() == KeyCode.W) {
|
||||
moveBirdUp();
|
||||
System.out.println(currentBirdPosition);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1065,4 +1079,13 @@ public class HappyBirdMain extends Application {
|
||||
generateMenueScreen();
|
||||
}
|
||||
|
||||
private void moveBirdUp() {
|
||||
currentBirdPosition = currentBirdPosition - 10;
|
||||
happyBird.setLayoutY(currentBirdPosition);
|
||||
}
|
||||
|
||||
private void moveBirdDown() {
|
||||
currentBirdPosition = currentBirdPosition + 10;
|
||||
happyBird.setLayoutY(currentBirdPosition);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user