From 302997cb31c889918ea6a4ba3b5d3ace35a097de Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 30 Mar 2018 19:23:57 +0100 Subject: [PATCH] Code clean up. --- src/entities/boss/boss.c | 4 --- src/entities/structures/horizontalDoor.c | 33 ----------------------- src/game/ending.h | 2 +- src/system/init.c | 1 + src/system/init.h | 1 + src/system/lookup.c | 25 ----------------- src/system/lookup.h | 2 -- src/system/sound.c | 15 ----------- src/util/util.c | 34 ------------------------ src/world/entities.c | 19 ++----------- 10 files changed, 5 insertions(+), 131 deletions(-) diff --git a/src/entities/boss/boss.c b/src/entities/boss/boss.c index 3f5f9fb..fa60d22 100644 --- a/src/entities/boss/boss.c +++ b/src/entities/boss/boss.c @@ -53,10 +53,6 @@ Boss *initBoss(void) return b; } -void bossIdle(void) -{ -} - static void init(void) { } diff --git a/src/entities/structures/horizontalDoor.c b/src/entities/structures/horizontalDoor.c index d297b77..31afcb7 100644 --- a/src/entities/structures/horizontalDoor.c +++ b/src/entities/structures/horizontalDoor.c @@ -32,36 +32,3 @@ Entity *initHorizontalDoor(void) return (Entity*)s; } - -Entity *initBronzeHorizontalDoor(void) -{ - Structure *s; - - s = (Structure*)initHorizontalDoor(); - - STRNCPY(s->requiredItem, "Bronze Key", MAX_NAME_LENGTH); - - return (Entity*)s; -} - -Entity *initSilverHorizontalDoor(void) -{ - Structure *s; - - s = (Structure*)initHorizontalDoor(); - - STRNCPY(s->requiredItem, "Silver Key", MAX_NAME_LENGTH); - - return (Entity*)s; -} - -Entity *initGoldHorizontalDoor(void) -{ - Structure *s; - - s = (Structure*)initHorizontalDoor(); - - STRNCPY(s->requiredItem, "Gold Key", MAX_NAME_LENGTH); - - return (Entity*)s; -} diff --git a/src/game/ending.h b/src/game/ending.h index c43b5e7..ab2c7a7 100644 --- a/src/game/ending.h +++ b/src/game/ending.h @@ -26,6 +26,7 @@ extern void blitRectScaled(SDL_Texture *texture, int x, int y, int w, int h, SDL extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); extern void endSectionTransition(void); +extern void fadeMusic(int ms); extern Atlas *getImageFromAtlas(char *filename); extern Texture *getTexture(const char *filename); extern int getWrappedTextHeight(const char *text, int size); @@ -33,7 +34,6 @@ extern void initCredits(int playMusic); extern void limitTextWidth(int width); extern char *readFile(const char *filename); extern void startSectionTransition(void); -extern void fadeMusic(int ms); extern App app; extern Colors colors; diff --git a/src/system/init.c b/src/system/init.c index 18d38bd..189bdba 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -131,6 +131,7 @@ void initGameSystem(void) int i, numInitFuns; void (*initFuncs[]) (void) = { initGraphics, + initTextures, initBackground, initFonts, initAtlas, diff --git a/src/system/init.h b/src/system/init.h index a55dfc4..176cae7 100644 --- a/src/system/init.h +++ b/src/system/init.h @@ -44,6 +44,7 @@ extern void initGraphics(void); extern void initSounds(void); extern void initSprites(void); extern void initStats(void); +extern void initTextures(void); extern void initTrophies(void); extern void initWidgets(void); extern long lookup(const char *name); diff --git a/src/system/lookup.c b/src/system/lookup.c index 030ffda..c448287 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -166,31 +166,6 @@ const char *getFlagValues(const char *prefix, long flags) return flagStr; } -long flagsToLong(const char *in) -{ - char *flag, *flags; - long total; - - total = 0; - - if (strlen(in) > 0) - { - flags = malloc(strlen(in) + 1); - STRNCPY(flags, in, strlen(in) + 1); - - flag = strtok(flags, "+"); - while (flag) - { - total += lookup(flag); - flag = strtok(NULL, "+"); - } - - free(flags); - } - - return total; -} - void destroyLookups(void) { Lookup *l; diff --git a/src/system/lookup.h b/src/system/lookup.h index 716f681..8ad0dc9 100644 --- a/src/system/lookup.h +++ b/src/system/lookup.h @@ -19,5 +19,3 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "../common.h" - -long flagsToLong(const char *in); diff --git a/src/system/sound.c b/src/system/sound.c index 072c280..004ba7d 100644 --- a/src/system/sound.c +++ b/src/system/sound.c @@ -61,21 +61,6 @@ void fadeMusic(int ms) Mix_FadeOutMusic(ms); } -void musicSetPlaying(int playing) -{ - if (music != NULL) - { - if (playing) - { - Mix_ResumeMusic(); - } - else - { - Mix_PauseMusic(); - } - } -} - void playSound(int snd, int ch) { Mix_PlayChannel(ch, sounds[snd], 0); diff --git a/src/util/util.c b/src/util/util.c index 3e25e1d..b638180 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -27,40 +27,6 @@ int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) return (MAX(x1, x2) < MIN(x1 + w1, x2 + w2)) && (MAX(y1, y2) < MIN(y1 + h1, y2 + h2)); } -int lineLineIntersection(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) -{ - int d, n1, n2, ua, ub; - - d = ((y4 - y3) * (x2 - x1)) - ((x4 - x3) * (y2 - y1)); - n1 = ((x4 - x3) * (y1 - y3)) - ((y4 - y3) * (x1 - x3)); - n2 = ((x2 - x1) * (y1 - y3)) - ((y2 - y1) * (x1 - x3)); - - if (d == 0) - { - if ( n1 == 0 && n2 == 0) - { - return 0; - } - - return 0; - } - - ua = n1 / d; - ub = n2 / d; - - return (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1); -} - -int lineRectIntersection(int x1, int y1, int x2, int y2, SDL_Rect *r) -{ - return ( - lineLineIntersection(x1, y1, x2, y2, r->x, r->y, r->x + r->w, r->y) || /* top */ - lineLineIntersection(x1, y1, x2, y2, r->x, r->y + r->h, r->x + r->w, r->y + r->h) || /* bottom */ - lineLineIntersection(x1, y1, x2, y2, r->x, r->y, r->x, r->y + r->h) || /* left */ - lineLineIntersection(x1, y1, x2, y2, r->x + r->w, r->y, r->x + r->w, r->y + r->h) /* right */ - ); -} - char *timeToString(int seconds, int showHours) { int hours, minutes; diff --git a/src/world/entities.c b/src/world/entities.c index 1e70874..f7fc4a0 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -570,14 +570,14 @@ static int canWalkOnEntity(float x, float y) srcRect.x = x; srcRect.y = y; - srcRect.w = 8; + srcRect.w = self->w; srcRect.h = MAP_TILE_SIZE * 4; candidates = getAllEntsWithin(srcRect.x, srcRect.y, srcRect.w, srcRect.h, NULL); for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { - if (self != e && e->isSolid && collision(x, y, 1, MAP_TILE_SIZE * 2, e->x, e->y, e->w, e->y)) + if (self != e && e->isSolid && collision(x, y, self->w, 8, e->x, e->y, e->w, e->y)) { return 1; } @@ -1047,21 +1047,6 @@ void teleport(Entity *e, float tx, float ty) } } -Entity *findEntity(char *name) -{ - Entity *e; - - for (e = world.entityHead.next ; e != NULL ; e = e->next) - { - if (strcmp(e->name, name) == 0) - { - return e; - } - } - - return NULL; -} - Entity *getRandomObjectiveEntity(void) { Entity *rtn, *e;