Add comments to make it clearer what's going on #4

Merged
doylet merged 1 commits from single_frame_attack into main 2023-09-28 00:13:45 +00:00
3 changed files with 32 additions and 16 deletions

View File

@ -424,6 +424,16 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_Ga
if (*state == FP_EntityTerryState_AttackUp || if (*state == FP_EntityTerryState_AttackUp ||
*state == FP_EntityTerryState_AttackDown || *state == FP_EntityTerryState_AttackDown ||
*state == FP_EntityTerryState_AttackSide) { *state == FP_EntityTerryState_AttackSide) {
// 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; entity->attack_box_size = entity->local_hit_box_size;
// NOTE: Position the attack box // NOTE: Position the attack box
@ -440,9 +450,14 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_Ga
entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x, 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->local_hit_box_offset.y + entity->attack_box_size.h);
} }
entity->attack_processed = true;
} else { } else {
entity->attack_box_size = {}; entity->attack_box_size = {};
} }
} else {
entity->attack_box_size = {};
entity->attack_processed = false;
}
} break; } break;
case FP_EntityType_Smoochie: { case FP_EntityType_Smoochie: {

View File

@ -44,7 +44,7 @@ static FP_GameEntityHandle FP_Entity_CreateSmoochie(FP_Game *game, Dqn_V2 pos, D
va_end(args); va_end(args);
entity->type = FP_EntityType_Smoochie; entity->type = FP_EntityType_Smoochie;
entity->hp = 3; entity->hp = 1;
entity->local_pos = pos; entity->local_pos = pos;
entity->sprite_height.meters = 1.6f; entity->sprite_height.meters = 1.6f;
entity->local_hit_box_size = FP_Game_MetersToPixelsNx2(game, 0.4f, 1.6f); entity->local_hit_box_size = FP_Game_MetersToPixelsNx2(game, 0.4f, 1.6f);

View File

@ -141,6 +141,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;
Dqn_FArray<Dqn_V2, 8> spawner_waypoints; Dqn_FArray<Dqn_V2, 8> spawner_waypoints;
FP_SentinelList<FP_GameEntityHandle> spawn_list; FP_SentinelList<FP_GameEntityHandle> spawn_list;