-
Notifications
You must be signed in to change notification settings - Fork 0
Infrastructure
Infrastructure is one of the keys features in a Tower Defense game. It encompasses all objects which are buildable by the player, but primarily focuses on Defensive Towers which the player can use to defend the Crystal, and also on other utility buildings such as Walls which allows the player to limit the movement of enemies.
Infrastructure in the game was primarily implemented through the creation of a Structure Factory which facilitates the abstraction of the creation of different Infrastructure objects.
The KeyboardPlayerInput Component was also extended to add the following functionality:
- Upon pressing b the build state is toggled, where on mouse-click the triggerBuildEvent method is called
The TriggerBuildEvent method allows the player to place a Wall at the location described by the cursor's position and updates the entity service to render the wall in the game map.
private void triggerBuildEvent() {
Entity camera = ServiceLocator.getEntityService().getNamedEntity("camera");
CameraComponent camComp = camera.getComponent(CameraComponent.class);
Vector3 mousePos = camComp.getCamera().unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
Vector2 mousePosV2 = new Vector2(mousePos.x, mousePos.y);
mousePosV2.x -= 0.5;
mousePosV2.y -= 0.5;
String entityName = String.valueOf(ServiceLocator.getTimeSource().getTime());
entityName = "wall" + entityName;
ServiceLocator.getEntityService().registerNamed(entityName, StructureFactory.createWall());
ServiceLocator.getEntityService().getNamedEntity(entityName).setPosition(mousePosV2);
}
In the future, it is intended that the number of buildable infrastructure objects will be increased, giving more tools and agency to the player to decide which Towers they will use.