Macaw (Enemy NPC) - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

The Green Macaw NPC is a new enemy inhabiting the Air Kingdom. It’s an agile and evasive opponent, designed to challenge players with its ability to fly swiftly and maneuver around obstacles. The macaw can be a tricky foe, requiring players to use precision and timing to capture it. Its attacks involve aerial strikes, making it a formidable adversary. However, it has moderate health, making it vulnerable once caught.

macaw

Special Attack

The Green Macaw NPC has a unique feature during general map exploration: it performs throw worms from the air. This attack is challenging for the player to dodge, requiring quick reactions to keep the player entertained.

Enemy Stats

Enemy Macaw NPC stats are defined in an NPC.json file which are loaded into the game using the FileLoader class.

  • Health : 5
  • Base Attack : 30
  • Base Defense : 2
  • Speed : 100
  • Experience : 10

Macaw Enemy NPC Implementation

The macaw enemy NPC is spawned through the EnemyFactory class, which is responsible for creating non-playable character (NPC) entities.

Creation of macaw enemy NPC, along with texture and animation:

public static Entity createMacaw(Entity target) {
        BaseEnemyEntityConfig config = configs.macaw;
        Entity macaw = createBaseEnemy(target, EnemyType.MACAW, config);
        macaw.setEnemyType(Entity.EnemyType.MACAW);

        TextureAtlas macawAtlas = ServiceLocator.getResourceService().getAsset(config.getSpritePath(), TextureAtlas.class);

        AnimationRenderComponent animator = new AnimationRenderComponent(macawAtlas);

        animator.addAnimation("chase", 0.5f, Animation.PlayMode.LOOP);
        animator.addAnimation("walk", 0.5f, Animation.PlayMode.LOOP);
        animator.addAnimation("spawn", 1.0f, Animation.PlayMode.NORMAL);

        macaw
                .addComponent(animator)
                .addComponent(new MacawAnimationController());


        macaw.setScale(2f,1.38f);

        return macaw;
    }

Enemy macau NPCs are spawned in ForestGameTerrain class through randomisation based on the player's position:

 private void spawnRandomEnemy(Supplier<Entity> creator, int numItems, double proximityRange) {
    GridPoint2 minPos = new GridPoint2(PLAYER_SPAWN.x - 20, PLAYER_SPAWN.y - 20);
    GridPoint2 maxPos = new GridPoint2(PLAYER_SPAWN.x + 20, PLAYER_SPAWN.y + 20);

    for (int i = 0; i < numItems; i++) {
      GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
      Entity enemy = creator.get();
      spawnEntityAt(enemy, randomPos, true, false);
      enemies.add(enemy);
      enemy.addComponent(new ProximityComponent(player, proximityRange)); // Add ProximityComponent
    }
  }

Sequence Diagram

sequenceDiagram
Player        -> EnemyFactory      : Player within proximity
EnemyFactory  -> Macaw Entity      : createMacaw(target)
Macaw Entity  -> AnimationRenderComponent : Add macaw animations (WAIT, RUNRIGHT)
Macaw Entity  -> AI Task Component : Add patrol task (PatrolTask)
Player        -> Macaw Entity      : Within patrol range
Macaw Entity  -> AnimationRenderComponent : Start patrol or chase animation
Macaw Entity  -> Player            : Attack or avoid player
Loading
⚠️ **GitHub.com Fallback** ⚠️