Tell missiles to turn more sharply when close to their target.

This commit is contained in:
Steve 2016-04-25 11:20:54 +01:00
parent 1913c844be
commit 9dd027b825
2 changed files with 21 additions and 8 deletions

View File

@ -244,10 +244,9 @@ void drawBullets(void)
static void faceTarget(Bullet *b) static void faceTarget(Bullet *b)
{ {
int dir; int dir, wantedAngle, dist;
int wantedAngle = getAngle(b->x, b->y, b->target->x, b->target->y);
wantedAngle %= 360; wantedAngle = (int)getAngle(b->x, b->y, b->target->x, b->target->y) % 360;
if (fabs(wantedAngle - b->angle) > TURN_THRESHOLD) if (fabs(wantedAngle - b->angle) > TURN_THRESHOLD)
{ {
@ -255,11 +254,24 @@ static void faceTarget(Bullet *b)
b->angle += dir * TURN_SPEED; b->angle += dir * TURN_SPEED;
dist = getDistance(b->x, b->y, b->target->x, b->target->y);
if (dist < 250)
{
dist = 250 - dist;
while (dist > 0)
{
b->angle += dir;
dist -= 50;
}
}
b->angle = mod(b->angle, 360); b->angle = mod(b->angle, 360);
/* lower your speed while you're not at the correct angle */ b->dx *= 0.75;
b->dx *= 0.38; b->dy *= 0.75;
b->dy *= 0.38;
} }
} }

View File

@ -45,6 +45,7 @@ extern char *getTranslatedString(char *string);
extern void *resize(void *array, int oldSize, int newSize); extern void *resize(void *array, int oldSize, int newSize);
extern void awardTrophy(char *id); extern void awardTrophy(char *id);
extern int isOnBattleScreen(int x, int y, int w, int h); extern int isOnBattleScreen(int x, int y, int w, int h);
extern int getDistance(int x1, int y1, int x2, int y2);
extern Battle battle; extern Battle battle;
extern Colors colors; extern Colors colors;