Skip to content

Commit 29b3700

Browse files
unknownunknown
unknown
authored and
unknown
committed
ActorStateMachine.cpp (or lyubuStateMachine)
AttackEnemy: beOutShot => shot_code
1 parent ecf6822 commit 29b3700

9 files changed

+74
-50
lines changed

AIControl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
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
}

AIControl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
class AIControl
1414
{
1515
public:
16-
AIControl(int);
16+
AIControl(ACTORid id);
1717
std::vector<ActorStateMachine *> npcStateMachineList;
1818
AIControl(void);
1919
virtual ~AIControl(void);
2020
int AddNPC(ACTORid ncp, char * ActionFilename);
2121
void PlayAction(int skip);
2222
void moveTowardLyubu();
2323
private:
24-
int lyubuId;
24+
ACTORid lyubuId;
2525
};
2626

ActorStateMachine.cpp

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ BOOL ActorStateMachine::PlayAttackAction(int skip){
233233

234234
char attackName[20] = "\0";
235235
if (this->startAttack == TRUE){// first attack
236+
this->lastAttackFrame = 0.0f;
236237
this->startAttack = FALSE; // reset
237238
//sprintf(debug, "%sstart attack\n", debug);
238239
if (this->attackKeyQueue[currentAttackIndex] == NORMAL_ATT ){
@@ -252,6 +253,7 @@ BOOL ActorStateMachine::PlayAttackAction(int skip){
252253
BOOL ret = actor.Play(0,ONCE, (float)skip, TRUE,TRUE);
253254
this->UpdateEffectiveAttack();
254255
if (ret == FALSE){
256+
this->lastAttackFrame = 0.0f;
255257
// play the next one
256258
this->effectiveAttack = FALSE;
257259
currentAttackIndex++;
@@ -333,10 +335,9 @@ BOOL ActorStateMachine::UpdateEffectiveAttack(){
333335
return FALSE;
334336
}
335337

336-
int ActorStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
337-
// beOutShot is a parameter
338-
if (beOutShot != NULL){
339-
*beOutShot = FALSE;
338+
int ActorStateMachine::AttackEnemy(float enemyPos[3], SHOT_CODE *shot_code){
339+
if (shot_code != NULL){
340+
*shot_code = FALSE;
340341
}
341342
// the return value is the attack power
342343
FnActor actor;
@@ -368,9 +369,9 @@ int ActorStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
368369
//sprintf(debug, "%s cosine = %lf\n",debug,cosine);
369370

370371
if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT || currentAttackIndex == MAXATTACK -1){
371-
*beOutShot = TRUE;
372+
*shot_code = BIG_SHOT;
372373
}else {
373-
*beOutShot = FALSE;
374+
*shot_code = SMALL_SHOT;
374375
}
375376

376377
if (this->currentAttackIndex == 0){
@@ -387,34 +388,45 @@ int ActorStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
387388
return 0;
388389
}
389390

390-
void ActorStateMachine::TakeDamage(float damage, BOOL beShot, float *attackerPos ){
391-
if (this->state == STATEGUARD){
392-
FnAudio audio;
393-
audio.Object(audioG);
394-
audio.Play(ONCE);
395-
return;
396-
}else{
397-
FnAudio audio;
398-
audio.Object(audioD);
399-
audio.Play(ONCE);
400-
}
391+
void ActorStateMachine::TakeDamage(int damage, SHOT_CODE shot_code, float *attackerPos ){
401392
FnActor actor;
402393
actor.Object(character);
403394
float pos[3];
404395
float dir[3];
405396
actor.GetWorldPosition(pos);
406397
actor.GetWorldDirection(dir, NULL);
407-
if (beShot == TRUE && attackerPos !=NULL){
398+
if ( shot_code != STUCK_SHOT && attackerPos !=NULL){
408399
float newDir[3];
409400
newDir[0] = attackerPos[0] - pos[0];
410401
newDir[1] = attackerPos[1] - pos[1];
411402
newDir[2] = 0.0f;
412403
actor.SetWorldDirection(newDir,NULL);
413-
actor.MoveForward(-OUTSHOT_DIS,TRUE, FALSE, 0.0, TRUE);
404+
if (shot_code == BIG_SHOT){
405+
actor.MoveForward(-OUTSHOT_DIS,TRUE, FALSE, 0.0, TRUE);
406+
//sprintf(debug, "%s OUTSHOT_DIS\n", debug);
407+
}else if (shot_code == SMALL_SHOT){
408+
actor.MoveForward(-SMALL_OUTSHOT_DIS,TRUE, FALSE, 0.0, TRUE);
409+
//sprintf(debug, "%s SMALL_OUTSHOT_DIS\n", debug);
410+
}
414411
actor.SetWorldDirection(dir,NULL);
415412
}
413+
414+
if (this->state == STATEGUARD){
415+
FnAudio audio;
416+
audio.Object(audioG);
417+
audio.Play(ONCE);
418+
return; // no damage
419+
}else{
420+
FnAudio audio;
421+
audio.Object(audioD);
422+
//if (audio.IsPlaying() == FALSE){
423+
audio.Play(ONCE);
424+
//}
425+
426+
427+
}
416428
this->life -= damage;
417-
sprintf(debug, "%s life=%d\n", debug, this->life);
429+
//sprintf(debug, "%s life=%d\n", debug, this->life);
418430
if (this->life <= 0) {
419431
this->ChangeState(STATEDIE, TRUE);
420432
}else {
@@ -425,6 +437,6 @@ void ActorStateMachine::TakeDamage(float damage, BOOL beShot, float *attackerPos
425437
blood.Object(bloodID, 0);
426438
float size[2];
427439
blood.GetSize(size);
428-
size[0] = life / MAX_LIFE * 50.0f;
440+
size[0] = (float) life / MAX_LIFE * 50.0f;
429441
blood.SetSize(size);
430442
}

ActorStateMachine.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ typedef int ActorState;
1919
#define ULTIMATE_ATT 2
2020
typedef int ATTACK_CODE;
2121

22-
#define OUTSHOT_DIS 100.0
22+
#define OUTSHOT_DIS 200.0
23+
#define SMALL_OUTSHOT_DIS 50.0
2324
#define MAX_LIFE 1000.0
2425
#define ROBOT_ATTACKRANGE 18000.0
2526

@@ -44,8 +45,7 @@ class ActorStateMachine
4445
int lastAttackIndex;
4546
BOOL attackDisable;
4647
BOOL startAttack;
47-
//AUDIOid audioG;//guard
48-
//AUDIOid audioD;//damage
48+
float lastAttackFrame;
4949
int life;
5050
BOOL initActionIDMap(char *ActionFilename);
5151
std::map<std::string, ACTIONid> ActionIDMap;
@@ -69,7 +69,7 @@ class ActorStateMachine
6969
BOOL AppendAttackCode(ATTACK_CODE code);
7070
virtual BOOL PlayAction(int skip);
7171
BOOL CheckEffectiveAttack();
72-
virtual int AttackEnemy(float enemyPos[3], BOOL *beOutShot = NULL); // beOutShot will be assgin a value after the call
73-
virtual void TakeDamage(float damage, BOOL beShot, float* attackerPos);
72+
virtual int AttackEnemy(float enemyPos[3], SHOT_CODE *shot_code = NULL); // shot_code will be assgin a value after the call
73+
virtual void TakeDamage(int damage, SHOT_CODE shot_code, float* attackerPos);
7474
};
7575

BattleRoom.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void BattleRoom::RefreshArena(){
2929
actor.GetWorldPosition(playerPos);
3030

3131
this->AreanList.clear();
32-
for (int i =0;i< this->npcStateMachineList.size();i++){
32+
for (unsigned int i =0;i< this->npcStateMachineList.size();i++){
3333
npc.Object(this->npcStateMachineList[i]->character);
3434
npc.GetWorldPosition(npcPos);
3535
//this->npcStateMachineList[i]->AppendAttackCode(NORMAL_ATT);
@@ -82,15 +82,15 @@ void BattleRoom::PerformAttack(){
8282
actor.GetWorldPosition(pPos);
8383

8484
int beOutShot;
85-
for (int i= 0;i< this->AreanList.size();i++){
85+
for (unsigned int i= 0;i< this->AreanList.size();i++){
8686
ACTORid tmpid = AreanList[i]->character;
8787
if (playerHitMap.find(tmpid) == playerHitMap.end()){
8888
npc.Object(tmpid);
8989
npc.GetWorldPosition(nPos);
9090
int attackPower = this->playerStateMachine->AttackEnemy(nPos, &beOutShot);
9191
if (attackPower > 0 ){
9292
// get a new victim;
93-
sprintf(debug, "%s new victim\n",debug);
93+
//sprintf(debug, "%s new victim\n",debug);
9494
if ( this->AreanList[i]->state != STATEDIE){
9595
this->AreanList[i]->TakeDamage(attackPower, beOutShot, pPos);
9696
}
@@ -113,13 +113,13 @@ void BattleRoom::PerformAttack(){
113113
if (npcHitMap.find(tmpid) == npcHitMap.end()){ // find nothing
114114
npc.Object(tmpid);
115115
npc.GetWorldPosition(nPos);
116-
BOOL beOutShot;
116+
int beOutShot;
117117

118118
int attackPower = this->AreanList[i]->AttackEnemy(pPos, &beOutShot);
119119
if (attackPower > 0 ){
120-
sprintf(debug, "%s player damage\n",debug);
120+
//sprintf(debug, "%s player damage\n",debug);
121121
if ( this->playerStateMachine->state != STATEDIE){
122-
this->playerStateMachine->TakeDamage(attackPower, beOutShot, pPos);
122+
this->playerStateMachine->TakeDamage(attackPower, beOutShot, nPos);
123123
}
124124
npcHitMap[tmpid] = TRUE;
125125
}

GameControl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,9 @@ void GameControl::ResetCamView(){
412412
cUDir[2] = vec[0] * cp[1] - vec[1] * cp[0];
413413

414414
cam.SetWorldDirection(vec, cUDir);
415-
this->CamMove(20.0f);
415+
for (int i= 0;i< 10;i++){
416+
this->CamMove(2.0f);
417+
}
416418
}
417419

418420
void GameControl::CamMove(float skip){

KeyboardControl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int KeyboardControl::DirControl(){
3737
key = MOVE_RIGHT;
3838
}
3939

40-
float theta = this->GenerateTargetDir(key);
40+
this->GenerateTargetDir(key);
4141

4242
if (this->isOnTargetDir()){
4343
//sprintf(debug ,"in move\n");

LyubuStateMachine.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ BOOL LyubuStateMachine::PlayAttackAction(int skip){
4343
// the difference from parent function is that this function contain the sound fx
4444
FnActor actor;
4545
actor.Object(this->character);
46-
ACTIONid actionID;
4746

4847
//this->setAttackState();
4948

5049
char attackName[20] = "\0";
5150
if (this->startAttack == TRUE){// first attack
51+
this->lastAttackFrame = 0.0f;
5252
this->startAttack = FALSE; // reset
5353
//sprintf(debug, "%sstart attack\n", debug);
5454
if (this->attackKeyQueue[currentAttackIndex] == NORMAL_ATT ){
@@ -77,6 +77,7 @@ BOOL LyubuStateMachine::PlayAttackAction(int skip){
7777
BOOL ret = actor.Play(0,ONCE, (float)skip, TRUE,TRUE);
7878
this->UpdateEffectiveAttack();
7979
if (ret == FALSE){
80+
this->lastAttackFrame = 0.0f;
8081
// play the next one
8182
this->effectiveAttack = FALSE;
8283
currentAttackIndex++;
@@ -118,16 +119,24 @@ BOOL LyubuStateMachine::UpdateEffectiveAttack(){
118119
//sprintf(debug, "%s frame:%lf\n", debug, frame );
119120
if (this->attackKeyQueue[currentAttackIndex] == ULTIMATE_ATT){
120121
if (frame > 20.0){
121-
this->newAttack = TRUE;
122+
if (frame - this->lastAttackFrame > 10.0f){
123+
this->lastAttackFrame = frame;
124+
this->newAttack = TRUE;
125+
}
122126
this->effectiveAttack = TRUE;
123127
}
124128
}else if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT){
125-
if (frame > 20.0){
129+
if (frame > 60.0f){
130+
this->effectiveAttack = FALSE;
131+
}else if (frame > 35.0f && frame <= 60.0f){
132+
if (frame - this->lastAttackFrame > 30.0f){// trick
133+
this->lastAttackFrame = frame;
134+
this->newAttack = TRUE; // another attack
135+
}
126136
this->effectiveAttack = TRUE;
127-
}else if (frame > 50.0){
128-
this->newAttack = TRUE;
137+
}else if (frame > 20.0 && frame <= 30.0f){
129138
this->effectiveAttack = TRUE;
130-
}
139+
}
131140
}else if (this->currentAttackIndex > 0){
132141
if (frame > 10.0){
133142
this->effectiveAttack = TRUE;
@@ -138,7 +147,7 @@ BOOL LyubuStateMachine::UpdateEffectiveAttack(){
138147
return FALSE;
139148
}
140149

141-
int LyubuStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
150+
int LyubuStateMachine::AttackEnemy(float enemyPos[3], SHOT_CODE *shot_code){
142151
// the return value is the attack power
143152
FnActor actor;
144153
actor.Object(this->character);
@@ -169,19 +178,20 @@ int LyubuStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
169178
//sprintf(debug, "%s cosine = %lf\n",debug,cosine);
170179

171180
if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT || currentAttackIndex == MAXATTACK -1){
172-
*beOutShot = TRUE;
181+
*shot_code = BIG_SHOT;
173182
}else {
174-
*beOutShot = FALSE;
183+
*shot_code = SMALL_SHOT;
175184
}
176185

177186
if (this->currentAttackIndex == 0){
178187
if (this->attackKeyQueue[currentAttackIndex] == ULTIMATE_ATT){
179188
if (frame > 100){ // almost finish attack
180-
*beOutShot = TRUE;
189+
*shot_code = BIG_SHOT;
181190
sprintf(debug, "%s attack power = %d\n",debug,10);
182191
return 10;
183192
}
184-
sprintf(debug, "%s attack power = %d\n",debug,1);
193+
*shot_code = STUCK_SHOT;
194+
//sprintf(debug, "%s attack power = %d\n",debug,1);
185195
return 1;
186196
}else if (cosine > 0.8){ // normal or heavy attack, only attack the front side enemy
187197
sprintf(debug, "%s attack power = %d\n",debug,1);

LyubuStateMachine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class LyubuStateMachine :
1313
virtual ~LyubuStateMachine(void);
1414
LyubuStateMachine(ACTORid character, char *ActionFilename);
1515
virtual BOOL PlayAttackAction(int skip);
16-
virtual int AttackEnemy(float enemyPos[3], BOOL *beOutShot = NULL);
16+
virtual int AttackEnemy(float enemyPos[3], SHOT_CODE *shot_code = NULL);
1717
protected:
1818
virtual BOOL UpdateEffectiveAttack();
1919
AUDIOid audioN1;

0 commit comments

Comments
 (0)