fp: Simplify attack push-back to push from side of attack

This commit is contained in:
doyle 2023-09-18 23:35:29 +10:00
parent 12e6e5d6f1
commit d2d4f3cfa7

View File

@ -627,35 +627,34 @@ void FP_GameUpdate(TELY_Platform *platform, FP_Game *game, TELY_Renderer *render
FP_GameEntity *attacker = attacker_it.entity;
// NOTE: Resolve attack boxes
if (Dqn_V2_Area(attacker->attack_box_size)) {
if (!Dqn_V2_Area(attacker->attack_box_size))
continue;
Dqn_Rect attacker_box = FP_Game_CalcEntityAttackWorldHitBox(game, attacker->handle);
Dqn_V2 attacker_world_pos = FP_Game_CalcEntityWorldPos(game, attacker->handle);
for (FP_GameEntityIterator defender_it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &defender_it, game->root_entity); ) {
FP_GameEntity *defender = defender_it.entity;
if (defender->handle == attacker->handle)
continue;
Dqn_Rect defender_box = FP_Game_CalcEntityWorldHitBox(game, defender->handle);
Dqn_Rect hit_rect = Dqn_Rect_Intersection(attacker_box, defender_box);
if (!Dqn_Rect_Area(hit_rect))
if (!Dqn_Rect_Intersects(attacker_box, defender_box))
continue;
TELY_Render_CircleColourV4(renderer, hit_rect.pos, 10.f, TELY_RenderShapeMode_Fill, TELY_COLOUR_MAGENTA_V4);
Dqn_V2 attacker_center_pos = Dqn_Rect_Center(attacker_box);
Dqn_V2 defender_center_pos = Dqn_Rect_Center(defender_box);
Dqn_V2 attacker_to_defender = defender_center_pos - attacker_center_pos;
Dqn_V2 attacker_to_defender_norm = Dqn_V2_Normalise(attacker_to_defender);
Dqn_V2 defender_world_pos = Dqn_Rect_Center(defender_box);
Dqn_V2 attack_dir_vector = {};
if (attacker_world_pos.x < defender_world_pos.x)
attack_dir_vector.x = 1.f;
else
attack_dir_vector.x = -1.f;
TELY_Render_LineColourV4(renderer, defender_center_pos, defender_center_pos + (attacker_to_defender_norm * 100.f), TELY_COLOUR_RED_V4, 3.f);
Dqn_V2 acceleration = attacker_to_defender_norm * 10000000.f;
Dqn_V2 acceleration = attack_dir_vector * 500000.f;
Dqn_f32 t = DQN_CAST(Dqn_f32)DQN_SQUARED(input->delta_s);
Dqn_f32 t_squared = DQN_SQUARED(t);
Dqn_V2 delta_p = (acceleration * 0.5f * t_squared) + (defender->velocity * t);
defender->velocity = (acceleration * t) + defender->velocity * 2.0f;
defender->local_pos += delta_p;
}
}
}
}