This commit is contained in:
aozhiwei 2019-03-16 11:29:46 +08:00
parent aae438b6c7
commit 1e27932ad6
2 changed files with 20 additions and 41 deletions

View File

@ -9,13 +9,13 @@ void AndroidAI::Update(int delta_time)
case AS_thinking:
{
if (state_elapsed_time < 1000) {
UpdateThink();
DoThink();
} else {
int rnd = rand();
if (rnd % 100 < 30) {
DoMove();
ChangeToState(AS_moving);
} else if (rnd % 100 < 50) {
DoAttack();
ChangeToState(AS_attack);
}
}
}
@ -23,13 +23,13 @@ void AndroidAI::Update(int delta_time)
case AS_moving:
{
if (state_elapsed_time < 1000) {
UpdateMove();
DoMove();
} else {
int rnd = rand();
if (rnd % 100 < 30) {
DoThink();
ChangeToState(AS_thinking);
} else if (rnd % 100 < 50) {
DoAttack();
ChangeToState(AS_attack);
}
}
}
@ -37,13 +37,13 @@ void AndroidAI::Update(int delta_time)
case AS_attack:
{
if (state_elapsed_time < 1000) {
UpdateAttack();
DoAttack();
} else {
int rnd = rand();
if (rnd % 100 < 30) {
DoMove();
ChangeToState(AS_moving);
} else if (rnd % 100 < 50) {
DoThink();
ChangeToState(AS_thinking);
}
}
}
@ -51,13 +51,13 @@ void AndroidAI::Update(int delta_time)
case AS_moving_and_attack:
{
if (state_elapsed_time < 1000) {
UpdateMoveAndAttack();
DoMoveAndAttack();
} else {
int rnd = rand();
if (rnd % 100 < 30) {
DoMove();
ChangeToState(AS_moving);
} else if (rnd % 100 < 50) {
DoAttack();
ChangeToState(AS_attack);
}
}
}
@ -65,46 +65,28 @@ void AndroidAI::Update(int delta_time)
}
}
void AndroidAI::UpdateThink()
void AndroidAI::ChangeToState(AndroidState_e to_state)
{
}
void AndroidAI::UpdateMove()
{
}
void AndroidAI::UpdateAttack()
{
}
void AndroidAI::UpdateMoveAndAttack()
{
state = to_state;
state_elapsed_time = 0;
}
void AndroidAI::DoThink()
{
state = AS_thinking;
state_elapsed_time = 0;
}
void AndroidAI::DoMove()
{
state = AS_moving;
state_elapsed_time = 0;
}
void AndroidAI::DoAttack()
{
state = AS_attack;
state_elapsed_time = 0;
}
void AndroidAI::DoMoveAndAttack()
{
state = AS_moving_and_attack;
state_elapsed_time = 0;
}

View File

@ -22,10 +22,7 @@ class AndroidAI : public AIComponent
private:
void UpdateThink();
void UpdateMove();
void UpdateAttack();
void UpdateMoveAndAttack();
void ChangeToState(AndroidState_e to_state);
void DoThink();
void DoMove();