-
Notifications
You must be signed in to change notification settings - Fork 1
Monkey (Enemy NPC)
The Monkey NPC is an advanced enemy NPC that is extremely swift and agile enemy, inhabiting the Land Kingdom. It has a speed of 3 units and moves very quickly and erratically, making it a formidable enemy. Its high speed and agility allow it to swiftly evade enemies. To defeat them in combat the player needs to catch them first. However, despite its speed it's health bar is relatively low.
The monkey has a unique feature implemented during general map exploration gameplay. This special feature is allows it to throw bananas at the player, adding an extra layer of challenge to the game and keeping the player entertained.
Enemy Monkey NPC stats are defined in an NPC.json file which are loaded into the game using the FileLoader class.
- Health : 8
- Base Attack : 2
- Base Defense : 1
- Speed : 3
The monkey enemy NPC is spawned through the EnemyFactory class, which is responsible for creating non-playable character (NPC) entities.
Creation of monkey enemy NPC, along with texture and animation:
public static Entity createMonkey(Entity target) {
Entity monkey = createBaseEnemy(target, EnemyType.MONKEY);
BaseEnemyEntityConfig config = configs.monkey;
AnimationRenderComponent animator =
new AnimationRenderComponent(
ServiceLocator.getResourceService().getAsset(config.getSpritePath(), TextureAtlas.class));
animator.addAnimation("run_down", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("run_up", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("run_left", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("run_right", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("run_left_down", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("run_right_down", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("run_left_up", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("run_right_up", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("wait", 0.1f, Animation.PlayMode.LOOP);
monkey
.addComponent(new CombatStatsComponent(config.getHealth() + (int)(Math.random() * 2) - 1, 0,
config.getBaseAttack() + (int)(Math.random() * 2), 0, 0, 0))
.addComponent(animator)
.addComponent(new MonkeyAnimationController());
monkey.getComponent(AnimationRenderComponent.class).scaleEntity();
monkey.getComponent(PhysicsMovementComponent.class).changeMaxSpeed(new Vector2(config.getSpeed(), config.getSpeed()));
return monkey;
}
Enemy monkey 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
}
}