Sprint 4: Firefly NPC - UQdeco2800/2021-studio-6 GitHub Wiki

Summary

A firefly that flies randomly around the environment in a proximity range. It provides some light to the player which player can use to see the enemies/level and can also be used as a way to reduce the enemy aggression onto the player if the player stays within the firefly light area it emits out if the player's torch happen to run out and is in the darkness.

Creating the Firefly

To spawn the firefly bug into the GameArea map (e.g. Level2.java), first is the GridPoint2 of where you want to spawn the firefly in X, Y coordinates. Then the NPCFactory.createFireFlyBugNPC function to create the firefly entity with the following parameters:

  • float speedX: The movement speed in X direction.
  • float speedY: The movement speed in Y direction.
  • float wanderX: The proximity X distance to move around in.
  • float wanderY: The proximity Y distance to move around in.
  • float lightRadius: The circle radius of the light emitted by the bug.
  • float waitTime: The time in seconds to hold the position after moving into a random location.

Example of the spawnFireFlyBugNPC method:

private void spawnFireFlyBugNPC() {
  GridPoint2[] spawnLocations = {
      new GridPoint2(22,29),
      new GridPoint2(41,23),
      new GridPoint2(45,9),
  };

  for (int i = 0; i < spawnLocations.length; i++) {
    Entity fireFlyBugNPC = NPCFactory.createFireFlyBugNPC(1f,1f,10f,10f,3f,0.5f);
    spawnEntityAt(fireFlyBugNPC, spawnLocations[i], true, false);
  }
}