forked from naclander/openmugen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.cpp
260 lines (207 loc) · 7.08 KB
/
player.cpp
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include "global.h"
//is for debug output
char *strState[]={
"stand",
"crouch",
"air",
"liedown",
"attack",
"idle",
"hit",
"none",
"unchange"};
/*
================================================================================
Main Player class which represents one Player
Handels everything the loading and acting of the player
Todo:
Change CSffManager,CAirManager,CStateManager to pointers
to add a CreateHelper function which returns a new Player
instace which will be a copy of its parent
================================================================================
*/
CPlayer::CPlayer()
{
bRightFaced=true;
bAlive=true;
bDebugInfo=false;
bHitDefPresit=false;
bHitCounterPresit=false;
bMoveHitPresit=false;
bHitDef=false;
nLife=1000;
nPower=1000;
nStateTime=0;
nStateType=0;
nPhysic=0;
nMoveType=0;
x=y=0;
xVel=0;
yVel=0;
}
CPlayer::~CPlayer()
{
}
//Set all the pointers to all the managers
void CPlayer::SetPointers(CVideoSystem *p,CAllocater *a,CGameTimer *t)
{
m_pAlloc=a;
m_pVideoSystem=p;
m_pTimer=t;
m_SffManager.SetPointers(p,a,t,&m_AirManager);
m_StateManager.SetAlloc(a);
m_AirManager.SetAlloc(a);
m_CmdManager.SetGameTimer(t);
}
//Load the player by his given .def filename
//ToDo:Handel the .def file loading
bool CPlayer::LoadPlayer(const char* strPlayer)
{
CStateParser StateParser;
//rest memory allocater
m_pAlloc->ResetAllocater();
m_SffManager.ResetManager();
m_StateManager.Reset();
m_AirManager.ResetManager();
m_CmdManager.LoadCMDFile("kfm/kfm.cmd");
StateParser.ParseStateFile("CNS.txt",m_StateManager,m_pAlloc);
m_AirManager.OpenAir("kfm/kfm.air");
m_SffManager.LoadActToSff("kfm/kfm.act");
m_SffManager.LoadSffFile("kfm/kfm.sff");
//Make always masked blit
m_SffManager.SetBltFlags(CSffManager::BLT_NORMALMASKED);
m_SffManager.PrepareAnim(0);
// ChangeState(0);
return true;
}
/*
================================================================================
Handles the players Physic
================================================================================
*/
void CPlayer::HandlePhysic()
{
x+=xVel;
y+=yVel;
}
/*
================================================================================
Handles the FSM of the player
-checks all trigger
-and activate controllers
================================================================================
*/
void CPlayer::HandleFSM()
{
//check every state in this statedef
/* for(u16 i=0;i < lpCurrStatedef->nHowManyState; i++)
{
if( CheckState(&lpCurrStatedef->lpState[i]) )
ExecuteController(&lpCurrStatedef->lpState[i]);
}
*/
}
/*
================================================================================
Checks all the triggers in the current state
================================================================================
*/
bool CPlayer::CheckState(PLSTATE* tempState)
{
bool bTriggerAll=true;
bool bTrigger=true;
u8 nTriggerType;
return (bTriggerAll && bTrigger) ;
}
void CPlayer::ExecuteController(PLSTATE* tempState)
{
}
//updates all interlal stuff of the player
void CPlayer::UpDatePlayer()
{
HandleFSM();
HandlePhysic();
UpDateFacing();
nStateTime++;
}
//handles the facing of the player
void CPlayer::UpDateFacing()
{
if(bRightFaced)
m_SffManager.SetBltFlags(CSffManager::BLT_NORMALMASKED);
else
m_SffManager.SetBltFlags(CSffManager::BLT_FLIPHMASKED);
}
//draw debug info of the player
void CPlayer::Debug()
{
ActionElement *Anim=m_SffManager.GetCurrAnimation();
//Print information about the current Animation
m_pVideoSystem->DrawText(0,10,"Action %3i | AnimElem %3i/%3i | AnimTime %3i/%3i ",Anim->nActionNumber
,Anim->nCurrentImage+1
,Anim->nNumberOfElements
,Anim->nCurrTime
,Anim->nCompletAnimTime);
m_pVideoSystem->DrawText(0,20,"StateType=%s | MoveType=%s | Physic=%s",strState[nStateType],
strState[nMoveType],
strState[nPhysic]);
m_pVideoSystem->DrawText(0,30,"x=%3f,y=%3f",x,y-nGround);
m_pVideoSystem->DrawText(0,40,"HitDef %i | State %i | StateTime %i",bHitDef,
10,
this->nStateTime);
}
//Change State controller
void CPlayer::ChangeState(s32 nStateNumber)
{
//restet StateTime
nStateTime=0;
//get the statedef
lpCurrStatedef=m_StateManager.GetStateDef(nStateNumber);
//Set StateType
if(lpCurrStatedef->type!=untouch)
nStateType=lpCurrStatedef->type;
//Set Physic
if(lpCurrStatedef->physics!=untouch)
nPhysic=lpCurrStatedef->physics;
if(lpCurrStatedef->movetype!=untouch)
nMoveType=lpCurrStatedef->movetype;
//Set the Ctrl flag
if(lpCurrStatedef->bCtrl != -1)
bCtrl=lpCurrStatedef->bCtrl;
bHitDefPresit =lpCurrStatedef->bHitdefpersist;
bHitCounterPresit =lpCurrStatedef->bHitcountpersist;
bMoveHitPresit =lpCurrStatedef->bMovehitpersist;
//change anim if needed
if(lpCurrStatedef->nAnim != -1)
m_SffManager.PrepareAnim(lpCurrStatedef->nAnim);
if(lpCurrStatedef->Velset.x != -3333)
xVel=lpCurrStatedef->Velset.x;
if(lpCurrStatedef->Velset.y != -3333)
yVel=lpCurrStatedef->Velset.y;
if(lpCurrStatedef->nSprpriority != 255)
nSprPrio=lpCurrStatedef->nSprpriority;
if(lpCurrStatedef->nPoweradd != -3333)
nPower+=lpCurrStatedef->nPoweradd;
if(lpCurrStatedef->nJuggle != -3333)
PrintMessage("TODO:Handel juggle parameter of Statedef");
}
//Draw the Player
void CPlayer::DrawPlayer()
{
m_SffManager.BlitAnim((s16)x,(s16)y);
//draw debug info
if(bDebugInfo)
Debug();
}
/*
================================================================================
Trigger helpers
================================================================================
*/
bool CPlayer::IsAnimAviable(s32 nAnim)
{
if(m_AirManager.GetAction(nAnim) == NULL)
return false;
else
return true;
}