From ff60ddf6de101bcba16950e6763b574a67a8573b Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 27 Jan 2018 10:47:53 +0000 Subject: [PATCH] Item pad. --- common.mk | 2 +- src/game/game.c | 7 +- src/structs.h | 1 + src/world/entities/structures/cardReader.c | 2 +- src/world/entities/structures/cardReader.h | 2 +- src/world/entities/structures/door.c | 2 +- src/world/entities/structures/door.h | 2 +- src/world/entities/structures/itemPad.c | 90 ++++++++++++++++++++++ src/world/entities/structures/itemPad.h | 30 ++++++++ 9 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 src/world/entities/structures/itemPad.c create mode 100644 src/world/entities/structures/itemPad.h diff --git a/common.mk b/common.mk index b50a0b1..dee90e7 100644 --- a/common.mk +++ b/common.mk @@ -32,7 +32,7 @@ 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 += init.o infoPoint.o input.o io.o item.o items.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 += main.o map.o maths.o mia.o diff --git a/src/game/game.c b/src/game/game.c index 9b66cfb..2d24ee7 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -76,7 +76,12 @@ int hasItem(char *name) return 0; } -void removeKey(char *name) +Entity *getItem(char *name) +{ + return NULL; +} + +void removeItem(char *name) { } diff --git a/src/structs.h b/src/structs.h index a0fbf75..f0a6eb4 100644 --- a/src/structs.h +++ b/src/structs.h @@ -147,6 +147,7 @@ struct Entity { char message[MAX_DESCRIPTION_LENGTH]; char requiredCard[MAX_NAME_LENGTH]; char requiredKey[MAX_NAME_LENGTH]; + char requiredItem[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 index 223abc7..51dd6b1 100644 --- a/src/world/entities/structures/cardReader.c +++ b/src/world/entities/structures/cardReader.c @@ -64,7 +64,7 @@ static void touch(Entity *other) setGameplayMessage(MSG_GAMEPLAY, "%s removed", self->requiredCard); - removeKey(self->requiredCard); + removeItem(self->requiredCard); self->active = 1; self->sprite[FACING_LEFT] = self->sprite[FACING_RIGHT] = self->sprite[FACING_DIE] = getSpriteIndex("CardReader"); diff --git a/src/world/entities/structures/cardReader.h b/src/world/entities/structures/cardReader.h index 68d6f66..2fc0d11 100644 --- a/src/world/entities/structures/cardReader.h +++ b/src/world/entities/structures/cardReader.h @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void initEntity(Entity *e); extern int getSpriteIndex(char *name); -extern void removeKey(char *name); +extern void removeItem(char *name); extern int hasItem(char *name); extern void setGameplayMessage(int type, char *format, ...); extern void activateEntities(char *names, int activate); diff --git a/src/world/entities/structures/door.c b/src/world/entities/structures/door.c index c76eeb0..fe2113f 100644 --- a/src/world/entities/structures/door.c +++ b/src/world/entities/structures/door.c @@ -187,7 +187,7 @@ static void openWithKey(void) return; } - removeKey(self->requiredKey); + removeItem(self->requiredKey); setGameplayMessage(MSG_GAMEPLAY, "%s removed", self->requiredKey); diff --git a/src/world/entities/structures/door.h b/src/world/entities/structures/door.h index f9d148e..62b9c7e 100644 --- a/src/world/entities/structures/door.h +++ b/src/world/entities/structures/door.h @@ -26,7 +26,7 @@ extern void playSound(int snd, int ch); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void setGameplayMessage(int type, char *format, ...); extern int hasItem(char *name); -extern void removeKey(char *name); +extern void removeItem(char *name); extern Entity *self; extern Dev dev; diff --git a/src/world/entities/structures/itemPad.c b/src/world/entities/structures/itemPad.c new file mode 100644 index 0000000..d64598b --- /dev/null +++ b/src/world/entities/structures/itemPad.c @@ -0,0 +1,90 @@ +/* +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 "itemPad.h" + +static void tick(void); +static void touch(Entity *other); + +void initItemPad(Entity *e) +{ + initEntity(e); + + e->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS; + + e->plane = PLANE_FOREGROUND; + + e->isStatic = 1; + + if (!e->active) + { + e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSpriteIndex("ItemPadActive"); + } + else + { + e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSpriteIndex("ItemPadInactive"); + } + + e->tick = tick; + e->touch = touch; +} + +static void tick(void) +{ + self->bobTouching = MAX(self->bobTouching - 1, 0); +} + +static void touch(Entity *other) +{ + Entity *i; + + if (other->type == ET_BOB && !self->active) + { + i = getItem(self->requiredItem); + + if (i != NULL) + { + removeItem(i->name); + + i->flags &= ~EF_GONE; + + i->x = self->x + (self->w / 2) - (i->w / 2); + i->y = self->y - i->h; + + i->canBeCarried = i->canBePickedUp = i->isMissionTarget = 0; + + self->active = 1; + + setGameplayMessage(MSG_GAMEPLAY, "%s removed", self->requiredItem); + + self->sprite[FACING_LEFT] = self->sprite[FACING_RIGHT] = self->sprite[FACING_DIE] = getSpriteIndex("ItemPadActive"); + + self->spriteFrame = 0; + + updateObjective(self->name); + } + else if (!self->bobTouching) + { + setGameplayMessage(MSG_GAMEPLAY, "%s required", self->requiredItem); + } + + self->bobTouching = 2; + } +} diff --git a/src/world/entities/structures/itemPad.h b/src/world/entities/structures/itemPad.h new file mode 100644 index 0000000..9299e97 --- /dev/null +++ b/src/world/entities/structures/itemPad.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 updateObjective(char *targetName); +extern void setGameplayMessage(int type, char *format, ...); +extern void removeItem(char *name); +extern Entity *getItem(char *name); + +extern Entity *self;