Skip to content
Snippets Groups Projects
Commit db2c9818 authored by Rebekka Aashaug Stangvik's avatar Rebekka Aashaug Stangvik
Browse files

added setting button to create game

parent a18f8680
No related branches found
No related tags found
1 merge request!19Resolve "Add settings button"
......@@ -2,10 +2,12 @@ package com.wordbattle.game.controller;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.wordbattle.game.network.FirebaseInterface;
import com.wordbattle.game.states.LobbyState;
import com.wordbattle.game.states.CreateGameState;
import com.wordbattle.game.states.SettingsState;
import com.wordbattle.game.view.CreateGameView;
public class CreateGameController {
......@@ -24,6 +26,7 @@ public class CreateGameController {
if (Gdx.input.justTouched()) {
Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
state.getCam().unproject(touchPos); // convert from screen coordinates to world coordinates
Rectangle settingsBounds = createGameView.getSettingsBounds();
// Assuming createGameView exposes the bounds via getters
if (createGameView.getEasyButtonBounds().contains(touchPos.x, touchPos.y)) {
......@@ -42,6 +45,10 @@ public class CreateGameController {
state.getStateManager().setState(new LobbyState(state.getStateManager(), createGameView.getPin(), createGameView.getNickname(), _FBIC));
}
if (settingsBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Settings Pressed");
state.getStateManager().setState(new SettingsState(state.getStateManager(), _FBIC));
}
}
}
......
......@@ -43,11 +43,12 @@ public class SettingsController {
if (goBackButtonBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Go back button is pressed");
state.getStateManager().setState(new MainMenuState(state.getStateManager(), _FBIC));
state.getStateManager().returnToPreviousState();
}
if (quitGameButtonBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Go back button is pressed");
System.out.println("Quit game");
state.getStateManager().setState(new MainMenuState(state.getStateManager(), _FBIC));
}
......
......@@ -6,6 +6,7 @@ public class StateManager {
private GameState currentState;
private GameState previousState;
public StateManager() {
......@@ -14,12 +15,19 @@ public class StateManager {
public void setState(GameState newState) {
if (currentState != null) {
previousState = currentState;
currentState.exit();
}
currentState = newState;
newState.enter(); // Ensure resources are ready before updating or rendering
}
public void returnToPreviousState() {
if (previousState != null) {
setState(previousState);
}
}
public void update(float dt) {
if (currentState != null) currentState.update(dt);
......
......@@ -43,7 +43,7 @@ public class CreateGameView {
private String pin;
private String selectedLevel = "easy"; // default to easy
private Rectangle settingsBounds;
public CreateGameView(OrthographicCamera cam) {
......@@ -71,14 +71,19 @@ public class CreateGameView {
nicknameField.setAlignment(1); // 1 = Center
nicknameField.setMaxLength(15); // Max chars set to 15
settingsBounds = new Rectangle(
WordBattle.WIDTH - 100,
WordBattle.HEIGHT - 100,
100,
100
);
// Generate a random PIN
pin = generateRandomPin();
// Load textures
backgroundTexture = new Texture("bg2.png");
backgroundTexture = new Texture("bgWithSettings.png");
nicknameTexture = new Texture("pink_long-01.png");
createGameTexture = new Texture("Golden_long-01.png");
// Levels, non-selected
......@@ -107,6 +112,7 @@ public class CreateGameView {
stage.addActor(nicknameField);
}
public Rectangle getSettingsBounds() { return settingsBounds; }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment