Skip to content

Commit 04eaa7d

Browse files
Merge pull request #404 from HiddenDreamStudio/feat/fix-bug-oso-and-enemies-lvl2
Feat/fix bug oso and enemies lvl2
2 parents 2e0cc8d + 7cf67bf commit 04eaa7d

8 files changed

Lines changed: 469 additions & 372 deletions

File tree

include/Animation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class AnimationSet {
5555
bool Has(const std::string& name) const;
5656

5757
void SetLoop(const std::string& name, bool loop);
58+
void SetFinished(const std::string& name);
5859
bool HasFinishedOnce(const std::string& name) const;
5960
int GetCurrentFrameIndex() const;
6061

include/EnemyStitchling.h

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
32
#include "Entity.h"
43
#include "Animation.h"
54
#include <box2d/box2d.h>
@@ -10,66 +9,68 @@ class Player;
109
class EnemyStitchling : public Entity
1110
{
1211
public:
13-
enum class State {
14-
IDLE, // Yoyo sitting on the ground, waiting
15-
ALERT, // Player is near, yoyo vibrates
16-
TRAP_ACTIVE, // Player stepped on rope: yoyo disappears then throws ropes
17-
DEATH // Dead / cleaned up
18-
};
19-
20-
EnemyStitchling();
21-
virtual ~EnemyStitchling();
22-
23-
bool Awake() override;
24-
bool Start() override;
25-
bool Update(float dt) override;
26-
bool CleanUp() override;
27-
28-
void OnCollision(PhysBody* physA, PhysBody* physB) override;
29-
void OnCollisionEnd(PhysBody* physA, PhysBody* physB) override;
30-
31-
void TakeDamage(int damage) override;
12+
enum class State {
13+
IDLE, // Yoyo sitting on the ground, waiting
14+
ALERT, // Player is near, yoyo vibrates
15+
TRAP_ACTIVE, // Player stepped on rope: yoyo disappears then throws ropes
16+
REVERSING, // Playing disappearing animation in reverse
17+
DEATH // Dead / cleaned up
18+
};
19+
20+
EnemyStitchling();
21+
virtual ~EnemyStitchling();
22+
23+
bool Awake() override;
24+
bool Start() override;
25+
bool Update(float dt) override;
26+
bool CleanUp() override;
27+
28+
void OnCollision(PhysBody* physA, PhysBody* physB) override;
29+
void OnCollisionEnd(PhysBody* physA, PhysBody* physB) override;
30+
void TakeDamage(int damage) override;
3231

3332
public:
34-
int texW = 256, texH = 256;
33+
int texW = 256, texH = 256;
3534

3635
private:
37-
void UpdateFSM(float dt);
38-
void EnterState(State newState);
39-
void Draw(float dt);
40-
void ApplyPlayerSlowdown();
41-
void RemovePlayerSlowdown();
42-
float GetDistanceToPlayer() const;
36+
void UpdateFSM(float dt);
37+
void EnterState(State newState);
38+
void Draw(float dt);
39+
void ApplyPlayerSlowdown();
40+
void RemovePlayerSlowdown();
41+
float GetDistanceToPlayer() const;
4342

4443
private:
45-
State currentState_ = State::IDLE;
46-
float stateTimer_ = 0.0f;
47-
48-
// Trap mechanic
49-
bool disappearDone_ = false; // true once the desaparecer animation has finished
50-
int escapeMashes_ = 0;
51-
static constexpr int MASHES_TO_ESCAPE = 5;
52-
53-
Player* playerRef_ = nullptr;
54-
bool playerWasSlowed_ = false;
55-
56-
// Box2D bodies
57-
PhysBody* pbody = nullptr;
58-
PhysBody* trapSensor_ = nullptr;
59-
60-
// Animations (only 3 needed for the yoyo)
61-
AnimationSet idleAnims_;
62-
AnimationSet alertAnims_;
63-
AnimationSet dieAnims_;
64-
65-
// Textures (only 3 needed for the yoyo)
66-
SDL_Texture* idleTexture_ = nullptr;
67-
SDL_Texture* alertTexture_ = nullptr;
68-
SDL_Texture* dieTexture_ = nullptr;
69-
70-
bool facingRight_ = false;
71-
72-
// Audio Fx IDs
73-
int attackFxId = -1;
74-
int disappearFxId = -1;
75-
};
44+
State currentState_ = State::IDLE;
45+
float stateTimer_ = 0.0f;
46+
47+
// Trap mechanic
48+
bool disappearDone_ = false; // true once the desaparecer animation has finished
49+
int escapeMashes_ = 0;
50+
float escapeTimer_ = 0.0f; // time the player has been trapped
51+
static constexpr int MASHES_TO_ESCAPE = 5;
52+
static constexpr float ESCAPE_TIME_LIMIT = 3000.0f; // ms before damage is dealt
53+
54+
Player* playerRef_ = nullptr;
55+
bool playerWasSlowed_ = false;
56+
57+
// Box2D bodies
58+
PhysBody* pbody = nullptr;
59+
PhysBody* trapSensor_ = nullptr;
60+
61+
// Animations
62+
AnimationSet idleAnims_;
63+
AnimationSet alertAnims_;
64+
AnimationSet dieAnims_;
65+
66+
// Textures
67+
SDL_Texture* idleTexture_ = nullptr;
68+
SDL_Texture* alertTexture_ = nullptr;
69+
SDL_Texture* dieTexture_ = nullptr;
70+
71+
bool facingRight_ = false;
72+
73+
// Audio
74+
int attackFxId = -1;
75+
int disappearFxId = -1;
76+
};

include/EnemyWindUpScurry.h

Lines changed: 94 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
32
#include "Entity.h"
43
#include "Animation.h"
54
#include <box2d/box2d.h>
@@ -10,88 +9,103 @@ class Player;
109
class EnemyWindUpScurry : public Entity
1110
{
1211
public:
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

3737
public:
38-
int texW = 128, texH = 128;
38+
int texW = 128, texH = 128;
3939

4040
private:
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

4747
private:
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+
};

include/Player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Player : public Entity
6666
bool HasStuffedAnimal() const { return hasStuffedAnimal_; }
6767
void SetHasStuffedAnimal(bool v) { hasStuffedAnimal_ = v; }
6868
bool IsBearMode() const { return isBearMode_; }
69+
bool IsBearModeActive() const { return isBearMode_ || isBearTransforming_ || isThrowingBear_ || isKidSleeping_; }
6970

7071
private:
7172

src/Animation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ void AnimationSet::SetLoop(const std::string& name, bool loop) {
167167
}
168168
}
169169

170+
void AnimationSet::SetFinished(const std::string& name) {
171+
if (Has(name)) {
172+
clips_[name].SetFinished();
173+
}
174+
}
175+
170176
bool AnimationSet::HasFinishedOnce(const std::string& name) const {
171177
if (Has(name)) {
172178
return clips_.at(name).HasFinishedOnce();

0 commit comments

Comments
 (0)