Add comments to make it clearer what's going on
This commit is contained in:
parent
d85fbe95fa
commit
44014a8add
@ -433,24 +433,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;
|
||||
|
||||
|
@ -63,7 +63,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);
|
||||
|
@ -141,6 +141,7 @@ struct FP_GameEntity
|
||||
|
||||
Dqn_V2 attack_box_size;
|
||||
Dqn_V2 attack_box_offset;
|
||||
bool attack_processed;
|
||||
|
||||
Dqn_FArray<Dqn_V2, 8> spawner_waypoints;
|
||||
FP_SentinelList<FP_GameEntityHandle> spawn_list;
|
||||
|
Loading…
Reference in New Issue
Block a user