Game Pause Screen Code Implementation Sprint Three - UQdeco2800/2022-studio-2 GitHub Wiki

Introduction

In sprint three, there is not too much changes made since last sprint. Since the code and logic foundation is there, changing to a new pause menu only requires changing the position of the buttons. In sprint two, there are two buttons, now we have three. Specifically, a keybind menu is added, when player presses "controls" on the main pause menu, a key bind menu will pop up and cover the main pause menu. Details of how key bind menu is working.

General Pausing/Resuming

Most of the pausing/resuming code logic, please see sprint 2 pause menu implementation.

The pausing/resuming code logic is modifed by @IsaccGraham128 since sprint two.

Button repositioning

To learn about the code logic of repositioning buttons, it is done by using transparent texture and more details at "Pause Menu Implementation Sprint 2". But for this sprint the changes are mainly done at GameAreaDisplay.java

buttonTexture = new Texture(Gdx.files.internal
                ("images/crafting_assets_sprint2/transparent-texture-buttonClick.png"));
        buttonTextureRegion = new TextureRegion(buttonTexture);
        buttonDrawable = new TextureRegionDrawable(buttonTextureRegion);
        controls = new ImageButton(buttonDrawable);
        controls.setSize(386, 122.4f);
        controls.setPosition(pauseMenu.getX() + 760f, pauseMenu.getY() + 460);
        controls.addListener(
                new ChangeListener() {
                    @Override
                    public void changed(ChangeEvent changeEvent, Actor actor) {
                        logger.info("Key binding button things");
                        OpenPauseComponent.openKeyBindings();
                    }
                });
        pausingGroup.addActor(controls);
        stage.addActor(pausingGroup);

As shown above, a new image button is added, and all ChangeListener is doing is to wire the button with the key bind menu. When the player click on the "controls" button, keybind menu will pop up. image

Level 1 map vs Level 2 map

Now the question is how to differentiate pause menu design in different level of map? The solution is easy, all we need to do is add an if statement within the setPauseMenu() method in GameAreaDisplay.java class to get the player's current game area name, if it is at "Underground" (level 2) then we bring up the level two pause menu. More importantly, only the style and colouring of the two pause menu are different, the formatting, size and position still remain the same:

logger.info("Opening Pause Menu");
        if (getGameAreaName().equals("Underground")) {
            pauseMenu = new Image(new Texture(Gdx.files.internal
                    ("images/PauseMenu/lvl2PauseScreen.png")));
        } else {
            pauseMenu = new Image(new Texture(Gdx.files.internal
                    ("images/PauseMenu/newPauseScreen.png")));
        }

Everything else stays the same.

Who to talk to?

Yingzheng Cai (@Rey_cyz#1464 on discord, @Rey-666 on github))