Skip to content

Infrastructure

harland-jensen edited this page Sep 13, 2022 · 26 revisions

Introduction

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, using the Factory Design Pattern. Furthermore, to interact with all structure objects, a Structure Service was created, based off of the Observer Design Pattern.

Further reading

Changes to base classes

KeyboardPlayerInput

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
  • Upon pressing n the next building will be selected to be built by the triggerBuildEvent method
  • Upon pressing u with a building selected, the upgradeStructure method is called
  • Upon pressing y with a building selected, the handleBuildingDestruction method is called

TriggerBuildEvent

The TriggerBuildEvent method allows the player to place a specified structure out of the available buildable structures, at the location described by the cursor's position and updates the Structure 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);
    }
  }

User Interaction Testing

Sprint 1: 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.

Sprint 2: Further testing is described at Code Testing

Future Expansion

In the future, further research will need to be executed to further understand what features user's would like to see included. The Ranged Damage component will need to be finished, as it is an expected part of the game's design.

Table of Contents

Home

How to Play

Introduction

Game Features

Main Character

Enemies
The Final Boss

Landscape Objects

Shop
Inventory
Achievements
Camera

Crystal

Infrastructure

Audio

User Interfaces Across All Pages
Juicy UI
User Interfaces Buildings
Guidebook
[Resource Management](Resource-Management)
Map
Day and Night Cycle
Unified Grid System (UGS)
Polishing

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally