Skip to content
Snippets Groups Projects
Commit eb1c303c authored by Sixten Müller's avatar Sixten Müller
Browse files

Merge branch '2-create-game-model' of...

Merge branch '2-create-game-model' of https://gitlab.stud.idi.ntnu.no/sixtenm/progarkproject into 2-create-game-model
parents 6d1ea92d 7c463135
No related branches found
No related tags found
No related merge requests found
Showing
with 347 additions and 57 deletions
...@@ -354,7 +354,8 @@ public class AndroidInterfaceClass implements FirebaseInterface { ...@@ -354,7 +354,8 @@ public class AndroidInterfaceClass implements FirebaseInterface {
if (!words.isEmpty()) { if (!words.isEmpty()) {
long seed = generateSeedFromPin(pin); long seed = generateSeedFromPin(pin);
Collections.shuffle(words, new Random(seed)); Collections.shuffle(words, new Random(seed));
String selectedWord = words.get(0);
String selectedWord = words.get(new Random().nextInt(words.size()));
callback.onWordFetched(selectedWord); callback.onWordFetched(selectedWord);
} }
} }
......
File added
assets/bgWithSettings.png

56.3 KiB

assets/bg_btn_settings.png

61.1 KiB

File added
assets/correctBg.png

87.6 KiB

assets/offButton.png

23 KiB

assets/onButton.png

24.5 KiB

assets/quitGameBtn.png

22 KiB

assets/settingsBg1.png

59.5 KiB

...@@ -8,6 +8,10 @@ import com.wordbattle.game.model.CreateWords; ...@@ -8,6 +8,10 @@ import com.wordbattle.game.model.CreateWords;
import com.wordbattle.game.network.FirebaseInterface; import com.wordbattle.game.network.FirebaseInterface;
import com.wordbattle.game.states.MainMenuState; import com.wordbattle.game.states.MainMenuState;
import com.wordbattle.game.states.StateManager; import com.wordbattle.game.states.StateManager;
import com.wordbattle.game.manager.SoundManager;
import com.wordbattle.game.manager.MusicManager;
import com.wordbattle.game.manager.MusicManager;
public class WordBattle extends ApplicationAdapter { public class WordBattle extends ApplicationAdapter {
public static final int WIDTH = 480; public static final int WIDTH = 480;
...@@ -30,6 +34,9 @@ public class WordBattle extends ApplicationAdapter { ...@@ -30,6 +34,9 @@ public class WordBattle extends ApplicationAdapter {
// createWords.updateDB(); // createWords.updateDB();
ScreenUtils.clear(1, 0, 0, 1); ScreenUtils.clear(1, 0, 0, 1);
stateManager.setState(new MainMenuState(stateManager, _FBIC)); // Set the main menu as the initial state stateManager.setState(new MainMenuState(stateManager, _FBIC)); // Set the main menu as the initial state
MusicManager.initialize();
MusicManager.playMusic();
SoundManager.initialize();
} }
@Override @Override
public void render() { public void render() {
...@@ -42,6 +49,5 @@ public class WordBattle extends ApplicationAdapter { ...@@ -42,6 +49,5 @@ public class WordBattle extends ApplicationAdapter {
stateManager.dispose(); // Assuming you have a dispose method in your StateManager stateManager.dispose(); // Assuming you have a dispose method in your StateManager
batch.dispose(); // Dispose of the SpriteBatch here. batch.dispose(); // Dispose of the SpriteBatch here.
} }
} }
\ No newline at end of file
...@@ -2,11 +2,20 @@ package com.wordbattle.game.controller; ...@@ -2,11 +2,20 @@ package com.wordbattle.game.controller;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.wordbattle.game.manager.SoundManager;
import com.wordbattle.game.network.FirebaseInterface; import com.wordbattle.game.network.FirebaseInterface;
import com.wordbattle.game.states.LobbyState; import com.wordbattle.game.states.LobbyState;
import com.wordbattle.game.states.CreateGameState; import com.wordbattle.game.states.CreateGameState;
import com.wordbattle.game.states.MainMenuState;
import com.wordbattle.game.states.SettingsState;
import com.wordbattle.game.view.CreateGameView; import com.wordbattle.game.view.CreateGameView;
import com.wordbattle.game.manager.SoundManager;
import com.wordbattle.game.states.MainMenuState;
import com.wordbattle.game.states.SettingsState;
import com.badlogic.gdx.math.Rectangle;
public class CreateGameController { public class CreateGameController {
private CreateGameState state; private CreateGameState state;
...@@ -22,8 +31,10 @@ public class CreateGameController { ...@@ -22,8 +31,10 @@ public class CreateGameController {
} }
public void handleInput() { public void handleInput() {
if (Gdx.input.justTouched()) { if (Gdx.input.justTouched()) {
SoundManager.playClickSound();
Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
state.getCam().unproject(touchPos); // convert from screen coordinates to world coordinates state.getCam().unproject(touchPos); // convert from screen coordinates to world coordinates
Rectangle settingsBounds = createGameView.getSettingsBounds();
// Assuming createGameView exposes the bounds via getters // Assuming createGameView exposes the bounds via getters
if (createGameView.getEasyButtonBounds().contains(touchPos.x, touchPos.y)) { if (createGameView.getEasyButtonBounds().contains(touchPos.x, touchPos.y)) {
...@@ -42,6 +53,26 @@ public class CreateGameController { ...@@ -42,6 +53,26 @@ public class CreateGameController {
if (confirmNickname()) { if (confirmNickname()) {
state.getStateManager().setState(new LobbyState(state.getStateManager(), createGameView.getPin(), createGameView.getNickname(), _FBIC)); state.getStateManager().setState(new LobbyState(state.getStateManager(), createGameView.getPin(), createGameView.getNickname(), _FBIC));
} }
else{
createGameView.setNickNameMessage("Wrong pin");
}
}
if (settingsBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Settings Pressed");
state.getStateManager().setState(new SettingsState(state.getStateManager(), _FBIC));
}
if (createGameView.getGoBackButtonBounds().contains(touchPos.x, touchPos.y)) {
state.getStateManager().setState(new MainMenuState(state.getStateManager(), _FBIC ));
}
if (settingsBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Settings Pressed");
state.getStateManager().setState(new SettingsState(state.getStateManager(), _FBIC));
}
if (createGameView.getGoBackButtonBounds().contains(touchPos.x, touchPos.y)) {
state.getStateManager().setState(new MainMenuState(state.getStateManager(), _FBIC ));
} }
} }
} }
...@@ -62,6 +93,8 @@ public class CreateGameController { ...@@ -62,6 +93,8 @@ public class CreateGameController {
createGameView.render(sb); createGameView.render(sb);
} }
public void dispose() { public void dispose() {
createGameView.dispose(); createGameView.dispose();
} }
......
...@@ -6,6 +6,7 @@ import com.badlogic.gdx.math.Rectangle; ...@@ -6,6 +6,7 @@ import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.wordbattle.game.network.FirebaseInterface; import com.wordbattle.game.network.FirebaseInterface;
import com.wordbattle.game.states.GamePlayState; import com.wordbattle.game.states.GamePlayState;
import com.wordbattle.game.states.SettingsState;
import com.wordbattle.game.states.WaitingLobbyState; import com.wordbattle.game.states.WaitingLobbyState;
import com.wordbattle.game.view.CreateGameView; import com.wordbattle.game.view.CreateGameView;
import com.wordbattle.game.view.GamePlayView; import com.wordbattle.game.view.GamePlayView;
...@@ -30,6 +31,8 @@ public class GamePlayController { ...@@ -30,6 +31,8 @@ public class GamePlayController {
public GamePlayController(GamePlayState state, FirebaseInterface _FBIC, String pin, String nickname) { public GamePlayController(GamePlayState state, FirebaseInterface _FBIC, String pin, String nickname) {
this.state = state; this.state = state;
this._FBIC = _FBIC; this._FBIC = _FBIC;
...@@ -46,12 +49,15 @@ public class GamePlayController { ...@@ -46,12 +49,15 @@ public class GamePlayController {
public void handleInput() { public void handleInput() {
if (Gdx.input.justTouched()) { if (Gdx.input.justTouched()) {
Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
state.getCam().unproject(touchPos); // Adjusts the touch position to the game's coordinate system. state.getCam().unproject(touchPos); // Adjusts the touch position to the game's coordinate system.
System.out.println("Clicked on the screen"); System.out.println("Clicked on the screen");
Rectangle settingsBounds = gamePlayView.getSettingsBounds();
if (settingsBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Settings Pressed");
state.getStateManager().setState(new SettingsState(state.getStateManager(), _FBIC));
}
for (int i = 0; i < gamePlayView.getLetterBounds().length; i++) { for (int i = 0; i < gamePlayView.getLetterBounds().length; i++) {
if (gamePlayView.getLetterBounds()[i].contains(touchPos.x, touchPos.y)) { if (gamePlayView.getLetterBounds()[i].contains(touchPos.x, touchPos.y)) {
// The i-th letter was clicked // The i-th letter was clicked
...@@ -97,8 +103,6 @@ public class GamePlayController { ...@@ -97,8 +103,6 @@ public class GamePlayController {
break; // Break from the loop checking letter bounds break; // Break from the loop checking letter bounds
} }
} }
for (int i = 0; i < gamePlayView.getLetterBoxBounds().length; i++) { for (int i = 0; i < gamePlayView.getLetterBoxBounds().length; i++) {
if (gamePlayView.getLetterBoxBounds()[i].contains(touchPos.x, touchPos.y)) { if (gamePlayView.getLetterBoxBounds()[i].contains(touchPos.x, touchPos.y)) {
Character letterToRemove = gamePlayView.getFilledBoxes()[i]; Character letterToRemove = gamePlayView.getFilledBoxes()[i];
...@@ -197,9 +201,15 @@ public class GamePlayController { ...@@ -197,9 +201,15 @@ public class GamePlayController {
public void update(float dt) { public void update(float dt) {
gamePlayView.update(dt); gamePlayView.update(dt);
handleInput(); handleInput();
//Check if gameTimer is up. If so allert database, award player 0 points and go to waitingLobby.
if (!gamePlayView.isTimerRunning()){
_FBIC.updateFinishedFlag(nickname, pin);
state.getStateManager().setState(new WaitingLobbyState(state.getStateManager(), _FBIC, nickname, 0, pin));
}
} }
public int calculateScore(float timeLeft, float maxTime) { public int calculateScore(float timeLeft, float maxTime) {
// Parameters to shape the S-curve // Parameters to shape the S-curve
float steepness = 10.0f; // Change this to make the curve steeper or shallower float steepness = 10.0f; // Change this to make the curve steeper or shallower
......
...@@ -8,11 +8,13 @@ import com.wordbattle.game.network.FirebaseInterface; ...@@ -8,11 +8,13 @@ import com.wordbattle.game.network.FirebaseInterface;
import com.wordbattle.game.states.CreateGameState; import com.wordbattle.game.states.CreateGameState;
import com.wordbattle.game.states.JoinGameState; import com.wordbattle.game.states.JoinGameState;
import com.wordbattle.game.states.MainMenuState; import com.wordbattle.game.states.MainMenuState;
import com.wordbattle.game.states.SettingsState;
import com.wordbattle.game.states.StartingGameState; import com.wordbattle.game.states.StartingGameState;
import com.wordbattle.game.states.WaitForHostState; import com.wordbattle.game.states.WaitForHostState;
import com.wordbattle.game.states.WaitingLobbyState; import com.wordbattle.game.states.WaitingLobbyState;
import com.wordbattle.game.view.JoinGameView; import com.wordbattle.game.view.JoinGameView;
import com.wordbattle.game.view.MainMenuView; import com.wordbattle.game.view.MainMenuView;
import com.wordbattle.game.states.SettingsState;
public class JoinGameController { public class JoinGameController {
...@@ -23,6 +25,7 @@ public class JoinGameController { ...@@ -23,6 +25,7 @@ public class JoinGameController {
private String errorMsg; private String errorMsg;
public JoinGameController(JoinGameState state, FirebaseInterface _FBIC, String errorMsg) { public JoinGameController(JoinGameState state, FirebaseInterface _FBIC, String errorMsg) {
this.state = state; this.state = state;
this._FBIC = _FBIC; this._FBIC = _FBIC;
...@@ -36,6 +39,7 @@ public class JoinGameController { ...@@ -36,6 +39,7 @@ public class JoinGameController {
Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
state.getCam().unproject(touchPos); state.getCam().unproject(touchPos);
Rectangle joinGameButtonBounds = joinGameView.getJoinGameButtonBounds(); Rectangle joinGameButtonBounds = joinGameView.getJoinGameButtonBounds();
Rectangle settingsBounds = joinGameView.getSettingsBounds();
if (joinGameButtonBounds.contains(touchPos.x, touchPos.y)) { if (joinGameButtonBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Join Game Button Pressed in joinGameController"); System.out.println("Join Game Button Pressed in joinGameController");
String nickname = joinGameView.getNickname(); String nickname = joinGameView.getNickname();
...@@ -53,13 +57,17 @@ public class JoinGameController { ...@@ -53,13 +57,17 @@ public class JoinGameController {
}); });
} else { } else {
// Stay on JoinGameState and display an error message if inputs are not valid // Stay on JoinGameState and display an error message if inputs are not valid
joinGameView.setErrorMessage("DB error"); //joinGameView.setErrorMessage("DB error");
} }
} }
if (settingsBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Settings Pressed");
state.getStateManager().setState(new SettingsState(state.getStateManager(), _FBIC));
}
if (joinGameView.getGoBackButtonBounds().contains(touchPos.x, touchPos.y)) {
state.getStateManager().setState(new MainMenuState(state.getStateManager(), _FBIC ));
}
} }
}; };
......
...@@ -12,16 +12,22 @@ import com.wordbattle.game.states.JoinGameState; ...@@ -12,16 +12,22 @@ import com.wordbattle.game.states.JoinGameState;
import com.wordbattle.game.states.MainMenuState; import com.wordbattle.game.states.MainMenuState;
import com.wordbattle.game.states.WaitForHostState; import com.wordbattle.game.states.WaitForHostState;
import com.wordbattle.game.view.MainMenuView; import com.wordbattle.game.view.MainMenuView;
import com.wordbattle.game.states.SettingsState;
import com.badlogic.gdx.audio.Sound;
import com.wordbattle.game.manager.SoundManager;
public class MainMenuController { public class MainMenuController {
private Sound clickSound;
private MainMenuState state; private MainMenuState state;
private MainMenuView mainMenuView; private MainMenuView mainMenuView;
FirebaseInterface _FBIC; FirebaseInterface _FBIC;
private Sound clickSound;
public MainMenuController(MainMenuState state, FirebaseInterface _FBIC) { public MainMenuController(MainMenuState state, FirebaseInterface _FBIC) {
this.state = state; this.state = state;
clickSound = Gdx.audio.newSound(Gdx.files.internal("click.wav"));
// This line initializes the view for the page // This line initializes the view for the page
this.mainMenuView = new MainMenuView(state.getCam()); // Assuming you provide a getter for the camera in BaseState this.mainMenuView = new MainMenuView(state.getCam()); // Assuming you provide a getter for the camera in BaseState
this._FBIC = _FBIC; this._FBIC = _FBIC;
...@@ -30,6 +36,7 @@ public class MainMenuController { ...@@ -30,6 +36,7 @@ public class MainMenuController {
public void handleInput() { public void handleInput() {
if (Gdx.input.justTouched()) { if (Gdx.input.justTouched()) {
SoundManager.playClickSound();
Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
System.out.println("Screen touch: " + touchPos.x + ", " + touchPos.y); System.out.println("Screen touch: " + touchPos.x + ", " + touchPos.y);
...@@ -39,11 +46,13 @@ public class MainMenuController { ...@@ -39,11 +46,13 @@ public class MainMenuController {
Rectangle joinGameButtonBounds = mainMenuView.getJoinGameButtonBounds(); Rectangle joinGameButtonBounds = mainMenuView.getJoinGameButtonBounds();
Rectangle newGameButtonBounds = mainMenuView.getNewGameButtonBounds(); Rectangle newGameButtonBounds = mainMenuView.getNewGameButtonBounds();
Rectangle howToPlayButtonBounds = mainMenuView.getHowToPlayButtonBounds(); Rectangle howToPlayButtonBounds = mainMenuView.getHowToPlayButtonBounds();
Rectangle settingsBounds = mainMenuView.getSettingsBounds();
// Debugging button bounds // Debugging button bounds
System.out.println("Join Game Button Bounds: " + joinGameButtonBounds.x +"," + joinGameButtonBounds.y); System.out.println("Join Game Button Bounds: " + joinGameButtonBounds.x +"," + joinGameButtonBounds.y);
System.out.println("New Game Button Bounds: " + newGameButtonBounds); System.out.println("New Game Button Bounds: " + newGameButtonBounds);
System.out.println("How to play Button Bounds: " + howToPlayButtonBounds); System.out.println("How to play Button Bounds: " + howToPlayButtonBounds);
System.out.println("How to play Button Bounds: " + howToPlayButtonBounds);
// Button checks // Button checks
if (joinGameButtonBounds.contains(touchPos.x, touchPos.y)) { if (joinGameButtonBounds.contains(touchPos.x, touchPos.y)) {
...@@ -58,6 +67,10 @@ public class MainMenuController { ...@@ -58,6 +67,10 @@ public class MainMenuController {
System.out.println("How to play Pressed"); System.out.println("How to play Pressed");
state.getStateManager().setState(new HowToPlayState(state.getStateManager(), _FBIC)); state.getStateManager().setState(new HowToPlayState(state.getStateManager(), _FBIC));
} }
if (settingsBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Settings Pressed");
state.getStateManager().setState(new SettingsState(state.getStateManager(), _FBIC));
}
} }
} }
......
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.manager.SoundManager;
import com.wordbattle.game.network.FirebaseInterface;
import com.wordbattle.game.states.MainMenuState;
import com.wordbattle.game.states.SettingsState;
import com.wordbattle.game.view.SettingsView;
import com.wordbattle.game.manager.MusicManager;
public class SettingsController {
private SettingsState state;
private SettingsView settingsView;
FirebaseInterface _FBIC;
public SettingsController(SettingsState state, FirebaseInterface _FBIC){
this.state = state;
this.settingsView = new SettingsView(state.getCam());
this._FBIC = _FBIC;
}
public void handleInput(){
if (Gdx.input.justTouched()) {
SoundManager.playClickSound();
Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
System.out.println("Screen touch: " + touchPos.x + ", " + touchPos.y);
state.getCam().unproject(touchPos);
System.out.println("World touch: " + touchPos.x + ", " + touchPos.y);
Rectangle goBackButtonBounds = settingsView.getGoBackButtonBounds();
Rectangle quitGameButtonBounds = settingsView.getQuitGameButtonBounds();
Rectangle switchMusicBounds = settingsView.getSwitchMusicBounds();
Rectangle switchSoundBounds = settingsView.getSwitchSoundBounds();
if (switchMusicBounds.contains(touchPos.x, touchPos.y)) {
MusicManager.toggleMusic();
}
if (goBackButtonBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Go back button is pressed");
state.getStateManager().returnToPreviousState();
}
if (quitGameButtonBounds.contains(touchPos.x, touchPos.y)) {
System.out.println("Quit game");
state.getStateManager().setState(new MainMenuState(state.getStateManager(), _FBIC));
}
if (switchSoundBounds.contains(touchPos.x, touchPos.y)) {
SoundManager.toggleSound();
}
}
}
public void update(float dt) {
handleInput();
}
public void render(SpriteBatch sb) {
settingsView.render(sb);
}
public void dispose() {
settingsView.dispose();
}
public void enter() {
}
public void exit() {
dispose();
}
}
\ No newline at end of file
package com.wordbattle.game.manager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
public class MusicManager {
private static Music backgroundMusic;
private static boolean isMusicOn = true;
public static void initialize() {
backgroundMusic = Gdx.audio.newMusic(Gdx.files.internal("bgMusic.mp3"));
backgroundMusic.setLooping(true);
}
public static void playMusic() {
if (backgroundMusic != null && !backgroundMusic.isPlaying() && isMusicOn) {
backgroundMusic.play();
}
}
public static void stopMusic() {
if (backgroundMusic != null && backgroundMusic.isPlaying()) {
backgroundMusic.stop();
}
}
public static void toggleMusic() {
isMusicOn = !isMusicOn;
if (isMusicOn) {
playMusic();
} else {
stopMusic();
}
}
public static void dispose() {
if (backgroundMusic != null) {
backgroundMusic.dispose();
}
}
public static boolean isMusicOn() {
return isMusicOn;
}
}
\ No newline at end of file
package com.wordbattle.game.manager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
public class SoundManager {
private static Sound clickSound;
private static boolean isSoundOn = true;
public static void initialize() {
clickSound = Gdx.audio.newSound(Gdx.files.internal("click.wav"));
}
public static void playClickSound() {
if (isSoundOn) {
clickSound.play();
}
}
public static void toggleSound() {
isSoundOn = !isSoundOn;
}
public static boolean isSoundOn() {
return isSoundOn;
}
public static void dispose() {
clickSound.dispose();
}
}
\ No newline at end of file
package com.wordbattle.game.states;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.wordbattle.game.WordBattle;
import com.wordbattle.game.controller.HowToPlayController;
import com.wordbattle.game.controller.SettingsController;
import com.wordbattle.game.network.FirebaseInterface;
public class SettingsState extends BaseState{
private SettingsController controller;
private FirebaseInterface _FBIC;
public SettingsState(StateManager gsm, FirebaseInterface _FBIC){
super(gsm);
this._FBIC = _FBIC;
this.controller = new SettingsController(this, _FBIC);
cam.setToOrtho(false, WordBattle.WIDTH, WordBattle.HEIGHT);
}
public StateManager getStateManager() {
return gsm;
}
@Override
public void handleInput() {
}
@Override
public void update(float dt) {
controller.update(dt);
cam.update();
}
@Override
public void render(SpriteBatch sb) {
controller.render(sb);
}
@Override
public void enter() {
}
@Override
public void exit() {
}
@Override
public void dispose() {
}
}
\ No newline at end of file
...@@ -6,6 +6,7 @@ public class StateManager { ...@@ -6,6 +6,7 @@ public class StateManager {
private GameState currentState; private GameState currentState;
private GameState previousState;
public StateManager() { public StateManager() {
...@@ -14,12 +15,19 @@ public class StateManager { ...@@ -14,12 +15,19 @@ public class StateManager {
public void setState(GameState newState) { public void setState(GameState newState) {
if (currentState != null) { if (currentState != null) {
previousState = currentState;
currentState.exit(); currentState.exit();
} }
currentState = newState; currentState = newState;
newState.enter(); // Ensure resources are ready before updating or rendering newState.enter(); // Ensure resources are ready before updating or rendering
} }
public void returnToPreviousState() {
if (previousState != null) {
setState(previousState);
}
}
public void update(float dt) { public void update(float dt) {
if (currentState != null) currentState.update(dt); if (currentState != null) currentState.update(dt);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment