From b27b3dd2f80e77a8b6f84d2d8867af153a20701a Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 7 Feb 2018 07:51:25 +0000 Subject: [PATCH] Draw inventory items on HUD. --- src/world/hud.c | 31 +++++++++++++++++++++++++++---- src/world/hud.h | 5 +++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/world/hud.c b/src/world/hud.c index 7a90bd3..9162223 100644 --- a/src/world/hud.c +++ b/src/world/hud.c @@ -31,6 +31,7 @@ static char message[MAX_DESCRIPTION_LENGTH]; static int messageType; static SDL_Color messageColor; static char infoMessage[MAX_DESCRIPTION_LENGTH]; +static Texture *atlasTexture; void initHud(void) { @@ -38,6 +39,8 @@ void initHud(void) messageType = MSG_STANDARD; strcpy(message, ""); messageColor = colors.white; + + atlasTexture = getTexture("gfx/atlas/atlas.png"); } void doHud(void) @@ -153,11 +156,14 @@ static void drawOxygen(void) static void drawInventory(void) { - int x, y, i, size; + int x, y, i, size, mid; + float w, h, d; + SDL_Rect r; size = 45; + mid = size / 2; - x = SCREEN_WIDTH - (size + 5); + x = 930; y = 5; for (i = 0 ; i < MAX_ITEMS ; i++) @@ -165,14 +171,31 @@ static void drawInventory(void) if (i > 0 && i % (MAX_ITEMS / 2) == 0) { y += (size + 5); - x = SCREEN_WIDTH - (size + 5); + x = 930; } drawRect(x, y, size, size, 0, 0, 0, 128); drawOutlineRect(x, y, size, size, 255, 255, 255, 255); - x -= (size + 5); + if (world.bob->items[i] != NULL) + { + r = getCurrentFrame(world.bob->items[i]->sprite[0]); + w = r.w; + h = r.h; + + d = 40; + d /= (w > h) ? w : h; + + w *= d; + h *= d; + + blitRectScaled(atlasTexture->texture, x + mid, y + mid, w, h, &r, 1); + + drawText(x + size - 5, y, 14, TA_RIGHT, colors.white, "%d", world.bob->items[i]->value); + } + + x += (size + 5); } } diff --git a/src/world/hud.h b/src/world/hud.h index ee5d7ce..b377135 100644 --- a/src/world/hud.h +++ b/src/world/hud.h @@ -26,8 +26,13 @@ const char *getWeaponName(int i); extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a); 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 Sprite *getSprite(char *name); +extern Texture *getTexture(const char *filename); +extern SDL_Rect getCurrentFrame(Sprite *s); extern Dev dev; extern Camera camera; extern Colors colors; +extern Game game; extern World world;