Triggers.
This commit is contained in:
parent
4fd1abd52d
commit
7380514a7e
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
|
@ -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"
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
Loading…
Reference in New Issue