please inspect, diagnose, and then fix / refactor my enemies pathing behaviour in order…
- User
please inspect, diagnose, and then fix / refactor my enemies pathing behaviour in order to fix its current issue of not going after the player whatsoever, for some reason there is never a trigger for it to get out of idle state
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.PriorityQueue;
enum AnimationState { IDLE, WALKING, ATTACKING, DAMAGED, DYING }
class Enemy {
codefloat x, y; float speed = 1.5; int health; int maxHealth = 100; float respawnTime; float respawnTimer; List<PVector> path; int pathIndex; int updatePathInterval = 60; // Update path every 60 frames int frameCount; boolean active; AnimationState currentState = AnimationState.IDLE; HashMap<AnimationState, Animation> animations = new HashMap<>(); Animation currentAnim; int stateTimer = 0; int damagedDuration = 30; int dyingDuration = 60; int attackingDuration = 55; //Duration for attacking state in frames (11 frames * 5 frame delay) boolean hasDealtDamage = false; //to ensure damage is dealt only once per attack PImage spriteSheet; int spriteWidth = 90; int spriteHeight = 64; Player player; // Reference to the player Enemy(float respawnTime, Player playerRef) { this.respawnTime = respawnTime; this.respawnTimer = respawnTime; this.health = maxHealth; this.player = playerRef; this.spriteSheet = random(1) < 0.5 ? enemySpriteSheet1 : enemySpriteSheet2; animations.put(AnimationState.ATTACKING, new Animation(0, 11, 5, false)); animations.put(AnimationState.DYING, new Animation(1, 13, 5, false)); animations.put(AnimationState.DAMAGED, new Animation(2, 4, 5, false)); animations.put(AnimationState.IDLE, new Animation(3, 8, 5, true)); animations.put(AnimationState.WALKING, new Animation(4, 10, 5, true)); // Set the initial animation currentAnim = animations.get(currentState); currentAnim.reset(); respawn(); //this takes care of initital position } - Assistant