From 6c135c6b9caf34189122205426cf8193041945b1 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Tue, 14 May 2019 22:27:13 +0200 Subject: [PATCH] Adds gui display for held keys Also makes the gold key actually golden --- assets/Extras/Keys.png | Bin 0 -> 321 bytes src/gui.c | 70 ++++++++++++++++++++++++++++++----------- src/gui.h | 3 ++ src/item_builder.c | 12 ++++--- 4 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 assets/Extras/Keys.png diff --git a/assets/Extras/Keys.png b/assets/Extras/Keys.png new file mode 100644 index 0000000000000000000000000000000000000000..3b11ce42dd2f659c578a7be8b1513722c5f7e583 GIT binary patch literal 321 zcmV-H0lxl;P)Px#`$Kld%fIFcd`}&T*?-+=>Va776`>4jnQ$I(F%np@NGj{)AI;@LxJQ zI2Nb)1r}T#u7gB^AeeM;@j?g*ymt>TH$;EENv0AqmGG@kLV+X{e)TeyP}LE-sl6bQ zP~cjXI3IEZjJwqv^MG+gLP0k*BB8!+V$AQi__e-)=-7wFm=Pb&sNcId!6%`>Zat;$ zWdFKbZAVT$i0C;5-PF)cjrr!}G=YF|EQ<{HTa0CqK^Ft}XCNYqghC{gR~8I}4dWfi zHV|gl#o#v(HcY@c&WHSW5C-I0mF^HG4>p8LFyA4(Ct(15&25NQKckKLU!U{sprites, create_xp_sprite( t, (SDL_Rect) { 6 * 16, 0, 16, 16 }, - (Position) { 16, POS_Y_XPBAR } + POS(16, POS_Y_XPBAR) )); // Right end linkedlist_append(&gui->sprites, create_xp_sprite( t, (SDL_Rect) { 8 * 16, 0, 16, 16 }, - (Position) { 16 + (16 * 7), POS_Y_XPBAR } + POS(16 + (16 * 7), POS_Y_XPBAR) )); for (i = 1; i < 7; ++i) { linkedlist_append(&gui->sprites, create_xp_sprite( t, (SDL_Rect) { 7 * 16, 0, 16, 16 }, - (Position) { 16 + (i * 16), POS_Y_XPBAR } + POS(16 + (i * 16), POS_Y_XPBAR) )); } @@ -134,7 +134,7 @@ init_sprites(Gui *gui, Camera *cam) linkedlist_append(&gui->xp_bar, create_xp_sprite( t, (SDL_Rect) { 6 * 16, 4 * 16, 16, 16 }, - (Position) { 16 + (i * 16), POS_Y_XPBAR } + POS(16 + (i * 16), POS_Y_XPBAR) )); } @@ -144,7 +144,7 @@ init_sprites(Gui *gui, Camera *cam) s->fixed = true; sprite_set_texture(s, t, 0); s->clip = CLIP16(0, 0); - s->pos = (Position) { 16, POS_Y_COLLECTABLES }; + s->pos = POS(16, POS_Y_COLLECTABLES); linkedlist_append(&gui->sprites, s); t = texturecache_add("Items/Money.png"); @@ -152,7 +152,7 @@ init_sprites(Gui *gui, Camera *cam) s->fixed = true; sprite_set_texture(s, t, 0); s->clip = CLIP16(16, 16); - s->pos = (Position) { 16, POS_Y_COLLECTABLES + 16 }; + s->pos = POS(16, POS_Y_COLLECTABLES + 16); linkedlist_append(&gui->sprites, s); t = texturecache_add("Items/ShortWep.png"); @@ -160,9 +160,25 @@ init_sprites(Gui *gui, Camera *cam) s->fixed = true; sprite_set_texture(s, t, 0); s->clip = CLIP16(0, 0); - s->pos = (Position) { 16, POS_Y_COLLECTABLES + 32 }; + s->pos = POS(16, POS_Y_COLLECTABLES + 32); linkedlist_append(&gui->sprites, s); + t = texturecache_add("Extras/Keys.png"); + s = sprite_create(); + s->fixed = true; + sprite_set_texture(s, t, 0); + s->clip = CLIP16(0, 0); + s->pos = POS(58, POS_Y_XPBAR + 15 + (3*14)); + gui->silverKey = s; + + t = texturecache_add("Extras/Keys.png"); + s = sprite_create(); + s->fixed = true; + sprite_set_texture(s, t, 0); + s->clip = CLIP16(16, 0); + s->pos = POS(74, POS_Y_XPBAR + 15 + (3*14)); + gui->goldKey = s; + gui->statsFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16, STATS_GUI_HEIGHT/16, cam); @@ -173,6 +189,10 @@ init_sprites(Gui *gui, Camera *cam) gui->miniMapFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16, MINIMAP_GUI_HEIGHT/16, cam); + + + texture_load_from_text(gui->labels[KEY_LABEL]->textures[0], "Keys:", C_WHITE, C_BLACK, cam->renderer); + gui->labels[KEY_LABEL]->dim = gui->labels[KEY_LABEL]->textures[0]->dim; } Gui* @@ -197,28 +217,33 @@ gui_create(Camera *cam) texture_load_font(gui->event_message, "GUI/SDS_8x8.ttf", EVENT_MESSAGE_FONT_SIZE, 2); gui->event_message_timer = _timer_create(); - gui->labels[CURRENT_XP_LABEL] = create_label_sprite((Position) { 16, POS_Y_XPBAR + 18 }); - gui->labels[LEVEL_LABEL] = create_label_sprite((Position) { 16, POS_Y_XPBAR + 18 + 14 }); + gui->labels[CURRENT_XP_LABEL] = create_label_sprite(POS(16, POS_Y_XPBAR + 18)); + gui->labels[LEVEL_LABEL] = create_label_sprite(POS(16, POS_Y_XPBAR + 18 + 14)); gui->labels[DUNGEON_LEVEL_LABEL] = - create_label_sprite((Position) { + create_label_sprite(POS( 16, POS_Y_XPBAR + 18 + (2*14) - }); + )); + gui->labels[KEY_LABEL] = + create_label_sprite(POS( + 16, + POS_Y_XPBAR + 18 + (3*14) + )); gui->labels[HEALTH_POTION_LABEL] = - create_label_sprite((Position) { + create_label_sprite(POS( 32, POS_Y_COLLECTABLES + 5 - }); + )); gui->labels[GOLD_LABEL] = - create_label_sprite((Position) { + create_label_sprite(POS( 32, POS_Y_COLLECTABLES + 16 + 5 - }); + )); gui->labels[DAGGER_LABEL] = - create_label_sprite((Position) { + create_label_sprite(POS( 32, POS_Y_COLLECTABLES + 32 + 5 - }); + )); gui_malloc_log(); gui_malloc_eventmessages(); @@ -251,7 +276,7 @@ set_max_health(Gui *gui, int max) sprite->fixed = true; sprite->animate = false; sprite->clip = (SDL_Rect) { 0, 16, 16, 16 }; - sprite->pos = (Position) { 16 + (i%8)*16, 16 + ((i-(i%8))/8)*16 }; + sprite->pos = POS(16 + (i%8)*16, 16 + ((i-(i%8))/8)*16); sprite_set_texture(sprite, texture0, 0); sprite_set_texture(sprite, texture1, 1); linkedlist_append(&gui->health, sprite); @@ -392,6 +417,10 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render gui->labels[LEVEL_LABEL]->dim = gui->labels[LEVEL_LABEL]->textures[0]->dim; last_level = data.level; } + + gui->silverKey->hidden = !(player->equipment.keys & LOCK_SILVER); + gui->goldKey->hidden = !(player->equipment.keys & LOCK_GOLD); + gui->goldKey->pos.x = gui->silverKey->hidden ? 58 : 74; } void @@ -410,6 +439,8 @@ gui_render_panel(Gui *gui, Camera *cam) sprite_render(s, cam); item = item->next; } + sprite_render(gui->silverKey, cam); + sprite_render(gui->goldKey, cam); item = gui->sprites; while (item != NULL) { Sprite *s = item->data; @@ -622,5 +653,8 @@ gui_destroy(Gui *gui) for (int i = 0; i < LABEL_COUNT; ++i) sprite_destroy(gui->labels[i]); + sprite_destroy(gui->silverKey); + sprite_destroy(gui->goldKey); + free(gui); } diff --git a/src/gui.h b/src/gui.h index f5a0d09..122f0e8 100644 --- a/src/gui.h +++ b/src/gui.h @@ -37,6 +37,7 @@ typedef enum Label_e { CURRENT_XP_LABEL, GOLD_LABEL, DUNGEON_LEVEL_LABEL, + KEY_LABEL, HEALTH_POTION_LABEL, DAGGER_LABEL, LABEL_COUNT @@ -51,6 +52,8 @@ typedef struct Gui { Sprite *miniMapFrame; Sprite *labels[LABEL_COUNT]; Sprite *activeTooltip; + Sprite *goldKey; + Sprite *silverKey; Texture *log_lines[LOG_LINES_COUNT]; Texture *event_message; Timer *event_message_timer; diff --git a/src/item_builder.c b/src/item_builder.c index 1a85029..f015efb 100644 --- a/src/item_builder.c +++ b/src/item_builder.c @@ -172,17 +172,21 @@ Item * item_builder_build_key(unsigned int type) { char label[20]; - SDL_Rect clip = CLIP16(0, 0); Item *item; switch (type) { case 1: m_sprintf(label, 20, "a silver key"); - item = create_item("Items/Key.png", NULL, clip, &pickup_silver_key); + item = create_item("Extras/Keys.png", + NULL, + CLIP16(0, 0), + &pickup_silver_key); break; case 2: m_sprintf(label, 20, "a gold key"); - item = create_item("Items/Key.png", NULL, clip, &pickup_gold_key); - clip.x = 16; + item = create_item("Extras/Keys.png", + NULL, + CLIP16(16, 0), + &pickup_gold_key); break; default: fatal("Bad keytype provided");