diff --git a/common.mk b/common.mk index 110a701..251db56 100644 --- a/common.mk +++ b/common.mk @@ -10,13 +10,14 @@ DEPS += defs.h structs.h OBJS += camera.o OBJS += draw.o +OBJS += entities.o OBJS += game.o OBJS += hud.o OBJS += init.o input.o io.o OBJS += lookup.o OBJS += main.o map.o maths.o OBJS += quadtree.o -OBJS += text.o textures.o title.o +OBJS += text.o textures.o title.o triggers.o OBJS += util.o OBJS += widgets.o diff --git a/src/structs.h b/src/structs.h index 77ab652..cd1bbee 100644 --- a/src/structs.h +++ b/src/structs.h @@ -22,6 +22,8 @@ typedef struct Texture Texture; typedef struct Lookup Lookup; typedef struct Quadtree Quadtree; typedef struct Entity Entity; +typedef struct Objective Objective; +typedef struct Trigger Trigger; typedef struct { int debug; @@ -79,6 +81,29 @@ struct Entity { int h; }; +struct Objective { + char id[MAX_NAME_LENGTH]; + char description[MAX_DESCRIPTION_LENGTH]; + char targetName[MAX_NAME_LENGTH]; + int currentValue; + int targetValue; + int totalValue; + int required; + Objective *next; +}; + +/* How you going, Dave? */ +struct Trigger { + char name[MAX_NAME_LENGTH]; + char message[MAX_DESCRIPTION_LENGTH]; + char targetNames[MAX_DESCRIPTION_LENGTH]; + int x; + int y; + int w; + int h; + Trigger *next; +}; + typedef struct { SDL_Rect bounds; float shakeAmount; @@ -140,6 +165,8 @@ struct Quadtree { }; typedef struct { + Entity *bob; Map map; Quadtree quadtree; + Trigger triggerHead, *triggerTail; } World; diff --git a/src/world/entities.c b/src/world/entities.c new file mode 100644 index 0000000..2f8819f --- /dev/null +++ b/src/world/entities.c @@ -0,0 +1,25 @@ +/* +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 "entities.h" + +void activateEntities(char *names, int activate) +{ +} diff --git a/src/world/entities.h b/src/world/entities.h new file mode 100644 index 0000000..8ad0dc9 --- /dev/null +++ b/src/world/entities.h @@ -0,0 +1,21 @@ +/* +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" diff --git a/src/world/triggers.c b/src/world/triggers.c new file mode 100644 index 0000000..97b4fee --- /dev/null +++ b/src/world/triggers.c @@ -0,0 +1,86 @@ +/* +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 "triggers.h" + +void doLocationTriggers(void) +{ + Trigger *t, *prev; + + prev = &world.triggerHead; + + for (t = world.triggerHead.next ; t != NULL ; t = t->next) + { + if (t->w > 0 && t->h > 0) + { + if (collision(t->x, t->y, t->w, t->h, world.bob->x, world.bob->y, world.bob->w, world.bob->h)) + { + activateEntities(t->targetNames, 1); + + if (t->message != NULL) + { + setGameplayMessage(t->message, MSG_GAMEPLAY); + } + + if (t == world.triggerTail) + { + world.triggerTail = prev; + } + + prev->next = t->next; + free(t); + t = prev; + } + } + + prev = t; + } +} + +void fireTriggers(char *name) +{ + Trigger *t, *prev; + + prev = &world.triggerHead; + + for (t = world.triggerHead.next ; t != NULL ; t = t->next) + { + if (strcmp(t->name, name) == 0) + { + activateEntities(t->targetNames, 1); + + if (t->message != NULL) + { + setGameplayMessage(t->message, MSG_GAMEPLAY); + } + + if (t == world.triggerTail) + { + world.triggerTail = prev; + } + + prev->next = t->next; + free(t); + t = prev; + } + + prev = t; + } +} diff --git a/src/world/triggers.h b/src/world/triggers.h new file mode 100644 index 0000000..b530ee6 --- /dev/null +++ b/src/world/triggers.h @@ -0,0 +1,27 @@ +/* +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 collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); +extern void activateEntities(char *names, int activate); +extern void setGameplayMessage(char *newMessage, int newMessageType); + +extern World world;