Add item pad.

This commit is contained in:
Steve 2018-02-15 07:48:51 +00:00
parent 3e23d83f3a
commit b3ed2b1762
4 changed files with 53 additions and 14 deletions

View File

@ -86,6 +86,7 @@ void initEntityFactory(void)
addEntityDef("HorizontalLaserTrap", initHorizontalLaserTrap);
addEntityDef("Exit", initExit);
addEntityDef("Destructable", initDestructable);
addEntityDef("ItemPad", initItemPad);
}
Entity *createEntity(char *name)

View File

@ -65,8 +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 Entity *initItemPad(void);
extern World world;

View File

@ -20,32 +20,45 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "itemPad.h"
static void init(void);
static void tick(void);
static void touch(Entity *other);
static void load(cJSON *root);
static void save(cJSON *root);
void initItemPad(Entity *e)
Entity *initItemPad(void)
{
initEntity(e);
Structure *s;
e->type = ET_ITEM_PAD;
s = createStructure();
e->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS;
s->type = ET_ITEM_PAD;
e->plane = PLANE_FOREGROUND;
s->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS;
e->isStatic = 1;
s->plane = PLANE_FOREGROUND;
if (!e->active)
s->isStatic = 1;
s->init = init;
s->tick = tick;
s->touch = touch;
s->load = load;
s->save = save;
return (Entity*)s;
}
static void init(void)
{
e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSprite("ItemPadActive");
if (self->active)
{
self->sprite[FACING_LEFT] = self->sprite[FACING_RIGHT] = self->sprite[FACING_DIE] = getSprite("ItemPadActive");
}
else
{
e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSprite("ItemPadInactive");
self->sprite[FACING_LEFT] = self->sprite[FACING_RIGHT] = self->sprite[FACING_DIE] = getSprite("ItemPadInactive");
}
e->tick = tick;
e->touch = touch;
}
static void tick(void)
@ -97,3 +110,27 @@ static void touch(Entity *other)
s->bobTouching = 2;
}
}
static void load(cJSON *root)
{
Structure *s;
s = (Structure*)self;
if (cJSON_GetObjectItem(root, "active"))
{
s->active = cJSON_GetObjectItem(root, "active")->valueint;
}
STRNCPY(s->requiredItem, cJSON_GetObjectItem(root, "requiredItem")->valuestring, MAX_NAME_LENGTH);
}
static void save(cJSON *root)
{
Structure *s;
s = (Structure*)self;
cJSON_AddStringToObject(root, "type", "ItemPad");
cJSON_AddNumberToObject(root, "active", s->active);
cJSON_AddStringToObject(root, "requiredItem", s->requiredItem);
}

View File

@ -19,8 +19,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../../common.h"
#include "../../json/cJSON.h"
extern void initEntity(Entity *e);
extern Structure *createStructure(void);
extern Sprite *getSprite(char *name);
extern void updateObjective(char *targetName);
extern void setGameplayMessage(int type, char *format, ...);