Skip to content
Snippets Groups Projects
Commit fb0202b1 authored by Sander Østrem Fagernes's avatar Sander Østrem Fagernes
Browse files

feat: Backround image added, logout button changed

Issue #14
parent 5d7541f9
No related branches found
No related tags found
1 merge request!1314 Main menu screen setup
Pipeline #204305 passed
frontend/assets/menu-background.png

9.95 KiB

......@@ -25,6 +25,7 @@ public class MainMenuController {
case 0: tankWarsGame.setScreen(new GameScreen(tankWarsGame)); break;
case 1: System.out.println("Leaderboard button: Not yet functional"); break;
case 2: System.out.println("Settings button: Not yet functional"); break;
case 3: System.out.println("Log out button: Not yet functional"); break;
}
}
}
......
......@@ -7,6 +7,9 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class MenuButton {
/* TODO: To increase modifiability, the class can have a static list of textures
The list is checked every time a new MenuButton instance is
created to avoid reloading already loaded textures and still provide flexibility */
private static final Texture buttonTexture = new Texture("menu-button.png");
private final SpriteBatch batch;
......@@ -20,6 +23,7 @@ public class MenuButton {
public MenuButton(SpriteBatch batch, BitmapFont font, int id, String content, float x, float y) {
this.batch = batch;
this.font = font;
// TODO: Find better way to differentiate between buttons, at least make ids unique
this.id = id;
this.content = content;
this.x = x - buttonTexture.getWidth() / 2f;
......
......@@ -26,7 +26,6 @@ public class MainMenuScreen implements Screen {
private final Texture logo;
private final Texture welcomeBox;
private final Texture logoutButton;
private final Texture background;
private final Array<MenuButton> menuButtons;
......@@ -43,16 +42,16 @@ public class MainMenuScreen implements Screen {
this.logo = new Texture("tankwars-logo.png");
this.welcomeBox = new Texture("main-menu-welcome-box.png");
// TODO: Add logout button to the list of menu buttons somehow to enable clicking
this.logoutButton = new Texture("main-menu-logout-button.png");
// TODO: Create our own pixel art background. ZyWDE4.jpg is a dummy background image
this.background = new Texture("ZyWDE4.jpg");
this.background = new Texture("menu-background.png");
// TODO: Instantiate in Controller instead ?
float startHeight = -40;
float buttonSpacing = viewport.getWorldHeight() / 7;
this.menuButtons = new Array<>();
this.menuButtons.add(new MenuButton(batch, font, 0, "Find Game", 0, -50 + viewport.getWorldHeight() / 6));
this.menuButtons.add(new MenuButton(batch, font, 1, "Leaderboard", 0, -50));
this.menuButtons.add(new MenuButton(batch, font, 2, "Settings", 0, -50 - viewport.getWorldHeight() / 6));
this.menuButtons.add(new MenuButton(batch, font, 0, "Find Game", 0, startHeight + buttonSpacing));
this.menuButtons.add(new MenuButton(batch, font, 1, "Leaderboard", 0, startHeight));
this.menuButtons.add(new MenuButton(batch, font, 2, "Settings", 0, startHeight - buttonSpacing));
this.menuButtons.add(new MenuButton(batch, font, 3, "Log out", 0, startHeight - 2 * buttonSpacing));
this.touchPos = new Vector3();
}
......@@ -70,10 +69,7 @@ public class MainMenuScreen implements Screen {
checkInput();
batch.begin();
float backgroundWidth = background.getWidth() * viewport.getWorldHeight() / background.getHeight();
float backgroundHeight = viewport.getWorldHeight();
batch.draw(background, -viewport.getWorldWidth() / 2 - backgroundWidth / 2, -viewport.getWorldHeight() / 2,
backgroundWidth, backgroundHeight);
batch.draw(background, -viewport.getWorldWidth() / 2, -viewport.getWorldHeight() / 2);
// TODO: Find a better way to scale the logo. Perhaps using a Pixmap
float logoScaling = 1.3f;
......@@ -93,11 +89,6 @@ public class MainMenuScreen implements Screen {
for (MenuButton menuButton : menuButtons) {
menuButton.draw();
}
// TODO: Find better way to scale logout button
float logoutButtonWidth = logoutButton.getWidth() * 1.2f;
batch.draw(logoutButton, -logoutButtonWidth / 2f, -viewport.getWorldHeight() / 2 + logoutButton.getHeight() / 2f,
logoutButtonWidth, logoutButton.getHeight() * 1.2f);
batch.end();
}
private void checkInput() {
......
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