From 17ee7642e9bd205f2092ff190cfe2f4ac5f2ce48 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 17 Feb 2018 16:53:30 +0000 Subject: [PATCH] Return pointer to sprite rect. --- src/system/sprites.c | 4 ++-- src/test/atlasTest.c | 17 ++++------------- src/world/entities.c | 14 ++++++++++++++ src/world/hud.c | 16 ++++++++-------- src/world/hud.h | 2 +- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/system/sprites.c b/src/system/sprites.c index 4e80bfa..7cf4b93 100644 --- a/src/system/sprites.c +++ b/src/system/sprites.c @@ -78,9 +78,9 @@ static void animateSprite(Sprite *s) } } -SDL_Rect getCurrentFrame(Sprite *s) +SDL_Rect *getCurrentFrame(Sprite *s) { - return s->frames[s->currentFrame]->rect; + return &s->frames[s->currentFrame]->rect; } static void loadGameSprites(void) diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index a9e20ab..c10ec7b 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -28,23 +28,14 @@ void initAtlasTest(void) dev.cheatKeys = 0; dev.cheatPower = 1; dev.cheatHealth = 1; - dev.cheatLevels = 1; + dev.cheatLevels = 0; loadGame(); - + /* - loadWorld("beachApproach"); - + STRNCPY(game.worldId, "", MAX_NAME_LENGTH); initWorld(); - - initMap(); - - initEntities(); - - saveConfig(); - - saveGame(); */ - + initHub(); } diff --git a/src/world/entities.c b/src/world/entities.c index ba80eb9..3f7d8e7 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -1079,3 +1079,17 @@ static int drawComparator(const void *a, const void *b) return e2->type - e1->type; } + +void destroyEntities(void) +{ + Entity *e; + + while (world.entityHead.next) + { + e = world.entityHead.next; + + world.entityHead.next = e->next; + + free(e); + } +} diff --git a/src/world/hud.c b/src/world/hud.c index a37df74..53a3307 100644 --- a/src/world/hud.c +++ b/src/world/hud.c @@ -165,7 +165,7 @@ static void drawInventory(void) { int x, y, i, size, mid; float w, h, d; - SDL_Rect r; + SDL_Rect *r; size = 45; mid = size / 2; @@ -188,8 +188,8 @@ static void drawInventory(void) if (world.bob->items[i] != NULL) { r = getCurrentFrame(world.bob->items[i]->sprite[0]); - w = r.w; - h = r.h; + w = r->w; + h = r->h; d = 40; d /= (w > h) ? w : h; @@ -197,7 +197,7 @@ static void drawInventory(void) w *= d; h *= d; - blitRectScaled(atlasTexture->texture, x + mid, y + mid, w, h, &r, 1); + blitRectScaled(atlasTexture->texture, x + mid, y + mid, w, h, r, 1); } x += (size + 5); @@ -210,7 +210,7 @@ void drawMissionStatus(void) int y, x, w, h, size, mid, i; float rw, rh, d; SDL_Color c; - SDL_Rect r; + SDL_Rect *r; char *status; drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 64); @@ -266,8 +266,8 @@ void drawMissionStatus(void) if (world.bob->items[i] != NULL) { r = getCurrentFrame(world.bob->items[i]->sprite[0]); - rw = r.w; - rh = r.h; + rw = r->w; + rh = r->h; d = 40; d /= (rw > rh) ? rw : rh; @@ -275,7 +275,7 @@ void drawMissionStatus(void) rw *= d; rh *= d; - blitRectScaled(atlasTexture->texture, x + mid, y + mid, rw, rh, &r, 1); + blitRectScaled(atlasTexture->texture, x + mid, y + mid, rw, rh, r, 1); drawText(x + size - 5, y, 14, TA_RIGHT, colors.white, "%d", world.bob->items[i]->value); } diff --git a/src/world/hud.h b/src/world/hud.h index f50fc2c..75b6bca 100644 --- a/src/world/hud.h +++ b/src/world/hud.h @@ -28,7 +28,7 @@ extern void limitTextWidth(int width); extern int getWrappedTextHeight(const char *text, int size); extern void blitRectScaled(SDL_Texture *texture, int x, int y, int w, int h, SDL_Rect *srcRect, int center); extern Texture *getTexture(const char *filename); -extern SDL_Rect getCurrentFrame(Sprite *s); +extern SDL_Rect *getCurrentFrame(Sprite *s); extern int getPercent(float current, float total); extern App app;