From 0118582a1c838dd8a7ab924a1b6837f756773a99 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 27 Jan 2018 08:53:08 +0000 Subject: [PATCH] Card Reader. --- common.mk | 3 +- src/defs.h | 1 + src/game/game.c | 9 +++ src/structs.h | 3 + src/world/entities/structures/cardReader.c | 84 ++++++++++++++++++++++ src/world/entities/structures/cardReader.h | 32 +++++++++ 6 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 src/world/entities/structures/cardReader.c create mode 100644 src/world/entities/structures/cardReader.h diff --git a/common.mk b/common.mk index 91851ca..b63ba42 100644 --- a/common.mk +++ b/common.mk @@ -17,6 +17,7 @@ SEARCHPATH += src/world/entities/cannons SEARCHPATH += src/world/entities/decoration SEARCHPATH += src/world/entities/items SEARCHPATH += src/world/entities/misc +SEARCHPATH += src/world/entities/structures vpath %.c $(SEARCHPATH) vpath %.h $(SEARCHPATH) @@ -25,7 +26,7 @@ DEPS += defs.h structs.h OBJS += atlas.o OBJS += battery.o blaze.o bob.o boss.o blobBoss.o -OBJS += camera.o cannon.o cell.o cherry.o combat.o consumable.o +OBJS += camera.o cannon.o cardReader.o cell.o cherry.o combat.o consumable.o OBJS += debris.o destructable.o draw.o OBJS += effects.o entities.o explosions.o eyeDroidCommander.o OBJS += fleshChunk.o frost.o diff --git a/src/defs.h b/src/defs.h index 6bec99c..aebb048 100644 --- a/src/defs.h +++ b/src/defs.h @@ -279,6 +279,7 @@ enum CH_WEAPON, CH_DEATH, CH_ITEM, + CH_TOUCH, CH_MAX }; diff --git a/src/game/game.c b/src/game/game.c index 42652db..9b66cfb 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -71,6 +71,15 @@ void addKey(char *name) } +int hasItem(char *name) +{ + return 0; +} + +void removeKey(char *name) +{ +} + void destroyGame(void) { } diff --git a/src/structs.h b/src/structs.h index f9c83a1..5136840 100644 --- a/src/structs.h +++ b/src/structs.h @@ -140,9 +140,12 @@ struct Entity { int canBePickedUp; int provided; int firstTouch; + int active; float sinVal; + int bobTouching; int messageTimer; char message[MAX_DESCRIPTION_LENGTH]; + char requiredCard[MAX_NAME_LENGTH]; long flags; SDL_Rect bounds; int sprite[3]; diff --git a/src/world/entities/structures/cardReader.c b/src/world/entities/structures/cardReader.c new file mode 100644 index 0000000..223abc7 --- /dev/null +++ b/src/world/entities/structures/cardReader.c @@ -0,0 +1,84 @@ +/* +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 "cardReader.h" + +static void tick(void); +static void touch(Entity *other); + +void initCardReader(Entity *e) +{ + initEntity(e); + + e->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS | EF_NO_TELEPORT; + + STRNCPY(e->requiredCard, "Black Keycard", MAX_NAME_LENGTH); + + e->isStatic = 1; + + if (!e->active) + { + e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSpriteIndex("CardReaderIdle"); + } + else + { + e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSpriteIndex("CardReader"); + } + + e->tick = tick; + e->touch = touch; +} + +static void tick(void) +{ + if (!self->active) + { + self->bobTouching = MAX(self->bobTouching - 1, 0); + } +} + +static void touch(Entity *other) +{ + if (!self->active && other->type == ET_BOB) + { + if (hasItem(self->requiredCard) || dev.cheatKeys) + { + activateEntities(self->targetNames, 1); + + setGameplayMessage(MSG_GAMEPLAY, "%s removed", self->requiredCard); + + removeKey(self->requiredCard); + + self->active = 1; + self->sprite[FACING_LEFT] = self->sprite[FACING_RIGHT] = self->sprite[FACING_DIE] = getSpriteIndex("CardReader"); + self->spriteTime = 0; + self->spriteFrame = 0; + + playSound(SND_CONFIRMED, CH_TOUCH); + } + else if (self->bobTouching == 0) + { + setGameplayMessage(MSG_GAMEPLAY, "%s required", self->requiredCard); + playSound(SND_DENIED, CH_TOUCH); + } + + self->bobTouching = 2; + } +} diff --git a/src/world/entities/structures/cardReader.h b/src/world/entities/structures/cardReader.h new file mode 100644 index 0000000..68d6f66 --- /dev/null +++ b/src/world/entities/structures/cardReader.h @@ -0,0 +1,32 @@ +/* +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 removeKey(char *name); +extern int hasItem(char *name); +extern void setGameplayMessage(int type, char *format, ...); +extern void activateEntities(char *names, int activate); +extern void playSound(int snd, int ch); + +extern Dev dev; +extern Entity *self;