Added Exit, Destructable, and Cannon.
This commit is contained in:
parent
6c2d39e1d1
commit
4258575a26
|
@ -27,7 +27,7 @@ static void animate(void);
|
||||||
static int canFire(Entity *target);
|
static int canFire(Entity *target);
|
||||||
static void preFire(void);
|
static void preFire(void);
|
||||||
|
|
||||||
void initCannon(void)
|
Entity *initCannon(void)
|
||||||
{
|
{
|
||||||
Unit *u;
|
Unit *u;
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ void initCannon(void)
|
||||||
u->walk = walk;
|
u->walk = walk;
|
||||||
u->die = die;
|
u->die = die;
|
||||||
u->canFire = canFire;
|
u->canFire = canFire;
|
||||||
|
|
||||||
|
return (Entity*)u;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void applyDamage(int damage)
|
static void applyDamage(int damage)
|
||||||
|
|
|
@ -49,6 +49,7 @@ void initEntityFactory(void)
|
||||||
addEntityDef("SpreadGunEyeDroid", initSpreadGunDroid);
|
addEntityDef("SpreadGunEyeDroid", initSpreadGunDroid);
|
||||||
addEntityDef("PlasmaEyeDroid", initPlasmaDroid);
|
addEntityDef("PlasmaEyeDroid", initPlasmaDroid);
|
||||||
addEntityDef("PlasmaBlob", initPlasmaBlob);
|
addEntityDef("PlasmaBlob", initPlasmaBlob);
|
||||||
|
addEntityDef("Cannon", initCannon);
|
||||||
|
|
||||||
addEntityDef("Bob", initBob);
|
addEntityDef("Bob", initBob);
|
||||||
addEntityDef("MIA", initMIA);
|
addEntityDef("MIA", initMIA);
|
||||||
|
@ -83,6 +84,8 @@ void initEntityFactory(void)
|
||||||
addEntityDef("CardReader", initCardReader);
|
addEntityDef("CardReader", initCardReader);
|
||||||
addEntityDef("LaserTrap", initLaserTrap);
|
addEntityDef("LaserTrap", initLaserTrap);
|
||||||
addEntityDef("HorizontalLaserTrap", initHorizontalLaserTrap);
|
addEntityDef("HorizontalLaserTrap", initHorizontalLaserTrap);
|
||||||
|
addEntityDef("Exit", initExit);
|
||||||
|
addEntityDef("Destructable", initDestructable);
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity *createEntity(char *name)
|
Entity *createEntity(char *name)
|
||||||
|
|
|
@ -65,5 +65,8 @@ extern Entity *initSpreadGunDroid(void);
|
||||||
extern Entity *initPlasmaDroid(void);
|
extern Entity *initPlasmaDroid(void);
|
||||||
extern Entity *initPlasmaBlob(void);
|
extern Entity *initPlasmaBlob(void);
|
||||||
extern Entity *initTeeka(void);
|
extern Entity *initTeeka(void);
|
||||||
|
extern Entity *initExit(void);
|
||||||
|
extern Entity *initDestructable(void);
|
||||||
|
extern Entity *initCannon(void);
|
||||||
|
|
||||||
extern World world;
|
extern World world;
|
||||||
|
|
|
@ -22,14 +22,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
static void applyDamage(int amount);
|
static void applyDamage(int amount);
|
||||||
static void action(void);
|
static void action(void);
|
||||||
|
static void load(cJSON *root);
|
||||||
|
static void save(cJSON *root);
|
||||||
|
|
||||||
void initDestructable(Entity *e)
|
Entity *initDestructable(void)
|
||||||
{
|
{
|
||||||
Structure *s;
|
Structure *s;
|
||||||
|
|
||||||
initEntity(e);
|
s = createStructure();
|
||||||
|
|
||||||
s = (Structure*)e;
|
|
||||||
|
|
||||||
s->type = ET_DESTRUCTABLE;
|
s->type = ET_DESTRUCTABLE;
|
||||||
|
|
||||||
|
@ -45,6 +45,10 @@ void initDestructable(Entity *e)
|
||||||
|
|
||||||
s->applyDamage = applyDamage;
|
s->applyDamage = applyDamage;
|
||||||
s->action = action;
|
s->action = action;
|
||||||
|
s->load = load;
|
||||||
|
s->save = save;
|
||||||
|
|
||||||
|
return (Entity*)s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void applyDamage(int amount)
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../common.h"
|
#include "../../common.h"
|
||||||
|
#include "../../json/cJSON.h"
|
||||||
|
|
||||||
extern void activateEntities(char *names, int activate);
|
extern void activateEntities(char *names, int activate);
|
||||||
extern void dropCarriedItem(void);
|
extern void dropCarriedItem(void);
|
||||||
|
@ -28,5 +29,6 @@ extern void addScorchDecal(int x, int y);
|
||||||
extern Sprite *getSprite(char *name);
|
extern Sprite *getSprite(char *name);
|
||||||
extern void updateObjective(char *targetName);
|
extern void updateObjective(char *targetName);
|
||||||
extern void initEntity(Entity *e);
|
extern void initEntity(Entity *e);
|
||||||
|
extern Structure *createStructure(void);
|
||||||
|
|
||||||
extern Entity *self;
|
extern Entity *self;
|
||||||
|
|
|
@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
static void tick(void);
|
static void tick(void);
|
||||||
static void action(void);
|
static void action(void);
|
||||||
static void touch(Entity *other);
|
static void touch(Entity *other);
|
||||||
|
static void load(cJSON *root);
|
||||||
|
static void save(cJSON *root);
|
||||||
|
|
||||||
Entity *initExit(void)
|
Entity *initExit(void)
|
||||||
{
|
{
|
||||||
|
@ -54,6 +56,8 @@ Entity *initExit(void)
|
||||||
s->tick = tick;
|
s->tick = tick;
|
||||||
s->action = action;
|
s->action = action;
|
||||||
s->touch = touch;
|
s->touch = touch;
|
||||||
|
s->load = load;
|
||||||
|
s->save = save;
|
||||||
|
|
||||||
return (Entity*)s;
|
return (Entity*)s;
|
||||||
}
|
}
|
||||||
|
@ -125,3 +129,21 @@ static void touch(Entity *other)
|
||||||
s->bobTouching = 2;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../common.h"
|
#include "../../common.h"
|
||||||
|
#include "../../json/cJSON.h"
|
||||||
|
|
||||||
extern Sprite *getSprite(char *name);
|
extern Sprite *getSprite(char *name);
|
||||||
extern void updateObjective(char *targetName);
|
extern void updateObjective(char *targetName);
|
||||||
|
|
|
@ -397,14 +397,14 @@ static void moveEntity(void)
|
||||||
haltAtEdge();
|
haltAtEdge();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deal with x movement
|
/* Deal with x movement */
|
||||||
position.x = self->x;
|
position.x = self->x;
|
||||||
position.y = self->y;
|
position.y = self->y;
|
||||||
position.x += self->dx;
|
position.x += self->dx;
|
||||||
moveToOthers(self->dx, 0, &position);
|
moveToOthers(self->dx, 0, &position);
|
||||||
moveToMap(self->dx, 0, &position);
|
moveToMap(self->dx, 0, &position);
|
||||||
|
|
||||||
// Deal with Y movement
|
/* Deal with Y movement */
|
||||||
position.y += self->dy;
|
position.y += self->dy;
|
||||||
moveToOthers(0, self->dy, &position);
|
moveToOthers(0, self->dy, &position);
|
||||||
moveToMap(0, self->dy, &position);
|
moveToMap(0, self->dy, &position);
|
||||||
|
|
Loading…
Reference in New Issue