diff --git a/common.mk b/common.mk index aa0b02e..6b0747f 100644 --- a/common.mk +++ b/common.mk @@ -28,7 +28,7 @@ OBJS += atlas.o OBJS += battery.o blaze.o bob.o boss.o blobBoss.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 entities.o explosions.o eyeDroidCommander.o +OBJS += effects.o entities.o exit.o explosions.o eyeDroidCommander.o OBJS += fleshChunk.o frost.o OBJS += game.o OBJS += heart.o hub.o hud.o diff --git a/src/defs.h b/src/defs.h index e57440a..5080cfa 100644 --- a/src/defs.h +++ b/src/defs.h @@ -200,7 +200,8 @@ enum enum { - WS_IN_PROGRESS + WS_IN_PROGRESS, + WS_COMPLETE }; enum diff --git a/src/structs.h b/src/structs.h index 261faad..a0fbf75 100644 --- a/src/structs.h +++ b/src/structs.h @@ -374,6 +374,8 @@ typedef struct { int isBossMission; int isBossActive; int isOutpostMission; + int isReturnVisit; + int missionCompleteTimer; PointF checkpoints[MAX_CHECKPOINTS]; Quadtree quadtree; Entity entityHead, *entityTail; diff --git a/src/world/entities/structures/exit.c b/src/world/entities/structures/exit.c new file mode 100644 index 0000000..ceb4f8d --- /dev/null +++ b/src/world/entities/structures/exit.c @@ -0,0 +1,120 @@ + /* +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 "exit.h" + +static void tick(void); +static void action(void); +static void touch(Entity *other); +static SDL_Rect getBounds(void); + +void initExit(Entity *e) +{ + e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSpriteIndex("Exit"); + + e->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS; + + e->isStatic = 1; + + e->active = 0; + + if (!e->active) + { + e->spriteFrame = 0; + } + else + { + e->spriteFrame = 1; + } + + e->spriteTime = -1; + + e->tick = tick; + e->action = action; + e->touch = touch; + e->getBounds = getBounds; +} + +static void tick(void) +{ + if (!self->active) + { + self->bobTouching = MAX(self->bobTouching - 1, 0); + } +} + +static void action(void) +{ + Objective *o; + + if (!self->active) + { + self->active = 1; + + for (o = world.objectiveHead.next ; o != NULL ; o = o->next) + { + if (o->required && strcmp(o->targetName, "EXIT") != 0 && o->currentValue < o->targetValue) + { + self->active = 0; + } + } + + if (self->active) + { + self->spriteFrame = 1; + } + } + + self->thinkTime = FPS; +} + +static void touch(Entity *other) +{ + if (other->type == ET_BOB && !world.isReturnVisit) + { + if (self->bobTouching == 0) + { + if (self->active) + { + updateObjective("EXIT"); + world.missionCompleteTimer = (int) (FPS * 1.5); + world.bob->flags |= (EF_IMMUNE | EF_GONE); + world.state = WS_COMPLETE; + stopMusic(); + } + else + { + setGameplayMessage(MSG_GAMEPLAY, "Can't exit yet - required objectives not met"); + } + } + + self->bobTouching = 2; + } +} + +static SDL_Rect getBounds(void) +{ + self->bounds.x = self->x + 64; + self->bounds.y = self->y; + self->bounds.w = 2; + self->bounds.h = self->h; + + return self->bounds; +} diff --git a/src/world/entities/structures/exit.h b/src/world/entities/structures/exit.h new file mode 100644 index 0000000..d751027 --- /dev/null +++ b/src/world/entities/structures/exit.h @@ -0,0 +1,29 @@ +/* +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 int getSpriteIndex(char *name); +extern void updateObjective(char *targetName); +extern void setGameplayMessage(int type, char *format, ...); +extern void stopMusic(void); + +extern Entity *self; +extern World world;