Skip to content
Snippets Groups Projects
Commit 3a29416d authored by Elias Fierke's avatar Elias Fierke
Browse files

[chore:] various improvements and initial-ESCAPE-Menu

parent ceedbdc3
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.TimeUtils;
import com.badlogic.gdx.graphics.Texture;
......@@ -22,6 +23,7 @@ import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.fiewie.idlespaceshiptycoon.gameobjects.SpaceShip;
import com.fiewie.idlespaceshiptycoon.logic.SoundManager;
import com.fiewie.idlespaceshiptycoon.gameobjects.Enemy;
import com.fiewie.idlespaceshiptycoon.Exception.NotImplementedException;
import com.fiewie.idlespaceshiptycoon.gameobjects.Background;
import com.fiewie.idlespaceshiptycoon.gameobjects.BackgroundManager;
import com.fiewie.idlespaceshiptycoon.gameobjects.Bullet;
......@@ -35,10 +37,12 @@ public class GameStage extends Stage {
private long lastSpawnTime;
private int score;
private boolean isGameOver;
private boolean isPaused = false;
private Table gameOverMenu;
public Label scoreLabel;
public Label coinLabel;
public Image coinImage;
private Table pausedMenu;
//public static BackgroundPool background_pool = new BackgroundPool();
......@@ -57,9 +61,9 @@ public class GameStage extends Stage {
addActor(scoreLabel);
coinImage = new Image(new Texture("icon/coin.png"));
coinImage.setPosition(getWidth() - coinImage.getWidth() - 10, getHeight()-coinImage.getHeight()-10);
coinImage.setPosition(10, getHeight()-coinImage.getHeight()-78);
coinLabel = new Label("0", defaultLabelStyle);
coinLabel.setPosition(getWidth() - coinImage.getWidth() - coinLabel.getWidth() - 20, getHeight()-coinLabel.getHeight()-10);
coinLabel.setPosition(coinImage.getWidth() + 20, getHeight()-coinLabel.getHeight()-70);
addActor(coinLabel);
addActor(coinImage);
......@@ -74,7 +78,7 @@ public class GameStage extends Stage {
@Override
public void act(float delta) {
if (isGameOver) return; // Stoppe das Spiel, wenn Game Over
if (isGameOver || isPaused) return; // Stoppe das Spiel, wenn Game Over
super.act(delta);
handleInput();
......@@ -82,6 +86,7 @@ public class GameStage extends Stage {
updateBullets(delta);
checkCollisions();
handleGameOver();
handlePaused();
updateBackground();
scoreLabel.setText("Score: " + score);
}
......@@ -92,7 +97,10 @@ public class GameStage extends Stage {
}
private void handleInput() {
if (isGameOver) return; // Keine Eingaben nach Game Over
if(Gdx.input.isKeyPressed(Input.Keys.ESCAPE)){
isPaused = !isPaused; // Wert tauschen
}
if (isGameOver || isPaused) return; // Keine weiteren Eingaben nach Game Over oder bei pausiertem Spiel
if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.isKeyPressed(Input.Keys.A)) {
ship.moveLeft();
......@@ -143,7 +151,7 @@ public class GameStage extends Stage {
coins.removeValue(coin, true);
SoundManager.getInstance().playSound("sounds/coin.mp3");
coinLabel.setText(ship.coins);
coinLabel.setPosition(getWidth() - coinImage.getWidth() - coinLabel.getWidth() - 20, getHeight()-coinLabel.getHeight()-10);
coinLabel.setPosition(coinImage.getWidth() + 20, getHeight()-coinLabel.getHeight()-70);
}
}
for (Enemy enemy : enemies) {
......@@ -184,6 +192,47 @@ public class GameStage extends Stage {
}
}
private void handlePaused() {
if (isPaused) {
System.out.println("Paused");
showPausedMenu();
} else {
if (pausedMenu != null) {
pausedMenu.remove();
}
}
}
private void showPausedMenu() {
pausedMenu = new Table();
pausedMenu.setFillParent(true);
TextureRegionDrawable buttonTexture = new TextureRegionDrawable(new Texture("button_new.png"));
TextureRegionDrawable buttonTextureClicked = new TextureRegionDrawable(new Texture("button_new_click.png"));
ImageButton resumeButton = new ImageButton(buttonTexture, buttonTextureClicked);
resumeButton.addListener(event -> {
if (event.isHandled()) {
isPaused = false;
}
return false;
});
ImageButton mainMenuButton = new ImageButton(buttonTexture, buttonTextureClicked);
mainMenuButton.addListener(event -> {
if(event.isHandled()){
throw new NotImplementedException();
}
return false;
});
pausedMenu.add(resumeButton).row();
pausedMenu.add(mainMenuButton).row();
// Füge das Pausenmenü zur Szene hinzu
addActor(pausedMenu);
}
private void showGameOverMenu() {
gameOverMenu = new Table();
gameOverMenu.setFillParent(true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment