-
Notifications
You must be signed in to change notification settings - Fork 4
Main Game Screen and Main Game Display
Once the player has navigated through all the pre-game screens (story, level select, turret select), the game screen switches to the MainGameScreen
class, which contains all the in-game elements which the player sees, hears and interacts with. The MainGameScreen
is the container and controlling class for all the services, determines the level-specific assets to use for the game environment, and contains the render()
function for rendering the game content to screen. A high-level overview of how the MainGameScreen fits into the game can be seen at Flow of screens.
The User Interface is attached to an entity instantiated in createUI()
. The main components that are added (among others) are:
- MainGameActions - contains event listeners for exit state, lose state and win state.
- InputDecorator - handles and propagates inputs on the main game stage
- MainGameDisplay - Contains all interactive UI buttons, and their behaviour handling. (At this stage, the Pause button and the tower build menu.) The following code snippet shows the addition of components to the class.
private void createUI() {
logger.debug("Creating ui");
Stage stage = ServiceLocator.getRenderService().getStage();
InputComponent inputComponent =
ServiceLocator.getInputService().getInputFactory().createForTerminal();
ui = new Entity();
ui.addComponent(new InputDecorator(stage, 10))
.addComponent(new PerformanceDisplay())
.addComponent(new MainGameActions(this.game))
.addComponent(ServiceLocator.getWaveService().getDisplay())
//.addComponent(new MainGameWinDisplay()) <- needs to be uncommented when team 3 have implemented the ui
.addComponent(new MainGameDisplay(this.game))
.addComponent(new Terminal())
.addComponent(inputComponent)
.addComponent(new TerminalDisplay());
ServiceLocator.getEntityService().register(ui);
The Pause button and the Tower build menu functionality is implemented in MainGameDisplay
, where the UI elements are instantiated, and event listeners are created to detect and respond to user input. This in turn interacts with game services such as EntityService
and CurrencyService
.
Some UI visual effects are also produced in this class using Actions added to various Actors in the UI table.
In-game background visual and audio assets are loaded via loadAssets()
. Any additional background assets that need to be added to the game need to be added in this class, by adding the paths the class variables and then ensuring that the assets are included in the loadAssets()
function.
MainGameScreen is the entry point for the instantiation of the game map area, entities, and game logic via the creation of ForestGameArea
, which in turn creates many key classes and starts the game proper.
The following class diagram illustrates the structure and relationships of MainGameScreen with many key classes.