From aa02babf98ec4c3808f0d814039ff8a1a498c144 Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 15 Feb 2018 07:49:20 +0000 Subject: [PATCH] Init functions. --- src/entities/misc/destructable.c | 13 +++++++++++-- src/entities/misc/destructable.h | 1 - src/entities/structures/exit.c | 25 ++++++++++++++++--------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/entities/misc/destructable.c b/src/entities/misc/destructable.c index 3000c8b..c5f2efa 100644 --- a/src/entities/misc/destructable.c +++ b/src/entities/misc/destructable.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "destructable.h" +static void init(void); static void applyDamage(int amount); static void action(void); static void load(cJSON *root); @@ -41,8 +42,7 @@ Entity *initDestructable(void) s->health = s->healthMax = 10; - s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite(s->spriteName); - + s->init = init; s->applyDamage = applyDamage; s->action = action; s->load = load; @@ -51,6 +51,15 @@ Entity *initDestructable(void) return (Entity*)s; } +static void init(void) +{ + Structure *s; + + s = (Structure*)self; + + s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite(s->spriteName); +} + static void applyDamage(int amount) { if (self->health > 0) diff --git a/src/entities/misc/destructable.h b/src/entities/misc/destructable.h index 05c31d5..8a678f9 100644 --- a/src/entities/misc/destructable.h +++ b/src/entities/misc/destructable.h @@ -28,7 +28,6 @@ extern void addExplosion(float x, float y, int radius, Entity *owner); 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; diff --git a/src/entities/structures/exit.c b/src/entities/structures/exit.c index 536a9fb..0795491 100644 --- a/src/entities/structures/exit.c +++ b/src/entities/structures/exit.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "exit.h" +static void init(void); static void tick(void); static void action(void); static void touch(Entity *other); @@ -41,18 +42,10 @@ Entity *initExit(void) s->isStatic = 1; s->active = 0; - - if (!s->active) - { - s->spriteFrame = 0; - } - else - { - s->spriteFrame = 1; - } s->spriteTime = -1; + s->init = init; s->tick = tick; s->action = action; s->touch = touch; @@ -62,6 +55,20 @@ Entity *initExit(void) return (Entity*)s; } +static void init(void) +{ + if (!self->active) + { + self->spriteFrame = 0; + } + else + { + self->spriteFrame = 1; + } + + self->spriteTime = -1; +} + static void tick(void) { Structure *s;