diff --git a/build.gradle b/build.gradle index b2e9fab3de46143a26267c72e6352ac8d9c20e6b..acde66935ce77c600303187ad43332da5a6081b4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,4 @@ buildscript { - - repositories { mavenLocal() mavenCentral() @@ -9,10 +7,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:8.1.2' - classpath 'com.google.gms:google-services:4.4.1' - - + classpath 'com.android.tools.build:gradle:8.2.1' } } @@ -29,7 +24,6 @@ allprojects { aiVersion = '1.8.2' gdxControllersVersion = '2.2.1' libGDXVersion = '1.9.12' // Replace with the version you're using - } repositories { @@ -46,14 +40,12 @@ allprojects { project(":desktop") { apply plugin: "java-library" - dependencies { implementation project(":core") api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion" api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop" - implementation "com.badlogicgames.gdx:gdx-freetype-platform:$libGDXVersion:natives-desktop" - + api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" } } @@ -74,29 +66,16 @@ project(":android") { natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a" natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86" natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64" - // Import the Firebase BoM - implementation platform('com.google.firebase:firebase-bom:32.8.0') - - - // TODO: Add the dependencies for Firebase products you want to use - // When using the BoM, don't specify versions in Firebase dependencies - implementation 'com.google.firebase:firebase-analytics' - - + api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" } } project(":core") { apply plugin: "java-library" - dependencies { api "com.badlogicgames.gdx:gdx:$gdxVersion" api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" - implementation "com.badlogicgames.gdx:gdx-freetype:$libGDXVersion" - } - - } diff --git a/core/src/com/wordbattle/game/controller/ConnectingLobbyController.java b/core/src/com/wordbattle/game/controller/ConnectingLobbyController.java new file mode 100644 index 0000000000000000000000000000000000000000..44967c5d0086edb70741c8e6cf9cd08bbc8fd310 --- /dev/null +++ b/core/src/com/wordbattle/game/controller/ConnectingLobbyController.java @@ -0,0 +1,20 @@ +package com.wordbattle.game.controller; + +import com.wordbattle.game.states.ConnectingLobbyState; + +public class ConnectingLobbyController { + private ConnectingLobbyState state; + + public ConnectingLobbyController(ConnectingLobbyState state) { + this.state = state; + } + + public void update(float dt) { + // Logic for updating the connecting lobby state + // For example, checking if all players have joined or handling any networking tasks + } + + public void dispose() { + // Clean up any resources when exiting the state + } +} diff --git a/core/src/com/wordbattle/game/controller/CreateGameController.java b/core/src/com/wordbattle/game/controller/CreateGameController.java index 3c314c7fa83ec19643bc8661576e593dda7b911e..2527ec11130c9761a76c5b6c8a3aaedf87286cbf 100644 --- a/core/src/com/wordbattle/game/controller/CreateGameController.java +++ b/core/src/com/wordbattle/game/controller/CreateGameController.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector3; import com.wordbattle.game.states.BaseState; +import com.wordbattle.game.states.ConnectingLobbyState; import com.wordbattle.game.states.CreateGameState; import com.wordbattle.game.view.CreateGameView; import com.wordbattle.game.view.MainMenuView; @@ -35,6 +36,11 @@ public class CreateGameController { selectedLevel = "hard"; createGameView.setSelectedLevel(selectedLevel); } + + if (createGameView.getCreateGameBounds().contains(touchPos.x, touchPos.y)) { + state.getStateManager().setState(new ConnectingLobbyState(state.getStateManager(), createGameView.getPin())); + + } } } diff --git a/core/src/com/wordbattle/game/states/ConnectingLobbyState.java b/core/src/com/wordbattle/game/states/ConnectingLobbyState.java new file mode 100644 index 0000000000000000000000000000000000000000..0645e187e4d4dc6e22e8ba022eb2483037eb6980 --- /dev/null +++ b/core/src/com/wordbattle/game/states/ConnectingLobbyState.java @@ -0,0 +1,49 @@ +package com.wordbattle.game.states; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.wordbattle.game.WordBattle; +import com.wordbattle.game.controller.ConnectingLobbyController; +import com.wordbattle.game.view.LobbyView; + +public class ConnectingLobbyState extends BaseState { + private LobbyView lobbyView; + private ConnectingLobbyController controller; + + public ConnectingLobbyState(StateManager gsm, String pin) { + super(gsm); + lobbyView = new LobbyView(cam, pin); + controller = new ConnectingLobbyController(this); + cam.setToOrtho(false, WordBattle.WIDTH, WordBattle.HEIGHT); + } + + @Override + public void handleInput() { + // Handle input for connecting lobby state + } + + @Override + public void update(float dt) { + controller.update(dt); + cam.update(); + } + + @Override + public void render(SpriteBatch sb) { + lobbyView.render(sb); + } + + @Override + public void enter() { + // Initialize any necessary components when entering the state + } + + @Override + public void exit() { + // Clean up any resources when exiting the state + } + + @Override + public void dispose() { + lobbyView.dispose(); + } +} diff --git a/core/src/com/wordbattle/game/states/CreateGameState.java b/core/src/com/wordbattle/game/states/CreateGameState.java index aaa34b3a4b9069016bf9c91af594bf6bb37aa4b4..6165bdf238e016c8c656e475beaf99e7279cee4a 100644 --- a/core/src/com/wordbattle/game/states/CreateGameState.java +++ b/core/src/com/wordbattle/game/states/CreateGameState.java @@ -45,4 +45,8 @@ public class CreateGameState extends BaseState { public void dispose() { controller.dispose(); } + + public StateManager getStateManager() { + return gsm; + } } diff --git a/core/src/com/wordbattle/game/view/CreateGameView.java b/core/src/com/wordbattle/game/view/CreateGameView.java index 0a70bb3e47f19725edb0074a8cb4afa05a9f7fa9..f462033ddf598211561857ec168a2b0e2b27b6bb 100644 --- a/core/src/com/wordbattle/game/view/CreateGameView.java +++ b/core/src/com/wordbattle/game/view/CreateGameView.java @@ -186,6 +186,9 @@ public class CreateGameView { public String returnBound () { return easyPinkTexture.getWidth() + ", and " + easyPinkTexture.getHeight(); } + public Rectangle getCreateGameBounds() { + return createGameBounds; + } } diff --git a/core/src/com/wordbattle/game/view/LobbyView.java b/core/src/com/wordbattle/game/view/LobbyView.java index 245636d04bb1081aca34f84baaf24333036f3455..7d9c0dc112388741e2326885fe282723e79bb37f 100644 --- a/core/src/com/wordbattle/game/view/LobbyView.java +++ b/core/src/com/wordbattle/game/view/LobbyView.java @@ -1,4 +1,109 @@ package com.wordbattle.game.view; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.GlyphLayout; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.utils.viewport.ScreenViewport; +import com.wordbattle.game.WordBattle; +import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; +import com.badlogic.gdx.graphics.g2d.TextureRegion; + public class LobbyView { + private Texture backgroundTexture; + private BitmapFont font; + private OrthographicCamera cam; + private String pin; + private ImageButton startGameButton; + private Stage stage; + + private Texture startGameTexture; // Texture for the "START GAME" button background + + public LobbyView(OrthographicCamera cam, String pin) { + this.cam = cam; + this.pin = pin; + + stage = new Stage(new ScreenViewport(cam)); + Gdx.input.setInputProcessor(stage); + + // Load and set up font + FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("Knewave-Regular.ttf")); + FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); + parameter.size = 36; + font = generator.generateFont(parameter); + generator.dispose(); + + // Create start game button with background texture + startGameTexture = new Texture("Golden_long-01.png"); + TextureRegionDrawable buttonBackground = new TextureRegionDrawable(new TextureRegion(startGameTexture)); + ImageButton.ImageButtonStyle buttonStyle = new ImageButton.ImageButtonStyle(); + buttonStyle.up = buttonBackground; + startGameButton = new ImageButton(buttonStyle); + startGameButton.setPosition(WordBattle.WIDTH / 2 - startGameButton.getWidth() / 2, 100); + stage.addActor(startGameButton); + + // Load background texture + backgroundTexture = new Texture("bg2.png"); + } + + public void render(SpriteBatch spriteBatch) { + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + font.setColor(Color.valueOf("E456CE")); // Set text color to E456CE + + cam.update(); + spriteBatch.setProjectionMatrix(cam.combined); + + spriteBatch.begin(); + spriteBatch.draw(backgroundTexture, 0, 0, WordBattle.WIDTH, WordBattle.HEIGHT); + + // Calculate the width of the text + float waitingForWidth = "WAITING FOR".length() * 14; // Approximate width per character is 14 + float playersToJoinWidth = "PLAYERS TO JOIN...".length() * 14; + + // Draw "WAITING FOR" in the middle of the screen + font.draw(spriteBatch, "WAITING FOR", (WordBattle.WIDTH - waitingForWidth) / 2, 500); + // Draw "PLAYERS TO JOIN..." in the middle of the screen + font.draw(spriteBatch, "PLAYERS TO JOIN...", (WordBattle.WIDTH - playersToJoinWidth) / 2, 450); + + // Draw PIN + font.draw(spriteBatch, "PIN: " + pin, 160, 750); + + spriteBatch.end(); + + stage.act(Gdx.graphics.getDeltaTime()); + stage.draw(); + + // Begin another batch to draw the text + spriteBatch.begin(); + font.setColor(Color.valueOf("000000")); // Set text color to E456CE + GlyphLayout layout = new GlyphLayout(font, "START GAME"); + float textWidth = layout.width; // Get the width of the text + float textHeight = layout.height; // Get the height of the text + float buttonWidth = startGameButton.getWidth(); // Get the width of the button + float buttonHeight = startGameButton.getHeight(); // Get the height of the button + float textX = startGameButton.getX() + (buttonWidth - textWidth) / 2; // Calculate the X position + float textY = startGameButton.getY() + (buttonHeight + textHeight) / 2; // Calculate the Y position + font.draw(spriteBatch, "START GAME", textX, textY); + spriteBatch.end(); + } + + + public void dispose() { + stage.dispose(); + font.dispose(); + backgroundTexture.dispose(); + startGameTexture.dispose(); // Dispose the start game button texture + } + + public ImageButton getStartGameButton() { + return startGameButton; + } }