fp: Redo the attack boxes

This commit is contained in:
doyle 2023-10-08 16:44:48 +11:00
parent da41e986c5
commit 95a8714513
2 changed files with 46 additions and 33 deletions

View File

@ -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) { if (!entity->attack_processed && game->play.clock_ms >= midpoint_clock_ms) {
// NOTE: Position the attack box // NOTE: Position the attack box
if (is_range_attack) {
Dqn_V2 dir_vector = {}; Dqn_V2 dir_vector = {};
switch (entity->direction) { switch (entity->direction) {
case FP_GameDirection_Left: { case FP_GameDirection_Left: dir_vector.x = -1.f; break;
dir_vector.x = -1.f; case FP_GameDirection_Right: dir_vector.x = +1.f; break;
entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x - entity->attack_box_size.w, case FP_GameDirection_Up: dir_vector.y = -1.f; break;
entity->local_hit_box_offset.y); case FP_GameDirection_Down: dir_vector.y = +1.f; break;
} 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; case FP_GameDirection_Count: break;
} }
if (is_range_attack) {
Dqn_Rect entity_hit_box = FP_Game_CalcEntityWorldHitBox(game, entity->handle); 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_pos = entity_hit_box.pos + entity->attack_box_offset;
Dqn_V2 projectile_acceleration = FP_Game_MetersToPixelsV2(game->play, dir_vector * 0.25f); 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, projectile_acceleration,
"Phone Message Projectile"); "Phone Message Projectile");
} else { } else {
entity->attack_box_size = entity->local_hit_box_size; Dqn_FArray<Dqn_Rect, FP_GameDirection_Count> 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); TELY_Audio_Play(audio, game->audio[FP_GameAudio_TerryHit], 1.f);
} }
entity->attack_processed = true; entity->attack_processed = true;
@ -2352,8 +2333,9 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
// NOTE: Render attack box ================================================================= // NOTE: Render attack box =================================================================
{ {
Dqn_Rect attack_box = FP_Game_CalcEntityAttackWorldHitBox(game, entity->handle); Dqn_FArray<Dqn_Rect, FP_GameDirection_Count> attack_boxes = FP_Game_CalcEntityMeleeAttackBoxes(game, entity->handle);
TELY_Render_RectColourV4(renderer, attack_box, TELY_RenderShapeMode_Line, TELY_COLOUR_RED_TOMATO_V4); for (Dqn_Rect box : attack_boxes)
TELY_Render_RectColourV4(renderer, box, TELY_RenderShapeMode_Line, TELY_COLOUR_RED_TOMATO_V4);
} }
// NOTE: Render world position ============================================================= // NOTE: Render world position =============================================================

View File

@ -414,6 +414,37 @@ static Dqn_Rect FP_Game_CalcEntityAttackWorldHitBox(FP_Game const *game, FP_Game
return result; return result;
} }
static Dqn_FArray<Dqn_Rect, FP_GameDirection_Count> FP_Game_CalcEntityMeleeAttackBoxes(FP_Game const *game, FP_GameEntityHandle handle)
{
Dqn_FArray<Dqn_Rect, FP_GameDirection_Count> 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) static Dqn_Rect FP_Game_CalcEntityArrayWorldBoundingBox(FP_Game const *game, FP_GameEntityHandle const *handles, Dqn_usize count)
{ {
Dqn_Rect result = {}; Dqn_Rect result = {};