MiniGame Menu Screen - UQcsse3200/2024-studio-2 GitHub Wiki
Overview
The MiniGameMenuScreen class provides players with a menu to select among various mini-games, including Snake, BirdieDash and Under-water maze mini games. Players can choose to play any mini-games or navigate back to the main menu for the main game. This screen utilises LibGDX's Scene2D module for managing UI elements and handling user input.
More information about specific mini-games are below.
Class Definition
public class MiniGameMenuScreen implements Screen {
private Stage stage;
private BitmapFont font;
private final GdxGame game;
private Skin skin;
private SpriteBatch batch;
private Texture snakeTexture;
private Texture skyTexture;
private Texture waterTexture;
private Texture backgroundTexture;
}
Imports
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.csse3200.game.GdxGame;
Methods
show()
-
Called when the screen is shown for the first time
-
Setup:
- Initialises
Stage
,SpriteBatch
,BitmapFont
, andSkin
. - Loads textures for the background and mini-game icons.
- Initialises
-
UI Elements:
- Creates
TextButton
for exiting the menu and selecting mini-games. - Creates
Image
for mini-game icons (Snake, Flappy Bird, Underwater Maze).
- Creates
-
Layout:
- Arranges UI elements using
Table
. - Adds images and buttons to the table and positions it on the screen.
- Arranges UI elements using
-
Listeners:
- Adds click listeners to buttons and images to handle user input, such as changing the screen or updating UI colors.
-
Background Rendering:
- Clears the screen with a specified colour.
- Draws the background texture using
SpriteBatch
.
-
UI Updates:
- Updates and renders the stage to reflect any changes.
-
Input Handling:
- Checks for the Escape key to return to the main menu.
resize(int width, int height)
- parameters: width and height of the new screen
- Called when the screen is resized
pause()
- Called when the game is paused
resume()
Called when the game is resumed after a pause
hide()
- Called when the screen is hidden
dispose()
- Called to dispose of resources to prevent memory leaks