From 95a871451390851d75ee51ee702647e98a3d71e5 Mon Sep 17 00:00:00 2001 From: doyle Date: Sun, 8 Oct 2023 16:44:48 +1100 Subject: [PATCH] fp: Redo the attack boxes --- feely_pona.cpp | 48 ++++++++++++++------------------------------- feely_pona_game.cpp | 31 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index c4fa470..9013b38 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -1308,37 +1308,16 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform if (!entity->attack_processed && game->play.clock_ms >= midpoint_clock_ms) { // NOTE: Position the attack box - Dqn_V2 dir_vector = {}; - switch (entity->direction) { - case FP_GameDirection_Left: { - dir_vector.x = -1.f; - entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x - entity->attack_box_size.w, - entity->local_hit_box_offset.y); - } break; - - case FP_GameDirection_Right: { - dir_vector.x = +1.f; - entity->attack_box_offset = Dqn_V2_InitNx2( - entity->local_hit_box_offset.x + entity->attack_box_size.w, - entity->local_hit_box_offset.y); - } break; - - case FP_GameDirection_Up: { - dir_vector.y = -1.f; - entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x, - entity->local_hit_box_offset.y - entity->attack_box_size.h); - } break; - - case FP_GameDirection_Down: { - dir_vector.y = +1.f; - entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x, - entity->local_hit_box_offset.y + entity->attack_box_size.h); - } break; - - case FP_GameDirection_Count: break; - } - if (is_range_attack) { + Dqn_V2 dir_vector = {}; + switch (entity->direction) { + case FP_GameDirection_Left: dir_vector.x = -1.f; break; + case FP_GameDirection_Right: dir_vector.x = +1.f; break; + case FP_GameDirection_Up: dir_vector.y = -1.f; break; + case FP_GameDirection_Down: dir_vector.y = +1.f; break; + case FP_GameDirection_Count: break; + } + Dqn_Rect entity_hit_box = FP_Game_CalcEntityWorldHitBox(game, entity->handle); Dqn_V2 projectile_pos = entity_hit_box.pos + entity->attack_box_offset; Dqn_V2 projectile_acceleration = FP_Game_MetersToPixelsV2(game->play, dir_vector * 0.25f); @@ -1348,7 +1327,9 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform projectile_acceleration, "Phone Message Projectile"); } else { - entity->attack_box_size = entity->local_hit_box_size; + Dqn_FArray attack_boxes = FP_Game_CalcEntityMeleeAttackBoxes(game, entity->handle); + entity->attack_box_size = attack_boxes.data[entity->direction].size; + entity->attack_box_offset = attack_boxes.data[entity->direction].pos - FP_Game_CalcEntityWorldPos(game, entity->handle); TELY_Audio_Play(audio, game->audio[FP_GameAudio_TerryHit], 1.f); } entity->attack_processed = true; @@ -2352,8 +2333,9 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) // NOTE: Render attack box ================================================================= { - Dqn_Rect attack_box = FP_Game_CalcEntityAttackWorldHitBox(game, entity->handle); - TELY_Render_RectColourV4(renderer, attack_box, TELY_RenderShapeMode_Line, TELY_COLOUR_RED_TOMATO_V4); + Dqn_FArray attack_boxes = FP_Game_CalcEntityMeleeAttackBoxes(game, entity->handle); + for (Dqn_Rect box : attack_boxes) + TELY_Render_RectColourV4(renderer, box, TELY_RenderShapeMode_Line, TELY_COLOUR_RED_TOMATO_V4); } // NOTE: Render world position ============================================================= diff --git a/feely_pona_game.cpp b/feely_pona_game.cpp index de27a66..e3478f5 100644 --- a/feely_pona_game.cpp +++ b/feely_pona_game.cpp @@ -414,6 +414,37 @@ static Dqn_Rect FP_Game_CalcEntityAttackWorldHitBox(FP_Game const *game, FP_Game return result; } +static Dqn_FArray FP_Game_CalcEntityMeleeAttackBoxes(FP_Game const *game, FP_GameEntityHandle handle) +{ + Dqn_FArray result = {}; + Dqn_Rect hit_box = FP_Game_CalcEntityWorldHitBox(game, handle); + DQN_FOR_UINDEX (dir_index, FP_GameDirection_Count) { + Dqn_Rect *rect = Dqn_FArray_Make(&result, Dqn_ZeroMem_Yes); + rect->size = hit_box.size; + switch (dir_index) { + case FP_GameDirection_Left: { + rect->pos = Dqn_Rect_InterpolatedPoint(hit_box, Dqn_V2_InitNx2(-1.f, 0.f)); + } break; + + case FP_GameDirection_Right: { + rect->pos = Dqn_Rect_InterpolatedPoint(hit_box, Dqn_V2_InitNx2(+1.f, 0.f)); + } break; + + case FP_GameDirection_Up: { + rect->pos = Dqn_Rect_InterpolatedPoint(hit_box, Dqn_V2_InitNx2(0.f, -1.f)); + } break; + + case FP_GameDirection_Down: { + rect->pos = Dqn_Rect_InterpolatedPoint(hit_box, Dqn_V2_InitNx2(0.f, +1.f)); + } break; + + case FP_GameDirection_Count: break; + } + } + + return result; +} + static Dqn_Rect FP_Game_CalcEntityArrayWorldBoundingBox(FP_Game const *game, FP_GameEntityHandle const *handles, Dqn_usize count) { Dqn_Rect result = {};