-
Notifications
You must be signed in to change notification settings - Fork 0
[Sprint 2] Structure Variety
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.
Further reading
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 specified structure, "wall", "tower1", or "stone quarry" at the location described by the cursor's position and updates the entity service to render the structure in the game map.
private void triggerBuildEvent(String name) {
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 = name + entityName;
if (Objects.equals(name, "wall")) {
ServiceLocator.getEntityService().registerNamed(entityName, StructureFactory.createWall());
ServiceLocator.getEntityService().getNamedEntity(entityName).setPosition(mousePosV2);
Rectangle rectangle = new Rectangle(mousePosV2.x, mousePosV2.y, 1, 1);
structureRects.put(entityName, rectangle);
} else if (Objects.equals(name, "stonequarry")) {
ServiceLocator.getEntityService().registerNamed(entityName, StructureFactory.createStoneQuarry());
ServiceLocator.getEntityService().getNamedEntity(entityName).setPosition(mousePosV2);
Rectangle rectangle = new Rectangle(mousePosV2.x, mousePosV2.y, 1, 1);
structureRects.put(entityName, rectangle);
} else if (Objects.equals(name, "tower1")) {
ServiceLocator.getEntityService().registerNamed(entityName, StructureFactory.createTower1());
ServiceLocator.getEntityService().getNamedEntity(entityName).setPosition(mousePosV2);
Rectangle rectangle = new Rectangle(mousePosV2.x, mousePosV2.y, 1, 1);
structureRects.put(entityName, rectangle);
}
}
To validate the implementation of building structures into the game, user interface testing was conducted by giving testers a brief overview of the interaction methods and then letting them try to create, move, and delete structures in the game. This video displays an overview of user interaction: https://youtu.be/Elqmh7kcmlw.
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.