-
Notifications
You must be signed in to change notification settings - Fork 9
Turret (Game Entity)
The Turret
class is a placeable entity within the game responsible for creating and managing turret entities. Turrets are structures that can automatically target and fire at enemy entities within their range, providing a defensive mechanism for players. This class encompasses the behavior, properties, and interactions of turrets, including ammunition management.
Players can place a turret by selecting it via the StructureToolPicker
(press 3 to select the hammer, press T to open the ToolPicker menu) and clicking at an available location on the map. Placing a turret via the StructureToolPicker
consumes resources based on the defined cost in the structure_tools.json
config file.
Turrets automatically target and fire at nearby enemy entities within their line of sight. The firing rate is rate-limited to prevent excessive damage. Each time a turret fires, its ammunition is reduced by one. Once its ammunition runs out, it will no longer be able to fire.
Players can interact with turrets to refill their ammunition using player resources. This action deducts the required resources from the player's inventory and replenishes the turret's ammunition.
Players can destroy a turret by right clicking on it whilst the hammer is selected (press 3 to select the hammer), which immediately removes the turret from the game world.
The Turret
class inherits from the PlaceableEntity
class and utilizes several key components to define its behavior:
-
PhysicsComponent
: Provides the necessary physics properties to handle collision and placement. -
ColliderComponent
: Defines the collision layer for turrets, ensuring they interact correctly with other game entities. -
HitboxComponent
: Specifies the hitbox layer, ensuring precise collision detection. -
CombatStatsComponent
: Manages the health, damage, and other combat-related properties of the turret. -
HealthBarComponent
: Displays a health bar above the turret for visual feedback. -
TextureRenderComponent
: Handles the rendering of the turret's visual representation. -
FOVComponent
: Defines the turret's field of view, allowing it to detect and target enemy entities within its range. Learn more here. -
StructureDestroyComponent
: Enables the destruction of turrets.
The following UML diagram illustrates the relationships between the Turret
class and the components it utilizes:
classDiagram
class Turret {
<<extends>>
- start : long
- turretConfigs : TurretConfigs
- type : TurretType
+ currentAmmo : int
- maxAmmo : int
- damage : int
+ Turret() Turret
+ refillAmmo()
+ canFire() boolean
+ refillAmmo(amount : int)
+ interact(player : Entity)
+ startDamage(focus : Entity)
+ stopDamage(focus : Entity)
+ giveDamage(focus : Entity)
+ rotateTurret(focus : Entity)
}
PlaceableEntity <|-- Turret
Turret --o PhysicsComponent
Turret --o CollidorComponent
CollidorComponent --o PhysicsComponent
Turret --o TurretConfigs
TurretConfigs --o TurretConfig
class TurretConfig {
<<extends>>
}
TurretConfig --|> BaseEntityConfig
Turret --o CombatStatsComponent
Turret --o HealthBarComponent
HealthBarComponent --o CombatStatsComponent
class FOVComponent {
<<extends>>
}
Turret --o TurretType
Turret --o TextureRendererComponent
Turret --o StructureDestroyComponent
Turret --o FOVComponent
FOVComponent --|> ProximityActivationComponent
FOVComponent --o TurretTargetableComponent
com.csse3200.game.entities.buildables.Turret
The Turret
class serves the purpose of creating and managing individual turret entities within the game world. Turrets are essential for defending against enemy entities and provide a strategic element to the game.
var TurretConfigs turretConfigs = FileLoader.readClass(TurretConfigs.class, "configs/turrets.json");
var turret = new Turret(turretConfigs.getTurretConfig(type));
ServiceLocator.getStructurePlacementService().placeStructureAt(turret, new GridPoint2(0,0));
there are two different levels of turrets:
- levelOne with max health of 200, max ammunition of 50 and damage level 2.
- levelTwo with max health of 500, max ammunition of 100 and damage level 5.
they can be swapped around by calling TurretConfig.
You can modify these values within assets/configs/turrets.json
.
Testing of the Turret
class involves verifying its functionality and interaction with other game entities. This includes placing turrets, ensuring they target and fire at enemies correctly, and testing their collision behavior.
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files