Skip to content

Infrastructure

jonooallen 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.

Demonstration video for sprint 2

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 when build area is clicked
  • Upon pressing u the upgradeStructure method is called upon selecting a building
  • Upon pressing y the handleBuildingDestruction method is called upon selecting a building

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.

 public static 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;
    GridPoint2 loc = ServiceLocator.getEntityService().getNamedEntity("terrain").getComponent(TerrainComponent.class).worldToTilePosition(mousePosV2.x, mousePosV2.y);

    String entityName = loc.toString();
    entityName = name + entityName;

    structureKey = name;
    if (!uiIsVisible) {
      if (Objects.equals(name, "wall")) {
        Entity wall = StructureFactory.createWall();
        ServiceLocator.getGameService().registerEntity(loc, entityName, wall);
        ServiceLocator.getStructureService().registerNamed(entityName, wall);
        ServiceLocator.getStructureService().getNamedEntity(entityName).setPosition(mousePosV2);
      } else if (Objects.equals(name, "tower1")) {
        Entity tower1 = StructureFactory.createTower1(1);
        ServiceLocator.getGameService().registerEntity(loc, entityName, tower1);
        ServiceLocator.getStructureService().registerNamed(entityName, tower1);
        ServiceLocator.getStructureService().getNamedEntity(entityName).setPosition(mousePosV2);
      } else if (Objects.equals(name, "tower2")) {
        Entity tower2 = StructureFactory.createTower2(1);
        ServiceLocator.getGameService().registerEntity(loc, entityName, tower2);
        ServiceLocator.getStructureService().registerNamed(entityName, tower2);
        ServiceLocator.getStructureService().getNamedEntity(entityName).setPosition(mousePosV2);
      }else if (Objects.equals(name, "tower3")) {
        Entity tower3 = StructureFactory.createTower3(1);
        ServiceLocator.getGameService().registerEntity(loc, entityName, tower3);
        ServiceLocator.getStructureService().registerNamed(entityName, tower3);
        ServiceLocator.getStructureService().getNamedEntity(entityName).setPosition(mousePosV2);
      }else if (Objects.equals(name, "trap")) {
        Entity trap = StructureFactory.createTrap();
        ServiceLocator.getGameService().registerEntity(loc, entityName, trap);
        ServiceLocator.getStructureService().registerNamed(entityName, trap);
        ServiceLocator.getStructureService().getNamedEntity(entityName).setPosition(mousePosV2);
      } 

    } else {
      if (uiIsVisible) {
        table1.remove();
        toggleUIisVisible();
      }
    }
  }

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