Add comments to make it clearer what's going on

This commit is contained in:
Joshalosh 2023-09-28 08:54:17 +10:00 committed by doylet
parent d85fbe95fa
commit 44014a8add
3 changed files with 32 additions and 16 deletions

View File

@ -433,24 +433,39 @@ 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) {
entity->attack_box_size = entity->local_hit_box_size;
// NOTE: Position the attack box // NOTE: Grab timings to narrow down a midpoint of the attack animation
if (entity->direction == FP_GameDirection_Left) { const uint32_t GRACE_PERIOD = 33;
entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x - entity->attack_box_size.w, uint64_t duration_ms = action->sprite.anim->count * action->sprite.anim->ms_per_frame;
entity->local_hit_box_offset.y); uint64_t midpoint_clock_ms = action->end_at_clock_ms - (duration_ms / 2);
} else if (entity->direction == FP_GameDirection_Right) { uint64_t window_start = midpoint_clock_ms - GRACE_PERIOD;
entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x + entity->attack_box_size.w, uint64_t window_end = midpoint_clock_ms + GRACE_PERIOD;
entity->local_hit_box_offset.y);
} else if (entity->direction == FP_GameDirection_Up) { // NOTE: Adding an attack_processed bool to make sure things only fire once
entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x, if (!entity->attack_processed && game->clock_ms >= window_start && game->clock_ms < window_end) {
entity->local_hit_box_offset.y - entity->attack_box_size.h); entity->attack_box_size = entity->local_hit_box_size;
} else if (entity->direction == FP_GameDirection_Down) {
entity->attack_box_offset = Dqn_V2_InitNx2(entity->local_hit_box_offset.x, // NOTE: Position the attack box
entity->local_hit_box_offset.y + entity->attack_box_size.h); 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 { } else {
entity->attack_box_size = {}; entity->attack_box_size = {};
entity->attack_processed = false;
} }
} break; } break;

View File

@ -63,7 +63,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;