From 1de986b6ac0ef761b7ccb8b49fc4cdf69c1ca4a7 Mon Sep 17 00:00:00 2001 From: doyle Date: Wed, 18 Oct 2023 00:19:09 +1100 Subject: [PATCH] fp: Add a hit confirmation visual marker --- feely_pona.cpp | 19 +++++++++++++++++-- feely_pona_game.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index 956ae39..0aa3f89 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -2244,7 +2244,9 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input continue; } - defender->hp = defender->hp >= attacker->base_attack ? defender->hp - attacker->base_attack : 0; + defender->hp = defender->hp >= attacker->base_attack ? defender->hp - attacker->base_attack : 0; + defender->hit_on_frame = game->play.update_counter; + if (defender->hp <= 0) { if (!defender->is_dying) { FP_GameEntity *coin_receiver = FP_Game_GetEntity(game, attacker->projectile_owner); @@ -2433,13 +2435,26 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, if (sprite.flip & TELY_AssetFlip_Y) dest_rect.size.h *= -1.f; // NOTE: Flip the texture vertically + Dqn_V4 sprite_colour = TELY_COLOUR_WHITE_V4; + if (entity->hit_on_frame) { + DQN_ASSERT(game->play.update_counter >= entity->hit_on_frame); + Dqn_usize frames_elapsed_since_hit = game->play.update_counter - entity->hit_on_frame; + Dqn_usize const HIT_CONFIRM_DURATION = 8; + if (frames_elapsed_since_hit < HIT_CONFIRM_DURATION) { + sprite_colour = TELY_COLOUR_RED_V4; + sprite_colour.g = ((1.f / HIT_CONFIRM_DURATION) * frames_elapsed_since_hit); + sprite_colour.b = ((1.f / HIT_CONFIRM_DURATION) * frames_elapsed_since_hit); + } + } + + sprite_colour.a *= entity->action.sprite_alpha; TELY_Render_TextureColourV4(renderer, sprite.sheet->tex_handle, src_rect, dest_rect, Dqn_V2_Zero /*rotate origin*/, 0.f /*rotate radians*/, - TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, entity->action.sprite_alpha)); + sprite_colour); if (entity->converted_faction) { Dqn_V2 label_p = Dqn_Rect_InterpolatedPoint(dest_rect, Dqn_V2_InitNx2(0, -0.25f)); diff --git a/feely_pona_game.h b/feely_pona_game.h index 7bd115b..736ee2f 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -195,6 +195,7 @@ struct FP_GameEntity Dqn_V2 attack_box_size; Dqn_V2 attack_box_offset; bool attack_processed; + Dqn_usize hit_on_frame; bool is_dying; uint64_t last_attack_timestamp; uint64_t attack_cooldown_ms;