Enemy Movement - UQdeco2800/2022-studio-3 GitHub Wiki

Overview

The enemy units roam freely within the city square. Roaming occurs where an enemy unit randomly selects a gridpoint within the city centre and moves towards the selected point. A timer is implemented to change the destination of the enemy unit at random intervals. A MovementTask object is created when a destination has been selected.

GridPoint Selection

    public GridPoint2 randomlySelectTileToMoveTo() {
        int height = this.mapGenerator.getHeight();
        ArrayList<int[]> legalMoves = this.mapGenerator.getLegalCoordinates();
        int size = legalMoves.size();
        int randomSeed = PseudoRandom.seedRandomInt(0, size);
        int[] coords = legalMoves.get(randomSeed);
        return new GridPoint2(coords[1], height - coords[0]);
    }

Timer

A timer is implemented that randomly selects an interval between 5 and 10 seconds. Once the timer has expired, a new grid point is chosen for the enemy unit to go to.

UML Diagram

⚠️ **GitHub.com Fallback** ⚠️