Skip to content

merge #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 72 additions & 5 deletions ActorStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ int ActorStateMachine::ChangeState(ActorState s, BOOL forceSet){
}else if (s == STATEDAMAGE){
FnActor actor;
actor.Object(this->character);
actor.MoveForward(-MOVE_LENGTH,TRUE, FALSE, 0.0, TRUE);
this->SetNewAction("LightDamage");
//actor.MoveForward(-MOVE_LENGTH,TRUE, FALSE, 0.0, TRUE);
//this->SetNewAction("LightDamage");
this->currentAttackIndex = 0;
this->lastAttackIndex = 0;
//this->SetNewAction("HeavyDamage");
this->SetNewAction("HeavyDamage");
}else if (s == STATEDIE){
this->SetNewAction("Die");
}
Expand Down Expand Up @@ -275,6 +275,28 @@ BOOL ActorStateMachine::CheckEffectiveAttack(){
return this->effectiveAttack;
}
BOOL ActorStateMachine::UpdateEffectiveAttack(){
FnActor actor;
actor.Object(this->character);
float frame = actor.QueryCurrentFrame(0);
//sprintf(debug, "%s frame:%lf\n", debug, frame );
if (frame > 10.0){
this->effectiveAttack = TRUE;
}
/*
if (this->attackKeyQueue[currentAttackIndex] == ULTIMATE_ATT){
if (frame > 20.0){
this->newAttack = TRUE;
this->effectiveAttack = TRUE;
}
}else if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT){
if (frame > 20.0){
this->effectiveAttack = TRUE;
}
}else if (this->currentAttackIndex > 0){
if (frame > 10.0){
this->effectiveAttack = TRUE;
}
}*/
return FALSE;
}

Expand All @@ -284,7 +306,52 @@ int ActorStateMachine::AttackEnemy(float enemyPos[3], BOOL *beOutShot){
*beOutShot = FALSE;
}
// the return value is the attack power
return FALSE;
FnActor actor;
actor.Object(this->character);
float attackerPos[3], attackerDir[3];
actor.GetWorldPosition(attackerPos);
actor.GetWorldDirection(attackerDir,NULL);
float frame = actor.QueryCurrentFrame(0);

float dist = 0.0;
for (int i = 0;i< 3;i++){
dist += (attackerPos[i] - enemyPos[i]) * (attackerPos[i] - enemyPos[i]);
}
//sprintf(debug, "%s dist = %lf\n",debug,dist);
if ( dist >= ROBOT_ATTACKRANGE ){
return 0; // no attack power
}
float cosine,dotProduct;
//float v[3];
dotProduct = 0.0;
for (int i = 0;i< 3;i++){
dotProduct += (enemyPos[i] - attackerPos[i]) * attackerDir[i];
}
float length = 0.0;
for (int i = 0;i< 3;i++){
length += (enemyPos[i] - attackerPos[i])* (enemyPos[i] - attackerPos[i]);
}
cosine = dotProduct / sqrt(length);
//sprintf(debug, "%s cosine = %lf\n",debug,cosine);

if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT || currentAttackIndex == MAXATTACK -1){
*beOutShot = TRUE;
}else {
*beOutShot = FALSE;
}

if (this->currentAttackIndex == 0){
if (cosine > 0.8){ // normal or heavy attack, only attack the front side enemy
sprintf(debug, "%s attack power = %d\n",debug,1);
return 1;
}
}else if (this->currentAttackIndex <= 3){
if (cosine >= 0.0){
sprintf(debug, "%s attack power = %d\n",debug,2);
return 3;
}
}
return 0;
}

void ActorStateMachine::TakeDamage(float damage, BOOL beShot, float *attackerPos ){
Expand All @@ -301,7 +368,7 @@ void ActorStateMachine::TakeDamage(float damage, BOOL beShot, float *attackerPos
newDir[2] = 0.0f;
actor.SetWorldDirection(newDir,NULL);
//if (beShot == TRUE){
//actor.MoveForward(-OUTSHOT_DIS,TRUE, FALSE, 0.0, TRUE);
actor.MoveForward(-OUTSHOT_DIS,TRUE, FALSE, 0.0, TRUE);
//}
actor.SetWorldDirection(dir,NULL);
}
Expand Down
3 changes: 2 additions & 1 deletion ActorStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ typedef int ActorState;
#define ULTIMATE_ATT 2
typedef int ATTACK_CODE;

#define OUTSHOT_DIS 200.0
#define OUTSHOT_DIS 100.0
#define MAX_LIFE 1000.0
#define ROBOT_ATTACKRANGE 18000.0

// actor free meaning it can do anything by the controller.
// actor stay meaning that it can't be move beacuse of being attacked.
Expand Down
45 changes: 36 additions & 9 deletions BattleRoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ BattleRoom::BattleRoom(ActorStateMachine *playerStateMachine, vector<ActorStateM
this->npcStateMachineList = npcStateMachineList;
this->playerStateMachine = playerStateMachine;
this->playerHitMap.clear();
this->npcHitMap.clear();
}

void BattleRoom::RefreshArena(){
Expand Down Expand Up @@ -66,21 +67,20 @@ void BattleRoom::PerformAttack(){
if (this->AreanList.empty() == true){// no npc in the arean means that no attack exists.
return;
}
FnActor actor;
actor.Object(this->playerStateMachine->character);
float pPos[3];

FnActor npc;
float nPos[3];

if (playerStateMachine->state == STATEATTACK && playerStateMachine->effectiveAttack == TRUE ){
if (this->playerStateMachine->newAttack == TRUE){
this->playerStateMachine->newAttack = FALSE;
this->playerHitMap.clear();
}
FnActor actor;
actor.Object(this->playerStateMachine->character);
float pPos[3];
//float pDir[3];
//float pUDir[3];
//actor.GetWorldDirection(pDir,NULL);
actor.GetWorldPosition(pPos);

FnActor npc;
float nPos[3];
int beOutShot;
for (int i= 0;i< this->AreanList.size();i++){
ACTORid tmpid = AreanList[i]->character;
Expand All @@ -99,7 +99,34 @@ void BattleRoom::PerformAttack(){
}
}
}
}// should check the npc's attack;
}

actor.GetWorldPosition(pPos);
//this->npcHitMap.clear();
for (int i= 0;i< this->AreanList.size();i++){
ACTORid tmpid = AreanList[i]->character;
if (this->AreanList[i]->newAttack == TRUE){
//sprintf(debug, "%s erase\n",debug);
this->AreanList[i]->newAttack = FALSE;
npcHitMap.erase(tmpid);
}
if (AreanList[i]->state == STATEATTACK && AreanList[i]->effectiveAttack == TRUE ){
if (npcHitMap.find(tmpid) == npcHitMap.end()){ // find nothing
npc.Object(tmpid);
npc.GetWorldPosition(nPos);
BOOL beOutShot;

int attackPower = this->AreanList[i]->AttackEnemy(pPos, &beOutShot);
if (attackPower > 0 ){
sprintf(debug, "%s player damage\n",debug);
if ( this->playerStateMachine->state != STATEDIE){
this->playerStateMachine->TakeDamage(attackPower, beOutShot, pPos);
}
npcHitMap[tmpid] = TRUE;
}
}
}
}
}

BOOL BattleRoom::AttackCheck(float attackerDir[3], float attackerPos[3], float vitimPos[3], float attackRange){
Expand Down
1 change: 1 addition & 0 deletions BattleRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BattleRoom
std::vector<ActorStateMachine *> npcStateMachineList; // they are candidates, not always in the arean.
std::vector<ActorStateMachine *> AreanList;
std::map<ACTORid, BOOL> playerHitMap;
std::map<ACTORid, BOOL> npcHitMap;
public:
BattleRoom(void);
virtual ~BattleRoom(void);
Expand Down
11 changes: 0 additions & 11 deletions LyubuStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ LyubuStateMachine::LyubuStateMachine(ACTORid character, char *ActionFilename):Ac
sprintf(debug, "%s audioN2 load failed\n", debug);
}
}
/*
BOOL LyubuStateMachine::isNowAttackState(void) { //if now is attack state(i.e. var attackState == true), return true
return attackState;
}
void LyubuStateMachine::resetAttackState(void) { //reset var attackState
attackState = FALSE;
}
void LyubuStateMachine::setAttackState(void) { //set var attackState
attackState = TRUE;
}
*/

BOOL LyubuStateMachine::PlayAttackAction(int skip){
// the difference from parent function is that this function contain the sound fx
Expand Down