Gravitation & Velocity Jump Fix

This commit is contained in:
Gregor Bickmann 2022-02-09 14:55:20 +01:00
parent d835ec3460
commit e21b4c0f2d
16 changed files with 44 additions and 24 deletions

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

View File

@ -3,4 +3,9 @@
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="15" />
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="Happy_Bird.main" options="--add-exports java.base/jdk.internal.module=com.example.happy_bird" />
</option>
</component>
</project>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -21,6 +21,10 @@ import java.sql.ResultSet;
import java.util.ArrayList;
public class HappyBirdMain extends Application {
Thread thread;
private float velocity = 0f;
private float gravity = 0.25f;
private int birdPositionMovedBy = 0;
private int collectedPoints;
private int playerhighscore;
@ -505,6 +509,7 @@ public class HappyBirdMain extends Application {
}
}
/***
* Hauptmenü wird ausgeblendet, Nameneingabe folgt
*/
@ -694,18 +699,19 @@ public class HappyBirdMain extends Application {
/***
* Startet Spiel nach Namenseingabe
*/
public void startGameButtonClick() {
if (correctName() == 0 && correctAcronym() == 0)
{
generateGameScreen();
System.out.println(gameRunning);
System.out.println(this.gameRunning);
pauseButton.setDefaultButton(false);
/*Klick auf den Pause-Button, um das Pause-Menü aufzurufen*/
pauseButton.setOnAction(event -> {
if (!menuScreenRunning) {
pauseButtonClick(gameRunning);
gameRunning = !gameRunning;
pauseButtonClick(this.gameRunning);
this.gameRunning = !this.gameRunning;
}
});
@ -717,20 +723,37 @@ public class HappyBirdMain extends Application {
*/
birdPositionMovedBy = 0;
scene.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.S) {
moveBirdDown();
System.out.println(birdPositionMovedBy);
}
/*if (event.getCode() == KeyCode.S) {
moveBirdDown();
System.out.println(birdPositionMovedBy);
}*/
// FUNKTIONIERT
// aktuelle birdPositionMovedBy rausfid
/*if (event.getCode() == KeyCode.W) {
moveBirdUp();
}
if (event.getCode() == KeyCode.S) {
moveBirdDown();
}*/
if (event.getCode() == KeyCode.W) {
moveBirdUp();
System.out.println(birdPositionMovedBy);
}
else {
moveBirdDown();
}
if (event.getCode() == KeyCode.ESCAPE && !menuScreenRunning) {
pauseButtonClick(gameRunning);
gameRunning = !gameRunning;
pauseButtonClick(this.gameRunning);
this.gameRunning = !this.gameRunning;
}
});
} else {
checkNameLabel.setVisible(false);
checkAcronymLabel.setVisible(false);
@ -1168,12 +1191,16 @@ public class HappyBirdMain extends Application {
}
private void moveBirdUp() {
birdPositionMovedBy = birdPositionMovedBy - 10;
velocity = (float) -1.5;
var pos = velocity += gravity;
birdPositionMovedBy += pos;
happyBird.setLayoutY(birdPositionMovedBy);
}
// Soll Automatisch runter fallen
private void moveBirdDown() {
birdPositionMovedBy = birdPositionMovedBy + 10;
var pos = velocity -= gravity;
birdPositionMovedBy -= pos;
happyBird.setLayoutY(birdPositionMovedBy);
}
}