From 357fbdc8a425795a25ab2ca066301da12ed319d3 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 17 Feb 2018 16:53:18 +0000 Subject: [PATCH] Destroy stuff at end of mission. --- src/world/objectives.c | 14 ++++++++++++++ src/world/particles.c | 14 ++++++++++++++ src/world/triggers.c | 14 ++++++++++++++ src/world/world.c | 35 ++++++++++++++++++++++++++++++++--- src/world/world.h | 9 ++++++++- 5 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/world/objectives.c b/src/world/objectives.c index 4345ff1..f832b0b 100644 --- a/src/world/objectives.c +++ b/src/world/objectives.c @@ -182,3 +182,17 @@ static int isMissingHeartCell(char *targetName) return 1; } + +void destroyObjectives(void) +{ + Objective *o; + + while (world.objectiveHead.next) + { + o = world.objectiveHead.next; + + world.objectiveHead.next = o->next; + + free(o); + } +} diff --git a/src/world/particles.c b/src/world/particles.c index f2d2097..98d6416 100644 --- a/src/world/particles.c +++ b/src/world/particles.c @@ -295,3 +295,17 @@ static Particle *createParticle(void) return p; } + +void destroyParticles(void) +{ + Particle *p; + + while (world.particleHead.next) + { + p = world.particleHead.next; + + world.particleHead.next = p->next; + + free(p); + } +} diff --git a/src/world/triggers.c b/src/world/triggers.c index 97b4fee..6d4c9a5 100644 --- a/src/world/triggers.c +++ b/src/world/triggers.c @@ -84,3 +84,17 @@ void fireTriggers(char *name) prev = t; } } + +void destroyTriggers(void) +{ + Trigger *t; + + while (world.triggerHead.next) + { + t = world.triggerHead.next; + + world.triggerHead.next = t->next; + + free(t); + } +} diff --git a/src/world/world.c b/src/world/world.c index bce2bb7..3cdb55d 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -42,6 +42,7 @@ static void options(void); static void stats(void); static void trophies(void); static void quit(void); +static void destroyWorld(void); static Texture *background; static int observationIndex; @@ -49,7 +50,7 @@ static int showingWidgets; void initWorld(void) { - SDL_ShowCursor(SDL_DISABLE); + loadWorld(game.worldId); background = getTexture(world.background); @@ -69,6 +70,10 @@ void initWorld(void) initItems(); + initMap(); + + initEntities(); + world.enemySpawnTimer = (FPS * rrnd(world.minEnemySpawnTime, world.maxEnemySpawnTime)); world.state = WS_START; @@ -101,8 +106,6 @@ void initWorld(void) app.delegate.logic = logic; app.delegate.draw = draw; - - startMission(); } static void logic(void) @@ -398,6 +401,10 @@ static void doWorldComplete(void) addTeleportStars((Entity*)world.bob); playSound(SND_TELEPORT, CH_BOB); } + else if (world.missionCompleteTimer == 0) + { + destroyWorld(); + } else { doBob(); @@ -669,3 +676,25 @@ static void trophies(void) static void quit(void) { } + +static void destroyWorld(void) +{ + int i; + + for (i = 0 ; i < world.numEnemyTypes ; i++) + { + free(world.enemyTypes[i]); + } + + free(world.enemyTypes); + + destroyTriggers(); + + destroyObjectives(); + + destroyEntities(); + + destroyParticles(); + + destroyQuadtree(); +} diff --git a/src/world/world.h b/src/world/world.h index c9a14eb..15ed57f 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -76,9 +76,16 @@ extern void drawWidgets(void); extern void showWidgetGroup(char *group); extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a); extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a); -extern void hideAllWidgets(void); extern void doWidgets(void); extern Widget *getWidget(char *name, char *group); +extern void destroyTriggers(void); +extern void destroyObjectives(void); +extern void destroyEntities(void); +extern void destroyParticles(void); +extern void destroyQuadtree(void); +extern void loadWorld(char *id); +extern void initMap(void); +extern void initEntities(void); extern App app; extern Colors colors;