From 442f561f007b311910866edf33cf12065dc7b21c Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 9 Feb 2018 19:10:19 +0000 Subject: [PATCH] Added Shotgun Blob / Droid, and laser traps. --- common.mk | 2 +- src/entities/entityFactory.c | 4 +++ src/entities/entityFactory.h | 4 +++ src/entities/evilBlobs/shotgunBlob.c | 12 +++++-- src/entities/evilBlobs/shotgunBlob.h | 27 ++++++++++++++++ src/entities/eyeDroids/shotgunDroid.c | 12 +++++-- src/entities/eyeDroids/shotgunDroid.h | 25 +++++++++++++++ src/entities/structures/structures.h | 1 - src/entities/traps/horizontalLaserTrap.c | 8 +++-- src/entities/traps/horizontalLaserTrap.h | 2 +- src/entities/traps/laserTrap.c | 40 ++++++++++++++++++++++-- src/entities/traps/laserTrap.h | 2 ++ 12 files changed, 126 insertions(+), 13 deletions(-) create mode 100644 src/entities/evilBlobs/shotgunBlob.h create mode 100644 src/entities/eyeDroids/shotgunDroid.h diff --git a/common.mk b/common.mk index b6264f4..81cf553 100644 --- a/common.mk +++ b/common.mk @@ -46,7 +46,7 @@ OBJS += machineGunBlob.o main.o map.o maths.o mia.o missile.o OBJS += objectives.o OBJS += particles.o player.o pistolBlob.o pistolDroid.o powerPoint.o powerPool.o pressurePlate.o pushBlock.o OBJS += quadtree.o -OBJS += sound.o sprites.o structures.o +OBJS += shotgunBlob.o shotgunDroid.o sound.o sprites.o structures.o OBJS += tankCommander.o tankTrack.o teeka.o teleporter.o text.o textures.o title.o triggers.o OBJS += unit.o util.o OBJS += weapons.o weaponPickup.o widgets.o world.o worldLoader.o diff --git a/src/entities/entityFactory.c b/src/entities/entityFactory.c index 00d4299..3485f6f 100644 --- a/src/entities/entityFactory.c +++ b/src/entities/entityFactory.c @@ -40,6 +40,8 @@ void initEntityFactory(void) addEntityDef("MachineGunBlob", initMachineGunBlob); addEntityDef("GrenadeBlob", initGrenadeBlob); addEntityDef("GrenadeEyeDroid", initGrenadeDroid); + addEntityDef("ShotgunBlob", initShotgunBlob); + addEntityDef("ShotgunEyeDroid", initShotgunDroid); addEntityDef("Bob", initBob); addEntityDef("MIA", initMIA); @@ -70,6 +72,8 @@ void initEntityFactory(void) addEntityDef("GoldDoor", initGoldDoor); addEntityDef("HorizontalDoor", initHorizontalDoor); addEntityDef("CardReader", initCardReader); + addEntityDef("LaserTrap", initLaserTrap); + addEntityDef("HorizontalLaserTrap", initHorizontalLaserTrap); } Entity *createEntity(char *name) diff --git a/src/entities/entityFactory.h b/src/entities/entityFactory.h index 962f68a..fc33957 100644 --- a/src/entities/entityFactory.h +++ b/src/entities/entityFactory.h @@ -26,6 +26,8 @@ extern Entity *initPistolBlob(void); extern Entity *initPistolDroid(void); extern Entity *initGrenadeDroid(void); extern Entity *initGrenadeBlob(void); +extern Entity *initShotgunDroid(void); +extern Entity *initShotgunBlob(void); extern Entity *initBob(void); extern Entity *initExit(void); extern Entity *initPowerPool(void); @@ -52,5 +54,7 @@ extern Entity *initCardReader(void); extern Entity *initBlueKeycard(void); extern Entity *initRedKeycard(void); extern Entity *initYellowKeycard(void); +extern Entity *initLaserTrap(void); +extern Entity *initHorizontalLaserTrap(void); extern World world; diff --git a/src/entities/evilBlobs/shotgunBlob.c b/src/entities/evilBlobs/shotgunBlob.c index b0e3766..605ca03 100644 --- a/src/entities/evilBlobs/shotgunBlob.c +++ b/src/entities/evilBlobs/shotgunBlob.c @@ -22,10 +22,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static int canFire(Entity *target); -void initShotgunBlob(Unit *u) +Entity *initShotgunBlob(void) { + Unit *u; + + u = createUnit(); + initEvilBlob(u); + u->unitType = "ShotgunBlob"; + u->sprite[FACING_LEFT] = getSprite("ShotgunBlobLeft"); u->sprite[FACING_RIGHT] = getSprite("ShotgunBlobRight"); u->sprite[FACING_DIE] = getSprite("ShotgunBlobSpin"); @@ -35,10 +41,12 @@ void initShotgunBlob(Unit *u) u->maxShotsToFire = 2; u->canFire = canFire; + + return (Entity*)u; } static int canFire(Entity *target) { - return true; + return 1; } diff --git a/src/entities/evilBlobs/shotgunBlob.h b/src/entities/evilBlobs/shotgunBlob.h new file mode 100644 index 0000000..87bb9bc --- /dev/null +++ b/src/entities/evilBlobs/shotgunBlob.h @@ -0,0 +1,27 @@ +/* +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 Unit *createUnit(void); +extern void initEvilBlob(Unit *u); +extern Sprite *getSprite(char *name); + +extern Entity *self; diff --git a/src/entities/eyeDroids/shotgunDroid.c b/src/entities/eyeDroids/shotgunDroid.c index 5e200af..27c69cf 100644 --- a/src/entities/eyeDroids/shotgunDroid.c +++ b/src/entities/eyeDroids/shotgunDroid.c @@ -22,9 +22,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static int canFire(Entity *target); -void initShotgunDroid(Unit *u) +Entity *initShotgunDroid(void) { + Unit *u; + + u = createUnit(); + initEyeDroid(u); + + u->unitType = "ShotgunEyeDroid"; u->sprite[FACING_LEFT] = getSprite("ShotgunDroidLeft"); u->sprite[FACING_RIGHT] = getSprite("ShotgunDroidRight"); @@ -35,9 +41,11 @@ void initShotgunDroid(Unit *u) u->maxShotsToFire = 2; u->canFire = canFire; + + return (Entity*)u; } static int canFire(Entity *target) { - return true; + return 1; } diff --git a/src/entities/eyeDroids/shotgunDroid.h b/src/entities/eyeDroids/shotgunDroid.h new file mode 100644 index 0000000..ad19b31 --- /dev/null +++ b/src/entities/eyeDroids/shotgunDroid.h @@ -0,0 +1,25 @@ +/* +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 Unit *createUnit(void); +extern void initEyeDroid(Unit *u); +extern Sprite *getSprite(char *name); diff --git a/src/entities/structures/structures.h b/src/entities/structures/structures.h index f14e979..7caefce 100644 --- a/src/entities/structures/structures.h +++ b/src/entities/structures/structures.h @@ -21,4 +21,3 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" extern void initEntity(Entity *e); - diff --git a/src/entities/traps/horizontalLaserTrap.c b/src/entities/traps/horizontalLaserTrap.c index 00fadc8..1a44fc6 100644 --- a/src/entities/traps/horizontalLaserTrap.c +++ b/src/entities/traps/horizontalLaserTrap.c @@ -20,11 +20,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "horizontalLaserTrap.h" -void initHorizontalLaserTrap(Entity *e) +Entity *initHorizontalLaserTrap(void) { - initLaserTrap(e); + Entity *e; - e->type = ET_TRAP; + e = initLaserTrap(); e->sprite[0] = e->sprite[1] = e->sprite[2] = getSprite("HorizontalLaserTrap"); + + return e; } diff --git a/src/entities/traps/horizontalLaserTrap.h b/src/entities/traps/horizontalLaserTrap.h index 5f9f134..59e39a0 100644 --- a/src/entities/traps/horizontalLaserTrap.h +++ b/src/entities/traps/horizontalLaserTrap.h @@ -20,5 +20,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initLaserTrap(Entity *e); extern Sprite *getSprite(char *name); +extern Entity *initLaserTrap(void); diff --git a/src/entities/traps/laserTrap.c b/src/entities/traps/laserTrap.c index 8ae55d5..0a54d17 100644 --- a/src/entities/traps/laserTrap.c +++ b/src/entities/traps/laserTrap.c @@ -25,14 +25,17 @@ static void tick(void); static void action(void); static void touch(Entity *other); static void activate(int active); +static void load(cJSON *root); +static void save(cJSON *root); -void initLaserTrap(Entity *e) +Entity *initLaserTrap(void) { Trap *t; - initEntity(e); + t = malloc(sizeof(Trap)); + memset(t, 0, sizeof(Trap)); - t = (Trap*)e; + initEntity((Entity*)t); t->type = ET_TRAP; @@ -50,6 +53,10 @@ void initLaserTrap(Entity *e) t->action = action; t->touch = touch; t->activate = activate; + t->load = load; + t->save = save; + + return (Entity*)t; } static void init(void) @@ -130,6 +137,8 @@ static void touch(Entity *other) other->applyDamage((int) other->health); swapSelf(other); } + + playSound(SND_FLESH_HIT, CH_ANY); } if (other == (Entity*)world.bob && world.bob->stunTimer == 0) @@ -172,3 +181,28 @@ static void activate(int active) } } } + +static void load(cJSON *root) +{ + Trap *t; + + t = (Trap*)self; + + if (cJSON_GetObjectItem(root, "active")) + { + t->active = cJSON_GetObjectItem(root, "active")->valueint; + } + t->onTime = cJSON_GetObjectItem(root, "onTime")->valueint; + t->offTime = cJSON_GetObjectItem(root, "offTime")->valueint; +} + +static void save(cJSON *root) +{ + Trap *t; + + t = (Trap*)self; + + cJSON_AddNumberToObject(root, "active", t->active); + cJSON_AddNumberToObject(root, "onTime", t->onTime); + cJSON_AddNumberToObject(root, "offTime", t->offTime); +} diff --git a/src/entities/traps/laserTrap.h b/src/entities/traps/laserTrap.h index 3e6c2fb..6afb41a 100644 --- a/src/entities/traps/laserTrap.h +++ b/src/entities/traps/laserTrap.h @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "../../common.h" +#include "../../json/cJSON.h" extern void initEntity(Entity *e); extern void observeActivation(Entity *e); @@ -30,6 +31,7 @@ extern void stunBob(void); extern void addSparkParticles(float x, float y); extern void addSmallFleshChunk(float x, float y); extern void swapSelf(Entity *e); +extern void playSound(int snd, int ch); extern Entity *self; extern World world;