Skip to content

Level Select Screens

Rakshit N edited this page Oct 16, 2023 · 5 revisions

Introduction

The Level-Select-Screen provides a way for the planet to choose different levels, this is done by clicking on a planet.

After clicking one of the planet events above you will load into a turret select screen, eventually taking you to the main game.

Development

The animation is based on how many render calls have occurred through the process, with this you can control how fast the planets spin. Below is the spawnPlanets() method:

private void spawnPlanets() {
    // Spawn desert planet
    spawnPlanet(150, 150, Planets.DESERT[0], Planets.DESERT[1], "Desert", 1, (int) (timeCounter * 60) % 60 + 1);
    // Spawn ice planet
    spawnPlanet(150, 150, Planets.ICE[0], Planets.ICE[1],"Barren_or_Moon", 2, (int) (timeCounter * 60) % 60 + 1);
    // Spawn lava planet
    spawnPlanet(200, 200, Planets.LAVA[0], Planets.LAVA[1],"Lava", 1, (int) (timeCounter * 60) % 60 + 1);

    spawnPlanetBorders();
}

where the $7^{\text{th}}$ parameter controls the which frame to spawn. Here timeCounter is the amount of time that the user has been on the screen.

Changing level

The level is changed here. Each specific planet has an attached id to it, which can be used to set the screen to a certain level.

Planet borders

spawnPlanetBorders is the method used to add a highlighted color around a planet when a cursor is placed on the respective planet

private void spawnPlanetBorders() {
        Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
        int highestLevelReached = currentLevel;

Iterates through the planets checking for the bounding box

        for (int[] planet : Planets.PLANETS) {
            Rectangle planetRect = new Rectangle(planet[0], planet[1], planet[2], planet[3]);
            if (planetRect.contains(mousePos.x, (float) Gdx.graphics.getHeight() - mousePos.y)) {

If the mouse is over a planet, draw the planet border

                Sprite planetBorder = new Sprite(new Texture("planets/planetBorder.png"));
                batch.draw(planetBorder, planet[0] - 2.0f, planet[1] - 2.0f, planet[2] + 3.0f, planet[3] + 3.0f);

Planet Description

Whenever the cursor is placed on a Planet / Level it displays certain information about the planet giving the player some context about it this is done using method getPlanetDescription which retrieves the information of a given planet

private String getPlanetDescription(int[] planet) {
        int planetIndex = getPlanetIndex(planet);
        if (planetIndex >= 0 && planetIndex < planetDescriptions.length) {
            return planetDescriptions[planetIndex];
        }
        return "Planet Description not available.";
    }

the method getPlanetIndex works with simultaneously to assess which planet is being selected withing the global planet array

 private int getPlanetIndex(int[] planet) {
        for (int i = 0; i < Planets.PLANETS.length; i++) {
            if (planet == Planets.PLANETS[i]) {
                return i;
            }
        }
        return -1;
    }

Render

it is one of the most important parts which displays and renders all the elements of the Level select screen this includes drawing the background, planets, and any necessary UI elements. It also handles user interactions such as hovering over and selecting planets and displaying the necessary and correct information.

background render

 batch.begin();
        batch.draw(background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        spawnPlanets();
        text.update();
        text.draw(batch, 100, 700);
        batch.end();
        boolean isMouseOverPlanetNow = false;
        Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);

level render / level load

 for (int[] planet : Planets.PLANETS) {
            Rectangle planetRect = new Rectangle(planet[0], planet[1], planet[2], planet[3]);
            if (planetRect.contains(mousePos.x, (float) Gdx.graphics.getHeight() - mousePos.y)) {
                isMouseOverPlanetNow = true;
                int conventionalPlanetLevel = mapToConventional(planet[4]);
                String description = getPlanetDescription(planet);
                descriptionBox.setText(description);
                descriptionTable.setVisible(true);
                int highestLevelReached = currentLevel;
                if (Gdx.input.justTouched()) {
                    if (conventionalPlanetLevel == 0 && highestLevelReached >= -1) {
                        loadPlanetLevel(planet);
                    } else if (conventionalPlanetLevel == 1 && highestLevelReached >= 0) {
                        loadPlanetLevel(planet);
                    } else if (conventionalPlanetLevel == 2 && highestLevelReached >= 1) {
                        loadPlanetLevel(planet);
                    } else {
                        logger.info("Attempted to load locked level {}", planet[4]);
                    }
                }
            }
        }

Screen resolution

this is used when the screen size is changed. This updates the viewport to ensure the UI scales and positions correctly for the new window size.

public void resize(int width, int height) {
        stage.getViewport().update(width, height, true);
    }

Test Plan

Due to the state of UI, it cannot be directly JUNIT/mockito tested. Here is a test plan for the screen.

  • Background appears
  • Display text correctly displays and animates
  • Planets appear in the correct position
  • Planets spin at the correct speed
  • When hovering a planet, the planet is highlighted with a blue indicator
  • When clicking a planet, screen correctly changes to the turret selection screen.
  • when hovering over a planet a description line is shown
  • when hovering over a planet the correct description is shown
  • when hovering over a planet the description is in the correct position and is not glitched out.
  • in the planet select the button appears in the correct position
  • in planet select the back button goes back to the main menu screen when clicked.

3 manual tests were conducted and a crash bug was found when clicking a planet, this is due to a resolution issue. See (Issue #149)

Clone this wiki locally