Commit 0472e956 authored by Sabrina Katharina Kotzem's avatar Sabrina Katharina Kotzem
Browse files

items can be collected and placed with SPACE (mouse position) - no item...

items can be collected and placed with SPACE (mouse position) - no item functions, just cubes in  different sizes as test
parent 61c2beb9
......@@ -12,7 +12,7 @@ namespace gdw {
class item_container_component : public component {
public:
item_container_component(engine& engine, entity& owner, item_type item, bool isPlaced);
item_container_component(engine& engine, entity& owner, item_type item);
~item_container_component();
static unsigned long type_id() {
......@@ -24,7 +24,6 @@ public:
void place(glm::vec3 worldPos);
private:
item_type item_type_;
bool placed;
int timer;
};
......
......@@ -5,7 +5,8 @@ enum class item_type {
magnet_field,
emp,
accelerator,
portal
portal,
NONE
};
#endif
......@@ -5,6 +5,7 @@
#include <gameplay/item/item_type.h>
#include <gameplay/item/item_container_component.h>
#include <ecs/entity.hpp>
#include <time.h>
#include <rendering/staticmesh_component.hpp>
namespace gdw {
......@@ -17,6 +18,10 @@ public:
item_type equipped_item() {return equipped_item_;}
void place_item(glm::vec3 world_pos);
void set_item(item_type item) {equipped_item_ = item;}
void set_item(void) { // random item
srand(time(0) * time(0));
equipped_item_ = static_cast<item_type>(rand() % 4);
}
private:
engine& engine_;
item_type equipped_item_;
......
......@@ -15,6 +15,7 @@
#include <rendering/rendering_system.hpp>
#include <physics/collision/object_type_component.h>
#include <audio/AudioEventHandler.hpp>
#include <gameplay/item/player_item_manager.h>
namespace gdw {
......@@ -69,6 +70,34 @@ namespace gdw {
} else
move->add_angular_force(glm::vec3(0.f, rotation_speed*(std::pow(diff, 1.4f)) , 0.f));
}
// SET ITEM WITH SPACE KEY
if (input.isKeyDown(SDLK_SPACE)) {
float x = (input.mousePos().x/engine_.graphics_system().width()) * 2.0f -1;
float y = (input.mousePos().y/engine_.graphics_system().height()) * 2.0f -1;
auto cam = level_manager.camera()->component<camera_component>();
auto camera = level_manager.camera();
auto mouse_pos = glm::vec2(x, -y);
auto inv_proj_view = glm::inverse(cam->projection_view());
auto world_pos_near = inv_proj_view * glm::vec4(mouse_pos,0.1f,1.f);
auto world_pos_far = inv_proj_view * glm::vec4(mouse_pos,0.9f,1.f);
world_pos_near /= world_pos_near.w;
world_pos_far /= world_pos_far.w;
auto ray_dir = world_pos_far - world_pos_near;
auto final_pos = world_pos_near + ray_dir;
auto& entity_manager = engine_.entity_manager();
auto plane_normal = glm::vec3(0,1,0); //Hardcoded ground plane
//HNF
float d = glm::dot(glm::vec3(0,3,15) - glm::vec3(world_pos_near), plane_normal) / glm::dot(glm::vec3(glm::normalize(-ray_dir)), plane_normal);
auto intersection_point = camera->position()-glm::vec3((glm::normalize(ray_dir))*d);
engine_.game_play_system().player_item_manager().place_item(intersection_point);
}
}
void game_input_manager::handle_mouse_input(float dt) {
......@@ -82,6 +111,7 @@ namespace gdw {
}
if(input.mouseWheelY() > 0.f) {
auto cam = engine_.game_play_system().level_manager().camera();
cam->position(cam->position()+glm::vec3(0,-1.f,-1.f));
}
......
......@@ -2,8 +2,8 @@
namespace gdw {
item_container_component::item_container_component(engine& engine, entity& owner, item_type item, bool isPlaced):
component(engine, owner), item_type_(item), placed(isPlaced), timer(1000) {
item_container_component::item_container_component(engine& engine, entity& owner, item_type item):
component(engine, owner), item_type_(item), timer(1000) {
}
......@@ -18,8 +18,6 @@ namespace gdw {
void item_container_component::update(float dt)
{
if(!placed)
return;
timer -= dt;
if(timer > 0){}
......
......@@ -3,35 +3,39 @@
namespace gdw {
player_item_manager::player_item_manager(engine& engine):engine_(engine) {
equipped_item_ = item_type::NONE;
}
player_item_manager::~player_item_manager() {}
void player_item_manager::place_item(glm::vec3 world_pos) {
//Construct item dependant on item_type
if(equipped_item_ == item_type::magnet_field){
auto& magnet_field = engine_.entity_manager().emplace_back(world_pos, glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0)));
magnet_field.emplace_back<staticmesh_component>("mesh/cube.msh");
magnet_field.emplace_back<item_container_component>(equipped_item_, true);
}
else if(equipped_item_ == item_type::emp){
auto& magnet_field = engine_.entity_manager().emplace_back(world_pos, glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0)));
magnet_field.emplace_back<staticmesh_component>("mesh/cube.msh");
magnet_field.scale(glm::vec3(2.f));
}
else if(equipped_item_ == item_type::accelerator){
auto& magnet_field = engine_.entity_manager().emplace_back(world_pos, glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0)));
magnet_field.emplace_back<staticmesh_component>("mesh/cube.msh");
magnet_field.scale(glm::vec3(.5f));
}
else if(equipped_item_ == item_type::portal){
auto& magnet_field = engine_.entity_manager().emplace_back(world_pos, glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0)));
magnet_field.emplace_back<staticmesh_component>("mesh/cube.msh");
magnet_field.scale(glm::vec3(.2));
}
equipped_item_ = item_type::NONE;
}
} //Namespace gdw
......@@ -22,6 +22,7 @@
#include <gameplay/gamemanager.h>
#include <physics/collision/object_type_component.h>
#include <gameplay/item/item_container_component.h>
#include <gameplay/item/player_item_manager.h>
#include <gameplay/item/item_type.h>
#include <util/config.hpp>
#include <util/config_manager.hpp>
......@@ -63,10 +64,14 @@ namespace gdw {
plane.emplace_back<staticmesh_component>("mesh/plane.msh");
plane.scale(glm::vec3(4.f));
// -------- PLAYER --------
auto& player = engine_.entity_manager().emplace_back(glm::vec3(0.f, 3.f, 42.f), glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)));
player.emplace_back<object_type_component>("PLAYER");
player.emplace_back<staticmesh_component>("mesh/pirate_ship.msh");
auto &player_coll = player.emplace_back<collision_component>(new sphere(glm::vec3(0.f), 3.f));
player_coll.set_trigger([this](unsigned long long self_id, unsigned long long coll_id) {
glm::vec3 player_pos = engine_.entity_manager().resolve(self_id)->position();
......@@ -75,18 +80,24 @@ namespace gdw {
if(type_comp) {
if(type_comp->get_object_type() == "ITEM") {
engine_.entity_manager().erase(coll_id);
engine_.game_play_system().player_item_manager().set_item();
}
}
});
auto &player_move = player.emplace_back<movement_component>();
player_move.set_damping(5.f);
player_ = player.id();
// ------- CANNON -----------
auto& cannon = engine_.entity_manager().emplace_back(glm::vec3(0.f, 0.f, 3.f), glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)));
cannon.emplace_back<staticmesh_component>("mesh/cannon.msh");
cannon_ = cannon.id();
// -------- MAPLOADER ---------
maploader_.load({"mesh/asteroid.msh"}, 1.f, 50, 1, 40, -25, 3, -2, static_cast<int>(time(0)), 30, 1.0f, 2.0f,engine_.getConfig().get("navDebug",false)); //old seed: 27389
float tpos[]{20+15,3,15};
......
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