Swoosh sound when passing close to obstacles
This commit is contained in:
Binary file not shown.
@@ -69,13 +69,13 @@ void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
|
|||||||
if(bCollisionComponent == nullptr)
|
if(bCollisionComponent == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto transformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||||
|
|
||||||
auto aBounds = m_World->GetComponent<Components::Bounds>(aEntity, "Bounds");
|
auto aBounds = m_World->GetComponent<Components::Bounds>(aEntity, "Bounds");
|
||||||
|
|
||||||
auto bBounds = m_World->GetComponent<Components::Bounds>(bEntity, "Bounds");
|
auto bBounds = m_World->GetComponent<Components::Bounds>(bEntity, "Bounds");
|
||||||
|
|
||||||
glm::vec3 aPos = aTransform->Position + (aBounds->Origin * aTransform->Scale);
|
glm::vec3 aPos = transformSystem->AbsolutePosition(aEntity) + (aBounds->Origin * aTransform->Scale);
|
||||||
glm::vec3 bPos = bTransform->Position + (bBounds->Origin * bTransform->Scale);
|
glm::vec3 bPos = transformSystem->AbsolutePosition(bEntity) + (bBounds->Origin * bTransform->Scale);
|
||||||
|
|
||||||
glm::vec3 aMax = aPos + aBounds->VolumeVector * aTransform->Scale;
|
glm::vec3 aMax = aPos + aBounds->VolumeVector * aTransform->Scale;
|
||||||
glm::vec3 aMin = aPos - aBounds->VolumeVector * aTransform->Scale;
|
glm::vec3 aMin = aPos - aBounds->VolumeVector * aTransform->Scale;
|
||||||
@@ -119,7 +119,7 @@ void Systems::CollisionSystem::CreateBoundingBox(std::shared_ptr<Components::Bou
|
|||||||
GLushort elements[] = {
|
GLushort elements[] = {
|
||||||
0, 1, 2, 3,
|
0, 1, 2, 3,
|
||||||
4, 5, 6, 7,
|
4, 5, 6, 7,
|
||||||
0, 4, 1, 5,
|
0, 4, 1, 5,
|
||||||
2, 6, 3, 7
|
2, 6, 3, 7
|
||||||
};
|
};
|
||||||
GLuint ibo_elements;
|
GLuint ibo_elements;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
#include "Components/Collision.h"
|
#include "Components/Collision.h"
|
||||||
#include "Components/Bounds.h"
|
#include "Components/Bounds.h"
|
||||||
|
#include "Systems/TransformSystem.h"
|
||||||
|
|
||||||
namespace Systems
|
namespace Systems
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,69 +15,80 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
|||||||
{
|
{
|
||||||
typeRandom = 0 + (rand() % 10);
|
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();
|
positionRandom = -500 + startx + (rand() % 1000);
|
||||||
|
transform->Position = glm::vec3(positionRandom, startyz);
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
|
transform->Velocity = glm::vec3(0.f, 30.f, 0);
|
||||||
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);
|
|
||||||
|
|
||||||
sound->Loop = true;
|
// Obstacle
|
||||||
sound->Gain = 1.f;
|
if (typeRandom >= 0 && typeRandom < 9)
|
||||||
sound->MaxDistance = 2.f;
|
{
|
||||||
sound->ReferenceDistance = 1.f;
|
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||||
m_World->GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(sound.get(), "Sounds/hum.wav");
|
|
||||||
|
|
||||||
if(typeRandom >= 0 && typeRandom < 1) // Mountain stuff :D
|
if (typeRandom >= 0 && typeRandom < 1) // Mountain stuff :D
|
||||||
{
|
{
|
||||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
float scale = 1.0f + (float)(rand() % 1000) / 250;
|
||||||
float scale = 1.0f + (float)(rand() % 1000) / 250;
|
transform->Scale = glm::vec3(scale);
|
||||||
transform->Scale = glm::vec3(scale);
|
bounds->VolumeVector = glm::vec3(8.5f, 12, 5);
|
||||||
bounds->VolumeVector = glm::vec3(8.5f, 12, 5);
|
bounds->Origin = glm::vec3(1, 11, -1);
|
||||||
bounds->Origin = glm::vec3(1,11,-1);
|
model->ModelFile = "Models/obstacle_mountain_1.obj";
|
||||||
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
|
|
||||||
{
|
// PowerUp
|
||||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
if (typeRandom >= 9 && typeRandom < 10)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
m_World->SetProperty(ent, "Name", std::string("PowerUp"));
|
m_World->SetProperty(ent, "Name", std::string("PowerUp"));
|
||||||
bounds->VolumeVector = glm::vec3(4, 4, 4);
|
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");
|
auto powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
|
||||||
powerUp->Speed = 200.f;
|
powerUp->Speed = 200.f;
|
||||||
|
|
||||||
model->ModelFile = "Models/powerup.obj";
|
model->ModelFile = "Models/powerup.obj";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Put it below ground level
|
// Put it below ground level
|
||||||
transform->Position.y -= transform->Scale.y * bounds->VolumeVector.y * 2.f;
|
transform->Position.y -= transform->Scale.y * bounds->VolumeVector.y * 2.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +115,9 @@ void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, E
|
|||||||
transform->Velocity.z = velocity;
|
transform->Velocity.z = velocity;
|
||||||
transform->Position += transform->Velocity * (float)dt;
|
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
|
// Stop raising obstacles when they reach ground level
|
||||||
if (transform->Velocity.y > 0 && transform->Position.y >= 0)
|
if (transform->Velocity.y > 0 && transform->Position.y >= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,7 +62,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") {
|
if (name == "Camera") {
|
||||||
@@ -198,6 +198,20 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
{
|
{
|
||||||
m_World->RemoveEntity(entity);
|
m_World->RemoveEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
//powerup
|
||||||
|
|||||||
Reference in New Issue
Block a user