From 937f63b0ca13f01b48704f3b78e10a45129d37a6 Mon Sep 17 00:00:00 2001 From: En Yi Date: Wed, 24 May 2023 21:54:59 +0800 Subject: [PATCH] Add pause feature on sprite animation Ladder animation now pauses on no movement --- scenes/engine/EC/EC.h | 1 + scenes/game_systems.c | 1 + scenes/player_ent.c | 3 +++ 3 files changed, 5 insertions(+) diff --git a/scenes/engine/EC/EC.h b/scenes/engine/EC/EC.h index d35299b..badc166 100644 --- a/scenes/engine/EC/EC.h +++ b/scenes/engine/EC/EC.h @@ -132,6 +132,7 @@ typedef struct _CSprite_t { unsigned int current_idx; bool flip_x; bool flip_y; + bool pause; } CSprite_t; static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y) diff --git a/scenes/game_systems.c b/scenes/game_systems.c index 84c9f06..130b49c 100644 --- a/scenes/game_systems.c +++ b/scenes/game_systems.c @@ -1076,6 +1076,7 @@ void sprite_animation_system(Scene_t* scene) p_cspr->sprites[spr_idx].sprite->current_frame = 0; } } + if (p_cspr->pause) return; SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx]; // Animate it (handle frame count) spr.sprite->elapsed++; diff --git a/scenes/player_ent.c b/scenes/player_ent.c index d6b6e58..3980c99 100644 --- a/scenes/player_ent.c +++ b/scenes/player_ent.c @@ -27,6 +27,8 @@ static unsigned int player_sprite_transition_func(Entity_t* ent) if (p_ctrans->velocity.x > 0) p_spr->flip_x = true; else if (p_ctrans->velocity.x < 0) p_spr->flip_x = false; + p_spr->pause = false; + if (p_move->ground_state & 1) { if (p_plr->is_crouch) @@ -44,6 +46,7 @@ static unsigned int player_sprite_transition_func(Entity_t* ent) } else if (p_plr->ladder_state) { + p_spr->pause = Vector2LengthSqr(p_ctrans->velocity) < 10.0f; return SPR_PLAYER_LADDER; } else if (p_move->water_state & 1)