Skip to content

PlanetScreen Class

Shaivika Anand edited this page Oct 26, 2023 · 3 revisions

PlanetScreen Class Documentation

Introduction

The PlanetScreen class is a component of game codebase, responsible for representing individual planets in the game with their corresponding game areas. It manages the generation of game areas, player movement, and various game-related services

Class Overview

Class Name

  • Class Name: PlanetScreen

Extends

  • Extends: com.badlogic.gdx.ScreenAdapter

Dependencies

  • Dependencies: Various libraries from the libGDX game development framework.

Constructor

PlanetScreen(GdxGame game, String name)

  • Description: Construct the PlanetScreen instance for the planet of a given name.
  • Parameters:
    • game: The current game instance to display the screen on.
    • name: The name of the planet to create a screen for.

Methods

show()

  • Description: Create the screen services and game areas on display.
  • Usage: Called when the screen is first displayed.

getNextPlanetName()

  • Description: Get the name of the next planet in the sequence after the current planet.
  • Return: The name of the next planet.

setCurrentArea(String name)

  • Description: Set the current game area the player is on.
  • Parameters:
    • name: The name of the game area.
  • Return: Whether the new game area was set correctly.

getCurrentGameArea()

  • Description: Get the currently displayed game area.
  • Return: The MapGameArea being utilized.

getCurentAreaName()

  • Description: Get the name of the currently displayed game area.
  • Return: The name of the area.

render(float delta)

  • Description: Render the game screen.
  • Parameters:
    • delta: The time since the last render in seconds.

resize(int width, int height)

  • Description: Resize the game screen.
  • Parameters:
    • width: The new width of the screen.
    • height: The new height of the screen.

pause()

  • Description: Pause the game.

resume()

  • Description: Resume the game.

dispose()

  • Description: Dispose of resources and services.
  • Usage: Called when the screen is no longer needed.

saveGame()

  • Description: Save the game state.

loadAssets()

  • Description: Load assets required for the screen.

unloadAssets()

  • Description: Unload assets used by the screen.

createUI()

  • Description: Create the game's UI elements.

followPlayer()

  • Description: Move the camera to follow the player around.

Attributes

Class Attributes

  • Attributes:
    • private final GdxGame game
    • public final String name
    • private String nextPlanetName
    • private Entity player
    • private String currentAreaName
    • private final Map<String, MapGameArea> allGameAreas
    • private LevelConfig levelConfig
    • private static final Vector2 CAMERA_POSITION
    • private Renderer renderer
    • private PhysicsEngine physicsEngine
    • public static boolean titleBoxDisplayed
    • private AssetsConfig assets

UML Diagram

Image 19-10-23 at 2 02 AM

Example Usage

// Creating a PlanetScreen instance
PlanetScreen planetScreen = new PlanetScreen(game, "Earth");

// Setting the current game area
planetScreen.setCurrentArea("Area1");

// Getting the name of the next planet
String nextPlanet = planetScreen.getNextPlanetName();

// Rendering the screen
planetScreen.render(0.1f);
Clone this wiki locally