From b56cb72aecaf5a995de54b85830a3ccc56a16039 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 27 Jan 2018 11:55:15 +0000 Subject: [PATCH] Teleporter, Laser traps. --- common.mk | 7 +- src/defs.h | 1 + src/structs.h | 3 + src/world/entities/entities.c | 4 + src/world/entities/structures/pushBlock.h | 2 - src/world/entities/structures/teleporter.c | 89 ++++++++++ src/world/entities/structures/teleporter.h | 31 ++++ .../entities/traps/horizontalLaserTrap.c | 28 ++++ .../entities/traps/horizontalLaserTrap.h | 24 +++ src/world/entities/traps/laserTrap.c | 152 ++++++++++++++++++ src/world/entities/traps/laserTrap.h | 34 ++++ 11 files changed, 370 insertions(+), 5 deletions(-) create mode 100644 src/world/entities/structures/teleporter.c create mode 100644 src/world/entities/structures/teleporter.h create mode 100644 src/world/entities/traps/horizontalLaserTrap.c create mode 100644 src/world/entities/traps/horizontalLaserTrap.h create mode 100644 src/world/entities/traps/laserTrap.c create mode 100644 src/world/entities/traps/laserTrap.h diff --git a/common.mk b/common.mk index f43b26c..adc0d46 100644 --- a/common.mk +++ b/common.mk @@ -18,6 +18,7 @@ SEARCHPATH += src/world/entities/decoration SEARCHPATH += src/world/entities/items SEARCHPATH += src/world/entities/misc SEARCHPATH += src/world/entities/structures +SEARCHPATH += src/world/entities/traps vpath %.c $(SEARCHPATH) vpath %.h $(SEARCHPATH) @@ -31,16 +32,16 @@ OBJS += debris.o destructable.o door.o draw.o OBJS += effects.o entities.o exit.o explosions.o eyeDroidCommander.o OBJS += fleshChunk.o frost.o OBJS += game.o -OBJS += heart.o horizontalDoor.o hub.o hud.o +OBJS += heart.o horizontalDoor.o horizontalLaserTrap.o hub.o hud.o OBJS += init.o infoPoint.o input.o io.o item.o items.o itemPad.o OBJS += key.o keycard.o -OBJS += lift.o lookup.o +OBJS += laserTrap.o lift.o lookup.o OBJS += main.o map.o maths.o mia.o OBJS += objectives.o OBJS += particles.o player.o powerPoint.o powerPool.o pressurePlate.o pushBlock.o OBJS += quadtree.o OBJS += sound.o sprites.o -OBJS += tankCommander.o tankTrack.o teeka.o text.o textures.o title.o triggers.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 diff --git a/src/defs.h b/src/defs.h index f204eaf..5164ce1 100644 --- a/src/defs.h +++ b/src/defs.h @@ -294,6 +294,7 @@ enum CH_ITEM, CH_TOUCH, CH_MECHANICAL, + CH_EFFECTS, CH_MAX }; diff --git a/src/structs.h b/src/structs.h index 9f041f9..26facce 100644 --- a/src/structs.h +++ b/src/structs.h @@ -162,8 +162,11 @@ struct Entity { int waitTime; int isWeighted; float weightApplied; + int onTime; + int offTime; Entity *carriedItem; Entity *owner; + void (*init)(void); void (*action)(void); void (*walk)(void); void (*attack)(void); diff --git a/src/world/entities/entities.c b/src/world/entities/entities.c index 7fead76..37ac4b4 100644 --- a/src/world/entities/entities.c +++ b/src/world/entities/entities.c @@ -154,6 +154,10 @@ void activateEntities(char *names, int activate) { } +void teleportEntity(Entity *e, float tx, float ty) +{ +} + static void applyDamage(int damage) { if (self->health < 0) diff --git a/src/world/entities/structures/pushBlock.h b/src/world/entities/structures/pushBlock.h index cbd550b..36b791f 100644 --- a/src/world/entities/structures/pushBlock.h +++ b/src/world/entities/structures/pushBlock.h @@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../../common.h" extern void initEntity(Entity *e); -extern int getSpriteIndex(char *name); -extern void activateEntities(char *names, int activate); extern void playSound(int snd, int ch); extern void addTeleportStars(Entity *e); diff --git a/src/world/entities/structures/teleporter.c b/src/world/entities/structures/teleporter.c new file mode 100644 index 0000000..3d55975 --- /dev/null +++ b/src/world/entities/structures/teleporter.c @@ -0,0 +1,89 @@ +/* +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 "teleporter.h" + +static void action(void); +static void touch(Entity *other); +static void activate(int active); + +void initTeleporter(Entity *e) +{ + initEntity(e); + + e->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_IGNORE_BULLETS | EF_NO_TELEPORT; + + e->plane = PLANE_FOREGROUND; + + e->isStatic = 1; + + e->active = 1; + + e->action = action; + e->touch = touch; + e->activate = activate; +} + +static void action(void) +{ + if (self->active) + { + addTeleporterEffect(self->x + rand() % 85, self->y); + } + + self->thinkTime = 1; +} + +static void touch(Entity *other) +{ + float tx, ty; + + if (self->active && other != self && (other->flags & (EF_TELEPORTING | EF_NO_TELEPORT)) == 0) + { + tx = self->tx; + other->tx += self->w / 2; + other->tx -= other->w / 2; + + ty = self->ty; + other->ty += self->h / 2; + other->ty -= other->h / 2; + + teleportEntity(other, tx, ty); + + playSound(SND_TELEPORT, CH_EFFECTS); + } +} + +static void activate(int active) +{ + self->active = active; + + self->init(); + + if (self->active) + { + observeActivation(self); + + if (!isOnScreen(self)) + { + setGameplayMessage(MSG_GAMEPLAY, "Teleporter activated ..."); + } + } +} diff --git a/src/world/entities/structures/teleporter.h b/src/world/entities/structures/teleporter.h new file mode 100644 index 0000000..b46f32b --- /dev/null +++ b/src/world/entities/structures/teleporter.h @@ -0,0 +1,31 @@ +/* +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 initEntity(Entity *e); +extern void playSound(int snd, int ch); +extern void addTeleporterEffect(float x, float y); +extern void teleportEntity(Entity *e, float tx, float ty); +extern void observeActivation(Entity *e); +extern int isOnScreen(Entity *e); +extern void setGameplayMessage(int type, char *format, ...); + +extern Entity *self; diff --git a/src/world/entities/traps/horizontalLaserTrap.c b/src/world/entities/traps/horizontalLaserTrap.c new file mode 100644 index 0000000..d80327b --- /dev/null +++ b/src/world/entities/traps/horizontalLaserTrap.c @@ -0,0 +1,28 @@ +/* +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 "horizontalLaserTrap.h" + +void initHorizontalLaserTrap(Entity *e) +{ + initLaserTrap(e); + + e->sprite[0] = e->sprite[1] = e->sprite[2] = getSpriteIndex("HorizontalLaserTrap"); +} diff --git a/src/world/entities/traps/horizontalLaserTrap.h b/src/world/entities/traps/horizontalLaserTrap.h new file mode 100644 index 0000000..974ea6d --- /dev/null +++ b/src/world/entities/traps/horizontalLaserTrap.h @@ -0,0 +1,24 @@ +/* +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 initLaserTrap(Entity *e); +extern int getSpriteIndex(char *name); diff --git a/src/world/entities/traps/laserTrap.c b/src/world/entities/traps/laserTrap.c new file mode 100644 index 0000000..3b0e42a --- /dev/null +++ b/src/world/entities/traps/laserTrap.c @@ -0,0 +1,152 @@ +/* +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 "laserTrap.h" + +static void init(void); +static void tick(void); +static void action(void); +static void touch(Entity *other); +static void activate(int active); + +void initLaserTrap(Entity *e) +{ + initEntity(e); + + e->flags |= EF_WEIGHTLESS | EF_IGNORE_BULLETS | EF_NO_ENVIRONMENT | EF_NO_CLIP | EF_ALWAYS_PROCESS; + + e->onTime = FPS * 2; + e->offTime = FPS * 2; + + e->sprite[0] = e->sprite[1] = e->sprite[2] = getSpriteIndex("LaserTrap"); + + e->active = 1; + + e->init = init; + e->tick = tick; + e->action = action; + e->touch = touch; + e->activate = activate; +} + +static void init(void) +{ + if (!self->active) + { + self->flags |= EF_GONE; + } +} + +static void tick(void) +{ + if (!self->active && self->spriteTime == -1) + { + self->flags |= EF_GONE; + } +} + +static void action(void) +{ + if (self->offTime != 0) + { + if (!self->active) + { + self->thinkTime = self->onTime; + self->spriteFrame = 0; + self->spriteTime = 0; + self->flags &= ~EF_GONE; + } + else if (self->offTime > 0) + { + self->thinkTime = self->offTime; + self->spriteTime = 0; + } + + self->active = !self->active; + } + else + { + self->spriteTime = -1; + self->spriteFrame = 4; + } +} + +static void touch(Entity *other) +{ + if (other != NULL && (other->type == ET_BOB || other->type == ET_ENEMY)) + { + if (!(other->flags & EF_IMMUNE)) + { + if (other->health > 0 || rand() % 100 < 5) + { + other->dx = rrnd(-12, 12); + other->dy = rrnd(-8, 0); + + if (self->offTime != 0) + { + other->applyDamage((int) (other->healthMax / 4)); + } + else + { + /* instant kill */ + other->applyDamage((int) other->health); + } + } + + if (other == world.bob && world.bob->stunTimer == 0) + { + stunPlayer(); + } + } + + if (other->flags & EF_EXPLODES) + { + addSparkParticles(self->x, self->y); + } + else + { + addSmallFleshChunk(self->x, self->y); + } + } +} + +static void activate(int active) +{ + self->active = !active; + + if (!self->active) + { + self->flags |= EF_GONE; + } + else + { + self->flags &= ~EF_GONE; + } + + if (!self->active) + { + observeActivation(self); + + if (!isOnScreen(self)) + { + setGameplayMessage(MSG_GAMEPLAY, "Lasers disabled ..."); + } + } +} diff --git a/src/world/entities/traps/laserTrap.h b/src/world/entities/traps/laserTrap.h new file mode 100644 index 0000000..50f32b3 --- /dev/null +++ b/src/world/entities/traps/laserTrap.h @@ -0,0 +1,34 @@ +/* +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 initEntity(Entity *e); +extern void observeActivation(Entity *e); +extern int isOnScreen(Entity *e); +extern void setGameplayMessage(int type, char *format, ...); +extern int getSpriteIndex(char *name); +extern int rrnd(int low, int high); +extern void stunPlayer(void); +extern void addSparkParticles(float x, float y); +extern void addSmallFleshChunk(float x, float y); + +extern Entity *self; +extern World world;