Allow enemies to fire missiles.

This commit is contained in:
Steve 2015-10-30 21:55:01 +00:00
parent c506ad32cf
commit aaf58614f4
5 changed files with 22 additions and 4 deletions

View File

@ -17,5 +17,9 @@
"x" : 8, "x" : 8,
"y" : 0 "y" : 0
} }
] ],
"missiles" : {
"type" : "MISSILE_MISSILE",
"ammo" : 2
}
} }

View File

@ -17,5 +17,9 @@
"x" : 8, "x" : 8,
"y" : 0 "y" : 0
} }
] ],
"missiles" : {
"type" : "MISSILE_MISSILE",
"ammo" : 2
}
} }

View File

@ -287,10 +287,17 @@ static int hasClearShot(void)
static void preAttack(void) static void preAttack(void)
{ {
if (!self->reload && self->guns[0].type) if (!self->reload)
{
if (self->missiles.ammo == 0 || (rand() % 50) > 0)
{ {
fireGuns(self); fireGuns(self);
} }
else
{
fireMissile(self);
}
}
} }
static void flyStraight(void) static void flyStraight(void)

View File

@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern int mod(int n, int x); extern int mod(int n, int x);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern void fireGuns(Entity *owner); extern void fireGuns(Entity *owner);
extern void fireMissile(Entity *owner);
extern float getAngle(int x1, int y1, int x2, int y2); extern float getAngle(int x1, int y1, int x2, int y2);
extern void applyFighterThrust(void); extern void applyFighterThrust(void);
extern void applyFighterBrakes(void); extern void applyFighterBrakes(void);

View File

@ -104,6 +104,8 @@ static void randomizeDart(Entity *dart)
randomizeDartGuns(dart); randomizeDartGuns(dart);
dart->missiles.ammo = rand() % 3;
sprintf(textureName, "gfx/fighters/dart0%d.png", 1 + rand() % 7); sprintf(textureName, "gfx/fighters/dart0%d.png", 1 + rand() % 7);
dart->texture = getTexture(textureName); dart->texture = getTexture(textureName);