hud: backpack animation when picking up items
This commit is contained in:
parent
27810b1ea0
commit
068f98249c
|
@ -62,6 +62,7 @@ set(ASSETS
|
|||
assets-cg/menu_title.png
|
||||
# HUD
|
||||
assets-cg/hud.png
|
||||
assets-cg/hud_backpack.ase
|
||||
assets-cg/hud_delay.png
|
||||
assets-cg/hud_flag.png
|
||||
assets-cg/hud_itemslots.png
|
||||
|
|
|
@ -9,6 +9,12 @@ hud_xp.ase:
|
|||
center: 6, 8
|
||||
next: Idle=Idle, Shine=Idle, Explode=Idle
|
||||
|
||||
hud_backpack.ase:
|
||||
custom-type: aseprite-anim
|
||||
name: frames_hud_backpack
|
||||
center: 0, 0
|
||||
next: Idle=Idle, Open=Idle
|
||||
|
||||
font_rogue.png:
|
||||
type: font
|
||||
name: font_rogue
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.0 KiB |
Binary file not shown.
|
@ -60,6 +60,8 @@ ANIM4(player, Hit);
|
|||
ANIM1(hud_xp_Idle);
|
||||
ANIM1(hud_xp_Shine);
|
||||
ANIM1(hud_xp_Explode);
|
||||
ANIM1(hud_backpack_Idle);
|
||||
ANIM1(hud_backpack_Open);
|
||||
|
||||
/* Items */
|
||||
ANIM1(item_life);
|
||||
|
|
|
@ -103,6 +103,8 @@ extern anim_t anims_player_Hit;
|
|||
extern anim_t anims_hud_xp_Idle;
|
||||
extern anim_t anims_hud_xp_Shine;
|
||||
extern anim_t anims_hud_xp_Explode;
|
||||
extern anim_t anims_hud_backpack_Idle;
|
||||
extern anim_t anims_hud_backpack_Open;
|
||||
|
||||
/* Items */
|
||||
extern anim_t anims_item_life;
|
||||
|
|
|
@ -273,8 +273,10 @@ void aoe_apply(game_t *game, entity_t *entity, entity_t *e)
|
|||
|
||||
if(aoe->type == AOE_ITEM && e_f && e_f->player) {
|
||||
bool picked = player_give_item(e, aoe->data.item.type);
|
||||
if(picked)
|
||||
if(picked) {
|
||||
game_hud_start_backpack_anim(game);
|
||||
aoe->lifetime = 0;
|
||||
}
|
||||
/* Don't bother recording the hit since the item will disappear */
|
||||
was_hit = false;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ bool game_load(game_t *g, level_t const *level)
|
|||
|
||||
g->hud_xp_anim.frame = anims_hud_xp_Idle.start[0];
|
||||
g->hud_xp_anim.elapsed = 0;
|
||||
g->hud_backpack_anim.frame = anims_hud_backpack_Idle.start[0];
|
||||
g->hud_backpack_anim.elapsed = 0;
|
||||
|
||||
g->menu_time = fix(0);
|
||||
g->menu_open = false;
|
||||
|
@ -185,6 +187,12 @@ void game_message(game_t *g, fixed_t duration, char const *fmt, ...)
|
|||
g->message_time = duration;
|
||||
}
|
||||
|
||||
void game_hud_start_backpack_anim(game_t *g)
|
||||
{
|
||||
g->hud_backpack_anim.frame = anims_hud_backpack_Open.start[0];
|
||||
g->hud_backpack_anim.elapsed = 0;
|
||||
}
|
||||
|
||||
//---
|
||||
// Object management functions
|
||||
//---
|
||||
|
@ -430,6 +438,7 @@ void game_update_animations(game_t *g, fixed_t dt)
|
|||
g->map_anim[i] += fround(dt * 1000);
|
||||
|
||||
anim_state_update(&g->hud_xp_anim, dt);
|
||||
anim_state_update(&g->hud_backpack_anim, dt);
|
||||
}
|
||||
|
||||
void game_update_effects(game_t *g, fixed_t dt)
|
||||
|
|
|
@ -52,6 +52,8 @@ typedef struct game {
|
|||
|
||||
/* XP bar animation */
|
||||
anim_state_t hud_xp_anim;
|
||||
/* Backpack animation */
|
||||
anim_state_t hud_backpack_anim;
|
||||
/* Inventory/status menu opening time (0 is closed, 1 is open) */
|
||||
fixed_t menu_time;
|
||||
/* Whether the menu is open or closed. Dictates whether menu_time goes
|
||||
|
@ -90,6 +92,9 @@ void game_shake(game_t *g, int amplitude, fixed_t duration);
|
|||
/* Set the current game message */
|
||||
void game_message(game_t *g, fixed_t duration, char const *fmt, ...);
|
||||
|
||||
/* Start the backpack animation */
|
||||
void game_hud_start_backpack_anim(game_t *g);
|
||||
|
||||
//---
|
||||
// Managing dynamic game elements
|
||||
//---
|
||||
|
|
12
src/render.c
12
src/render.c
|
@ -527,6 +527,11 @@ static void dtext_multi(int x0, int y, int color, char const *str)
|
|||
}
|
||||
}
|
||||
|
||||
static int skill_x(int i)
|
||||
{
|
||||
return 23 + 44*i + 103*(i>=3);
|
||||
}
|
||||
|
||||
void render_game(game_t const *g, bool show_hitboxes)
|
||||
{
|
||||
camera_t const *camera = &g->camera;
|
||||
|
@ -627,7 +632,7 @@ void render_game(game_t const *g, bool show_hitboxes)
|
|||
fixed_t cooldown_remaining = player_f->actions_cooldown[i+1];
|
||||
int skill = player_f->skills[i+1];
|
||||
|
||||
int x = 23 + 44*i + 103*(i>=3);
|
||||
int x = skill_x(i);
|
||||
int y = HUD_Y - 33;
|
||||
int bg = (cooldown_remaining != 0) ? 2 : 1;
|
||||
skill_render(x+2, y+2, skill, bg, C_WHITE);
|
||||
|
@ -648,6 +653,9 @@ void render_game(game_t const *g, bool show_hitboxes)
|
|||
}
|
||||
}
|
||||
|
||||
/* Render backpack icon */
|
||||
anim_frame_render(skill_x(5)+2, HUD_Y-33+2, g->hud_backpack_anim.frame);
|
||||
|
||||
if(g->menu_time > 0) {
|
||||
int x1 = cubic(-130, 0, g->menu_time, fix(1));
|
||||
int x2 = DWIDTH - 130 - x1;
|
||||
|
@ -745,7 +753,7 @@ void render_game(game_t const *g, bool show_hitboxes)
|
|||
for(int i = 0; i < 5; i++) {
|
||||
int s1 = player_f->skills[i+1], s2 = switched_skills[i+1];
|
||||
if(s1 == s2) continue;
|
||||
int x = 23 + 44*i + 103*(i>=3);
|
||||
int x = skill_x(i);
|
||||
int y = HUD_Y - 33;
|
||||
skill_render(x+2, y+2, s2, 3, C_WHITE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue