Skip to content

Commit 1527fb3

Browse files
author
Chun-Yi
committed
Merge pull request #13 from wingzero0/master
給你測試用
2 parents 539dff5 + 338ad7b commit 1527fb3

11 files changed

+247
-69
lines changed

AIControl.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,44 @@
77
using namespace std;
88
extern char debug[1024];
99

10-
AIControl::AIControl(int id)
10+
AIControl::AIControl(ACTORid id)
1111
{
1212
this->lyubuId = id;
1313
}
1414

1515

1616
AIControl::~AIControl(void)
1717
{
18-
for (int i = 0;i< this->npcStateMachineList.size(); i++){
18+
for (unsigned int i = 0;i< this->npcStateMachineList.size(); i++){
1919
delete this->npcStateMachineList[i];
2020
}
2121
}
2222

2323
int AIControl::AddNPC(ACTORid npc, char * ActionFilename){
2424
ActorStateMachine* stm = new ActorStateMachine(npc, ActionFilename);
2525
this->npcStateMachineList.push_back(stm);
26+
stm->life = 10;
27+
return 0;
28+
}
29+
30+
int AIControl::AddBossNPC(ACTORid npc, char * ActionFilename){
31+
ActorStateMachine* stm = new ActorStateMachine(npc, ActionFilename);
32+
this->npcStateMachineList.push_back(stm);
33+
this->bossStateMachine = stm;
34+
this->bossStateMachine->life = 100;
2635
return 0;
2736
}
2837

2938
void AIControl::PlayAction(int skip){
30-
for (int i = 0;i< this->npcStateMachineList.size(); i++){
39+
for (unsigned int i = 0;i< this->npcStateMachineList.size(); i++){
3140
npcStateMachineList[i]->PlayAction(skip);
3241
}
3342
}
3443
void AIControl::moveTowardLyubu() {
3544
for (int i = 0;i< this->npcStateMachineList.size(); i++){
45+
if (this->npcStateMachineList[i]->state == STATEDIE){
46+
47+
}
3648
if (npcStateMachineList[i]->CanBeControl() == FALSE){
3749
continue;
3850
}
@@ -108,7 +120,7 @@ void AIControl::moveTowardLyubu() {
108120
npcStateMachineList[i]->AppendAttackCode(NORMAL_ATT);
109121
}
110122
else {
111-
npcStateMachineList[i]->ChangeState(STATEIDLE);
123+
npcStateMachineList[i]->CharacterSetIdle();
112124
}
113125
}
114126
}

AIControl.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
class AIControl
1414
{
1515
public:
16-
AIControl(int);
16+
AIControl(ACTORid id);
1717
std::vector<ActorStateMachine *> npcStateMachineList;
18+
ActorStateMachine * bossStateMachine;
1819
AIControl(void);
1920
virtual ~AIControl(void);
2021
int AddNPC(ACTORid ncp, char * ActionFilename);
22+
int AddBossNPC(ACTORid ncp, char * ActionFilename);
2123
void PlayAction(int skip);
2224
void moveTowardLyubu();
2325
private:
24-
int lyubuId;
26+
ACTORid lyubuId;
27+
//ACTORid boss;
28+
std::vector<ActorStateMachine *> npcDropList;
2529
};
2630

ActorStateMachine.cpp

Lines changed: 110 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
extern char debug[1024];
44
extern SCENEid sID;
5+
extern WORLDid gID;
6+
extern AUDIOid audioG;
7+
extern AUDIOid audioD;
58
using namespace std;
69
#define MOVE_LENGTH 20.0
710

@@ -15,6 +18,12 @@ ActorStateMachine::~ActorStateMachine(void)
1518
FnScene scene;
1619
scene.Object(sID);
1720
scene.DeleteObject(this->bloodID);
21+
/*
22+
FnWorld gw;
23+
gw.Object(gID);
24+
gw.DeleteAudio(audioG);
25+
gw.DeleteAudio(audioD);
26+
*/
1827
}
1928

2029
ActorStateMachine::ActorStateMachine(ACTORid character, char * ActionFilename){
@@ -27,6 +36,25 @@ ActorStateMachine::ActorStateMachine(ACTORid character, char * ActionFilename){
2736
this->effectiveAttack = FALSE;
2837
this->initActionIDMap(ActionFilename);
2938
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+
*/
3058
}
3159

3260
BOOL ActorStateMachine::initLife(){
@@ -95,13 +123,7 @@ BOOL ActorStateMachine::CanAttack(){
95123
}
96124

97125
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){
105127
return TRUE;
106128
}else {
107129
return FALSE;
@@ -115,7 +137,7 @@ int ActorStateMachine::ChangeState(ActorState s, BOOL forceSet){
115137
this->state = s;
116138
}
117139

118-
if (s == STATEIDLE || s == STATERUN || s == STATEDAMAGE || s == STATEDIE){
140+
if (s == STATEIDLE || s == STATERUN || s == STATEDAMAGE || s == STATEDIE ||s == STATEGUARD){
119141
if (s == STATEIDLE){
120142
this->SetNewAction("CombatIdle");
121143
}else if (s == STATERUN){
@@ -130,14 +152,45 @@ int ActorStateMachine::ChangeState(ActorState s, BOOL forceSet){
130152
this->SetNewAction("HeavyDamage");
131153
}else if (s == STATEDIE){
132154
this->SetNewAction("Die");
155+
}else if (s == STATEGUARD){
156+
this->SetNewAction("Guard");
133157
}
134158
}else if (s == STATEATTACK){
135159
// Serial attack start;
136160
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+
}
137181
}
138182
return 0;
139183
}
140184

185+
BOOL ActorStateMachine::CharacterSetGuard(){
186+
if (this->CanBeControl() == TRUE){
187+
this->ChangeState(STATEGUARD);
188+
return TRUE;
189+
}else{
190+
return FALSE;
191+
}
192+
}
193+
141194
BOOL ActorStateMachine::CharacterSetIdle(){
142195
if (this->CanBeControl() == TRUE){
143196
this->ChangeState(STATEIDLE);
@@ -180,15 +233,29 @@ BOOL ActorStateMachine::PlayAction(int skip){
180233
}else if (this->state == STATEDAMAGE){
181234
BOOL ret = actor.Play(0,ONCE, (float)skip, TRUE,TRUE);
182235
if (ret == FALSE){
183-
sprintf(debug, "%s damage end\n",debug);
236+
//sprintf(debug, "%s damage end\n",debug);
184237
this->ChangeState(STATEIDLE);
185238
}
186239
}else if (this->state == STATEDIE){
187240
BOOL ret = actor.Play(0,ONCE, (float)skip, TRUE,TRUE);
188-
/*
241+
189242
if (ret == FALSE){
190243
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+
}
192259
}
193260
return TRUE;
194261
}
@@ -200,6 +267,7 @@ BOOL ActorStateMachine::PlayAttackAction(int skip){
200267

201268
char attackName[20] = "\0";
202269
if (this->startAttack == TRUE){// first attack
270+
this->lastAttackFrame = 0.0f;
203271
this->startAttack = FALSE; // reset
204272
//sprintf(debug, "%sstart attack\n", debug);
205273
if (this->attackKeyQueue[currentAttackIndex] == NORMAL_ATT ){
@@ -219,6 +287,7 @@ BOOL ActorStateMachine::PlayAttackAction(int skip){
219287
BOOL ret = actor.Play(0,ONCE, (float)skip, TRUE,TRUE);
220288
this->UpdateEffectiveAttack();
221289
if (ret == FALSE){
290+
this->lastAttackFrame = 0.0f;
222291
// play the next one
223292
this->effectiveAttack = FALSE;
224293
currentAttackIndex++;
@@ -300,10 +369,9 @@ BOOL ActorStateMachine::UpdateEffectiveAttack(){
300369
return FALSE;
301370
}
302371

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;
307375
}
308376
// the return value is the attack power
309377
FnActor actor;
@@ -335,9 +403,9 @@ int ActorStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
335403
//sprintf(debug, "%s cosine = %lf\n",debug,cosine);
336404

337405
if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT || currentAttackIndex == MAXATTACK -1){
338-
*beOutShot = TRUE;
406+
*shot_code = BIG_SHOT;
339407
}else {
340-
*beOutShot = FALSE;
408+
*shot_code = SMALL_SHOT;
341409
}
342410

343411
if (this->currentAttackIndex == 0){
@@ -354,26 +422,45 @@ int ActorStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
354422
return 0;
355423
}
356424

357-
void ActorStateMachine::TakeDamage(float damage, BOOL beShot, float *attackerPos ){
425+
void ActorStateMachine::TakeDamage(int damage, SHOT_CODE shot_code, float *attackerPos ){
358426
FnActor actor;
359427
actor.Object(character);
360428
float pos[3];
361429
float dir[3];
362430
actor.GetWorldPosition(pos);
363431
actor.GetWorldDirection(dir, NULL);
364-
if (beShot == TRUE && attackerPos !=NULL){
432+
if ( shot_code != STUCK_SHOT && attackerPos !=NULL){
365433
float newDir[3];
366434
newDir[0] = attackerPos[0] - pos[0];
367435
newDir[1] = attackerPos[1] - pos[1];
368436
newDir[2] = 0.0f;
369437
actor.SetWorldDirection(newDir,NULL);
370-
//if (beShot == TRUE){
438+
if (shot_code == BIG_SHOT){
371439
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+
}
373445
actor.SetWorldDirection(dir,NULL);
374446
}
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+
}
375462
this->life -= damage;
376-
sprintf(debug, "%s life=%d\n", debug, this->life);
463+
//sprintf(debug, "%s life=%d\n", debug, this->life);
377464
if (this->life <= 0) {
378465
this->ChangeState(STATEDIE, TRUE);
379466
}else {
@@ -384,6 +471,6 @@ void ActorStateMachine::TakeDamage(float damage, BOOL beShot, float *attackerPos
384471
blood.Object(bloodID, 0);
385472
float size[2];
386473
blood.GetSize(size);
387-
size[0] = life / MAX_LIFE * 50.0f;
474+
size[0] = (float) life / MAX_LIFE * 50.0f;
388475
blood.SetSize(size);
389476
}

0 commit comments

Comments
 (0)