Added Exit, Destructable, and Cannon.

This commit is contained in:
Steve 2018-02-14 22:31:21 +00:00
parent 6c2d39e1d1
commit 4258575a26
8 changed files with 72 additions and 7 deletions

View File

@ -27,7 +27,7 @@ static void animate(void);
static int canFire(Entity *target);
static void preFire(void);
void initCannon(void)
Entity *initCannon(void)
{
Unit *u;
@ -56,6 +56,8 @@ void initCannon(void)
u->walk = walk;
u->die = die;
u->canFire = canFire;
return (Entity*)u;
}
static void applyDamage(int damage)

View File

@ -49,6 +49,7 @@ void initEntityFactory(void)
addEntityDef("SpreadGunEyeDroid", initSpreadGunDroid);
addEntityDef("PlasmaEyeDroid", initPlasmaDroid);
addEntityDef("PlasmaBlob", initPlasmaBlob);
addEntityDef("Cannon", initCannon);
addEntityDef("Bob", initBob);
addEntityDef("MIA", initMIA);
@ -83,6 +84,8 @@ void initEntityFactory(void)
addEntityDef("CardReader", initCardReader);
addEntityDef("LaserTrap", initLaserTrap);
addEntityDef("HorizontalLaserTrap", initHorizontalLaserTrap);
addEntityDef("Exit", initExit);
addEntityDef("Destructable", initDestructable);
}
Entity *createEntity(char *name)

View File

@ -65,5 +65,8 @@ extern Entity *initSpreadGunDroid(void);
extern Entity *initPlasmaDroid(void);
extern Entity *initPlasmaBlob(void);
extern Entity *initTeeka(void);
extern Entity *initExit(void);
extern Entity *initDestructable(void);
extern Entity *initCannon(void);
extern World world;

View File

@ -22,14 +22,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void applyDamage(int amount);
static void action(void);
static void load(cJSON *root);
static void save(cJSON *root);
void initDestructable(Entity *e)
Entity *initDestructable(void)
{
Structure *s;
initEntity(e);
s = (Structure*)e;
s = createStructure();
s->type = ET_DESTRUCTABLE;
@ -45,6 +45,10 @@ void initDestructable(Entity *e)
s->applyDamage = applyDamage;
s->action = action;
s->load = load;
s->save = save;
return (Entity*)s;
}
static void applyDamage(int amount)
@ -92,3 +96,31 @@ static void action(void)
}
}
}
static void load(cJSON *root)
{
Structure *s;
s = (Structure*)self;
s->health = cJSON_GetObjectItem(root, "health")->valueint;
s->healthMax = cJSON_GetObjectItem(root, "healthMax")->valueint;
STRNCPY(s->spriteName, cJSON_GetObjectItem(root, "spriteName")->valuestring, MAX_NAME_LENGTH);
if (cJSON_GetObjectItem(root, "targetNames"))
{
STRNCPY(s->targetNames, cJSON_GetObjectItem(root, "targetNames")->valuestring, MAX_DESCRIPTION_LENGTH);
}
}
static void save(cJSON *root)
{
Structure *s;
s = (Structure*)self;
cJSON_AddNumberToObject(root, "health", s->health);
cJSON_AddNumberToObject(root, "healthMax", s->healthMax);
cJSON_AddStringToObject(root, "spriteName", s->spriteName);
cJSON_AddStringToObject(root, "targetNames", s->targetNames);
}

View File

@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../../common.h"
#include "../../json/cJSON.h"
extern void activateEntities(char *names, int activate);
extern void dropCarriedItem(void);
@ -28,5 +29,6 @@ extern void addScorchDecal(int x, int y);
extern Sprite *getSprite(char *name);
extern void updateObjective(char *targetName);
extern void initEntity(Entity *e);
extern Structure *createStructure(void);
extern Entity *self;

View File

@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void tick(void);
static void action(void);
static void touch(Entity *other);
static void load(cJSON *root);
static void save(cJSON *root);
Entity *initExit(void)
{
@ -54,6 +56,8 @@ Entity *initExit(void)
s->tick = tick;
s->action = action;
s->touch = touch;
s->load = load;
s->save = save;
return (Entity*)s;
}
@ -125,3 +129,21 @@ static void touch(Entity *other)
s->bobTouching = 2;
}
}
static void load(cJSON *root)
{
Structure *s;
s = (Structure*)self;
s->active = cJSON_GetObjectItem(root, "active")->valueint;
}
static void save(cJSON *root)
{
Structure *s;
s = (Structure*)self;
cJSON_AddNumberToObject(root, "active", s->active);
}

View File

@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../../common.h"
#include "../../json/cJSON.h"
extern Sprite *getSprite(char *name);
extern void updateObjective(char *targetName);

View File

@ -397,14 +397,14 @@ static void moveEntity(void)
haltAtEdge();
}
// Deal with x movement
/* Deal with x movement */
position.x = self->x;
position.y = self->y;
position.x += self->dx;
moveToOthers(self->dx, 0, &position);
moveToMap(self->dx, 0, &position);
// Deal with Y movement
/* Deal with Y movement */
position.y += self->dy;
moveToOthers(0, self->dy, &position);
moveToMap(0, self->dy, &position);