Start of waypoints.
This commit is contained in:
parent
d0a3d0d6c5
commit
73eb5517bf
|
@ -8,12 +8,12 @@
|
||||||
"type" : "Nymph",
|
"type" : "Nymph",
|
||||||
"side" : "SIDE_CSN"
|
"side" : "SIDE_CSN"
|
||||||
},
|
},
|
||||||
"triggers" : [
|
"entities" : [
|
||||||
{
|
{
|
||||||
"type" : "TRIGGER_TIME",
|
"name" : "Waypoint",
|
||||||
"targetName" : "TIME",
|
"type" : "ET_WAYPOINT",
|
||||||
"targetValue" : 10,
|
"x" : 100,
|
||||||
"action" : "TA_COMPLETE_MISSION"
|
"y" : 100
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
4
makefile
4
makefile
|
@ -19,7 +19,7 @@ OBJS += ai.o
|
||||||
OBJS += battle.o bullets.o
|
OBJS += battle.o bullets.o
|
||||||
OBJS += challenges.o cJSON.o
|
OBJS += challenges.o cJSON.o
|
||||||
OBJS += draw.o
|
OBJS += draw.o
|
||||||
OBJS += effects.o
|
OBJS += effects.o entities.o
|
||||||
OBJS += fighters.o fighterDefs.o
|
OBJS += fighters.o fighterDefs.o
|
||||||
OBJS += galacticMap.o game.o
|
OBJS += galacticMap.o game.o
|
||||||
OBJS += hud.o
|
OBJS += hud.o
|
||||||
|
@ -32,7 +32,7 @@ OBJS += radar.o
|
||||||
OBJS += save.o sound.o starfield.o starSystems.o stats.o
|
OBJS += save.o sound.o starfield.o starSystems.o stats.o
|
||||||
OBJS += testMission.o textures.o text.o title.o transition.o triggers.o
|
OBJS += testMission.o textures.o text.o title.o transition.o triggers.o
|
||||||
OBJS += util.o
|
OBJS += util.o
|
||||||
OBJS += widgets.o
|
OBJS += waypoints.o widgets.o
|
||||||
|
|
||||||
# top-level rule to create the program.
|
# top-level rule to create the program.
|
||||||
all: $(PROG)
|
all: $(PROG)
|
||||||
|
|
|
@ -41,6 +41,7 @@ void initBattle(void)
|
||||||
{
|
{
|
||||||
memset(&battle, 0, sizeof(Battle));
|
memset(&battle, 0, sizeof(Battle));
|
||||||
battle.bulletTail = &battle.bulletHead;
|
battle.bulletTail = &battle.bulletHead;
|
||||||
|
battle.entityTail = &battle.entityHead;
|
||||||
battle.fighterTail = &battle.fighterHead;
|
battle.fighterTail = &battle.fighterHead;
|
||||||
battle.effectTail = &battle.effectHead;
|
battle.effectTail = &battle.effectHead;
|
||||||
battle.objectiveTail = &battle.objectiveHead;
|
battle.objectiveTail = &battle.objectiveHead;
|
||||||
|
@ -119,6 +120,8 @@ static void doBattle(void)
|
||||||
|
|
||||||
doFighters();
|
doFighters();
|
||||||
|
|
||||||
|
doEntities();
|
||||||
|
|
||||||
doEffects();
|
doEffects();
|
||||||
|
|
||||||
doPlayer();
|
doPlayer();
|
||||||
|
@ -161,6 +164,8 @@ static void draw(void)
|
||||||
|
|
||||||
drawFighters();
|
drawFighters();
|
||||||
|
|
||||||
|
drawEntities();
|
||||||
|
|
||||||
drawEffects();
|
drawEffects();
|
||||||
|
|
||||||
drawHud();
|
drawHud();
|
||||||
|
@ -316,6 +321,7 @@ static void postBattle(void)
|
||||||
void destroyBattle(void)
|
void destroyBattle(void)
|
||||||
{
|
{
|
||||||
Fighter *f;
|
Fighter *f;
|
||||||
|
Entity *ent;
|
||||||
Bullet *b;
|
Bullet *b;
|
||||||
Effect *e;
|
Effect *e;
|
||||||
Objective *o;
|
Objective *o;
|
||||||
|
@ -329,6 +335,14 @@ void destroyBattle(void)
|
||||||
}
|
}
|
||||||
battle.fighterTail = &battle.fighterHead;
|
battle.fighterTail = &battle.fighterHead;
|
||||||
|
|
||||||
|
while (battle.entityHead.next)
|
||||||
|
{
|
||||||
|
ent = battle.entityHead.next;
|
||||||
|
battle.entityHead.next = ent->next;
|
||||||
|
free(ent);
|
||||||
|
}
|
||||||
|
battle.entityTail = &battle.entityHead;
|
||||||
|
|
||||||
while (battle.bulletHead.next)
|
while (battle.bulletHead.next)
|
||||||
{
|
{
|
||||||
b = battle.bulletHead.next;
|
b = battle.bulletHead.next;
|
||||||
|
|
|
@ -35,6 +35,8 @@ extern void drawBullets(void);
|
||||||
extern void doStars(float dx, float dy);
|
extern void doStars(float dx, float dy);
|
||||||
extern void drawStars(void);
|
extern void drawStars(void);
|
||||||
extern void doFighters(void);
|
extern void doFighters(void);
|
||||||
|
extern void doEntities(void);
|
||||||
|
extern void drawEntities(void);
|
||||||
extern void drawFighters(void);
|
extern void drawFighters(void);
|
||||||
extern void initStars(void);
|
extern void initStars(void);
|
||||||
extern void doPlayer(void);
|
extern void doPlayer(void);
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 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 doEntities(void)
|
||||||
|
{
|
||||||
|
Entity *e, *prev;
|
||||||
|
|
||||||
|
prev = &battle.entityHead;
|
||||||
|
|
||||||
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||||
|
{
|
||||||
|
e->x += e->dx;
|
||||||
|
e->y += e->dy;
|
||||||
|
|
||||||
|
e->x -= battle.ssx;
|
||||||
|
e->y -= battle.ssy;
|
||||||
|
|
||||||
|
if (e->action != NULL)
|
||||||
|
{
|
||||||
|
if (--e->thinkTime <= 0)
|
||||||
|
{
|
||||||
|
e->action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e->health <= 0)
|
||||||
|
{
|
||||||
|
prev->next = e->next;
|
||||||
|
free(e);
|
||||||
|
e = prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawEntities(void)
|
||||||
|
{
|
||||||
|
Entity *e;
|
||||||
|
|
||||||
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||||
|
{
|
||||||
|
blitRotated(e->texture, e->x, e->y, e->angle);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 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 "SDL2/SDL.h"
|
||||||
|
|
||||||
|
#include "../defs.h"
|
||||||
|
#include "../structs.h"
|
||||||
|
|
||||||
|
extern void blitRotated(SDL_Texture *t, int x, int y, int angle);
|
||||||
|
|
||||||
|
extern Battle battle;
|
|
@ -30,4 +30,3 @@ extern void failMission(void);
|
||||||
|
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
extern Game game;
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 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 "waypoints.h"
|
||||||
|
|
||||||
|
static void rotate(void);
|
||||||
|
|
||||||
|
Entity *spawnWaypoint(void)
|
||||||
|
{
|
||||||
|
Entity *waypoint = malloc(sizeof(Entity));
|
||||||
|
memset(waypoint, 0, sizeof(Entity));
|
||||||
|
battle.entityTail->next = waypoint;
|
||||||
|
battle.entityTail = waypoint;
|
||||||
|
|
||||||
|
waypoint->health = waypoint->maxHealth = FPS;
|
||||||
|
waypoint->texture = getTexture("gfx/entities/waypoint.png");
|
||||||
|
waypoint->action = rotate;
|
||||||
|
|
||||||
|
return waypoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rotate(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 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 "SDL2/SDL.h"
|
||||||
|
|
||||||
|
#include "../defs.h"
|
||||||
|
#include "../structs.h"
|
||||||
|
|
||||||
|
extern Battle battle;
|
||||||
|
|
||||||
|
extern SDL_Texture *getTexture(char *filename);
|
|
@ -57,6 +57,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#define FF_IMMORTAL (2 << 2)
|
#define FF_IMMORTAL (2 << 2)
|
||||||
#define FF_MISSION_TARGET (2 << 3)
|
#define FF_MISSION_TARGET (2 << 3)
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ET_WAYPOINT
|
||||||
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
TA_LEFT,
|
TA_LEFT,
|
||||||
|
|
|
@ -25,6 +25,7 @@ static void loadTriggers(cJSON *node);
|
||||||
static void loadPlayer(cJSON *node);
|
static void loadPlayer(cJSON *node);
|
||||||
static void loadFighters(cJSON *node);
|
static void loadFighters(cJSON *node);
|
||||||
static void loadFighterGroups(cJSON *node);
|
static void loadFighterGroups(cJSON *node);
|
||||||
|
static void loadEntities(cJSON *node);
|
||||||
static unsigned long hashcode(const char *str);
|
static unsigned long hashcode(const char *str);
|
||||||
static char **toFighterTypeArray(char *types, int *numTypes);
|
static char **toFighterTypeArray(char *types, int *numTypes);
|
||||||
|
|
||||||
|
@ -58,6 +59,8 @@ void loadMission(char *filename)
|
||||||
|
|
||||||
loadFighterGroups(cJSON_GetObjectItem(root, "fighterGroups"));
|
loadFighterGroups(cJSON_GetObjectItem(root, "fighterGroups"));
|
||||||
|
|
||||||
|
loadEntities(cJSON_GetObjectItem(root, "entities"));
|
||||||
|
|
||||||
STRNCPY(music, cJSON_GetObjectItem(root, "music")->valuestring, MAX_NAME_LENGTH);
|
STRNCPY(music, cJSON_GetObjectItem(root, "music")->valuestring, MAX_NAME_LENGTH);
|
||||||
|
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
|
@ -246,6 +249,40 @@ static void loadFighterGroups(cJSON *node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void loadEntities(cJSON *node)
|
||||||
|
{
|
||||||
|
Entity *e;
|
||||||
|
int type;
|
||||||
|
|
||||||
|
if (node)
|
||||||
|
{
|
||||||
|
node = node->child;
|
||||||
|
|
||||||
|
while (node)
|
||||||
|
{
|
||||||
|
type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ET_WAYPOINT:
|
||||||
|
e = spawnWaypoint();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
STRNCPY(e->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
|
||||||
|
e->x = cJSON_GetObjectItem(node, "x")->valueint;
|
||||||
|
e->y = cJSON_GetObjectItem(node, "y")->valueint;
|
||||||
|
|
||||||
|
if (cJSON_GetObjectItem(node, "flags"))
|
||||||
|
{
|
||||||
|
e->flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring);
|
||||||
|
}
|
||||||
|
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static char **toFighterTypeArray(char *types, int *numTypes)
|
static char **toFighterTypeArray(char *types, int *numTypes)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -35,6 +35,7 @@ extern void playMusic(char *filename);
|
||||||
extern void stopMusic(void);
|
extern void stopMusic(void);
|
||||||
extern void initPlayer(void);
|
extern void initPlayer(void);
|
||||||
extern long flagsToLong(char *flags);
|
extern long flagsToLong(char *flags);
|
||||||
|
extern Entity *spawnWaypoint(void);
|
||||||
|
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
extern Fighter *player;
|
extern Fighter *player;
|
||||||
|
|
|
@ -338,7 +338,7 @@ cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int r
|
||||||
/* Default options for cJSON_Parse */
|
/* Default options for cJSON_Parse */
|
||||||
cJSON *cJSON_Parse(const char *value) {return cJSON_ParseWithOpts(value,0,0);}
|
cJSON *cJSON_Parse(const char *value) {return cJSON_ParseWithOpts(value,0,0);}
|
||||||
|
|
||||||
/* Render a cJSON item/Fighter/structure to text. */
|
/* Render a cJSON item/entity/structure to text. */
|
||||||
char *cJSON_Print(cJSON *item) {return print_value(item,0,1,0);}
|
char *cJSON_Print(cJSON *item) {return print_value(item,0,1,0);}
|
||||||
char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0,0);}
|
char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0,0);}
|
||||||
|
|
||||||
|
|
|
@ -65,13 +65,13 @@ extern void cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||||
|
|
||||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
|
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
|
||||||
extern cJSON *cJSON_Parse(const char *value);
|
extern cJSON *cJSON_Parse(const char *value);
|
||||||
/* Render a cJSON Fighter to text for transfer/storage. Free the char* when finished. */
|
/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
|
||||||
extern char *cJSON_Print(cJSON *item);
|
extern char *cJSON_Print(cJSON *item);
|
||||||
/* Render a cJSON Fighter to text for transfer/storage without any formatting. Free the char* when finished. */
|
/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
|
||||||
extern char *cJSON_PrintUnformatted(cJSON *item);
|
extern char *cJSON_PrintUnformatted(cJSON *item);
|
||||||
/* Render a cJSON Fighter to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||||
extern char *cJSON_PrintBuffered(cJSON *item,int prebuffer,int fmt);
|
extern char *cJSON_PrintBuffered(cJSON *item,int prebuffer,int fmt);
|
||||||
/* Delete a cJSON Fighter and all subentities. */
|
/* Delete a cJSON entity and all subentities. */
|
||||||
extern void cJSON_Delete(cJSON *c);
|
extern void cJSON_Delete(cJSON *c);
|
||||||
|
|
||||||
/* Returns the number of items in an array (or object). */
|
/* Returns the number of items in an array (or object). */
|
||||||
|
|
|
@ -23,6 +23,7 @@ typedef struct Texture Texture;
|
||||||
typedef struct Lookup Lookup;
|
typedef struct Lookup Lookup;
|
||||||
typedef struct Weapon Weapon;
|
typedef struct Weapon Weapon;
|
||||||
typedef struct Fighter Fighter;
|
typedef struct Fighter Fighter;
|
||||||
|
typedef struct Entity Entity;
|
||||||
typedef struct Bullet Bullet;
|
typedef struct Bullet Bullet;
|
||||||
typedef struct Effect Effect;
|
typedef struct Effect Effect;
|
||||||
typedef struct Objective Objective;
|
typedef struct Objective Objective;
|
||||||
|
@ -68,6 +69,27 @@ struct Weapon {
|
||||||
int y;
|
int y;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Entity {
|
||||||
|
int type;
|
||||||
|
char name[MAX_NAME_LENGTH];
|
||||||
|
int side;
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float dx;
|
||||||
|
float dy;
|
||||||
|
int angle;
|
||||||
|
int health;
|
||||||
|
int maxHealth;
|
||||||
|
int shield;
|
||||||
|
int thinkTime;
|
||||||
|
long flags;
|
||||||
|
void (*action)(void);
|
||||||
|
void (*defaultAction)(void);
|
||||||
|
void (*die)(void);
|
||||||
|
SDL_Texture *texture;
|
||||||
|
Entity *next;
|
||||||
|
};
|
||||||
|
|
||||||
struct Fighter {
|
struct Fighter {
|
||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
int active;
|
int active;
|
||||||
|
@ -223,6 +245,7 @@ typedef struct {
|
||||||
SDL_Texture *background, *planetTexture;
|
SDL_Texture *background, *planetTexture;
|
||||||
PointF planet;
|
PointF planet;
|
||||||
Fighter fighterHead, *fighterTail;
|
Fighter fighterHead, *fighterTail;
|
||||||
|
Entity entityHead, *entityTail;
|
||||||
Bullet bulletHead, *bulletTail;
|
Bullet bulletHead, *bulletTail;
|
||||||
Effect effectHead, *effectTail;
|
Effect effectHead, *effectTail;
|
||||||
Objective objectiveHead, *objectiveTail;
|
Objective objectiveHead, *objectiveTail;
|
||||||
|
|
|
@ -30,6 +30,8 @@ void initLookups(void)
|
||||||
memset(&head, 0, sizeof(Lookup));
|
memset(&head, 0, sizeof(Lookup));
|
||||||
tail = &head;
|
tail = &head;
|
||||||
|
|
||||||
|
addLookup("ET_WAYPOINT", ET_WAYPOINT);
|
||||||
|
|
||||||
addLookup("FF_NO_KILL", FF_NO_KILL);
|
addLookup("FF_NO_KILL", FF_NO_KILL);
|
||||||
addLookup("FF_DISABLE", FF_DISABLE);
|
addLookup("FF_DISABLE", FF_DISABLE);
|
||||||
addLookup("FF_IMMORTAL", FF_IMMORTAL);
|
addLookup("FF_IMMORTAL", FF_IMMORTAL);
|
||||||
|
|
Loading…
Reference in New Issue