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"
Entity *createBaseBullet(Entity *owner);
Bullet *createBaseBullet(Entity *owner);
static int bulletSprite[2];
static int plasmaSprite[2];
@ -60,7 +60,7 @@ void initWeapons(void)
void firePistol(Entity *owner)
{
Entity *bullet;
Bullet *bullet;
bullet = createBaseBullet(owner);
bullet->weaponType = WPN_PISTOL;
@ -77,7 +77,7 @@ void fireAimedShot(Entity *owner)
{
int x, y;
float dx, dy;
Entity *bullet;
Bullet *bullet;
x = (int) (world.bob->x + rrnd(-8, 24));
y = (int) (world.bob->y + rrnd(-8, 24));
@ -98,7 +98,7 @@ void fireAimedShot(Entity *owner)
void fireMachineGun(Entity *owner)
{
Entity *bullet;
Bullet *bullet;
bullet = createBaseBullet(owner);
bullet->weaponType = WPN_MACHINE_GUN;
@ -111,7 +111,7 @@ void fireMachineGun(Entity *owner)
void firePlasma(Entity *owner)
{
Entity *bullet;
Bullet *bullet;
bullet = createBaseBullet(owner);
bullet->weaponType = WPN_PLASMA;
@ -126,7 +126,7 @@ void firePlasma(Entity *owner)
void fireSpread(Entity *owner, int numberOfShots)
{
Entity *bullet;
Bullet *bullet;
int i;
float dy;
@ -150,7 +150,7 @@ void fireSpread(Entity *owner, int numberOfShots)
void fireLaser(Entity *owner)
{
Entity *laser;
Bullet *laser;
laser = createBaseBullet(owner);
laser->x = owner->x + owner->w / 2;
@ -168,7 +168,7 @@ void fireLaser(Entity *owner)
void fireGrenade(Entity *owner)
{
Entity *grenade;
Bullet *grenade;
grenade = createBaseBullet(owner);
grenade->x = owner->x + owner->w / 2;
@ -190,7 +190,7 @@ void fireShotgun(Entity *owner)
{
int i;
float dx, dy;
Entity *bullet;
Bullet *bullet;
for (i = 0 ; i < 8 ; i++)
{
@ -213,7 +213,7 @@ void fireShotgun(Entity *owner)
void fireMissile(Entity *owner)
{
Entity *missile;
Bullet *missile;
missile = createBaseBullet(owner);
missile->x = owner->x + owner->w / 2;
@ -230,11 +230,15 @@ void fireMissile(Entity *owner)
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->y = (owner->y + owner->h / 2) - 3;
bullet->dx = owner->facing == FACING_RIGHT ? 15 : -15;

View File

@ -31,6 +31,7 @@ typedef struct Tuple Tuple;
typedef struct HubMission HubMission;
typedef struct Widget Widget;
typedef struct Atlas Atlas;
typedef struct Bullet Bullet;
typedef struct {
int debug;
@ -333,13 +334,25 @@ struct Particle {
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 {
char id[MAX_NAME_LENGTH];
int state;
Entity *bob, *boss;
Map map;
Entity entityHead, *entityTail;
Particle particleHead, *particleTail;
int allObjectivesComplete;
int frameCounter;
int currentStatus;
@ -348,6 +361,9 @@ typedef struct {
int isOutpostMission;
PointF checkpoints[MAX_CHECKPOINTS];
Quadtree quadtree;
Entity entityHead, *entityTail;
Particle particleHead, *particleTail;
Bullet bulletHead, *bulletTail;
Objective objectiveHead, *objectiveTail;
Trigger triggerHead, *triggerTail;
} World;

View File

@ -139,7 +139,7 @@ static void preFire(void)
static void attack(void)
{
Entity *bullet;
Bullet *bullet;
float 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 int getSpriteIndex(char *name);
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 int getDistance(int x1, int y1, int x2, int y2);
extern int hasLineOfSight(Entity *src, Entity *dest);

View File

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

View File

@ -29,7 +29,7 @@ extern float limit(float i, float a, float b);
extern double randF(void);
extern void playSound(int snd, int ch);
extern void animateEntity(Entity *e);
extern Entity *createBaseBullet(Entity *owner);
extern Bullet *createBaseBullet(Entity *owner);
extern int getSpriteIndex(char *name);
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);

View File

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

View File

@ -33,7 +33,7 @@ extern void addDefeatedTarget(char *name);
extern void updateObjective(char *targetName);
extern double randF(void);
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 addExplosion(float x, float y, int radius, Entity *owner);

View File

@ -208,7 +208,7 @@ static void attackPistol(void)
{
int bx, by;
float dx, dy;
Entity *bullet;
Bullet *bullet;
bx = world.bob->x + rrnd(-8, 24);
by = world.bob->y + rrnd(-8, 24);
@ -234,7 +234,7 @@ static void attackPistol(void)
static void attackMissile(void)
{
Entity *missile;
Bullet *missile;
missile = createBaseBullet(self);
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 updateObjective(char *targetName);
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 addExplosion(float x, float y, int radius, Entity *owner);
extern void addScorchDecal(int x, int y);