Teleporter, Laser traps.

This commit is contained in:
Steve 2018-01-27 11:55:15 +00:00
parent 5323d1b2b2
commit b56cb72aec
11 changed files with 370 additions and 5 deletions

View File

@ -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

View File

@ -294,6 +294,7 @@ enum
CH_ITEM,
CH_TOUCH,
CH_MECHANICAL,
CH_EFFECTS,
CH_MAX
};

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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 ...");
}
}
}

View File

@ -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;

View File

@ -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");
}

View File

@ -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);

View File

@ -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 ...");
}
}
}

View File

@ -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;