Commit 3fa6fd82 authored by Tim Scheiber's avatar Tim Scheiber
Browse files

Merge branch 'develop' into feature/7-enemy-attack

parents 7bdd592c 95776e86
Pipeline #3350 failed with stage
in 4 minutes and 17 seconds
No preview for this file type
......@@ -13,8 +13,7 @@ namespace phase_shifter::gameplay {
float attack_width = 1;
bool was_move = false;
bool dash = false;
glm::vec2 last_position;
};
sf2_structDef(Dash_comp, attack_width, was_move, dash, last_position);
sf2_structDef(Dash_comp, attack_width);
}
\ No newline at end of file
......@@ -76,16 +76,17 @@ namespace phase_shifter::gameplay {
{
for(auto&& [transform, move, dash] : _ecs.list<Transform_comp, Movement_comp, Dash_comp>()) {
if((dash.dash || dash.was_move) && move.step_time_left > 0) {
if(dash.dash || move.step_time_left > 0) {
//dash
std::cout << "dash" << std::endl;
glm::vec2 position(transform.position.x, transform.position.z);
auto movement = position - dash.last_position;
auto movement = (position - move.last_position) * 1.1f;
auto angle = std::atan2(movement.y, movement.x);
auto width = glm::length(movement);
auto height = dash.attack_width;
auto center = rotate_point(
{dash.last_position.x + movement.x / 2, dash.last_position.y + movement.y / 2},
{move.last_position.x + movement.x / 2, move.last_position.y + movement.y / 2},
angle);
glm::vec2 topleft(center.x - width / 2, center.y + height / 2);
......@@ -98,10 +99,10 @@ namespace phase_shifter::gameplay {
if(rect_circle_intersects(topleft.x, topleft.y, width, height, circle.x, circle.y, kill.radius)) {
// calc attack angle
auto target_dir = glm::vec2(k_transform.position.x, k_transform.position.z)
- dash.last_position;
auto attacker_angle = std::atan2(move.last_step.y, move.last_step.x);
- move.last_position;
auto attacker_angle = std::atan2(move.last_position.y, move.last_position.x);
auto attack_angle = normalize_angle(std::atan2(target_dir.y, target_dir.x)
- std::atan2(move.last_step.y, move.last_step.x));
- std::atan2(move.last_position.y, move.last_position.x));
if(attack_angle < (-15_deg).value())
attack_angle = (-45_deg).value();
......@@ -118,20 +119,10 @@ namespace phase_shifter::gameplay {
}
}
dash.last_position = position;
dash.dash = true;
dash.dash = move.step_time_left > 0;
} else {
dash.dash = false;
}
if(move.move) {
if(!dash.was_move || move.step_time_left <= 0) {
dash.was_move = true;
dash.last_position = {transform.position.x, transform.position.z};
}
} else {
dash.was_move = false;
}
}
}
} // namespace phase_shifter::gameplay
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment