Start of waypoints.
This commit is contained in:
parent
d0a3d0d6c5
commit
73eb5517bf
|
@ -8,12 +8,12 @@
|
|||
"type" : "Nymph",
|
||||
"side" : "SIDE_CSN"
|
||||
},
|
||||
"triggers" : [
|
||||
"entities" : [
|
||||
{
|
||||
"type" : "TRIGGER_TIME",
|
||||
"targetName" : "TIME",
|
||||
"targetValue" : 10,
|
||||
"action" : "TA_COMPLETE_MISSION"
|
||||
"name" : "Waypoint",
|
||||
"type" : "ET_WAYPOINT",
|
||||
"x" : 100,
|
||||
"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 += challenges.o cJSON.o
|
||||
OBJS += draw.o
|
||||
OBJS += effects.o
|
||||
OBJS += effects.o entities.o
|
||||
OBJS += fighters.o fighterDefs.o
|
||||
OBJS += galacticMap.o game.o
|
||||
OBJS += hud.o
|
||||
|
@ -32,7 +32,7 @@ OBJS += radar.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 += util.o
|
||||
OBJS += widgets.o
|
||||
OBJS += waypoints.o widgets.o
|
||||
|
||||
# top-level rule to create the program.
|
||||
all: $(PROG)
|
||||
|
|
|
@ -41,6 +41,7 @@ void initBattle(void)
|
|||
{
|
||||
memset(&battle, 0, sizeof(Battle));
|
||||
battle.bulletTail = &battle.bulletHead;
|
||||
battle.entityTail = &battle.entityHead;
|
||||
battle.fighterTail = &battle.fighterHead;
|
||||
battle.effectTail = &battle.effectHead;
|
||||
battle.objectiveTail = &battle.objectiveHead;
|
||||
|
@ -119,6 +120,8 @@ static void doBattle(void)
|
|||
|
||||
doFighters();
|
||||
|
||||
doEntities();
|
||||
|
||||
doEffects();
|
||||
|
||||
doPlayer();
|
||||
|
@ -161,6 +164,8 @@ static void draw(void)
|
|||
|
||||
drawFighters();
|
||||
|
||||
drawEntities();
|
||||
|
||||
drawEffects();
|
||||
|
||||
drawHud();
|
||||
|
@ -316,6 +321,7 @@ static void postBattle(void)
|
|||
void destroyBattle(void)
|
||||
{
|
||||
Fighter *f;
|
||||
Entity *ent;
|
||||
Bullet *b;
|
||||
Effect *e;
|
||||
Objective *o;
|
||||
|
@ -329,6 +335,14 @@ void destroyBattle(void)
|
|||
}
|
||||
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)
|
||||
{
|
||||
b = battle.bulletHead.next;
|
||||
|
|
|
@ -35,6 +35,8 @@ extern void drawBullets(void);
|
|||
extern void doStars(float dx, float dy);
|
||||
extern void drawStars(void);
|
||||
extern void doFighters(void);
|
||||
extern void doEntities(void);
|
||||
extern void drawEntities(void);
|
||||
extern void drawFighters(void);
|
||||
extern void initStars(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 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_MISSION_TARGET (2 << 3)
|
||||
|
||||
enum
|
||||
{
|
||||
ET_WAYPOINT
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
TA_LEFT,
|
||||
|
|
|
@ -25,6 +25,7 @@ static void loadTriggers(cJSON *node);
|
|||
static void loadPlayer(cJSON *node);
|
||||
static void loadFighters(cJSON *node);
|
||||
static void loadFighterGroups(cJSON *node);
|
||||
static void loadEntities(cJSON *node);
|
||||
static unsigned long hashcode(const char *str);
|
||||
static char **toFighterTypeArray(char *types, int *numTypes);
|
||||
|
||||
|
@ -58,6 +59,8 @@ void loadMission(char *filename)
|
|||
|
||||
loadFighterGroups(cJSON_GetObjectItem(root, "fighterGroups"));
|
||||
|
||||
loadEntities(cJSON_GetObjectItem(root, "entities"));
|
||||
|
||||
STRNCPY(music, cJSON_GetObjectItem(root, "music")->valuestring, MAX_NAME_LENGTH);
|
||||
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
|
|
|
@ -35,6 +35,7 @@ extern void playMusic(char *filename);
|
|||
extern void stopMusic(void);
|
||||
extern void initPlayer(void);
|
||||
extern long flagsToLong(char *flags);
|
||||
extern Entity *spawnWaypoint(void);
|
||||
|
||||
extern Battle battle;
|
||||
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 */
|
||||
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_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. */
|
||||
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);
|
||||
/* 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);
|
||||
/* 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);
|
||||
/* Delete a cJSON Fighter and all subentities. */
|
||||
/* Delete a cJSON entity and all subentities. */
|
||||
extern void cJSON_Delete(cJSON *c);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
|
|
|
@ -23,6 +23,7 @@ typedef struct Texture Texture;
|
|||
typedef struct Lookup Lookup;
|
||||
typedef struct Weapon Weapon;
|
||||
typedef struct Fighter Fighter;
|
||||
typedef struct Entity Entity;
|
||||
typedef struct Bullet Bullet;
|
||||
typedef struct Effect Effect;
|
||||
typedef struct Objective Objective;
|
||||
|
@ -68,6 +69,27 @@ struct Weapon {
|
|||
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 {
|
||||
char name[MAX_NAME_LENGTH];
|
||||
int active;
|
||||
|
@ -223,6 +245,7 @@ typedef struct {
|
|||
SDL_Texture *background, *planetTexture;
|
||||
PointF planet;
|
||||
Fighter fighterHead, *fighterTail;
|
||||
Entity entityHead, *entityTail;
|
||||
Bullet bulletHead, *bulletTail;
|
||||
Effect effectHead, *effectTail;
|
||||
Objective objectiveHead, *objectiveTail;
|
||||
|
|
|
@ -30,6 +30,8 @@ void initLookups(void)
|
|||
memset(&head, 0, sizeof(Lookup));
|
||||
tail = &head;
|
||||
|
||||
addLookup("ET_WAYPOINT", ET_WAYPOINT);
|
||||
|
||||
addLookup("FF_NO_KILL", FF_NO_KILL);
|
||||
addLookup("FF_DISABLE", FF_DISABLE);
|
||||
addLookup("FF_IMMORTAL", FF_IMMORTAL);
|
||||
|
|
Loading…
Reference in New Issue