diff --git a/feely_pona.cpp b/feely_pona.cpp index c898571..c19e233 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -424,24 +424,39 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_Ga if (*state == FP_EntityTerryState_AttackUp || *state == FP_EntityTerryState_AttackDown || *state == FP_EntityTerryState_AttackSide) { - entity->attack_box_size = entity->local_hit_box_size; - // NOTE: Position the attack box - if (entity->direction == FP_GameDirection_Left) { - entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x - entity->attack_box_size.w, - entity->local_hit_box_offset.y); - } else if (entity->direction == FP_GameDirection_Right) { - entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x + entity->attack_box_size.w, - entity->local_hit_box_offset.y); - } else if (entity->direction == FP_GameDirection_Up) { - entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x, - entity->local_hit_box_offset.y - entity->attack_box_size.h); - } else if (entity->direction == FP_GameDirection_Down) { - entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x, - entity->local_hit_box_offset.y + entity->attack_box_size.h); + // NOTE: Grab timings to narrow down a midpoint of the attack animation + const uint32_t GRACE_PERIOD = 33; + uint64_t duration_ms = action->sprite.anim->count * action->sprite.anim->ms_per_frame; + uint64_t midpoint_clock_ms = action->end_at_clock_ms - (duration_ms / 2); + uint64_t window_start = midpoint_clock_ms - GRACE_PERIOD; + uint64_t window_end = midpoint_clock_ms + GRACE_PERIOD; + + // NOTE: Adding an attack_processed bool to make sure things only fire once + if (!entity->attack_processed && game->clock_ms >= window_start && game->clock_ms < window_end) { + entity->attack_box_size = entity->local_hit_box_size; + + // NOTE: Position the attack box + if (entity->direction == FP_GameDirection_Left) { + entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x - entity->attack_box_size.w, + entity->local_hit_box_offset.y); + } else if (entity->direction == FP_GameDirection_Right) { + entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x + entity->attack_box_size.w, + entity->local_hit_box_offset.y); + } else if (entity->direction == FP_GameDirection_Up) { + entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x, + entity->local_hit_box_offset.y - entity->attack_box_size.h); + } else if (entity->direction == FP_GameDirection_Down) { + entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x, + entity->local_hit_box_offset.y + entity->attack_box_size.h); + } + entity->attack_processed = true; + } else { + entity->attack_box_size = {}; } } else { - entity->attack_box_size = {}; + entity->attack_box_size = {}; + entity->attack_processed = false; } } break; diff --git a/feely_pona_entity.cpp b/feely_pona_entity.cpp index aaa50e7..b5c1f9a 100644 --- a/feely_pona_entity.cpp +++ b/feely_pona_entity.cpp @@ -44,7 +44,7 @@ static FP_GameEntityHandle FP_Entity_CreateSmoochie(FP_Game *game, Dqn_V2 pos, D va_end(args); entity->type = FP_EntityType_Smoochie; - entity->hp = 3; + entity->hp = 1; entity->local_pos = pos; entity->sprite_height.meters = 1.6f; entity->local_hit_box_size = FP_Game_MetersToPixelsNx2(game, 0.4f, 1.6f); diff --git a/feely_pona_game.h b/feely_pona_game.h index fb9c5b4..00ef7c6 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -141,6 +141,7 @@ struct FP_GameEntity Dqn_V2 attack_box_size; Dqn_V2 attack_box_offset; + bool attack_processed; Dqn_FArray spawner_waypoints; FP_SentinelList spawn_list;