From 5bcebe8b0339ada237436ad8e64e410284ad8d75 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 27 Jan 2018 08:37:22 +0000 Subject: [PATCH] Added Info Point. --- common.mk | 2 +- src/structs.h | 4 ++ src/world/entities/misc/destructable.c | 2 + src/world/entities/misc/destructable.h | 1 + src/world/entities/misc/infoPoint.c | 81 ++++++++++++++++++++++++++ src/world/entities/misc/infoPoint.h | 34 +++++++++++ 6 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/world/entities/misc/infoPoint.c create mode 100644 src/world/entities/misc/infoPoint.h diff --git a/common.mk b/common.mk index b831450..91851ca 100644 --- a/common.mk +++ b/common.mk @@ -31,7 +31,7 @@ OBJS += effects.o entities.o explosions.o eyeDroidCommander.o OBJS += fleshChunk.o frost.o OBJS += game.o OBJS += heart.o hub.o hud.o -OBJS += init.o input.o io.o item.o items.o +OBJS += init.o infoPoint.o input.o io.o item.o items.o OBJS += key.o keycard.o OBJS += lookup.o OBJS += main.o map.o maths.o mia.o diff --git a/src/structs.h b/src/structs.h index 6f25b37..f9c83a1 100644 --- a/src/structs.h +++ b/src/structs.h @@ -139,6 +139,10 @@ struct Entity { int canBeCarried; int canBePickedUp; int provided; + int firstTouch; + float sinVal; + int messageTimer; + char message[MAX_DESCRIPTION_LENGTH]; long flags; SDL_Rect bounds; int sprite[3]; diff --git a/src/world/entities/misc/destructable.c b/src/world/entities/misc/destructable.c index b38f410..4aae5d7 100644 --- a/src/world/entities/misc/destructable.c +++ b/src/world/entities/misc/destructable.c @@ -25,6 +25,8 @@ static void action(void); void initDestructable(Entity *e) { + initEntity(e); + e->isMissionTarget = 1; STRNCPY(e->spriteName, "Crate4", MAX_NAME_LENGTH); diff --git a/src/world/entities/misc/destructable.h b/src/world/entities/misc/destructable.h index 38f9f9e..409a448 100644 --- a/src/world/entities/misc/destructable.h +++ b/src/world/entities/misc/destructable.h @@ -27,5 +27,6 @@ extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addScorchDecal(int x, int y); extern int getSpriteIndex(char *name); extern void updateObjective(char *targetName); +extern void initEntity(Entity *e); extern Entity *self; diff --git a/src/world/entities/misc/infoPoint.c b/src/world/entities/misc/infoPoint.c new file mode 100644 index 0000000..439bc42 --- /dev/null +++ b/src/world/entities/misc/infoPoint.c @@ -0,0 +1,81 @@ +/* +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 "infoPoint.h" + +static void tick(void); +static void touch(Entity *other); + +void initInfoPoint(Entity *e) +{ + initEntity(e); + + e->sprite[0] = e->sprite[1] = e->sprite[2] = getSpriteIndex("InfoPoint"); + + e->flags |= EF_WEIGHTLESS | EF_IGNORE_BULLETS | EF_NO_CLIP | EF_NO_ENVIRONMENT; + + e->ty = e->y; + + e->firstTouch = 1; + + e->tick = tick; + e->touch = touch; +} + +static void tick(void) +{ + self->sinVal -= 0.05; + self->y += (float) sin(self->sinVal) * 0.1; +} + +static void touch(Entity *other) +{ + int showMessage; + + if (other == world.bob) + { + showMessage = 0; + + if (self->firstTouch) + { + self->firstTouch = 0; + showMessage = 1; + self->messageTimer = FPS; + } + else if (world.bob->dx == 0 && world.bob->dy == 0 && world.bob->isOnGround) + { + self->messageTimer++; + + if (self->messageTimer == FPS) + { + showMessage = 1; + } + } + else + { + self->messageTimer = 0; + } + + if (showMessage) + { + showInfoMessage(self->message); + } + } +} diff --git a/src/world/entities/misc/infoPoint.h b/src/world/entities/misc/infoPoint.h new file mode 100644 index 0000000..0018cb1 --- /dev/null +++ b/src/world/entities/misc/infoPoint.h @@ -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 activateEntities(char *names, int activate); +extern void dropCarriedItem(void); +extern int rrnd(int low, int high); +extern void addExplosion(float x, float y, int radius, Entity *owner); +extern void addScorchDecal(int x, int y); +extern int getSpriteIndex(char *name); +extern void updateObjective(char *targetName); +extern void initEntity(Entity *e); +extern void showInfoMessage(char *message); + +extern Entity *self; +extern World world;