Commit fd00cf88 authored by Tim Scheiber's avatar Tim Scheiber
Browse files

Merge branch 'feature/7-enemy-attack' of...

Merge branch 'feature/7-enemy-attack' of gitlab.fsi.hochschule-trier.de:GameDevWeek/sommersemester-2019/cpp/phaseshifter into feature/7-enemy-attack
parents 1b0fdeda 492648c1
Pipeline #3339 failed with stage
in 4 minutes and 13 seconds
...@@ -206,13 +206,14 @@ namespace phase_shifter::gameplay { ...@@ -206,13 +206,14 @@ namespace phase_shifter::gameplay {
glm::vec2 last_bullet_pos = bullet_movement.last_position; glm::vec2 last_bullet_pos = bullet_movement.last_position;
glm::vec2 player_pos{player_transform.position.x, player_transform.position.z}; glm::vec2 player_pos{player_transform.position.x, player_transform.position.z};
glm::vec2 last_player_pos = player_movement.last_position; glm::vec2 last_player_pos = player_movement.last_position;
if (!bullet_movement.moved) { if(!bullet_movement.moved) {
last_bullet_pos = bullet_pos; last_bullet_pos = bullet_pos;
} }
if (!player_movement.moved) { if(!player_movement.moved) {
last_player_pos = player_pos; last_player_pos = player_pos;
} }
if(intersect(Stadium{last_bullet_pos, bullet_pos, bullet_body.radius}, Stadium{last_player_pos, player_pos, player_body.radius})) { if(intersect(Stadium{last_bullet_pos, bullet_pos, bullet_body.radius},
Stadium{last_player_pos, player_pos, player_body.radius})) {
_entity_manager.erase(bullet_handle); _entity_manager.erase(bullet_handle);
_bus.send<Damaged_msg>(player_handle); _bus.send<Damaged_msg>(player_handle);
} }
...@@ -220,17 +221,17 @@ namespace phase_shifter::gameplay { ...@@ -220,17 +221,17 @@ namespace phase_shifter::gameplay {
} }
} }
bool Enemy_system::intersect(Stadium& stad1, Stadium& stad2) bool Enemy_system::intersect(const Stadium& stad1, const Stadium& stad2)
{ {
glm::vec2 direction1 = stad1.point2 - stad1.point1; glm::vec2 direction1 = stad1.point2 - stad1.point1;
glm::vec2 direction2 = stad2.point2 - stad2.point1; glm::vec2 direction2 = stad2.point2 - stad2.point1;
glm::vec2 eliminator{-direction1.y, direction1.x}; glm::vec2 eliminator{-direction1.y, direction1.x};
float temp = glm::dot(direction2, eliminator); float temp = glm::dot(direction2, eliminator);
if(temp != 0) { if(temp != 0) {
float lambda = glm::dot((stad1.point1 - stad2.point1), eliminator) / temp; float lambda = glm::dot((stad1.point1 - stad2.point1), eliminator) / temp;
if (lambda >= 0 && lambda <= 1) { if(lambda >= 0 && lambda <= 1) {
return true; return true;
} }
} }
...@@ -238,8 +239,9 @@ namespace phase_shifter::gameplay { ...@@ -238,8 +239,9 @@ namespace phase_shifter::gameplay {
float comb_radius = stad1.radius + stad2.radius; float comb_radius = stad1.radius + stad2.radius;
float length2 = glm::length2(direction1); float length2 = glm::length2(direction1);
if (length2 <= 0.001f) { if(length2 <= 0.001f) {
if (glm::distance(stad2.point1, stad1.point1) < comb_radius || glm::distance(stad2.point2, stad1.point1) < comb_radius) { if(glm::distance(stad2.point1, stad1.point1) < comb_radius
|| glm::distance(stad2.point2, stad1.point1) < comb_radius) {
return true; return true;
} }
} }
...@@ -254,7 +256,8 @@ namespace phase_shifter::gameplay { ...@@ -254,7 +256,8 @@ namespace phase_shifter::gameplay {
length2 = glm::length2(direction2); length2 = glm::length2(direction2);
if(length2 <= 0.001f) { if(length2 <= 0.001f) {
if(glm::distance(stad1.point1, stad2.point1) < comb_radius || glm::distance(stad1.point2, stad2.point1) < comb_radius) { if(glm::distance(stad1.point1, stad2.point1) < comb_radius
|| glm::distance(stad1.point2, stad2.point1) < comb_radius) {
return true; return true;
} }
} }
...@@ -270,5 +273,5 @@ namespace phase_shifter::gameplay { ...@@ -270,5 +273,5 @@ namespace phase_shifter::gameplay {
return false; return false;
} }
float Enemy_system::dot(glm::vec2& a, glm::vec2& b) { return a.x * b.x + a.y * b.y; } float Enemy_system::dot(const glm::vec2& a, const glm::vec2& b) { return a.x * b.x + a.y * b.y; }
} // namespace phase_shifter::gameplay } // namespace phase_shifter::gameplay
\ No newline at end of file
#pragma once #pragma once
#include <mirrage/utils/units.hpp>
#include <mirrage/ecs/entity_manager.hpp> #include <mirrage/ecs/entity_manager.hpp>
#include <mirrage/utils/units.hpp>
#include "bullet_comp.hpp"
#include "continuous_path_comp.hpp"
#include "fixed_path_comp.hpp" #include "fixed_path_comp.hpp"
#include "follow_target_comp.hpp" #include "follow_target_comp.hpp"
#include "continuous_path_comp.hpp"
#include "shooting_comp.hpp" #include "shooting_comp.hpp"
#include "target_comp.hpp" #include "target_comp.hpp"
#include "bullet_comp.hpp"
#include "beat_system.hpp" #include "beat_system.hpp"
namespace phase_shifter::gameplay { namespace phase_shifter::gameplay {
struct Stadium { struct Stadium {
glm::vec2 point1; glm::vec2 point1;
glm::vec2 point2; glm::vec2 point2;
...@@ -39,7 +39,7 @@ namespace phase_shifter::gameplay { ...@@ -39,7 +39,7 @@ namespace phase_shifter::gameplay {
void do_shooting(Beat_state& beat); void do_shooting(Beat_state& beat);
void do_bullet_hit_detection(); void do_bullet_hit_detection();
bool intersect(Stadium& stad1, Stadium& stad2); bool intersect(const Stadium& stad1, const Stadium& stad2);
float dot(glm::vec2& a, glm::vec2& b); float dot(const glm::vec2& a, const glm::vec2& b);
}; };
} } // namespace phase_shifter::gameplay
\ No newline at end of file
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