Moved bullets into entities/bullets.

This commit is contained in:
Steve 2018-02-04 11:00:14 +00:00
parent 7577482cc4
commit 1fbf7971b8
11 changed files with 161 additions and 112 deletions

View File

@ -7,6 +7,7 @@ SEARCHPATH += src/combat
SEARCHPATH += src/entities
SEARCHPATH += src/entities/blobs
SEARCHPATH += src/entities/boss
SEARCHPATH += src/entities/bullets
SEARCHPATH += src/entities/cannons
SEARCHPATH += src/entities/decoration
SEARCHPATH += src/entities/evilBlobs
@ -30,7 +31,7 @@ vpath %.h $(SEARCHPATH)
DEPS += defs.h structs.h
OBJS += atlas.o atlasTest.o aquaBlob.o
OBJS += battery.o blaze.o bob.o boss.o blobBoss.o
OBJS += battery.o blaze.o bob.o boss.o blobBoss.o bullet.o
OBJS += camera.o cannon.o cardReader.o cell.o cherry.o combat.o consumable.o
OBJS += debris.o destructable.o door.o draw.o
OBJS += effects.o ending.o entities.o entity.o entityFactory.o exit.o explosions.o eyeDroid.o eyeDroidCommander.o evilBlob.o

View File

@ -20,10 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "weapons.h"
Bullet *createBaseBullet(Unit *owner);
static void tick(void);
static void touch(Entity *other);
static Sprite *bulletSprite[2];
static Sprite *plasmaSprite[2];
static Sprite *aimedSprite;
@ -243,104 +239,6 @@ void fireMissile(Unit *owner)
playSound(SND_MISSILE, CH_WEAPON);
}
Bullet *createBaseBullet(Unit *owner)
{
Bullet *bullet;
bullet = malloc(sizeof(Bullet));
memset(bullet, 0, sizeof(Bullet));
initEntity((Entity*)bullet);
bullet->x = (owner->x + owner->w / 2);
bullet->y = (owner->y + owner->h / 2) - 3;
bullet->dx = owner->facing == FACING_RIGHT ? 15 : -15;
bullet->facing = owner->facing;
bullet->damage = 1;
bullet->owner = (Entity*)owner;
bullet->health = FPS * 3;
bullet->flags |= EF_WEIGHTLESS | EF_IGNORE_BULLETS | EF_NO_ENVIRONMENT | EF_KILL_OFFSCREEN | EF_NO_TELEPORT;
bullet->tick = tick;
bullet->touch = touch;
return bullet;
}
static void tick(void)
{
Bullet *b;
b = (Bullet*)self;
b->health--;
if (b->x <= 0 || b->y <= 0 || b->x >= (MAP_WIDTH * MAP_TILE_SIZE) - b->w || b->y >= (MAP_HEIGHT * MAP_TILE_SIZE) - b->h)
{
b->alive = ALIVE_DEAD;
}
// don't allow the player to kill everything on the map by firing
// constantly
if (b->owner->type == ET_BOB)
{
if (b->x < camera.x || b->y < camera.y || b->x > camera.x + SCREEN_WIDTH || b->y > camera.y + SCREEN_HEIGHT)
{
b->alive = ALIVE_DEAD;
}
}
}
static void touch(Entity *other)
{
Bullet *b;
b = (Bullet*)self;
if (b->alive == ALIVE_ALIVE)
{
if (other == NULL)
{
addSparkParticles(b->x, b->y);
b->alive = ALIVE_DEAD;
if (rand() % 2)
{
playSound(SND_RICO_1, CH_ANY);
}
else
{
playSound(SND_RICO_2, CH_ANY);
}
}
else if (other != b->owner && (!(other->flags & EF_IGNORE_BULLETS)) && b->owner->type != other->type)
{
other->applyDamage(b->damage);
if (other->flags & EF_EXPLODES)
{
playSound(SND_METAL_HIT, CH_ANY);
addSparkParticles(b->x, b->y);
}
else
{
playSound(SND_FLESH_HIT, CH_ANY);
addSmallFleshChunk(b->x, b->y);
}
b->alive = ALIVE_DEAD;
if (b->owner->type == world.bob->type)
{
game.statShotsHit[b->weaponType]++;
}
}
}
}
int getRandomPlayerWeapon(int excludeGrenades)
{
if (excludeGrenades)

View File

@ -27,11 +27,6 @@ extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy);
extern void initLaser(Bullet *b);
extern void initGrenade(Bullet *b);
extern void initMissile(Bullet *b);
extern void initEntity(Entity *e);
extern void addSmallFleshChunk(float x, float y);
extern void addSparkParticles(float x, float y);
extern Bullet *createBaseBullet(Unit *owner);
extern Camera camera;
extern Entity *self;
extern Game game;
extern World world;

View File

@ -0,0 +1,123 @@
/*
Copyright (C) 2018 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "bullet.h"
static void tick(void);
static void touch(Entity *other);
Bullet *createBaseBullet(Unit *owner)
{
Bullet *bullet;
bullet = malloc(sizeof(Bullet));
memset(bullet, 0, sizeof(Bullet));
initEntity((Entity*)bullet);
bullet->x = (owner->x + owner->w / 2);
bullet->y = (owner->y + owner->h / 2) - 3;
bullet->dx = owner->facing == FACING_RIGHT ? 15 : -15;
bullet->facing = owner->facing;
bullet->damage = 1;
bullet->owner = (Entity*)owner;
bullet->health = FPS * 3;
bullet->flags |= EF_WEIGHTLESS | EF_IGNORE_BULLETS | EF_NO_ENVIRONMENT | EF_KILL_OFFSCREEN | EF_NO_TELEPORT;
bullet->tick = tick;
bullet->touch = touch;
bullet->spriteFrame = 0;
return bullet;
}
static void tick(void)
{
Bullet *b;
b = (Bullet*)self;
b->health--;
if (b->x <= 0 || b->y <= 0 || b->x >= (MAP_WIDTH * MAP_TILE_SIZE) - b->w || b->y >= (MAP_HEIGHT * MAP_TILE_SIZE) - b->h)
{
b->alive = ALIVE_DEAD;
}
/* don't allow the player to kill everything on the map by firing constantly */
if (b->owner->type == ET_BOB)
{
if (b->x < camera.x || b->y < camera.y || b->x > camera.x + SCREEN_WIDTH || b->y > camera.y + SCREEN_HEIGHT)
{
b->alive = ALIVE_DEAD;
}
}
}
static void touch(Entity *other)
{
Bullet *b;
b = (Bullet*)self;
if (b->alive == ALIVE_ALIVE)
{
if (other == NULL)
{
addSparkParticles(b->x, b->y);
b->alive = ALIVE_DEAD;
if (rand() % 2)
{
playSound(SND_RICO_1, CH_ANY);
}
else
{
playSound(SND_RICO_2, CH_ANY);
}
}
else if (other != b->owner && (!(other->flags & EF_IGNORE_BULLETS)) && b->owner->type != other->type)
{
other->applyDamage(b->damage);
if (other->flags & EF_EXPLODES)
{
playSound(SND_METAL_HIT, CH_ANY);
addSparkParticles(b->x, b->y);
}
else
{
playSound(SND_FLESH_HIT, CH_ANY);
addSmallFleshChunk(b->x, b->y);
}
b->alive = ALIVE_DEAD;
if (b->owner->type == world.bob->type)
{
game.statShotsHit[b->weaponType]++;
}
}
}
}

View File

@ -0,0 +1,32 @@
/*
Copyright (C) 2018 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../../common.h"
extern void playSound(int snd, int ch);
extern void initEntity(Entity *e);
extern void addSmallFleshChunk(float x, float y);
extern void addSparkParticles(float x, float y);
extern Bullet *createBaseBullet(Unit *owner);
extern Camera camera;
extern Entity *self;
extern Game game;
extern World world;

View File

@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../common.h"
#include "../../common.h"
extern void playSound(int snd, int ch);
extern void initGrenade(Bullet *b);

View File

@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../common.h"
#include "../../common.h"
extern void playSound(int snd, int ch);
extern int rrnd(int low, int high);

View File

@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../common.h"
#include "../../common.h"
extern int rrnd(int low, int high);
extern void initMissile(Bullet *b);