11#pragma once
2-
32#include " Entity.h"
43#include " Animation.h"
54#include < box2d/box2d.h>
@@ -10,88 +9,103 @@ class Player;
109class EnemyWindUpScurry : public Entity
1110{
1211public:
13- enum class State {
14- IDLE , // Roaming around randomly (no fixed pattern)
15- ALERTA , // Detected the player, wind-up key spinning faster
16- ANTES_WALK_FAST , // Transition animation before chasing
17- WALK_FAST , // Actively chasing the player (~12 seconds)
18- CANSADO , // Transition to fatigue (winding down)
19- IDLE_CANSADO , // Exhausted, immobile (~3 seconds) - VULNERABLE
20- HIT , // Taking damage (only possible during IDLE_CANSADO)
21- DEATH // Dead
22- };
23-
24- EnemyWindUpScurry ();
25- virtual ~EnemyWindUpScurry ();
26-
27- bool Awake () override ;
28- bool Start () override ;
29- bool Update (float dt) override ;
30- bool CleanUp () override ;
31-
32- void OnCollision (PhysBody* physA, PhysBody* physB) override ;
33- void OnCollisionEnd (PhysBody* physA, PhysBody* physB) override ;
34-
35- void TakeDamage (int damage) override ;
12+ enum class State {
13+ IDLE , // Roaming around randomly (no fixed pattern)
14+ ALERTA , // Detected the player, wind-up key spinning faster
15+ ANTES_WALK_FAST , // Transition animation before chasing
16+ WALK_FAST , // Actively chasing the player
17+ BITE , // Lunging and biting the player (stops, deals damage once)
18+ BITE_RETREAT , // Retreating in opposite direction after bite
19+ CANSADO , // Transition to fatigue (winding down)
20+ IDLE_CANSADO , // Exhausted, immobile (~3 seconds) - VULNERABLE
21+ HIT , // Taking damage (only possible during IDLE_CANSADO)
22+ DEATH // Dead
23+ };
24+
25+ EnemyWindUpScurry ();
26+ virtual ~EnemyWindUpScurry ();
27+
28+ bool Awake () override ;
29+ bool Start () override ;
30+ bool Update (float dt) override ;
31+ bool CleanUp () override ;
32+
33+ void OnCollision (PhysBody* physA, PhysBody* physB) override ;
34+ void OnCollisionEnd (PhysBody* physA, PhysBody* physB) override ;
35+ void TakeDamage (int damage) override ;
3636
3737public:
38- int texW = 128 , texH = 128 ;
38+ int texW = 128 , texH = 128 ;
3939
4040private:
41- void UpdateFSM (float dt);
42- void EnterState (State newState);
43- void Draw (float dt);
44- float GetDistanceToPlayer () const ;
45- void ChooseNewPatrolDirection ();
41+ void UpdateFSM (float dt);
42+ void EnterState (State newState);
43+ void Draw (float dt);
44+ float GetDistanceToPlayer () const ;
45+ void ChooseNewPatrolDirection ();
4646
4747private:
48- State currentState_ = State::IDLE ;
49- float stateTimer_ = 0 .0f ;
50-
51- Player* playerRef_ = nullptr ;
52-
53- // Patrol (random roaming)
54- float patrolDirX_ = 1 .0f ;
55- float patrolTimer_ = 0 .0f ;
56- static constexpr float PATROL_CHANGE_INTERVAL = 2000 .0f ; // ms between random direction changes
57- static constexpr float PATROL_SPEED = 1 .5f ;
58-
59- // Detection
60- static constexpr float DETECTION_RADIUS = 200 .0f ;
61-
62- // Chase
63- static constexpr float CHASE_SPEED = 4 .0f ;
64- static constexpr float CHASE_DURATION = 12000 .0f ; // 12 seconds in ms
65-
66- // Fatigue
67- static constexpr float FATIGUE_DURATION = 3000 .0f ; // 3 seconds in ms
68-
69- // Physics
70- PhysBody* pbody = nullptr ;
71-
72- // Animations
73- AnimationSet idleAnims_;
74- AnimationSet alertaAnims_;
75- AnimationSet antesWalkFastAnims_;
76- AnimationSet walkFastAnims_;
77- AnimationSet cansadoAnims_;
78- AnimationSet idleCansadoAnims_;
79- AnimationSet hitAnims_;
80- AnimationSet dieAnims_;
81-
82- // Textures
83- SDL_Texture* idleTexture_ = nullptr ;
84- SDL_Texture* alertaTexture_ = nullptr ;
85- SDL_Texture* antesWalkFastTexture_ = nullptr ;
86- SDL_Texture* walkFastTexture_ = nullptr ;
87- SDL_Texture* cansadoTexture_ = nullptr ;
88- SDL_Texture* idleCansadoTexture_ = nullptr ;
89- SDL_Texture* hitTexture_ = nullptr ;
90- SDL_Texture* dieTexture_ = nullptr ;
91-
92- bool facingRight_ = false ;
93-
94- // Audio Fx IDs
95- int attackFxId = -1 ;
96- int deadFxId = -1 ;
97- };
48+ State currentState_ = State::IDLE ;
49+ float stateTimer_ = 0 .0f ;
50+ Player* playerRef_ = nullptr ;
51+
52+ // ?? Patrol (random roaming) ??????????????????????????????????????????????
53+ float patrolDirX_ = 1 .0f ;
54+ float patrolTimer_ = 0 .0f ;
55+ static constexpr float PATROL_CHANGE_INTERVAL = 2000 .0f ; // ms
56+ static constexpr float PATROL_SPEED = 1 .5f ;
57+
58+ // ?? Detection ???????????????????????????????????????????????????????????
59+ static constexpr float DETECTION_RADIUS = 200 .0f ;
60+
61+ // ?? Chase ???????????????????????????????????????????????????????????????
62+ static constexpr float CHASE_SPEED = 4 .0f ;
63+ static constexpr float CHASE_DURATION = 12000 .0f ; // ms safety timeout
64+
65+ // ?? Bite ????????????????????????????????????????????????????????????????
66+ static constexpr float BITE_RANGE = 40 .0f ; // px — trigger bite when this close
67+ static constexpr float BITE_RETREAT_SPEED = 5 .0f ; // faster than chase
68+ static constexpr float BITE_RETREAT_DURATION = 600 .0f ; // ms running away
69+ float biteReturnDirX_ = -1 .0f ; // direction opposite to player at bite moment
70+ bool biteDamageDealt_ = false ; // ensures damage fires only once per bite
71+
72+ // ?? Fatigue ?????????????????????????????????????????????????????????????
73+ static constexpr float FATIGUE_DURATION = 3000 .0f ; // ms
74+
75+ // ?? Attack cooldown (IDLE wall-contact damage) ???????????????????????????
76+ float attackCooldown_ = 0 .0f ;
77+ static constexpr float ATTACK_COOLDOWN = 800 .0f ; // ms
78+
79+ // ?? Physics ?????????????????????????????????????????????????????????????
80+ PhysBody* pbody = nullptr ;
81+
82+ // ?? Animations ??????????????????????????????????????????????????????????
83+ AnimationSet idleAnims_;
84+ AnimationSet alertaAnims_;
85+ AnimationSet antesWalkFastAnims_;
86+ AnimationSet walkFastAnims_;
87+ AnimationSet biteAnims_;
88+ AnimationSet biteRetreatAnims_;
89+ AnimationSet cansadoAnims_;
90+ AnimationSet idleCansadoAnims_;
91+ AnimationSet hitAnims_;
92+ AnimationSet dieAnims_;
93+
94+ // ?? Textures ?????????????????????????????????????????????????????????????
95+ SDL_Texture* idleTexture_ = nullptr ;
96+ SDL_Texture* alertaTexture_ = nullptr ;
97+ SDL_Texture* antesWalkFastTexture_ = nullptr ;
98+ SDL_Texture* walkFastTexture_ = nullptr ;
99+ SDL_Texture* biteTexture_ = nullptr ;
100+ SDL_Texture* biteRetreatTexture_ = nullptr ;
101+ SDL_Texture* cansadoTexture_ = nullptr ;
102+ SDL_Texture* idleCansadoTexture_ = nullptr ;
103+ SDL_Texture* hitTexture_ = nullptr ;
104+ SDL_Texture* dieTexture_ = nullptr ;
105+
106+ bool facingRight_ = false ;
107+
108+ // ?? Audio ????????????????????????????????????????????????????????????????
109+ int attackFxId = -1 ;
110+ int deadFxId = -1 ;
111+ };
0 commit comments