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

Overview

The Pigeon is the weakest enemy in the flying kingdom. Arguably one of the most annoying animals in existence, the pigeon lives to distract and irritate. It's agility and abundant proliferation means that you will seldom find yourself outside of a battle with one of these little runts. Fortunately, they are frail creatures and require little strength to defeat.

image

Enemy Stats

  • Health: 10
  • baseAttack: 5
  • baseDefense: 5
  • speed: 2

Pigeon NPC Implementation

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

Create new pigeon enemy NPC:

Entity pigeon = createBaseEnemy(playerEntity, EnemyType.PIGEON);

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

    public static Entity createPigeon(Entity target) {
        BaseEnemyEntityConfig config = configs.pigeon;
        Entity pigeon = createBaseEnemy(target, EnemyType.PIGEON, config);
        pigeon.setEnemyType(Entity.EnemyType.PIGEON);
        
        TextureAtlas pigeonAtlas = ServiceLocator.getResourceService().getAsset(config.getSpritePath(), TextureAtlas.class);
        
        AnimationRenderComponent animator = new AnimationRenderComponent(pigeonAtlas);
        
        animator.addAnimation(FLOAT, 0.06f, Animation.PlayMode.LOOP);
        animator.addAnimation(SPAWN, 1.0f, Animation.PlayMode.NORMAL);
        
        pigeon
                .addComponent(animator)
                .addComponent(new PigeonAnimationController());
        
        pigeon.setScale(0.842f,0.55f);
        
        return pigeon;
    }

Pigeon Special Ability

The pigeon has the special ability to steal items from the map. It will swoop in and steal an available item from the map. Here is how the task is implemented:

case EnemyType.PIGEON -> {
    aiComponent.addTask(new StealTask(((ForestGameArea)MapHandler.getCurrentMap()).getDynamicItems(), 2f));
}

Sequence Diagram

sequenceDiagram
Player        -> EnemyFactory      : Player within proximity
EnemyFactory  -> Pigeon Entity     : createPigeon(target)
Pigeon Entity -> AnimationRenderComponent : Add pigeon animations (WAIT, RUNRIGHT)
Pigeon Entity -> AI Task Component : Add steal task (StealTask)
Player        -> Pigeon Entity     : Within interaction range
Pigeon Entity -> AnimationRenderComponent : Start RUNRIGHT animation
Pigeon Entity -> Player            : Steal or fly away