2
2
3
3
extern char debug[1024 ];
4
4
extern SCENEid sID ;
5
+ extern WORLDid gID ;
6
+ extern AUDIOid audioG;
7
+ extern AUDIOid audioD;
5
8
using namespace std ;
6
9
#define MOVE_LENGTH 20.0
7
10
@@ -15,6 +18,12 @@ ActorStateMachine::~ActorStateMachine(void)
15
18
FnScene scene;
16
19
scene.Object (sID );
17
20
scene.DeleteObject (this ->bloodID );
21
+ /*
22
+ FnWorld gw;
23
+ gw.Object(gID);
24
+ gw.DeleteAudio(audioG);
25
+ gw.DeleteAudio(audioD);
26
+ */
18
27
}
19
28
20
29
ActorStateMachine::ActorStateMachine (ACTORid character, char * ActionFilename){
@@ -27,6 +36,25 @@ ActorStateMachine::ActorStateMachine(ACTORid character, char * ActionFilename){
27
36
this ->effectiveAttack = FALSE ;
28
37
this ->initActionIDMap (ActionFilename);
29
38
this ->initLife ();
39
+ /*
40
+ FnWorld gw;
41
+ gw.Object(gID);
42
+ gw.SetAudioPath("Data\\Audio");
43
+ audioG = gw.CreateAudio();
44
+ FnAudio audio;
45
+ audio.Object(audioG);
46
+ BOOL beA = audio.Load("guard"); // au_bullet.hit1.wav
47
+ if (beA == FALSE){
48
+ sprintf(debug, "%s guard load failed\n", debug);
49
+ }
50
+
51
+ audioD = gw.CreateAudio();
52
+ audio.Object(audioD);
53
+ beA = audio.Load("damage"); // au_bullet.hit1.wav
54
+ if (beA == FALSE){
55
+ sprintf(debug, "%s damage load failed\n", debug);
56
+ }
57
+ */
30
58
}
31
59
32
60
BOOL ActorStateMachine::initLife (){
@@ -95,13 +123,7 @@ BOOL ActorStateMachine::CanAttack(){
95
123
}
96
124
97
125
BOOL ActorStateMachine::CanBeControl (){
98
- /*
99
- if (this->state == STATEATTACK || this->state == STATEBEATTACK){
100
- return FALSE;
101
- }else{
102
- return TRUE;
103
- }*/
104
- if (this ->state == STATEIDLE || this ->state == STATERUN){
126
+ if (this ->state == STATEIDLE || this ->state == STATERUN || this ->state == STATEGUARD){
105
127
return TRUE ;
106
128
}else {
107
129
return FALSE ;
@@ -115,7 +137,7 @@ int ActorStateMachine::ChangeState(ActorState s, BOOL forceSet){
115
137
this ->state = s;
116
138
}
117
139
118
- if (s == STATEIDLE || s == STATERUN || s == STATEDAMAGE || s == STATEDIE){
140
+ if (s == STATEIDLE || s == STATERUN || s == STATEDAMAGE || s == STATEDIE ||s == STATEGUARD ){
119
141
if (s == STATEIDLE){
120
142
this ->SetNewAction (" CombatIdle" );
121
143
}else if (s == STATERUN){
@@ -130,14 +152,45 @@ int ActorStateMachine::ChangeState(ActorState s, BOOL forceSet){
130
152
this ->SetNewAction (" HeavyDamage" );
131
153
}else if (s == STATEDIE){
132
154
this ->SetNewAction (" Die" );
155
+ }else if (s == STATEGUARD){
156
+ this ->SetNewAction (" Guard" );
133
157
}
134
158
}else if (s == STATEATTACK){
135
159
// Serial attack start;
136
160
this ->startAttack = TRUE ;
161
+ }else if (s == STATEVANISH){
162
+ FnWorld gw;
163
+ gw.Object (gID );
164
+ gw.SetTexturePath (" Data\\ FXs\\ Textures" );
165
+ gw.SetObjectPath (" Data\\ FXs\\ Models" );
166
+
167
+ float pos[3 ];
168
+ FnActor actor;
169
+ actor.Object (this ->character );
170
+ actor.GetWorldPosition (pos);
171
+
172
+ fxDie = new eF3DFX (sID );
173
+ fxDie->SetWorkPath (" Data\\ FXs" );
174
+ BOOL beOK = fxDie->Load (" dust3" );
175
+ eF3DBaseFX *fx;
176
+ int i, numFX = fxDie->NumberFXs ();
177
+ for (i = 0 ; i < numFX; i++) {
178
+ fx = fxDie->GetFX (i);
179
+ fx->InitPosition (pos);
180
+ }
137
181
}
138
182
return 0 ;
139
183
}
140
184
185
+ BOOL ActorStateMachine::CharacterSetGuard (){
186
+ if (this ->CanBeControl () == TRUE ){
187
+ this ->ChangeState (STATEGUARD);
188
+ return TRUE ;
189
+ }else {
190
+ return FALSE ;
191
+ }
192
+ }
193
+
141
194
BOOL ActorStateMachine::CharacterSetIdle (){
142
195
if (this ->CanBeControl () == TRUE ){
143
196
this ->ChangeState (STATEIDLE);
@@ -180,15 +233,29 @@ BOOL ActorStateMachine::PlayAction(int skip){
180
233
}else if (this ->state == STATEDAMAGE){
181
234
BOOL ret = actor.Play (0 ,ONCE, (float )skip, TRUE ,TRUE );
182
235
if (ret == FALSE ){
183
- sprintf (debug, " %s damage end\n " ,debug);
236
+ // sprintf(debug, "%s damage end\n",debug);
184
237
this ->ChangeState (STATEIDLE);
185
238
}
186
239
}else if (this ->state == STATEDIE){
187
240
BOOL ret = actor.Play (0 ,ONCE, (float )skip, TRUE ,TRUE );
188
- /*
241
+
189
242
if (ret == FALSE ){
190
243
sprintf (debug, " %s character die\n " ,debug);
191
- }*/
244
+ this ->ChangeState (STATEVANISH);
245
+ }
246
+ }else if (this ->state == STATEVANISH){
247
+ if (this ->fxDie != NULL ) {
248
+ BOOL beOK = this ->fxDie ->Play ((float ) skip);
249
+ if (!beOK) {
250
+ // fxDie->Reset(); // make it from the starting position and play it again
251
+ // should delete the character
252
+ delete fxDie;
253
+ this ->fxDie = NULL ;
254
+ FnScene scene;
255
+ scene.Object (sID );
256
+ scene.DeleteActor (this ->character );
257
+ }
258
+ }
192
259
}
193
260
return TRUE ;
194
261
}
@@ -200,6 +267,7 @@ BOOL ActorStateMachine::PlayAttackAction(int skip){
200
267
201
268
char attackName[20 ] = " \0 " ;
202
269
if (this ->startAttack == TRUE ){// first attack
270
+ this ->lastAttackFrame = 0 .0f ;
203
271
this ->startAttack = FALSE ; // reset
204
272
// sprintf(debug, "%sstart attack\n", debug);
205
273
if (this ->attackKeyQueue [currentAttackIndex] == NORMAL_ATT ){
@@ -219,6 +287,7 @@ BOOL ActorStateMachine::PlayAttackAction(int skip){
219
287
BOOL ret = actor.Play (0 ,ONCE, (float )skip, TRUE ,TRUE );
220
288
this ->UpdateEffectiveAttack ();
221
289
if (ret == FALSE ){
290
+ this ->lastAttackFrame = 0 .0f ;
222
291
// play the next one
223
292
this ->effectiveAttack = FALSE ;
224
293
currentAttackIndex++;
@@ -300,10 +369,9 @@ BOOL ActorStateMachine::UpdateEffectiveAttack(){
300
369
return FALSE ;
301
370
}
302
371
303
- int ActorStateMachine::AttackEnemy (float enemyPos[3 ], BOOL *beOutShot){
304
- // beOutShot is a parameter
305
- if (beOutShot != NULL ){
306
- *beOutShot = FALSE ;
372
+ int ActorStateMachine::AttackEnemy (float enemyPos[3 ], SHOT_CODE *shot_code){
373
+ if (shot_code != NULL ){
374
+ *shot_code = FALSE ;
307
375
}
308
376
// the return value is the attack power
309
377
FnActor actor;
@@ -335,9 +403,9 @@ int ActorStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
335
403
// sprintf(debug, "%s cosine = %lf\n",debug,cosine);
336
404
337
405
if (this ->attackKeyQueue [currentAttackIndex] == HEAVY_ATT || currentAttackIndex == MAXATTACK -1 ){
338
- *beOutShot = TRUE ;
406
+ *shot_code = BIG_SHOT ;
339
407
}else {
340
- *beOutShot = FALSE ;
408
+ *shot_code = SMALL_SHOT ;
341
409
}
342
410
343
411
if (this ->currentAttackIndex == 0 ){
@@ -354,26 +422,45 @@ int ActorStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
354
422
return 0 ;
355
423
}
356
424
357
- void ActorStateMachine::TakeDamage (float damage, BOOL beShot , float *attackerPos ){
425
+ void ActorStateMachine::TakeDamage (int damage, SHOT_CODE shot_code , float *attackerPos ){
358
426
FnActor actor;
359
427
actor.Object (character);
360
428
float pos[3 ];
361
429
float dir[3 ];
362
430
actor.GetWorldPosition (pos);
363
431
actor.GetWorldDirection (dir, NULL );
364
- if (beShot == TRUE && attackerPos !=NULL ){
432
+ if ( shot_code != STUCK_SHOT && attackerPos !=NULL ){
365
433
float newDir[3 ];
366
434
newDir[0 ] = attackerPos[0 ] - pos[0 ];
367
435
newDir[1 ] = attackerPos[1 ] - pos[1 ];
368
436
newDir[2 ] = 0 .0f ;
369
437
actor.SetWorldDirection (newDir,NULL );
370
- // if (beShot == TRUE ){
438
+ if (shot_code == BIG_SHOT ){
371
439
actor.MoveForward (-OUTSHOT_DIS,TRUE , FALSE , 0.0 , TRUE );
372
- // }
440
+ // sprintf(debug, "%s OUTSHOT_DIS\n", debug);
441
+ }else if (shot_code == SMALL_SHOT){
442
+ actor.MoveForward (-SMALL_OUTSHOT_DIS,TRUE , FALSE , 0.0 , TRUE );
443
+ // sprintf(debug, "%s SMALL_OUTSHOT_DIS\n", debug);
444
+ }
373
445
actor.SetWorldDirection (dir,NULL );
374
446
}
447
+
448
+ if (this ->state == STATEGUARD){
449
+ FnAudio audio;
450
+ audio.Object (audioG);
451
+ audio.Play (ONCE);
452
+ return ; // no damage
453
+ }else {
454
+ FnAudio audio;
455
+ audio.Object (audioD);
456
+ // if (audio.IsPlaying() == FALSE){
457
+ audio.Play (ONCE);
458
+ // }
459
+
460
+
461
+ }
375
462
this ->life -= damage;
376
- sprintf (debug, " %s life=%d\n " , debug, this ->life );
463
+ // sprintf(debug, "%s life=%d\n", debug, this->life);
377
464
if (this ->life <= 0 ) {
378
465
this ->ChangeState (STATEDIE, TRUE );
379
466
}else {
@@ -384,6 +471,6 @@ void ActorStateMachine::TakeDamage(float damage, BOOL beShot, float *attackerPos
384
471
blood.Object (bloodID, 0 );
385
472
float size[2 ];
386
473
blood.GetSize (size);
387
- size[0 ] = life / MAX_LIFE * 50 .0f ;
474
+ size[0 ] = ( float ) life / MAX_LIFE * 50 .0f ;
388
475
blood.SetSize (size);
389
476
}
0 commit comments