diff --git a/Escape-the-Dawn/Sounds/swoosh.wav b/Escape-the-Dawn/Sounds/swoosh.wav new file mode 100644 index 0000000..7980fba Binary files /dev/null and b/Escape-the-Dawn/Sounds/swoosh.wav differ diff --git a/Escape-the-Dawn/Systems/CollisionSystem.cpp b/Escape-the-Dawn/Systems/CollisionSystem.cpp index 00affe4..1e80841 100644 --- a/Escape-the-Dawn/Systems/CollisionSystem.cpp +++ b/Escape-the-Dawn/Systems/CollisionSystem.cpp @@ -69,12 +69,12 @@ void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity) if(bCollisionComponent == nullptr) return; + auto transformSystem = m_World->GetSystem("TransformSystem"); auto aBounds = m_World->GetComponent(aEntity, "Bounds"); - auto bBounds = m_World->GetComponent(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_ptrCreateEntity(); + { + auto transform = m_World->AddComponent(ent, "Transform"); + auto bounds = m_World->AddComponent(ent, "Bounds"); + auto collision = m_World->AddComponent(ent, "Collision"); + auto model = m_World->AddComponent(ent, "Model"); - ent = m_World->CreateEntity(); - - auto transform = m_World->AddComponent(ent, "Transform"); - auto bounds = m_World->AddComponent(ent, "Bounds"); - auto collision = m_World->AddComponent(ent, "Collision"); - auto model = m_World->AddComponent(ent, "Model"); - auto sound = m_World->AddComponent(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("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(ent, "Transform"); + auto obstacleBounds = m_World->GetComponent(ent, "Bounds"); + + m_World->SetProperty(soundTrigger, "Name", std::string("Obstacle_SoundTrigger")); + auto transform = m_World->AddComponent(soundTrigger, "Transform"); + auto bounds = m_World->AddComponent(soundTrigger, "Bounds"); + auto collision = m_World->AddComponent(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(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(entity, "Name"); + auto pname = m_World->GetProperty(parent, "Name"); + // Stop raising obstacles when they reach ground level if (transform->Velocity.y > 0 && transform->Position.y >= 0) { diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 0bb2381..4589bfd 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -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(ent, "Name") == "Obstacle_SoundTrigger") + { + auto parent = m_World->GetEntityParent(ent); + auto swoosh = m_World->CreateEntity(parent); + m_World->AddComponent(swoosh, "Transform"); + auto swooshSound = m_World->AddComponent(swoosh, "SoundEmitter"); + swooshSound->Gain = 2.f; + swooshSound->MaxDistance = 5.f; + swooshSound->ReferenceDistance = 1.f; + auto soundSystem = m_World->GetSystem("SoundSystem"); + soundSystem->PlaySound(swooshSound.get(), "Sounds/swoosh.wav"); + m_World->RemoveEntity(ent); + } } //powerup