fp: Fix attack box changing direction at last second due to using the live entity direction
This commit is contained in:
parent
1c82071686
commit
de7d8c1341
@ -569,6 +569,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform
|
||||
case FP_EntityTerryState_Attack: {
|
||||
if (entering_new_state) {
|
||||
uint64_t duration_ms = render_data.sprite.anim->count * render_data.sprite.anim->ms_per_frame;
|
||||
entity->attack_direction = entity->direction;
|
||||
FP_Game_EntityActionReset(game, entity->handle, duration_ms, render_data.sprite);
|
||||
}
|
||||
|
||||
@ -581,6 +582,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform
|
||||
if (entering_new_state) {
|
||||
uint64_t duration_ms = render_data.sprite.anim->count * render_data.sprite.anim->ms_per_frame;
|
||||
FP_Game_EntityActionReset(game, entity->handle, duration_ms, render_data.sprite);
|
||||
entity->attack_direction = entity->direction;
|
||||
entity->terry_mobile_data_plan -= FP_TERRY_MOBILE_DATA_PER_RANGE_ATTACK;
|
||||
}
|
||||
|
||||
@ -715,6 +717,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform
|
||||
if (entering_new_state) {
|
||||
uint64_t duration_ms = render_data.sprite.anim->count * render_data.sprite.anim->ms_per_frame;
|
||||
FP_Game_EntityActionReset(game, entity->handle, duration_ms, render_data.sprite);
|
||||
entity->attack_direction = entity->direction;
|
||||
|
||||
// NOTE: Deal with this further down with the gameplay attack code.
|
||||
TELY_Audio_Play(audio, game->audio[FP_GameAudio_Smooch], 1.f);
|
||||
@ -830,7 +833,8 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform
|
||||
|
||||
case FP_EntityClingerState_Attack: {
|
||||
if (entering_new_state) {
|
||||
uint64_t duration_ms = render_data.sprite.anim->count * render_data.sprite.anim->ms_per_frame;
|
||||
uint64_t duration_ms = render_data.sprite.anim->count * render_data.sprite.anim->ms_per_frame;
|
||||
entity->attack_direction = entity->direction;
|
||||
FP_Game_EntityActionReset(game, entity->handle, duration_ms, render_data.sprite);
|
||||
}
|
||||
|
||||
@ -1078,6 +1082,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform
|
||||
if (entering_new_state) {
|
||||
uint64_t duration_ms = render_data.sprite.anim->count * render_data.sprite.anim->ms_per_frame;
|
||||
FP_Game_EntityActionReset(game, entity->handle, duration_ms, render_data.sprite);
|
||||
entity->attack_direction = entity->direction;
|
||||
}
|
||||
|
||||
if (action_has_finished)
|
||||
@ -1245,7 +1250,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform
|
||||
// NOTE: Position the attack box
|
||||
if (is_range_attack) {
|
||||
Dqn_V2 dir_vector = {};
|
||||
switch (entity->direction) {
|
||||
switch (entity->attack_direction) {
|
||||
case FP_GameDirection_Left: dir_vector.x = -1.f; break;
|
||||
case FP_GameDirection_Right: dir_vector.x = +1.f; break;
|
||||
case FP_GameDirection_Up: dir_vector.y = -1.f; break;
|
||||
@ -1263,8 +1268,8 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform
|
||||
TELY_Audio_Play(audio, game->audio[FP_GameAudio_Message], 1.f /*volume*/);
|
||||
} else {
|
||||
Dqn_FArray<Dqn_Rect, FP_GameDirection_Count> attack_boxes = FP_Game_CalcEntityMeleeAttackBoxes(game, entity->handle);
|
||||
entity->attack_box_size = attack_boxes.data[entity->direction].size;
|
||||
entity->attack_box_offset = attack_boxes.data[entity->direction].pos - FP_Game_CalcEntityWorldPos(game, entity->handle);
|
||||
entity->attack_box_size = attack_boxes.data[entity->attack_direction].size;
|
||||
entity->attack_box_offset = attack_boxes.data[entity->attack_direction].pos - FP_Game_CalcEntityWorldPos(game, entity->handle);
|
||||
TELY_Audio_Play(audio, game->audio[FP_GameAudio_TerryHit], 1.f);
|
||||
}
|
||||
entity->attack_processed = true;
|
||||
@ -1390,10 +1395,12 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
|
||||
acceleration_meters_per_s += dir_vector * entity->base_acceleration_per_s.meters;
|
||||
}
|
||||
|
||||
if (entity->velocity.x)
|
||||
entity->direction = entity->velocity.x > 0.f ? FP_GameDirection_Right : FP_GameDirection_Left;
|
||||
else if (entity->velocity.y)
|
||||
entity->direction = entity->velocity.y > 0.f ? FP_GameDirection_Down : FP_GameDirection_Up;
|
||||
if (dir_vector == Dqn_V2_Zero) {
|
||||
if (entity->velocity.x)
|
||||
entity->direction = entity->velocity.x > 0.f ? FP_GameDirection_Right : FP_GameDirection_Left;
|
||||
else if (entity->velocity.y)
|
||||
entity->direction = entity->velocity.y > 0.f ? FP_GameDirection_Down : FP_GameDirection_Up;
|
||||
}
|
||||
|
||||
// NOTE: Determine AI movement =============================================================
|
||||
Dqn_V2 entity_pos = FP_Game_CalcEntityWorldPos(game, entity->handle);
|
||||
|
@ -232,6 +232,7 @@ struct FP_GameEntity
|
||||
Dqn_V2 local_hit_box_offset;
|
||||
Dqn_f32 trauma01;
|
||||
|
||||
FP_GameDirection attack_direction;
|
||||
Dqn_V2 attack_box_size;
|
||||
Dqn_V2 attack_box_offset;
|
||||
bool attack_processed;
|
||||
|
Loading…
Reference in New Issue
Block a user