Commit 9530d73f authored by Elias Broschin's avatar Elias Broschin
Browse files

integrated seismic bomb

parent b8abf66a
......@@ -33,6 +33,7 @@ public:
void create_asteroid(glm::vec3 pos, std::string mesh_name, float scale, glm::vec3 rotation);
void create_item(glm::vec3 pos, int type);
void destroy_victim(glm::vec3 item_spawn_pos, unsigned long long id);
void destroy_all_victims();
void destroy_all_asteroids();
......
nanovg @ 504060e5
Subproject commit 504060e52a47d96cf18530deff221312773c4175
......@@ -6,11 +6,12 @@
#include <physics/physics_system.h>
#include <physics/movement/movement_component.h>
#include <util/list_helper.h>
#include <gameplay/level_manager.h>
namespace gdw {
player_item_manager::player_item_manager(engine& engine):engine_(engine) {
equipped_item_ = item_type::NONE;
equipped_item_ = item_type::magnet_field;
}
player_item_manager::~player_item_manager() {}
......@@ -28,78 +29,40 @@ namespace gdw {
case item_type::magnet_field: {
auto& placed_item = engine_.entity_manager().emplace_back(world_pos, glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0)));
placed_item.emplace_back<staticmesh_component>("mesh/cube.msh");
placed_item.scale(glm::vec3(1.f,1.f,1.f));
auto &placed_item_coll = placed_item.emplace_back<collision_component>(new sphere(glm::vec3(0.f),5.f));
auto &placed_item_coll = placed_item.emplace_back<collision_component>(new sphere(glm::vec3(0.f),7.f));
placed_item.emplace_back<object_type_component>("MAGNET_FIELD");
placed_item_coll.set_trigger([this](unsigned long long self_id, unsigned long long coll_id){
placed_item_coll.set_trigger([this](unsigned long long self_id, unsigned long long coll_id) {
std::vector<unsigned long long> doomed;
sphere sp(engine_.entity_manager().resolve(self_id)->position(), 5.f);
auto sp_collider = engine_.physics_system().checkCollisions<gdw::shape_type::sphere>(&sp);
for(auto &s : sp_collider) {
auto collider = engine_.entity_manager().resolve(s);
auto type_comp = collider->component<object_type_component>();
if(type_comp){
if(type_comp->get_object_type()=="VICTIM"){
auto move = collider->component<movement_component>();
if(move){
move->add_force((engine_.entity_manager().resolve(self_id)->position()-
engine_.entity_manager().resolve(s)->position()));
}
if(glm::length(engine_.entity_manager().resolve(s)->position()
-engine_.entity_manager().resolve(self_id)->position())<1.f){
sphere doomball(engine_.entity_manager().resolve(self_id)->position(),5.f);
auto doomball_collider = engine_.physics_system().checkCollisions<gdw::shape_type::sphere>(&doomball);
for(auto &s : doomball_collider){
auto collider = engine_.entity_manager().resolve(s);
auto type_comp = collider->component<object_type_component>();
if(type_comp){
if(type_comp->get_object_type()=="VICTIM"){
bool is_member = false;
if(doomed.empty()){
doomed.push_back(s);
}
else{
for(int i = 0; i <= doomed.size(); i++){
if(s==doomed.at(i)){
is_member = true;
}
if(is_member == false && i == doomed.size()){
doomed.push_back(s);
}
}}
// engine_.entity_manager().erase(s);
//engine_.game_play_system().gamemanager().add_points(1);
//list_helper::removeElement(victims_, s);
}
auto collider = engine_.entity_manager().resolve(coll_id);
auto type_comp = collider->component<object_type_component>();
if(type_comp) {
if(type_comp->get_object_type()=="VICTIM"){
auto move = collider->component<movement_component>();
if(move){
move->add_force((engine_.entity_manager().resolve(self_id)->position()-
collider->position()) * 1.7f);
}
std::vector<unsigned long long> doomed;
if(glm::length(collider->position()
-engine_.entity_manager().resolve(self_id)->position())<2.f) {
sphere doomball(engine_.entity_manager().resolve(self_id)->position(),5.f);
auto doomball_collider = engine_.physics_system().checkCollisions<gdw::shape_type::sphere>(&doomball);
for(auto &s : doomball_collider){
auto collider = engine_.entity_manager().resolve(s);
auto type_comp = collider->component<object_type_component>();
if(type_comp){
if(type_comp->get_object_type()=="VICTIM") {
engine_.game_play_system().level_manager().destroy_victim(collider->position(), s);
}
}
while(!doomed.empty()){
engine_.entity_manager().erase(doomed.back());
doomed.pop_back();
}
engine_.entity_manager().erase(self_id);
}
engine_.entity_manager().erase(self_id);
}
}
}
}
});
break;
}
......
......@@ -222,16 +222,14 @@ namespace gdw {
auto &victim_coll = victim.emplace_back<collision_component>(new sphere(glm::vec3(0.f), 1.f));
victim.emplace_back<object_type_component>("VICTIM");
victim_coll.set_trigger([this](unsigned long long self_id, unsigned long long coll_id) {
glm::vec3 victim_pos = engine_.entity_manager().resolve(self_id)->position();
auto collider = engine_.entity_manager().resolve(coll_id);
auto type_comp = collider->component<object_type_component>();
if(type_comp) {
if(type_comp->get_object_type() == "ASTEROID") {
engine_.entity_manager().erase(self_id);
engine_.game_play_system().gamemanager().add_points(1);
list_helper::removeElement(victims_, self_id);
items_to_create.emplace_back(victim_pos);
destroy_victim(victim_pos, self_id);
}
}
});
......@@ -284,4 +282,13 @@ namespace gdw {
asteroids_.clear();
}
void level_manager::destroy_victim(glm::vec3 item_spawn_pos, unsigned long long id) {
if(list_helper::findElement(victims_, id)) {
list_helper::removeElement(victims_, id);
engine_.entity_manager().erase(id);
engine_.game_play_system().gamemanager().add_points(1);
items_to_create.emplace_back(item_spawn_pos);
}
}
} //Namespace gdw
Subproject commit 3d4dbe849e8db70238497c1546f390aea8cf51bb
Subproject commit ad9ab973a17ebbf0471883a5d25d9f295c56af59
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