Adds gui display for held keys

Also makes the gold key actually golden
This commit is contained in:
Linus Probert 2019-05-14 22:27:13 +02:00
parent fb031e2af3
commit 6c135c6b9c
4 changed files with 63 additions and 22 deletions

BIN
assets/Extras/Keys.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

View File

@ -112,21 +112,21 @@ init_sprites(Gui *gui, Camera *cam)
linkedlist_append(&gui->sprites, create_xp_sprite( linkedlist_append(&gui->sprites, create_xp_sprite(
t, t,
(SDL_Rect) { 6 * 16, 0, 16, 16 }, (SDL_Rect) { 6 * 16, 0, 16, 16 },
(Position) { 16, POS_Y_XPBAR } POS(16, POS_Y_XPBAR)
)); ));
// Right end // Right end
linkedlist_append(&gui->sprites, create_xp_sprite( linkedlist_append(&gui->sprites, create_xp_sprite(
t, t,
(SDL_Rect) { 8 * 16, 0, 16, 16 }, (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) { for (i = 1; i < 7; ++i) {
linkedlist_append(&gui->sprites, create_xp_sprite( linkedlist_append(&gui->sprites, create_xp_sprite(
t, t,
(SDL_Rect) { 7 * 16, 0, 16, 16 }, (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( linkedlist_append(&gui->xp_bar, create_xp_sprite(
t, t,
(SDL_Rect) { 6 * 16, 4 * 16, 16, 16 }, (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; s->fixed = true;
sprite_set_texture(s, t, 0); sprite_set_texture(s, t, 0);
s->clip = CLIP16(0, 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); linkedlist_append(&gui->sprites, s);
t = texturecache_add("Items/Money.png"); t = texturecache_add("Items/Money.png");
@ -152,7 +152,7 @@ init_sprites(Gui *gui, Camera *cam)
s->fixed = true; s->fixed = true;
sprite_set_texture(s, t, 0); sprite_set_texture(s, t, 0);
s->clip = CLIP16(16, 16); 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); linkedlist_append(&gui->sprites, s);
t = texturecache_add("Items/ShortWep.png"); t = texturecache_add("Items/ShortWep.png");
@ -160,9 +160,25 @@ init_sprites(Gui *gui, Camera *cam)
s->fixed = true; s->fixed = true;
sprite_set_texture(s, t, 0); sprite_set_texture(s, t, 0);
s->clip = CLIP16(0, 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); 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, gui->statsFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16,
STATS_GUI_HEIGHT/16, STATS_GUI_HEIGHT/16,
cam); cam);
@ -173,6 +189,10 @@ init_sprites(Gui *gui, Camera *cam)
gui->miniMapFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16, gui->miniMapFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16,
MINIMAP_GUI_HEIGHT/16, MINIMAP_GUI_HEIGHT/16,
cam); 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* Gui*
@ -197,28 +217,33 @@ gui_create(Camera *cam)
texture_load_font(gui->event_message, "GUI/SDS_8x8.ttf", EVENT_MESSAGE_FONT_SIZE, 2); texture_load_font(gui->event_message, "GUI/SDS_8x8.ttf", EVENT_MESSAGE_FONT_SIZE, 2);
gui->event_message_timer = _timer_create(); gui->event_message_timer = _timer_create();
gui->labels[CURRENT_XP_LABEL] = create_label_sprite((Position) { 16, POS_Y_XPBAR + 18 }); gui->labels[CURRENT_XP_LABEL] = create_label_sprite(POS(16, POS_Y_XPBAR + 18));
gui->labels[LEVEL_LABEL] = create_label_sprite((Position) { 16, POS_Y_XPBAR + 18 + 14 }); gui->labels[LEVEL_LABEL] = create_label_sprite(POS(16, POS_Y_XPBAR + 18 + 14));
gui->labels[DUNGEON_LEVEL_LABEL] = gui->labels[DUNGEON_LEVEL_LABEL] =
create_label_sprite((Position) { create_label_sprite(POS(
16, 16,
POS_Y_XPBAR + 18 + (2*14) 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] = gui->labels[HEALTH_POTION_LABEL] =
create_label_sprite((Position) { create_label_sprite(POS(
32, 32,
POS_Y_COLLECTABLES + 5 POS_Y_COLLECTABLES + 5
}); ));
gui->labels[GOLD_LABEL] = gui->labels[GOLD_LABEL] =
create_label_sprite((Position) { create_label_sprite(POS(
32, 32,
POS_Y_COLLECTABLES + 16 + 5 POS_Y_COLLECTABLES + 16 + 5
}); ));
gui->labels[DAGGER_LABEL] = gui->labels[DAGGER_LABEL] =
create_label_sprite((Position) { create_label_sprite(POS(
32, 32,
POS_Y_COLLECTABLES + 32 + 5 POS_Y_COLLECTABLES + 32 + 5
}); ));
gui_malloc_log(); gui_malloc_log();
gui_malloc_eventmessages(); gui_malloc_eventmessages();
@ -251,7 +276,7 @@ set_max_health(Gui *gui, int max)
sprite->fixed = true; sprite->fixed = true;
sprite->animate = false; sprite->animate = false;
sprite->clip = (SDL_Rect) { 0, 16, 16, 16 }; 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, texture0, 0);
sprite_set_texture(sprite, texture1, 1); sprite_set_texture(sprite, texture1, 1);
linkedlist_append(&gui->health, sprite); 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; gui->labels[LEVEL_LABEL]->dim = gui->labels[LEVEL_LABEL]->textures[0]->dim;
last_level = data.level; 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 void
@ -410,6 +439,8 @@ gui_render_panel(Gui *gui, Camera *cam)
sprite_render(s, cam); sprite_render(s, cam);
item = item->next; item = item->next;
} }
sprite_render(gui->silverKey, cam);
sprite_render(gui->goldKey, cam);
item = gui->sprites; item = gui->sprites;
while (item != NULL) { while (item != NULL) {
Sprite *s = item->data; Sprite *s = item->data;
@ -622,5 +653,8 @@ gui_destroy(Gui *gui)
for (int i = 0; i < LABEL_COUNT; ++i) for (int i = 0; i < LABEL_COUNT; ++i)
sprite_destroy(gui->labels[i]); sprite_destroy(gui->labels[i]);
sprite_destroy(gui->silverKey);
sprite_destroy(gui->goldKey);
free(gui); free(gui);
} }

View File

@ -37,6 +37,7 @@ typedef enum Label_e {
CURRENT_XP_LABEL, CURRENT_XP_LABEL,
GOLD_LABEL, GOLD_LABEL,
DUNGEON_LEVEL_LABEL, DUNGEON_LEVEL_LABEL,
KEY_LABEL,
HEALTH_POTION_LABEL, HEALTH_POTION_LABEL,
DAGGER_LABEL, DAGGER_LABEL,
LABEL_COUNT LABEL_COUNT
@ -51,6 +52,8 @@ typedef struct Gui {
Sprite *miniMapFrame; Sprite *miniMapFrame;
Sprite *labels[LABEL_COUNT]; Sprite *labels[LABEL_COUNT];
Sprite *activeTooltip; Sprite *activeTooltip;
Sprite *goldKey;
Sprite *silverKey;
Texture *log_lines[LOG_LINES_COUNT]; Texture *log_lines[LOG_LINES_COUNT];
Texture *event_message; Texture *event_message;
Timer *event_message_timer; Timer *event_message_timer;

View File

@ -172,17 +172,21 @@ Item *
item_builder_build_key(unsigned int type) item_builder_build_key(unsigned int type)
{ {
char label[20]; char label[20];
SDL_Rect clip = CLIP16(0, 0);
Item *item; Item *item;
switch (type) { switch (type) {
case 1: case 1:
m_sprintf(label, 20, "a silver key"); 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; break;
case 2: case 2:
m_sprintf(label, 20, "a gold key"); m_sprintf(label, 20, "a gold key");
item = create_item("Items/Key.png", NULL, clip, &pickup_gold_key); item = create_item("Extras/Keys.png",
clip.x = 16; NULL,
CLIP16(16, 0),
&pickup_gold_key);
break; break;
default: default:
fatal("Bad keytype provided"); fatal("Bad keytype provided");