Skip to content

Level Progress Bar

Mohamad Dabboussi edited this page Oct 16, 2023 · 1 revision

LevelProgressBar Class

The LevelProgressBar class is an extension of the ProgressBar class, providing a visual representation of progress in a game level. It utilizes a custom style for the bar to display the level's progress based on the number of mobs.

image

Attributes:

  • selectedLevel: The currently selected game level, fetched from GameLevelData.getSelectedLevel().

Constructors:

  • LevelProgressBar(int width, int height)
    • Parameters:
      • width - the width of the progress bar in pixels.
      • height - the height of the progress bar in pixels.
    • Description: This constructor initializes a new progress bar with the given dimensions, style properties, and a default starting value.

Methods:

  • Drawable getColoredDrawable(int width, int height, Color color)

    • Parameters:
      • width - the width of the drawable in pixels.
      • height - the height of the drawable in pixels.
      • color - the color to fill the drawable with.
    • Returns: A Drawable filled with the specified color.
    • Description: This method creates a colored drawable based on provided width, height, and color parameters.
  • int getMobCount()

    • Returns: The total number of mobs for the selected level.
    • Description: This method calculates and returns the total number of mobs based on the currently selected game level.

MainGameDisplay Class

In the MainGameDisplay class, an instance of the LevelProgressBar class is created and added as an actor with dimensions 500x10.

Attributes:

  • progressbar: An instance of the LevelProgressBar class, representing the game's progress bar.

Methods:

  • void updateLevelProgressBar()
    • Description: This method updates the value of the progressbar based on the difference between the total number of mobs and the remaining mobs for the level. The value represents the number of mobs that have been dealt with in the game.

Usage:

To initialize the progress bar in the MainGameDisplay class:

progressbar = new LevelProgressBar(500, 10);

To update the progress bar's value during the game:

public void updateLevelProgressBar() {
    int totalSecs = ServiceLocator.getWaveService().totalMobs() - ServiceLocator.getWaveService().remainingMobsForLevel();
    progressbar.setValue(totalSecs);
}
Clone this wiki locally