-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayerStates.h
192 lines (158 loc) · 4.27 KB
/
PlayerStates.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
#ifndef PLAYERSTATES_H
#define PLAYERSTATES_H
#include "Animation.h"
#include "Creature.h"
#include "SDL/include/SDL_rect.h"
class Player;
class PlayerState
{
public:
PlayerState(Player* player) : player(player) {}
virtual ~PlayerState() {}
virtual PlayerState* HandleInput() { return nullptr; }
virtual update_status Update() { return UPDATE_CONTINUE; }
virtual void OnExit() {}
protected:
Player* player;
};
class Player_StandState : public PlayerState
{
public:
Player_StandState(Player* player, const char* staticframe);
~Player_StandState() {}
PlayerState* HandleInput();
update_status Update();
void OnExit();
public:
SDL_Rect initial_rect = { 0,0,0,0 };
SDL_Rect current_rect = { 0,0,0,0 };
};
class Player_MoveState : public PlayerState
{
public:
Player_MoveState(Player* player, const char* move_animation, const char* moveup_animation);
~Player_MoveState() {}
PlayerState* HandleInput();
update_status Update();
void OnExit();
public:
Animation moving;
Animation moving_up;
Animation* current_animation = nullptr;
SDL_Rect last_moving = { 0,0,0,0 };
SDL_Rect last_moving_up = { 0,0,0,0 };
};
class Player_JumpState : public PlayerState
{
public:
Player_JumpState(Player* player, const char* jump_frame, const char* jumpattack_frame);
~Player_JumpState() {}
PlayerState* HandleInput();
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 Player_AttackState : public PlayerState
{
public:
Player_AttackState(Player* player, const char* punch_animation, const char* kick_animation);
~Player_AttackState() {}
PlayerState* HandleInput();
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;
};
class Player_DamageState : public PlayerState
{
public:
Player_DamageState(Player* player, const char* high_frame, const char* low_frame);
~Player_DamageState() { RELEASE(in_damaged_state); }
PlayerState* HandleInput() { return this; }
update_status Update();
void OnExit();
void SetFrame(Creature::Attack attack_type)
{
switch (attack_type)
{
case Creature::PUNCH:
damage_rect = &high_rect;
break;
case Creature::KICK:
damage_rect = &low_rect;
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;
};
class Player_FallState : public PlayerState
{
private:
enum FallingState { FALLING, LYING, RISING };
public:
Player_FallState(Player* player, const char* falling_frame, const char* fallen_frame, const char* rising_frame);
~Player_FallState() { RELEASE(states_timer); }
PlayerState* HandleInput();
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 };
};
#endif // !PLAYERSTATES_H