This commit is contained in:
aozhiwei 2019-05-20 16:29:50 +08:00
parent 0a74273831
commit cd8191e2b1

View File

@ -1,5 +1,7 @@
#include "precompile.h" #include "precompile.h"
#include <float.h>
#include "android.ai.h" #include "android.ai.h"
#include "android.h" #include "android.h"
#include "room.h" #include "room.h"
@ -119,10 +121,13 @@ void AndroidAI::DoAttack()
if (enemy) { if (enemy) {
Human* sender = (Human*)owner; Human* sender = (Human*)owner;
Vector2D shot_dir = enemy->pos - sender->pos; Vector2D shot_dir = enemy->pos - sender->pos;
shot_dir.Normalize(); if (std::abs(shot_dir.x) > FLT_EPSILON ||
shot_dir.Rotate((rand() % 10) / 180.0f); std::abs(shot_dir.y) > FLT_EPSILON) {
sender->attack_dir = shot_dir; shot_dir.Normalize();
sender->Shot(shot_dir); shot_dir.Rotate((rand() % 10) / 180.0f);
sender->attack_dir = shot_dir;
sender->Shot(shot_dir);
}
} }
} }
} }