From 70b1596bb9f79cc2b3f5df65f9a10236db70c5f5 Mon Sep 17 00:00:00 2001 From: doyle Date: Fri, 29 Sep 2023 15:18:38 +1000 Subject: [PATCH] fp: Merge duplicate attack loops --- feely_pona.cpp | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index 3c3497a..165365a 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -836,6 +836,11 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input move_entity = *state == FP_EntitySmoochieState_Run || *state == FP_EntitySmoochieState_Idle; } break; + case FP_EntityType_Clinger: { + auto *state = DQN_CAST(FP_EntityClingerState *)&entity->action.state; + move_entity = *state == FP_EntityClingerState_Run || *state == FP_EntityClingerState_Idle; + } break; + case FP_EntityType_Merchant: break; case FP_EntityType_Nil: break; } @@ -1067,35 +1072,6 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input entity->local_pos += delta_pos; } } - - // NOTE: Attack collisions ================================================================= - { - // NOTE: Check if there's an active attack box - if (entity->attack_box_size.x != 0 && entity->attack_box_size.y != 0) { - Dqn_Rect entity_attack_box = {}; - // NOTE: Convert from centre origin to top-left origin - entity_attack_box.pos = entity->local_pos + entity->attack_box_offset - (entity->attack_box_size * 0.5f); - entity_attack_box.size = entity->attack_box_size; - - for (FP_GameEntityIterator target_it = {}; FP_Game_DFSPreOrderWalkEntityTree(game, &target_it, game->root_entity);) { - FP_GameEntity *target = target_it.entity; - if (target->handle == entity->handle) - continue; - - if (target->flags & FP_GameEntityFlag_Attackable) { - Dqn_Rect target_world_hit_box = FP_Game_CalcEntityWorldHitBox(game, target->handle); - - if (Dqn_Rect_Intersects(entity_attack_box, target_world_hit_box)) { - target->hp -= 1; - - if (target->hp <= 0) { - target->is_dying = true; - } - } - } - } - } - } // NOTE: Move entity by mouse ============================================================== if (game->active_entity == entity->handle && entity->flags & FP_GameEntityFlag_MoveByMouse) { @@ -1188,10 +1164,19 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input if (defender->handle == attacker->handle) continue; + if ((defender->flags & FP_GameEntityFlag_Attackable) == 0) + continue; + Dqn_Rect defender_box = FP_Game_CalcEntityWorldHitBox(game, defender->handle); if (!Dqn_Rect_Intersects(attacker_box, defender_box)) continue; + // NOTE: Do HP ========================================================================= + defender->hp -= 1; + if (defender->hp <= 0) + defender->is_dying = true; + + // NOTE: Kickback ====================================================================== Dqn_V2 defender_world_pos = Dqn_Rect_Center(defender_box); Dqn_V2 attack_dir_vector = {}; if (attacker_world_pos.x < defender_world_pos.x)