-
Notifications
You must be signed in to change notification settings - Fork 4
Tower Build Menu
The In-Game Tower Build Menu allows the player to make use of the defensive towers selected in the Turret Select Screen prior to starting the level. The player selects one of the towers, and provided there is sufficient currency to 'buy' the tower, the player can attempt to place the tower. Tower placement is also conditional on the chosen tile being empty of existing towers, engineers or mobs.
Tower selection is done via the CurrencyService
, in which the tower type to be bought will be 'set' and the appropriate currency decrement can occur when a tower is bought. Input handling is performed in a BuildInputComponent
which parses mouse click locations and performs the appropriate tower setting and instantiates towers in the GameArea.
The menu takes the form of five buttons arranged in a row at the top of the screen, and labeled with the tower names and tower sprites that were selected by the player
These buttons will be populated as a result of the players selections in the Turret Selection screen
If the player does not select towers in the pre-game turret select screen, the build menu will be populated with a default set of tower types, which are defined in UIElementsDisplay.java
in the addActors()
method
TowerType[] defaultTowers = {
TowerType.TNT,
TowerType.DROID,
TowerType.INCOME,
TowerType.WALL,
TowerType.WEAPON
};
Each of the buttons in UIElementsDisplay
has an associated listener. When a button is clicked, the towerType is toggled in CurrencyService
. Any subsequent mouse clicks on unoccupied tiles in the map area will cause an attempt at instantiating the selected tower. If the tile is not occupied by a tower or engineer, and if the scrap balance is sufficient, a new tower entity will be created and registered with the EntityService
, resulting in the tower spawning at the selected location. The cost of the tower is then decremented from the balance, and the currency display is updated to suit.
The following UML diagram represents class structure of the BuildInputComponent
The sequence diagram below illustrates the logical flow of building a tower in-game when a tower has been selected\