forked from GuillemFP/DoubleDragon3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemyStates.h
203 lines (168 loc) · 4.57 KB
/
EnemyStates.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#ifndef ENEMYSTATES_H
#define ENEMYSTATES_H
#include "Animation.h"
#include "Creature.h"
#include "SDL/include/SDL_rect.h"
class Enemy;
class EnemyState
{
public:
EnemyState(Enemy* enemy) : enemy(enemy) {}
virtual ~EnemyState() {}
virtual EnemyState* Logic() { return nullptr; }
virtual update_status Update() { return UPDATE_CONTINUE; }
virtual void OnExit() {}
protected:
Enemy* enemy;
};
class Enemy_StandState : public EnemyState
{
public:
Enemy_StandState(Enemy* enemy, const char* staticframe);
~Enemy_StandState() {}
EnemyState* Logic();
update_status Update();
void OnExit();
public:
SDL_Rect initial_rect = { 0,0,0,0 };
SDL_Rect current_rect = { 0,0,0,0 };
SDL_Rect current_collider = { 0,0,0,0 };
};
class Enemy_MoveState : public EnemyState
{
public:
Enemy_MoveState(Enemy* enemy, const char* move_animation, const char* moveup_animation);
~Enemy_MoveState() {}
EnemyState* Logic();
update_status Update();
void OnExit();
public:
Animation moving;
Animation moving_up;
Animation* current_animation = nullptr;
SDL_Rect collider_moving = { 0,0,0,0 };
SDL_Rect collider_moving_up = { 0,0,0,0 };
SDL_Rect* current_collider = nullptr;
};
class Enemy_JumpState : public EnemyState
{
public:
Enemy_JumpState(Enemy* enemy, const char* jump_frame, const char* jumpattack_frame);
~Enemy_JumpState() {}
EnemyState* Logic();
update_status Update();
void OnExit();
private:
void SetJumpParameters();
private:
SDL_Rect jump_rect = { 0,0,0,0 };
SDL_Rect jumpkick_rect = { 0,0,0,0 };
fPoint speed = { 0.0,0.0 };
float gravity = 1.0f;
iPoint initial_pos = { 0,0 };
iPoint final_pos = { 0,0 };
Creature::XDirection jump_direction = Creature::XDirection::XIDLE;
int time = 0;
fPoint current_position = { 0.0,0.0 };
bool direct_jump = false;
bool jumping_to_platform = false;
bool jumping_off_platform = false;
bool maximum_reached = true;
bool attacking = false;
SDL_Rect jump_collider = { 0,0,0,0 };
SDL_Rect aerialkick_collider = { 0,0,0,0 };
SDL_Rect attack_collider = { 0,0,0,0 };
int kick_damage = 0;
};
class Enemy_AttackState : public EnemyState
{
public:
Enemy_AttackState(Enemy* enemy, const char* punch_animation, const char* kick_animation = nullptr);
~Enemy_AttackState() { RELEASE_ARRAY(animation_colliders); RELEASE_ARRAY(shift_frames); }
EnemyState* Logic();
update_status Update();
void OnExit();
public:
Animation punch;
Animation kick;
Animation* current_animation = nullptr;
private:
SDL_Rect punch_rect = { 0,0,0,0 };
SDL_Rect kick_rect = { 0,0,0,0 };
int punch_damage = 0;
int kick_damage = 0;
int punch_frame = 0;
int kick_frame = 0;
bool attacking = false;
int attack_frame = 0;
SDL_Rect* attack_rect;
SDL_Rect* animation_colliders;
iPoint* shift_frames;
};
class Enemy_DamageState : public EnemyState
{
public:
Enemy_DamageState(Enemy* enemy, const char* high_frame, const char* low_frame);
~Enemy_DamageState() { RELEASE(in_damaged_state); }
EnemyState* Logic() { return this; }
update_status Update();
void OnExit();
void SetFrame(Creature::Attack attack_type)
{
switch (attack_type)
{
case Creature::PUNCH:
damage_rect = &high_rect;
damage_shift = &high_shift;
break;
case Creature::KICK:
damage_rect = &low_rect;
damage_shift = &low_shift;
break;
}
}
public:
Timer* in_damaged_state = nullptr;
private:
SDL_Rect high_rect = { 0,0,0,0 };
SDL_Rect low_rect = { 0,0,0,0 };
SDL_Rect* damage_rect = &high_rect;
iPoint high_shift = { 0,0 };
iPoint low_shift = { 0,0 };
iPoint* damage_shift = &high_shift;
};
class Enemy_FallState : public EnemyState
{
private:
enum FallingState { FALLING, LYING, RISING };
public:
Enemy_FallState(Enemy* player, const char* falling_frame, const char* fallen_frame, const char* rising_frame);
~Enemy_FallState() { RELEASE(states_timer); }
EnemyState* Logic();
update_status Update();
void OnExit();
void InitFall(Creature::XDirection fall_direction) { this->fall_direction = fall_direction; }
private:
void SetFallParameters();
private:
SDL_Rect falling_rect = { 0,0,0,0 };
SDL_Rect fallen_rect = { 0,0,0,0 };
SDL_Rect rising_rect = { 0,0,0,0 };
fPoint speed = { 0.0,0.0 };
float gravity = 1.0f;
iPoint initial_pos = { 0,0 };
iPoint final_pos = { 0,0 };
Creature::XDirection fall_direction = Creature::XDirection::XIDLE;
int time = 0;
fPoint current_position = { 0.0,0.0 };
bool jumping_to_platform = false;
bool jumping_off_platform = false;
bool maximum_reached = true;
FallingState state = FALLING;
Timer* states_timer;
float fallen_time = 1.0f;
float rising_time = 1.0f;
iPoint fallen_shift = { 0,0 };
iPoint rising_shift = { 0,0 };
};
#endif // !ENEMYSTATES_H