Destroy stuff at end of mission.

This commit is contained in:
Steve 2018-02-17 16:53:18 +00:00
parent 94db89cc08
commit 357fbdc8a4
5 changed files with 82 additions and 4 deletions

View File

@ -182,3 +182,17 @@ static int isMissingHeartCell(char *targetName)
return 1; return 1;
} }
void destroyObjectives(void)
{
Objective *o;
while (world.objectiveHead.next)
{
o = world.objectiveHead.next;
world.objectiveHead.next = o->next;
free(o);
}
}

View File

@ -295,3 +295,17 @@ static Particle *createParticle(void)
return p; return p;
} }
void destroyParticles(void)
{
Particle *p;
while (world.particleHead.next)
{
p = world.particleHead.next;
world.particleHead.next = p->next;
free(p);
}
}

View File

@ -84,3 +84,17 @@ void fireTriggers(char *name)
prev = t; prev = t;
} }
} }
void destroyTriggers(void)
{
Trigger *t;
while (world.triggerHead.next)
{
t = world.triggerHead.next;
world.triggerHead.next = t->next;
free(t);
}
}

View File

@ -42,6 +42,7 @@ static void options(void);
static void stats(void); static void stats(void);
static void trophies(void); static void trophies(void);
static void quit(void); static void quit(void);
static void destroyWorld(void);
static Texture *background; static Texture *background;
static int observationIndex; static int observationIndex;
@ -49,7 +50,7 @@ static int showingWidgets;
void initWorld(void) void initWorld(void)
{ {
SDL_ShowCursor(SDL_DISABLE); loadWorld(game.worldId);
background = getTexture(world.background); background = getTexture(world.background);
@ -69,6 +70,10 @@ void initWorld(void)
initItems(); initItems();
initMap();
initEntities();
world.enemySpawnTimer = (FPS * rrnd(world.minEnemySpawnTime, world.maxEnemySpawnTime)); world.enemySpawnTimer = (FPS * rrnd(world.minEnemySpawnTime, world.maxEnemySpawnTime));
world.state = WS_START; world.state = WS_START;
@ -101,8 +106,6 @@ void initWorld(void)
app.delegate.logic = logic; app.delegate.logic = logic;
app.delegate.draw = draw; app.delegate.draw = draw;
startMission();
} }
static void logic(void) static void logic(void)
@ -398,6 +401,10 @@ static void doWorldComplete(void)
addTeleportStars((Entity*)world.bob); addTeleportStars((Entity*)world.bob);
playSound(SND_TELEPORT, CH_BOB); playSound(SND_TELEPORT, CH_BOB);
} }
else if (world.missionCompleteTimer == 0)
{
destroyWorld();
}
else else
{ {
doBob(); doBob();
@ -669,3 +676,25 @@ static void trophies(void)
static void quit(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();
}

View File

@ -76,9 +76,16 @@ extern void drawWidgets(void);
extern void showWidgetGroup(char *group); 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 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 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 void doWidgets(void);
extern Widget *getWidget(char *name, char *group); 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 App app;
extern Colors colors; extern Colors colors;