From d4f310119f5efa1de67193c45adf7a01f656eb5c Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 24 Apr 2018 19:04:08 +0100 Subject: [PATCH] Centre bullets more inside shooter. --- src/combat/weapons.c | 22 +++++++++------------- src/combat/weapons.h | 2 +- src/entities/blobs/teeka.c | 4 +--- src/entities/blobs/teeka.h | 2 +- src/entities/boss/blobBoss.c | 4 +--- src/entities/boss/blobBoss.h | 2 +- src/entities/boss/eyeDroidCommander.c | 12 +++--------- src/entities/boss/eyeDroidCommander.h | 2 +- src/entities/boss/tankCommander.c | 4 ++-- src/entities/boss/tankCommander.h | 2 +- src/entities/bullets/bullet.c | 4 ++-- src/entities/bullets/bullet.h | 1 - src/system/sprites.c | 3 +++ 13 files changed, 26 insertions(+), 38 deletions(-) diff --git a/src/combat/weapons.c b/src/combat/weapons.c index 4d5b25b..2968cea 100644 --- a/src/combat/weapons.c +++ b/src/combat/weapons.c @@ -71,7 +71,7 @@ void firePistol(void) if (world.bob->facing != FACING_DIE) { - bullet = createBaseBullet((Unit*)world.bob); + bullet = createBaseBullet((Unit*)world.bob, bulletSprite[0]->frames[0]->rect.w); bullet->weaponType = WPN_PISTOL; bullet->facing = world.bob->facing; bullet->sprite[0] = bulletSprite[0]; @@ -96,7 +96,7 @@ void fireAimedShot(Unit *owner) getSlope(x, y, owner->x, owner->y, &dx, &dy); - bullet = createBaseBullet(owner); + bullet = createBaseBullet(owner, aimedSprite->w); bullet->weaponType = WPN_AIMED_PISTOL; bullet->dx = dx * 6; bullet->dy = dy * 6; @@ -115,7 +115,7 @@ void fireMachineGun(Unit *owner) if (owner->facing != FACING_DIE) { - bullet = createBaseBullet(owner); + bullet = createBaseBullet(owner, bulletSprite[0]->w); bullet->weaponType = WPN_MACHINE_GUN; bullet->sprite[0] = bulletSprite[0]; bullet->sprite[1] = bulletSprite[1]; @@ -131,7 +131,7 @@ void firePlasma(Unit *owner) if (owner->facing != FACING_DIE) { - bullet = createBaseBullet(owner); + bullet = createBaseBullet(owner, plasmaSprite[0]->w); bullet->weaponType = WPN_PLASMA; bullet->sprite[0] = plasmaSprite[0]; bullet->sprite[1] = plasmaSprite[1]; @@ -155,7 +155,7 @@ void fireSpread(Unit *owner, int numberOfShots) for (i = 0 ; i < numberOfShots ; i++) { - bullet = createBaseBullet(owner); + bullet = createBaseBullet(owner, spreadShotSprite->w); bullet->weaponType = WPN_SPREAD; bullet->sprite[0] = bullet->sprite[1] = owner->type == ET_BOB ? spreadShotSprite : alienSpreadShotSprite; bullet->dx = owner->facing == FACING_RIGHT ? 15 : -15; @@ -176,9 +176,7 @@ void fireLaser(Unit *owner) if (owner->facing != FACING_DIE) { - laser = createBaseBullet(owner); - laser->x = owner->x + owner->w / 2; - laser->y = owner->y + owner->h / 2; + laser = createBaseBullet(owner, laserSprite[0]->w); laser->facing = owner->facing; laser->dx = owner->facing == FACING_RIGHT ? 20 : -20; laser->health = FPS * 3; @@ -198,8 +196,7 @@ void fireGrenade(Unit *owner) if (owner->facing != FACING_DIE) { - grenade = createBaseBullet(owner); - grenade->x = owner->x + owner->w / 2; + grenade = createBaseBullet(owner, grenadeSprite->w); grenade->y = owner->y; grenade->facing = owner->facing; grenade->health = FPS * 3; @@ -227,7 +224,7 @@ void fireShotgun(Unit *owner) { getSlope(world.bob->x + rrnd(0, 40), world.bob->y + rrnd(0, 40), owner->x, owner->y, &dx, &dy); - bullet = createBaseBullet(owner); + bullet = createBaseBullet(owner, 0); bullet->weaponType = WPN_SHOTGUN; bullet->x = owner->x + (owner->w / 2) + rrnd(-8, 8); bullet->y = owner->y + (owner->h / 2) + rrnd(-8, 8); @@ -249,8 +246,7 @@ void fireMissile(Unit *owner) if (owner->facing != FACING_DIE) { - missile = createBaseBullet(owner); - missile->x = owner->x + owner->w / 2; + missile = createBaseBullet(owner, missileSprite[0]->w); missile->y = owner->y + 10; missile->facing = owner->facing; missile->dx = owner->facing == FACING_RIGHT ? 10 : -10; diff --git a/src/combat/weapons.h b/src/combat/weapons.h index 748d68a..92fe3a6 100644 --- a/src/combat/weapons.h +++ b/src/combat/weapons.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -extern Bullet *createBaseBullet(Unit *owner); +extern Bullet *createBaseBullet(Unit *owner, int bulletWidth); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern Sprite *getSprite(char *name); extern void initGrenade(Bullet *b); diff --git a/src/entities/blobs/teeka.c b/src/entities/blobs/teeka.c index eb524ca..90740b9 100644 --- a/src/entities/blobs/teeka.c +++ b/src/entities/blobs/teeka.c @@ -161,9 +161,7 @@ static void attack(void) getSlope(target->x, target->y, self->x, self->y, &dx, &dy); - bullet = createBaseBullet((Unit*)self); - bullet->x = self->x; - bullet->y = (self->y + self->h / 2) - 3; + bullet = createBaseBullet((Unit*)self, aimedSprite->w); bullet->facing = self->facing; bullet->damage = 1; bullet->owner = self; diff --git a/src/entities/blobs/teeka.h b/src/entities/blobs/teeka.h index 6df5eee..357ef89 100644 --- a/src/entities/blobs/teeka.h +++ b/src/entities/blobs/teeka.h @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" extern void addTeleportStars(Entity *e); -extern Bullet *createBaseBullet(Unit *owner); +extern Bullet *createBaseBullet(Unit *owner, int bulletWidth); extern Unit *createUnit(void); 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); diff --git a/src/entities/boss/blobBoss.c b/src/entities/boss/blobBoss.c index 9644a1c..be88138 100644 --- a/src/entities/boss/blobBoss.c +++ b/src/entities/boss/blobBoss.c @@ -313,9 +313,7 @@ static void attack(void) getSlope(bx, by, self->x, self->y, &dx, &dy); - bullet = createBaseBullet((Unit*)self); - bullet->x = self->x; - bullet->y = (self->y + self->h / 2) - 3; + bullet = createBaseBullet((Unit*)self, aimedSprite->w); bullet->facing = self->facing; bullet->damage = 1; bullet->owner = self; diff --git a/src/entities/boss/blobBoss.h b/src/entities/boss/blobBoss.h index 32cd85a..fb97f20 100644 --- a/src/entities/boss/blobBoss.h +++ b/src/entities/boss/blobBoss.h @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void addTeleportStars(Entity *e); extern void awardTrophy(char *id); -extern Bullet *createBaseBullet(Unit *owner); +extern Bullet *createBaseBullet(Unit *owner, int bulletWidth); extern int enemyCanSeePlayer(Entity *e); extern void entityIdle(void); extern int getDistance(int x1, int y1, int x2, int y2); diff --git a/src/entities/boss/eyeDroidCommander.c b/src/entities/boss/eyeDroidCommander.c index 346e2ae..4c49482 100644 --- a/src/entities/boss/eyeDroidCommander.c +++ b/src/entities/boss/eyeDroidCommander.c @@ -278,9 +278,7 @@ static void attackPistol(void) getSlope(bx, by, self->x, self->y, &dx, &dy); - bullet = createBaseBullet((Unit*)self); - bullet->x = (self->x + self->w / 2); - bullet->y = (self->y + self->h / 2) - 3; + bullet = createBaseBullet((Unit*)self, aimedSprite->w); bullet->facing = self->facing; bullet->damage = 1; bullet->owner = self; @@ -302,9 +300,7 @@ static void attackPlasma(void) b = (Boss*)self; - bullet = createBaseBullet((Unit*)self); - bullet->x = (self->x + self->w / 2); - bullet->y = (self->y + self->h / 2) - 3; + bullet = createBaseBullet((Unit*)self, plasmaSprite[0]->w); bullet->facing = self->facing; bullet->damage = 2; bullet->owner = self; @@ -327,9 +323,7 @@ static void attackMissile(void) b = (Boss*)self; - missile = createBaseBullet((Unit*)self); - missile->x = b->x + b->w / 2; - missile->y = b->y + b->h / 2; + missile = createBaseBullet((Unit*)self, missileSprite[0]->w); missile->facing = b->facing; missile->dx = b->facing == FACING_RIGHT ? 15 : -15; missile->owner = self; diff --git a/src/entities/boss/eyeDroidCommander.h b/src/entities/boss/eyeDroidCommander.h index d1eae93..c3712e1 100644 --- a/src/entities/boss/eyeDroidCommander.h +++ b/src/entities/boss/eyeDroidCommander.h @@ -24,7 +24,7 @@ extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addSmokeParticles(float x, float y, int rising); extern void addTeleportStars(Entity *e); extern void awardTrophy(char *id); -extern Bullet *createBaseBullet(Unit *owner); +extern Bullet *createBaseBullet(Unit *owner, int bulletWidth); extern int enemyCanSeePlayer(Entity *e); extern void entityIdle(void); extern int getDistance(int x1, int y1, int x2, int y2); diff --git a/src/entities/boss/tankCommander.c b/src/entities/boss/tankCommander.c index 3d32235..d7931fa 100644 --- a/src/entities/boss/tankCommander.c +++ b/src/entities/boss/tankCommander.c @@ -250,7 +250,7 @@ static void attackPistol(void) getSlope(bx, by, b->x, b->y, &dx, &dy); - bullet = createBaseBullet((Unit*)self); + bullet = createBaseBullet((Unit*)self, aimedSprite->w); bullet->x = (b->x + b->w / 2); bullet->y = b->y + 30; bullet->facing = b->facing; @@ -274,7 +274,7 @@ static void attackMissile(void) b = (Boss*)self; - missile = createBaseBullet((Unit*)self); + missile = createBaseBullet((Unit*)self, missileSprite[0]->w); missile->x = b->x + b->w / 2; missile->y = b->y + 30; missile->facing = b->facing; diff --git a/src/entities/boss/tankCommander.h b/src/entities/boss/tankCommander.h index baa4550..ff971a1 100644 --- a/src/entities/boss/tankCommander.h +++ b/src/entities/boss/tankCommander.h @@ -24,7 +24,7 @@ extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addScorchDecal(int x, int y); extern void addTeleportStars(Entity *e); extern void awardTrophy(char *id); -extern Bullet *createBaseBullet(Unit *owner); +extern Bullet *createBaseBullet(Unit *owner, int bulletWidth); extern int enemyCanSeePlayer(Entity *e); extern void entityIdle(void); extern int getDistance(int x1, int y1, int x2, int y2); diff --git a/src/entities/bullets/bullet.c b/src/entities/bullets/bullet.c index 7afab56..f088034 100644 --- a/src/entities/bullets/bullet.c +++ b/src/entities/bullets/bullet.c @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void tick(void); static void touch(Entity *other); -Bullet *createBaseBullet(Unit *owner) +Bullet *createBaseBullet(Unit *owner, int bulletWidth) { Bullet *bullet; @@ -32,7 +32,7 @@ Bullet *createBaseBullet(Unit *owner) initEntity((Entity*)bullet); - bullet->x = (owner->x + owner->w / 2); + bullet->x = owner->x + (owner->w / 2) - (bulletWidth / 2); bullet->y = (owner->y + owner->h / 2) - 3; bullet->dx = owner->facing == FACING_RIGHT ? 15 : -15; bullet->facing = owner->facing; diff --git a/src/entities/bullets/bullet.h b/src/entities/bullets/bullet.h index 2e778d0..dacef7f 100644 --- a/src/entities/bullets/bullet.h +++ b/src/entities/bullets/bullet.h @@ -22,7 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void addSmallFleshChunk(float x, float y); extern void addSparkParticles(float x, float y); -extern Bullet *createBaseBullet(Unit *owner); extern void initEntity(Entity *e); extern void playBattleSound(int snd, int ch, int x, int y); extern void swapSelf(Entity *e); diff --git a/src/system/sprites.c b/src/system/sprites.c index 7cf4b93..d6f5d77 100644 --- a/src/system/sprites.c +++ b/src/system/sprites.c @@ -163,6 +163,9 @@ void loadSprite(cJSON *root) i++; } + + s->w = s->frames[0]->rect.w; + s->h = s->frames[0]->rect.h; } void destroySprites(void)