fp: Add a hit confirmation visual marker

This commit is contained in:
doyle 2023-10-18 00:19:09 +11:00
parent 395e8dc58a
commit 1de986b6ac
2 changed files with 18 additions and 2 deletions

View File

@ -2244,7 +2244,9 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
continue; 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->hp <= 0) {
if (!defender->is_dying) { if (!defender->is_dying) {
FP_GameEntity *coin_receiver = FP_Game_GetEntity(game, attacker->projectile_owner); 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) if (sprite.flip & TELY_AssetFlip_Y)
dest_rect.size.h *= -1.f; // NOTE: Flip the texture vertically 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, TELY_Render_TextureColourV4(renderer,
sprite.sheet->tex_handle, sprite.sheet->tex_handle,
src_rect, src_rect,
dest_rect, dest_rect,
Dqn_V2_Zero /*rotate origin*/, Dqn_V2_Zero /*rotate origin*/,
0.f /*rotate radians*/, 0.f /*rotate radians*/,
TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, entity->action.sprite_alpha)); sprite_colour);
if (entity->converted_faction) { if (entity->converted_faction) {
Dqn_V2 label_p = Dqn_Rect_InterpolatedPoint(dest_rect, Dqn_V2_InitNx2(0, -0.25f)); Dqn_V2 label_p = Dqn_Rect_InterpolatedPoint(dest_rect, Dqn_V2_InitNx2(0, -0.25f));

View File

@ -195,6 +195,7 @@ struct FP_GameEntity
Dqn_V2 attack_box_size; Dqn_V2 attack_box_size;
Dqn_V2 attack_box_offset; Dqn_V2 attack_box_offset;
bool attack_processed; bool attack_processed;
Dqn_usize hit_on_frame;
bool is_dying; bool is_dying;
uint64_t last_attack_timestamp; uint64_t last_attack_timestamp;
uint64_t attack_cooldown_ms; uint64_t attack_cooldown_ms;