Spawn animation - UQcsse3200/2024-studio-2 GitHub Wiki
Overview
The spawn animation for enemy NPCs is designed to enhance the realism of the game. This feature ensures that enemy NPCs do not simply appear out of nowhere but are instead introduced into the game environment through an animation sequence that is triggered only when the player character gets close to them.
Loads a texture atlas for the chicken from the game's assets using a resource service.
public static Entity createChicken(Entity target) {
Entity chicken = createBaseNPC(target);
BaseEntityConfig config = configs.chicken;
TextureAtlas chickenAtlas = ServiceLocator.getResourceService().getAsset("images/chicken.atlas", TextureAtlas.class);
AnimationRenderComponent animator = new AnimationRenderComponent(chickenAtlas);
animator.addAnimation("spawn", 1.0f, Animation.PlayMode.NORMAL);
animator.addAnimation("walk", 0.25f, Animation.PlayMode.LOOP);
chicken
.addComponent(animator)
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent(new ChickenAnimationController());
chicken.getComponent(AnimationRenderComponent.class).scaleEntity();
return chicken;
}
Sequence Diagram
sequenceDiagram
Player -> ProximityComponent : Player enters proximity range
ProximityComponent -> Entity : Trigger proximityTriggered event
ProximityComponent -> Entity : Enable entity
ProximityComponent -> AnimationRenderComponent : Start spawn animation
AnimationRenderComponent -> Entity : Notify on animationEnd (spawn)
Entity -> AnimationRenderComponent : Start walk animation