Bee (Enemy NPC) - UQcsse3200/2024-studio-2 GitHub Wiki
The Bee NPC is a swift and elusive enemy found in the Air Kingdom. Known for its quick movements and aerial agility, this enemy challenges players with its high movement speed. While the Bee NPC has moderate health, during combat its speed makes it a tricky target, requiring players to employ precise timing and strategy to capture or defeat it.
Enemy Bee NPC stats are defined in an NPC.json file which are loaded into the game using the FileLoader class.
- health : 10
- baseAttack : 2
- defense : 3
- speed : 270
- experience : 15
The bee enemy NPC is spawned through the EnemyFactory class, which is responsible for creating non-playable character (NPC) entities.
Creation of bee enemy NPC, along with texture and animation:
public static Entity createBee(Entity target) {
BaseEnemyEntityConfig config = configs.bee;
Entity bee = createBaseEnemy(target, EnemyType.BEE, config);
bee.setEnemyType(Entity.EnemyType.BEE);
TextureAtlas beeAtlas = ServiceLocator.getResourceService().getAsset(config.getSpritePath(), TextureAtlas.class);
AnimationRenderComponent animator = new AnimationRenderComponent(beeAtlas);
animator.addAnimation("float", 1.0f, Animation.PlayMode.LOOP);
animator.addAnimation("chase", 1.0f,Animation.PlayMode.LOOP);
animator.addAnimation("alert", 1.0f, Animation.PlayMode.NORMAL);
bee
.addComponent(animator)
.addComponent(new BeeAnimationController());
bee.setScale(0.542f,0.35f);
return bee;
}
Enemy bees 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
}
}
Bee NPCs spawn from the hive
sequenceDiagram
Player -> EnemyFactory : Player within proximity
EnemyFactory -> Bee Entity : createBee(target)
Bee Entity -> AnimationRenderComponent : Add bee animations (WAIT, RUNLEFT)
Bee Entity -> AI Task Component : Add attack task (AttackTask)
Player -> Bee Entity : Within attack range
Bee Entity -> AnimationRenderComponent : Start RUNLEFT or attack animation
Bee Entity -> Player : Attack player