From 1337fb2602c254033f9ae1883a72167d556df897 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 27 Jan 2018 10:58:47 +0000 Subject: [PATCH] Added lift. --- common.mk | 4 +- src/defs.h | 6 ++ src/structs.h | 1 + src/world/entities/structures/lift.c | 102 +++++++++++++++++++++++++++ src/world/entities/structures/lift.h | 30 ++++++++ src/world/world.c | 4 ++ src/world/world.h | 2 + 7 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 src/world/entities/structures/lift.c create mode 100644 src/world/entities/structures/lift.h diff --git a/common.mk b/common.mk index dee90e7..9048ca5 100644 --- a/common.mk +++ b/common.mk @@ -34,7 +34,7 @@ OBJS += game.o OBJS += heart.o horizontalDoor.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 += lookup.o +OBJS += lift.o lookup.o OBJS += main.o map.o maths.o mia.o OBJS += objectives.o OBJS += particles.o player.o @@ -42,7 +42,7 @@ OBJS += quadtree.o OBJS += sound.o sprites.o OBJS += tankCommander.o tankTrack.o teeka.o text.o textures.o title.o triggers.o OBJS += unit.o util.o -OBJS += weapons.o weaponPickup.o widgets.o +OBJS += weapons.o weaponPickup.o widgets.o world.o # top-level rule to create the program. all: $(PROG) $(LOCALE_MO) diff --git a/src/defs.h b/src/defs.h index 5080cfa..f204eaf 100644 --- a/src/defs.h +++ b/src/defs.h @@ -149,6 +149,12 @@ enum DOOR_CLOSED }; +enum +{ + LIFT_GOTO_FINISH, + LIFT_GOTO_START +}; + enum { WPN_PISTOL, diff --git a/src/structs.h b/src/structs.h index f0a6eb4..d0194fd 100644 --- a/src/structs.h +++ b/src/structs.h @@ -158,6 +158,7 @@ struct Entity { int closedY; int state; int speed; + int waitTime; Entity *carriedItem; Entity *owner; void (*action)(void); diff --git a/src/world/entities/structures/lift.c b/src/world/entities/structures/lift.c new file mode 100644 index 0000000..dbb0ad8 --- /dev/null +++ b/src/world/entities/structures/lift.c @@ -0,0 +1,102 @@ +/* +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 "lift.h" + +static void action(void); +static void activate(int active); + +void initLift(Entity *e) +{ + initEntity(e); + + e->state = LIFT_GOTO_FINISH; + + e->flags |= EF_WEIGHTLESS | EF_NO_ENVIRONMENT | EF_EXPLODES | EF_NO_CLIP | EF_ALWAYS_PROCESS | EF_NO_TELEPORT; + + e->speed = 2; + + e->waitTime = 2; + + e->startX = e->startY = -1; + + e->sprite[0] = e->sprite[1] = e->sprite[2] = getSpriteIndex("Lift"); + + e->active = 1; + + e->action = action; + e->activate = activate; +} + +static void action(void) +{ + self->dx = self->dy = 0; + + if (self->active) + { + if (self->state == LIFT_GOTO_START) + { + getSlope(self->startX, self->startY, self->x, self->y, &self->dx, &self->dy); + + self->dx *= self->speed; + self->dy *= self->speed; + + if (abs(self->x - self->startX) < self->speed && abs(self->y - self->startY) < self->speed) + { + self->x = self->startX; + self->y = self->startY; + self->state = LIFT_GOTO_FINISH; + self->thinkTime = self->waitTime * FPS; + self->dx = self->dy = 0; + } + } + else if (self->state == LIFT_GOTO_FINISH) + { + getSlope(self->tx, self->ty, self->x, self->y, &self->dx, &self->dy); + + self->dx *= self->speed; + self->dy *= self->speed; + + if (abs(self->x - self->tx) < self->speed && abs(self->y - self->ty) < self->speed) + { + self->x = self->tx; + self->y = self->ty; + self->state = LIFT_GOTO_START; + self->thinkTime = self->waitTime * FPS; + self->dx = self->dy = 0; + } + } + } +} + +static void activate(int active) +{ + self->active = active; + + if (self->active) + { + observeActivation(self); + + if (!isOnScreen(self)) + { + setGameplayMessage(MSG_GAMEPLAY, "Lift activated ..."); + } + } +} diff --git a/src/world/entities/structures/lift.h b/src/world/entities/structures/lift.h new file mode 100644 index 0000000..bc0753b --- /dev/null +++ b/src/world/entities/structures/lift.h @@ -0,0 +1,30 @@ +/* +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 int getSpriteIndex(char *name); +extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); +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/world.c b/src/world/world.c index 6aabc0e..8eb7e03 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -19,3 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "world.h" + +void observeActivation(Entity *e) +{ +} diff --git a/src/world/world.h b/src/world/world.h index d07721d..8ad0dc9 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -17,3 +17,5 @@ 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"