Skip to content

Infrastructure

harland-jensen edited this page Sep 9, 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.

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

TriggerBuildEvent

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);
    }
  }

User Interaction Testing

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.

Future Expansion

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.

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