Merge branch 'master' of https://github.com/sippeangelo/Escape-the-Dawn
Conflicts: Escape-the-Dawn/Systems/CollisionSystem.cpp
This commit is contained in:
Binary file not shown.
@@ -69,12 +69,12 @@ void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
|
||||
if(bCollisionComponent == nullptr)
|
||||
return;
|
||||
|
||||
auto transformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||
auto aBounds = m_World->GetComponent<Components::Bounds>(aEntity, "Bounds");
|
||||
|
||||
auto bBounds = m_World->GetComponent<Components::Bounds>(bEntity, "Bounds");
|
||||
|
||||
glm::vec3 aPos = aTransform->Position + (aBounds->Origin * aTransform->Scale);
|
||||
glm::vec3 bPos = bTransform->Position + (bBounds->Origin * bTransform->Scale);
|
||||
glm::vec3 aPos = transformSystem->AbsolutePosition(aEntity) + (aBounds->Origin * aTransform->Scale);
|
||||
glm::vec3 bPos = transformSystem->AbsolutePosition(bEntity) + (bBounds->Origin * bTransform->Scale);
|
||||
|
||||
glm::vec3 aMax = aPos + aBounds->VolumeVector * aTransform->Scale;
|
||||
glm::vec3 aMin = aPos - aBounds->VolumeVector * aTransform->Scale;
|
||||
@@ -118,7 +118,7 @@ void Systems::CollisionSystem::CreateBoundingBox(std::shared_ptr<Components::Bou
|
||||
GLushort elements[] = {
|
||||
0, 1, 2, 3,
|
||||
4, 5, 6, 7,
|
||||
0, 4, 1, 5,
|
||||
0, 4, 1, 5,
|
||||
2, 6, 3, 7
|
||||
};
|
||||
GLuint ibo_elements;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
@@ -15,69 +15,80 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||
{
|
||||
typeRandom = 0 + (rand() % 10);
|
||||
|
||||
EntityID ent;
|
||||
auto ent = m_World->CreateEntity();
|
||||
{
|
||||
auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
|
||||
auto bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
|
||||
auto collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
|
||||
auto model = m_World->AddComponent<Components::Model>(ent, "Model");
|
||||
|
||||
ent = m_World->CreateEntity();
|
||||
|
||||
auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
|
||||
auto bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
|
||||
auto collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
|
||||
auto model = m_World->AddComponent<Components::Model>(ent, "Model");
|
||||
auto sound = m_World->AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
|
||||
|
||||
positionRandom = -500 + startx + (rand() % 1000);
|
||||
transform->Position = glm::vec3(positionRandom, startyz);
|
||||
transform->Velocity = glm::vec3(0.f, 30.f, 0);
|
||||
positionRandom = -500 + startx + (rand() % 1000);
|
||||
transform->Position = glm::vec3(positionRandom, startyz);
|
||||
transform->Velocity = glm::vec3(0.f, 30.f, 0);
|
||||
|
||||
sound->Loop = true;
|
||||
sound->Gain = 1.f;
|
||||
sound->MaxDistance = 2.f;
|
||||
sound->ReferenceDistance = 1.f;
|
||||
m_World->GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(sound.get(), "Sounds/hum.wav");
|
||||
// Obstacle
|
||||
if (typeRandom >= 0 && typeRandom < 9)
|
||||
{
|
||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||
|
||||
if(typeRandom >= 0 && typeRandom < 1) // Mountain stuff :D
|
||||
{
|
||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||
float scale = 1.0f + (float)(rand() % 1000) / 250;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(8.5f, 12, 5);
|
||||
bounds->Origin = glm::vec3(1,11,-1);
|
||||
model->ModelFile = "Models/obstacle_mountain_1.obj";
|
||||
if (typeRandom >= 0 && typeRandom < 1) // Mountain stuff :D
|
||||
{
|
||||
float scale = 1.0f + (float)(rand() % 1000) / 250;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(8.5f, 12, 5);
|
||||
bounds->Origin = glm::vec3(1, 11, -1);
|
||||
model->ModelFile = "Models/obstacle_mountain_1.obj";
|
||||
}
|
||||
else if (typeRandom >= 1 && typeRandom < 5) // Single Mountain :D
|
||||
{
|
||||
float scale = 1.0f + (float)(rand() % 1000) / 200;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
|
||||
bounds->Origin = glm::vec3(0, 7.5f, 0);
|
||||
model->ModelFile = "Models/obstacle_mountain_2.obj";
|
||||
}
|
||||
else if (typeRandom >= 5 && typeRandom < 9)
|
||||
{
|
||||
float scale = 2.f + (float)(rand() % 1000) / 100;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(1, 1, 1);
|
||||
bounds->Origin = glm::vec3(0, 1, 0);
|
||||
model->ModelFile = "Models/obstacle_cube_1.obj";
|
||||
}
|
||||
|
||||
auto soundTrigger = m_World->CreateEntity(ent);
|
||||
{
|
||||
auto obstacleTransform = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
||||
auto obstacleBounds = m_World->GetComponent<Components::Bounds>(ent, "Bounds");
|
||||
|
||||
m_World->SetProperty(soundTrigger, "Name", std::string("Obstacle_SoundTrigger"));
|
||||
auto transform = m_World->AddComponent<Components::Transform>(soundTrigger, "Transform");
|
||||
auto bounds = m_World->AddComponent<Components::Bounds>(soundTrigger, "Bounds");
|
||||
auto collision = m_World->AddComponent<Components::Collision>(soundTrigger, "Collision");
|
||||
bounds->VolumeVector = obstacleBounds->VolumeVector * obstacleTransform->Scale + glm::vec3(25, 0, 50);
|
||||
bounds->Origin = obstacleBounds->Origin;
|
||||
}
|
||||
}
|
||||
else if(typeRandom >= 1 && typeRandom < 5) // Single Mountain :D
|
||||
{
|
||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||
float scale = 1.0f + (float)(rand() % 1000) / 200;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
|
||||
bounds->Origin = glm::vec3(0,7.5f,0);
|
||||
model->ModelFile = "Models/obstacle_mountain_2.obj";
|
||||
}
|
||||
else if(typeRandom >= 5 && typeRandom < 9)
|
||||
{
|
||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||
float scale = 2.f + (float)(rand() % 1000) / 100;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(1, 1, 1);
|
||||
bounds->Origin = glm::vec3(0,1,0);
|
||||
model->ModelFile = "Models/obstacle_cube_1.obj";
|
||||
}
|
||||
if(typeRandom >= 9 && typeRandom < 10)
|
||||
|
||||
// PowerUp
|
||||
if (typeRandom >= 9 && typeRandom < 10)
|
||||
{
|
||||
m_World->SetProperty(ent, "Name", std::string("PowerUp"));
|
||||
bounds->VolumeVector = glm::vec3(4, 4, 4);
|
||||
bounds->Origin = glm::vec3(0,4,0);
|
||||
|
||||
bounds->Origin = glm::vec3(0, 4, 0);
|
||||
|
||||
|
||||
auto powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
|
||||
powerUp->Speed = 200.f;
|
||||
|
||||
model->ModelFile = "Models/powerup.obj";
|
||||
}
|
||||
|
||||
|
||||
// Put it below ground level
|
||||
transform->Position.y -= transform->Scale.y * bounds->VolumeVector.y * 2.f;
|
||||
// Put it below ground level
|
||||
transform->Position.y -= transform->Scale.y * bounds->VolumeVector.y * 2.f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -100,6 +111,9 @@ void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, E
|
||||
transform->Velocity.z = velocity;
|
||||
transform->Position += transform->Velocity * (float)dt;
|
||||
|
||||
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
||||
auto pname = m_World->GetProperty<std::string>(parent, "Name");
|
||||
|
||||
// Stop raising obstacles when they reach ground level
|
||||
if (transform->Velocity.y > 0 && transform->Position.y >= 0)
|
||||
{
|
||||
|
||||
@@ -63,7 +63,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DEBUG("Constant: %f\nLinear: %f\nQuadratic: %f", light->constantAttenuation, light->linearAttenuation, light->quadraticAttenuation);
|
||||
//LOG_DEBUG("Constant: %f\nLinear: %f\nQuadratic: %f", light->constantAttenuation, light->linearAttenuation, light->quadraticAttenuation);
|
||||
}
|
||||
|
||||
if (name == "Camera") {
|
||||
@@ -212,6 +212,20 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
|
||||
//TODO: Ljud som kommer från crashsite
|
||||
}
|
||||
|
||||
if (m_World->GetProperty<std::string>(ent, "Name") == "Obstacle_SoundTrigger")
|
||||
{
|
||||
auto parent = m_World->GetEntityParent(ent);
|
||||
auto swoosh = m_World->CreateEntity(parent);
|
||||
m_World->AddComponent<Components::Transform>(swoosh, "Transform");
|
||||
auto swooshSound = m_World->AddComponent<Components::SoundEmitter>(swoosh, "SoundEmitter");
|
||||
swooshSound->Gain = 2.f;
|
||||
swooshSound->MaxDistance = 5.f;
|
||||
swooshSound->ReferenceDistance = 1.f;
|
||||
auto soundSystem = m_World->GetSystem<Systems::SoundSystem>("SoundSystem");
|
||||
soundSystem->PlaySound(swooshSound.get(), "Sounds/swoosh.wav");
|
||||
m_World->RemoveEntity(ent);
|
||||
}
|
||||
}
|
||||
|
||||
//powerup
|
||||
|
||||
Reference in New Issue
Block a user