Alien Fauna Implementation ‐ Adding Animals - UQcsse3200/2023-studio-1 GitHub Wiki

New animals can be created within the NPCFactory. The code below outlines the necessary components for chicken animal.

  /**
   * Creates a chicken entity
   * @param player player entity
   * @return chicken entity
   */
  public static Entity createChicken(Entity player) {
    Entity chicken = createBaseAnimal(EntityType.Chicken);
    BaseAnimalConfig config = configs.chicken;

    AnimationRenderComponent animator = new AnimationRenderComponent(
            ServiceLocator.getResourceService().getAsset("images/animals/chicken.atlas", TextureAtlas.class),
            16f
    );

    // Add desired animations

    AITaskComponent aiTaskComponent = new AITaskComponent()
    // Add desired tasks

    List<SingleDropHandler> singleDropHandlers = new ArrayList<>();
    MultiDropComponent multiDropComponent = new MultiDropComponent(singleDropHandlers, true);
    
    // Add drop handlers

    chicken
            .addComponent(aiTaskComponent)
            .addComponent(multiDropComponent)
            .addComponent(animator)
            .addComponent(new AnimalAnimationController())
            .addComponent(new CombatStatsComponent(10, 0))
            .addComponent(new TamableComponent(player, config.tamingThreshold,
                    config.tamingProbability, config.favouriteFood));

    // configure components

    return chicken;
  }

The chicken animal has associated sprites and animations, tasks (e.g. runaway from player), drops, health stats and can be tamed.

Base Animal

When creating each animal, a base animal entity is used to add components that are shared across each animal.

Example Entity - Chicken

After creating the base animal, further components are added to each animal depending on its type. The following diagram shows what components are added to the chicken entity.