Skip to content
Snippets Groups Projects
Commit 30e445ee authored by Thea Slemdal Bergersen's avatar Thea Slemdal Bergersen
Browse files

Merge branch '8-create-lobby-page' into 'main'

creates LobbyView from CreateGameView

Closes #8

See merge request !9
parents 31254571 b711f374
Branches
No related tags found
1 merge request!9creates LobbyView from CreateGameView
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"
}
}
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
}
}
......@@ -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()));
}
}
}
......
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();
}
}
......@@ -45,4 +45,8 @@ public class CreateGameState extends BaseState {
public void dispose() {
controller.dispose();
}
public StateManager getStateManager() {
return gsm;
}
}
......@@ -186,6 +186,9 @@ public class CreateGameView {
public String returnBound () {
return easyPinkTexture.getWidth() + ", and " + easyPinkTexture.getHeight();
}
public Rectangle getCreateGameBounds() {
return createGameBounds;
}
}
......
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment