Added new bullet struct.

This commit is contained in:
Steve 2018-01-27 08:13:50 +00:00
parent 1b426ec9d3
commit 45244303f8
10 changed files with 46 additions and 26 deletions

View File

@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "weapons.h" #include "weapons.h"
Entity *createBaseBullet(Entity *owner); Bullet *createBaseBullet(Entity *owner);
static int bulletSprite[2]; static int bulletSprite[2];
static int plasmaSprite[2]; static int plasmaSprite[2];
@ -60,7 +60,7 @@ void initWeapons(void)
void firePistol(Entity *owner) void firePistol(Entity *owner)
{ {
Entity *bullet; Bullet *bullet;
bullet = createBaseBullet(owner); bullet = createBaseBullet(owner);
bullet->weaponType = WPN_PISTOL; bullet->weaponType = WPN_PISTOL;
@ -77,7 +77,7 @@ void fireAimedShot(Entity *owner)
{ {
int x, y; int x, y;
float dx, dy; float dx, dy;
Entity *bullet; Bullet *bullet;
x = (int) (world.bob->x + rrnd(-8, 24)); x = (int) (world.bob->x + rrnd(-8, 24));
y = (int) (world.bob->y + rrnd(-8, 24)); y = (int) (world.bob->y + rrnd(-8, 24));
@ -98,7 +98,7 @@ void fireAimedShot(Entity *owner)
void fireMachineGun(Entity *owner) void fireMachineGun(Entity *owner)
{ {
Entity *bullet; Bullet *bullet;
bullet = createBaseBullet(owner); bullet = createBaseBullet(owner);
bullet->weaponType = WPN_MACHINE_GUN; bullet->weaponType = WPN_MACHINE_GUN;
@ -111,7 +111,7 @@ void fireMachineGun(Entity *owner)
void firePlasma(Entity *owner) void firePlasma(Entity *owner)
{ {
Entity *bullet; Bullet *bullet;
bullet = createBaseBullet(owner); bullet = createBaseBullet(owner);
bullet->weaponType = WPN_PLASMA; bullet->weaponType = WPN_PLASMA;
@ -126,7 +126,7 @@ void firePlasma(Entity *owner)
void fireSpread(Entity *owner, int numberOfShots) void fireSpread(Entity *owner, int numberOfShots)
{ {
Entity *bullet; Bullet *bullet;
int i; int i;
float dy; float dy;
@ -150,7 +150,7 @@ void fireSpread(Entity *owner, int numberOfShots)
void fireLaser(Entity *owner) void fireLaser(Entity *owner)
{ {
Entity *laser; Bullet *laser;
laser = createBaseBullet(owner); laser = createBaseBullet(owner);
laser->x = owner->x + owner->w / 2; laser->x = owner->x + owner->w / 2;
@ -168,7 +168,7 @@ void fireLaser(Entity *owner)
void fireGrenade(Entity *owner) void fireGrenade(Entity *owner)
{ {
Entity *grenade; Bullet *grenade;
grenade = createBaseBullet(owner); grenade = createBaseBullet(owner);
grenade->x = owner->x + owner->w / 2; grenade->x = owner->x + owner->w / 2;
@ -190,7 +190,7 @@ void fireShotgun(Entity *owner)
{ {
int i; int i;
float dx, dy; float dx, dy;
Entity *bullet; Bullet *bullet;
for (i = 0 ; i < 8 ; i++) for (i = 0 ; i < 8 ; i++)
{ {
@ -213,7 +213,7 @@ void fireShotgun(Entity *owner)
void fireMissile(Entity *owner) void fireMissile(Entity *owner)
{ {
Entity *missile; Bullet *missile;
missile = createBaseBullet(owner); missile = createBaseBullet(owner);
missile->x = owner->x + owner->w / 2; missile->x = owner->x + owner->w / 2;
@ -230,11 +230,15 @@ void fireMissile(Entity *owner)
playSound(SND_MISSILE, CH_WEAPON); playSound(SND_MISSILE, CH_WEAPON);
} }
Entity *createBaseBullet(Entity *owner) Bullet *createBaseBullet(Entity *owner)
{ {
Entity *bullet; Bullet *bullet;
bullet = malloc(sizeof(Bullet));
memset(bullet, 0, sizeof(Bullet));
world.bulletTail->next = bullet;
world.bulletTail = bullet;
bullet = createEntity();
bullet->x = (owner->x + owner->w / 2); bullet->x = (owner->x + owner->w / 2);
bullet->y = (owner->y + owner->h / 2) - 3; bullet->y = (owner->y + owner->h / 2) - 3;
bullet->dx = owner->facing == FACING_RIGHT ? 15 : -15; bullet->dx = owner->facing == FACING_RIGHT ? 15 : -15;

View File

@ -31,6 +31,7 @@ typedef struct Tuple Tuple;
typedef struct HubMission HubMission; typedef struct HubMission HubMission;
typedef struct Widget Widget; typedef struct Widget Widget;
typedef struct Atlas Atlas; typedef struct Atlas Atlas;
typedef struct Bullet Bullet;
typedef struct { typedef struct {
int debug; int debug;
@ -333,13 +334,25 @@ struct Particle {
Particle *next; Particle *next;
}; };
struct Bullet {
int x;
int y;
int facing;
int damage;
int health;
int weaponType;
float dx;
float dy;
int sprite[2];
Entity *owner;
Bullet *next;
};
typedef struct { typedef struct {
char id[MAX_NAME_LENGTH]; char id[MAX_NAME_LENGTH];
int state; int state;
Entity *bob, *boss; Entity *bob, *boss;
Map map; Map map;
Entity entityHead, *entityTail;
Particle particleHead, *particleTail;
int allObjectivesComplete; int allObjectivesComplete;
int frameCounter; int frameCounter;
int currentStatus; int currentStatus;
@ -348,6 +361,9 @@ typedef struct {
int isOutpostMission; int isOutpostMission;
PointF checkpoints[MAX_CHECKPOINTS]; PointF checkpoints[MAX_CHECKPOINTS];
Quadtree quadtree; Quadtree quadtree;
Entity entityHead, *entityTail;
Particle particleHead, *particleTail;
Bullet bulletHead, *bulletTail;
Objective objectiveHead, *objectiveTail; Objective objectiveHead, *objectiveTail;
Trigger triggerHead, *triggerTail; Trigger triggerHead, *triggerTail;
} World; } World;

View File

@ -139,7 +139,7 @@ static void preFire(void)
static void attack(void) static void attack(void)
{ {
Entity *bullet; Bullet *bullet;
float dx, dy; float dx, dy;
getSlope(target->x, target->y, self->x, self->y, &dx, &dy); getSlope(target->x, target->y, self->x, self->y, &dx, &dy);

View File

@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern void unitTick(void); extern void unitTick(void);
extern int getSpriteIndex(char *name); extern int getSpriteIndex(char *name);
extern int rrnd(int low, int high); extern int rrnd(int low, int high);
extern Entity *createBaseBullet(Entity *owner); extern Bullet *createBaseBullet(Entity *owner);
extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern int hasLineOfSight(Entity *src, Entity *dest); extern int hasLineOfSight(Entity *src, Entity *dest);

View File

@ -247,7 +247,7 @@ static void preFire(void)
static void attack(void) static void attack(void)
{ {
Entity *bullet; Bullet *bullet;
float dx, dy; float dx, dy;
int bx, by; int bx, by;

View File

@ -29,7 +29,7 @@ extern float limit(float i, float a, float b);
extern double randF(void); extern double randF(void);
extern void playSound(int snd, int ch); extern void playSound(int snd, int ch);
extern void animateEntity(Entity *e); extern void animateEntity(Entity *e);
extern Entity *createBaseBullet(Entity *owner); extern Bullet *createBaseBullet(Entity *owner);
extern int getSpriteIndex(char *name); extern int getSpriteIndex(char *name);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy);

View File

@ -228,7 +228,7 @@ static void attackPistol(void)
{ {
int bx, by; int bx, by;
float dx, dy; float dx, dy;
Entity *bullet; Bullet *bullet;
bx = world.bob->x + rrnd(-8, 24); bx = world.bob->x + rrnd(-8, 24);
by = world.bob->y + rrnd(-8, 24); by = world.bob->y + rrnd(-8, 24);
@ -254,7 +254,7 @@ static void attackPistol(void)
static void attackPlasma(void) static void attackPlasma(void)
{ {
Entity *bullet; Bullet *bullet;
bullet = createBaseBullet(self); bullet = createBaseBullet(self);
bullet->x = (self->x + self->w / 2); bullet->x = (self->x + self->w / 2);
@ -276,7 +276,7 @@ static void attackPlasma(void)
static void attackMissile(void) static void attackMissile(void)
{ {
Entity *missile; Bullet *missile;
missile = createBaseBullet(self); missile = createBaseBullet(self);
missile->x = self->x + self->w / 2; missile->x = self->x + self->w / 2;

View File

@ -33,7 +33,7 @@ extern void addDefeatedTarget(char *name);
extern void updateObjective(char *targetName); extern void updateObjective(char *targetName);
extern double randF(void); extern double randF(void);
extern void playSound(int snd, int ch); extern void playSound(int snd, int ch);
extern Entity *createBaseBullet(Entity *owner); extern Bullet *createBaseBullet(Entity *owner);
extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy);
extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addExplosion(float x, float y, int radius, Entity *owner);

View File

@ -208,7 +208,7 @@ static void attackPistol(void)
{ {
int bx, by; int bx, by;
float dx, dy; float dx, dy;
Entity *bullet; Bullet *bullet;
bx = world.bob->x + rrnd(-8, 24); bx = world.bob->x + rrnd(-8, 24);
by = world.bob->y + rrnd(-8, 24); by = world.bob->y + rrnd(-8, 24);
@ -234,7 +234,7 @@ static void attackPistol(void)
static void attackMissile(void) static void attackMissile(void)
{ {
Entity *missile; Bullet *missile;
missile = createBaseBullet(self); missile = createBaseBullet(self);
missile->x = self->x + self->w / 2; missile->x = self->x + self->w / 2;

View File

@ -31,7 +31,7 @@ extern int enemyCanSeePlayer(Entity *e);
extern void addDefeatedTarget(char *name); extern void addDefeatedTarget(char *name);
extern void updateObjective(char *targetName); extern void updateObjective(char *targetName);
extern void playSound(int snd, int ch); extern void playSound(int snd, int ch);
extern Entity *createBaseBullet(Entity *owner); extern Bullet *createBaseBullet(Entity *owner);
extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy);
extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addExplosion(float x, float y, int radius, Entity *owner);
extern void addScorchDecal(int x, int y); extern void addScorchDecal(int x, int y);