Allow shadow mines to hunt player, or wander around if not near them.

This commit is contained in:
Steve 2016-04-14 16:10:21 +01:00
parent 7dea0c440e
commit 915eec5cf0
2 changed files with 36 additions and 18 deletions

View File

@ -128,30 +128,45 @@ static void lookForPlayer(void)
{
distance = getDistance(self->x, self->y, player->x, player->y);
if (distance < SCREEN_WIDTH)
if (distance < SCREEN_WIDTH * 2)
{
dx = player->x - self->x;
dy = player->y - self->y;
norm = sqrt(dx * dx + dy * dy);
dx /= norm;
dy /= norm;
self->dx = dx * self->speed;
self->dy = dy * self->speed;
if (distance <= TRIGGER_RANGE)
}
else
{
if (--self->aiActionTime > 0)
{
self->systemPower--;
if (self->systemPower <= 0)
{
self->health = 0;
}
return;
}
dx = rand() % 1000;
dx -= rand() % 1000;
dy = rand() % 1000;
dy -= rand() % 1000;
self->aiActionTime = FPS * (5 + (rand() % 15));
}
norm = sqrt(dx * dx + dy * dy);
dx /= norm;
dy /= norm;
self->dx = dx * self->speed;
self->dy = dy * self->speed;
if (distance <= TRIGGER_RANGE)
{
self->systemPower--;
if (self->systemPower <= 0)
{
self->health = 0;
}
return;
}
}
@ -174,6 +189,8 @@ static void die(void)
self->alive = ALIVE_DEAD;
updateObjective(self->name, TT_DESTROY);
runScriptFunction("MINES_DESTROYED %d", battle.stats[STAT_MINES_DESTROYED]);
}
static void doSplashDamage(void)

View File

@ -32,6 +32,7 @@ extern void addMineExplosion(void);
extern void damageFighter(Entity *e, int amount, long flags);
extern void playBattleSound(int id, int x, int y);
extern void updateObjective(char *name, int type);
extern void runScriptFunction(const char *format, ...);
extern Battle battle;
extern Entity *player;