diff --git a/src/entities/entityFactory.c b/src/entities/entityFactory.c index e18f4ab..00d4299 100644 --- a/src/entities/entityFactory.c +++ b/src/entities/entityFactory.c @@ -49,6 +49,9 @@ void initEntityFactory(void) addEntityDef("SilverKey", initSilverKey); addEntityDef("GoldKey", initGoldKey); addEntityDef("GreenKeycard", initGreenKeycard); + addEntityDef("BlueKeycard", initBlueKeycard); + addEntityDef("RedKeycard", initRedKeycard); + addEntityDef("YellowKeycard", initYellowKeycard); addEntityDef("Cell", initCell); addEntityDef("Heart", initHeart); @@ -66,6 +69,7 @@ void initEntityFactory(void) addEntityDef("SilverDoor", initSilverDoor); addEntityDef("GoldDoor", initGoldDoor); addEntityDef("HorizontalDoor", initHorizontalDoor); + addEntityDef("CardReader", initCardReader); } Entity *createEntity(char *name) @@ -76,6 +80,7 @@ Entity *createEntity(char *name) { if (strcmp(def->name, name) == 0) { + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Creating '%s'", name); return def->initFunc(); } } diff --git a/src/entities/entityFactory.h b/src/entities/entityFactory.h index bc32f27..962f68a 100644 --- a/src/entities/entityFactory.h +++ b/src/entities/entityFactory.h @@ -48,5 +48,9 @@ extern Entity *initGoldKey(void); extern Entity *initCell(void); extern Entity *initHeart(void); extern Entity *initGreenKeycard(void); +extern Entity *initCardReader(void); +extern Entity *initBlueKeycard(void); +extern Entity *initRedKeycard(void); +extern Entity *initYellowKeycard(void); extern World world; diff --git a/src/entities/structures/cardReader.c b/src/entities/structures/cardReader.c index 12dea36..9d3d546 100644 --- a/src/entities/structures/cardReader.c +++ b/src/entities/structures/cardReader.c @@ -20,18 +20,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "cardReader.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 initCardReader(Entity *e) +Entity *initCardReader(void) { Structure *s; - initEntity(e); - - s = (Structure*)e; + s = createStructure(); s->type = ET_CARD_READER; @@ -41,6 +40,21 @@ void initCardReader(Entity *e) s->isStatic = 1; + s->tick = tick; + s->init = init; + s->touch = touch; + s->load = load; + s->save = save; + + return (Entity*)s; +} + +static void init(void) +{ + Structure *s; + + s = (Structure*)self; + if (!s->active) { s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite("CardReaderIdle"); @@ -49,11 +63,6 @@ void initCardReader(Entity *e) { s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite("CardReader"); } - - s->tick = tick; - s->touch = touch; - s->load = load; - s->save = save; } static void tick(void) diff --git a/src/entities/structures/cardReader.h b/src/entities/structures/cardReader.h index 0d25c2a..927a87e 100644 --- a/src/entities/structures/cardReader.h +++ b/src/entities/structures/cardReader.h @@ -28,6 +28,7 @@ extern int hasItem(char *name); extern void setGameplayMessage(int type, char *format, ...); extern void activateEntities(char *names, int activate); extern void playSound(int snd, int ch); +extern Structure *createStructure(void); extern Dev dev; extern Entity *self;