-
Notifications
You must be signed in to change notification settings - Fork 1
Enemy NPC speed alteration
JackMccabe2 edited this page Aug 29, 2024
·
2 revisions
The speed component of Enemy NPC's is altered in the declaration of the enemy in the EnemyFactory.java file. The physical component of the entity is retrieved through a 'get' and then the speed is changed through the "changeMaxSpeed" function. The NPC's speed is specified in the NPCs.json file under each entity with the attribute "speed".
- getComponent(PhysicsMovementComponent.class): Calls the instance of the physics component for the current entity.
- Vector2(config.speed, config.speed): new Vector 2 instance containing the speed of the enemy NPC, has an X and Y component.
- changeMaxSpeed(Vector2()): Alters an entities speed to the specified speed in the inserted Vector.
- On entity spawn: In enemyFactory, when entity is spawned, methods are called to update the entity instance speed.
public class EnemyFactory {
public static Entity createChicken(Entity target) {
BaseEntityConfig config = NPCConfigs.chicken;
chicken.getComponent(PhysicsMovementComponent.class).changeMaxSpeed(new Vector2(config.speed, config.speed));