hud: backpack animation when opening/closing inventory

This commit is contained in:
Lephenixnoir 2022-12-28 11:27:05 +01:00
parent ac42a425a5
commit 8254b76c77
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
8 changed files with 36 additions and 11 deletions

View File

@ -13,7 +13,7 @@ hud_backpack.ase:
custom-type: aseprite-anim
name: frames_hud_backpack
center: 0, 0
next: Idle=Idle, Open=Idle
next: Idle=Idle, Open=Idle, InventoryOpen=InventoryIdle, InventoryIdle=InventoryIdle, InventoryClose=Idle
font_rogue.png:
type: font

Binary file not shown.

View File

@ -62,6 +62,9 @@ ANIM1(hud_xp_Shine);
ANIM1(hud_xp_Explode);
ANIM1(hud_backpack_Idle);
ANIM1(hud_backpack_Open);
ANIM1(hud_backpack_InventoryOpen);
ANIM1(hud_backpack_InventoryIdle);
ANIM1(hud_backpack_InventoryClose);
/* Items */
ANIM1(item_life);

View File

@ -105,6 +105,9 @@ 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;
extern anim_t anims_hud_backpack_InventoryIdle;
extern anim_t anims_hud_backpack_InventoryOpen;
extern anim_t anims_hud_backpack_InventoryClose;
/* Items */
extern anim_t anims_item_life;

View File

@ -274,7 +274,7 @@ 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) {
game_hud_start_backpack_anim(game);
game_hud_anim_backpack_item(game);
aoe->lifetime = 0;
}
/* Don't bother recording the hit since the item will disappear */

View File

@ -187,12 +187,24 @@ 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)
void game_hud_anim_backpack_item(game_t *g)
{
g->hud_backpack_anim.frame = anims_hud_backpack_Open.start[0];
g->hud_backpack_anim.elapsed = 0;
}
void game_hud_anim_backpack_open(game_t *g)
{
g->hud_backpack_anim.frame = anims_hud_backpack_InventoryOpen.start[0];
g->hud_backpack_anim.elapsed = 0;
}
void game_hud_anim_backpack_close(game_t *g)
{
g->hud_backpack_anim.frame = anims_hud_backpack_InventoryClose.start[0];
g->hud_backpack_anim.elapsed = 0;
}
//---
// Object management functions
//---
@ -425,7 +437,7 @@ void game_spawn_enemies(game_t *g)
}
}
void game_update_animations(game_t *g, fixed_t dt)
void game_update_animations(game_t *g, fixed_t dt, fixed_t dt_rt)
{
for(int i = 0; i < g->entity_count; i++) {
entity_t *e = g->entities[i];
@ -437,8 +449,8 @@ void game_update_animations(game_t *g, fixed_t dt)
for(int i = 0; i < g->map->width * g->map->height; i++)
g->map_anim[i] += fround(dt * 1000);
anim_state_update(&g->hud_xp_anim, dt);
anim_state_update(&g->hud_backpack_anim, dt);
anim_state_update(&g->hud_xp_anim, dt_rt);
anim_state_update(&g->hud_backpack_anim, dt_rt);
}
void game_update_effects(game_t *g, fixed_t dt)

View File

@ -92,8 +92,10 @@ 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);
/* Start backpack animations */
void game_hud_anim_backpack_item(game_t *g);
void game_hud_anim_backpack_open(game_t *g);
void game_hud_anim_backpack_close(game_t *g);
//---
// Managing dynamic game elements
@ -136,7 +138,7 @@ int game_sort_entities(game_t const *g, entity_measure_t *measure,
void game_spawn_enemies(game_t *g);
/* Update all entities' and effect areas' animations. */
void game_update_animations(game_t *g, fixed_t dt);
void game_update_animations(game_t *g, fixed_t dt, fixed_t dt_rt);
/* Update all entities' status ailments and temporary buffs/debuffs */
void game_update_effects(game_t *g, fixed_t dt);

View File

@ -442,8 +442,13 @@ int main(void)
/* Menus */
if(!debug.paused && ev.key == KEY_F6 && !debug.dev_menu
&& !keydown(KEY_ALPHA))
&& !keydown(KEY_ALPHA)) {
if(game.menu_open)
game_hud_anim_backpack_close(&game);
else
game_hud_anim_backpack_open(&game);
game.menu_open = !game.menu_open;
}
/* Inventory movement */
if(!debug.paused && game.menu_open) {
@ -599,7 +604,7 @@ int main(void)
- XP boosts
- Weaker but longer-lasting buffs */
game_update_animations(&game, dt);
game_update_animations(&game, dt, dt_rt);
game_update_effects(&game, dt);
game_update_aoes(&game, dt);
game_update_particles(&game, dt);