-
Notifications
You must be signed in to change notification settings - Fork 4
Mob SpawnWaveTask
The SpawnWaveTask
spawns a wave of enemies at a set interval, currently set to be every 10 seconds. This is accomplished by using the GameTime
service. The update()
method checks whether the time since a last wave was spawned is greater than the 10 second interval. If so, the spawnWave
event is triggered. The associated listener is added to the player entity within the create()
function of ForestGameArea
. spawnXenoGrunts()
from ForestGameArea
is called every time the spawnWave
event is triggered.
The spawning of the mobs was taken care of within the spawnXenoGrunts()
method in ForestGameArea
. Minimum and maximum bounds are assigned for mob spawning, which constrain the mob to only spawn in the rightmost map column, however at random y levels. The RandomUtils
class is utilised to accomplish this. Each mob is randomly assigned to a GridPoint
, where the entity spawns at the beginning of the game.
This method was modified such that mobs would spawn within the lanes, and to ensure no more than one mob could spawn in a lane at a time. Lanes for the mobs are picked using the Random()
class. 5 distinct integers are generated and assigned to an array pickedLanes
. When spawning a mob, this array is indexed into to select a distinct lane for each.
Currently the SpawnWaveTask
is linked to the player entity, as shown below, however this will need to be changed as it is anticipated that the player will be removed from the game. The task takes no positional arguments.
Entity player = createPlayer();
AITaskComponent ai= new AITaskComponent();
player.addComponent(ai);
player.getComponent(AITaskComponent.class).addTask(new SpawnWaveTask());
Testing of this task has been completed as JUnit tests in SpawnWaveTaskTest
. This test class contains one method: shouldTriggerSpawning()
. A mock GameTime
class is instantiated which returns 11000 when getTime()
is called on it. This is 11000 milliseconds, or 11 seconds of game time. This value was chosen since it is greater than 10 seconds. Then, when update()
is called on the created entity, the EventListener
callback is verified to ensure the mob spawn event is triggered, since more than 10 seconds has passed.