From 074b2d6348e4f818e2ab12920393b692e74f70d2 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 2 Jun 2015 00:06:52 +0200 Subject: [PATCH] Pitch of swoosh based on obstacle scale. Light fading back to blue. --- Escape-the-Dawn/Components/PowerUp.h | 1 + .../Systems/LevelGenerationSystem.cpp | 1 + Escape-the-Dawn/Systems/PlayerSystem.cpp | 122 ++++++++++-------- Escape-the-Dawn/Systems/PlayerSystem.h | 1 + 4 files changed, 68 insertions(+), 57 deletions(-) diff --git a/Escape-the-Dawn/Components/PowerUp.h b/Escape-the-Dawn/Components/PowerUp.h index fce5d6e..21fd71d 100644 --- a/Escape-the-Dawn/Components/PowerUp.h +++ b/Escape-the-Dawn/Components/PowerUp.h @@ -9,6 +9,7 @@ namespace Components struct PowerUp : Component { float Speed; + float Duration; }; } diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp index f87f336..eca9183 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp @@ -80,6 +80,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle() auto powerUp = m_World->AddComponent(ent, "PowerUp"); powerUp->Speed = 200.f; + powerUp->Duration = 5.f; model->ModelFile = "Models/powerup.obj"; } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 8cae412..a4cc371 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -10,6 +10,7 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world) m_CameraOrientation = glm::angleAxis(glm::radians(15.0f),glm::vec3(1,0,0)); freecamEnabled = false; + m_PowerUpTotalDuration = 5.f; m_poweruptimeleft = 0; m_basespeed = 125.f; m_maxspeed = 125.f; @@ -17,7 +18,10 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world) void Systems::PlayerSystem::Update(double dt) { - m_poweruptimeleft -= (float)dt; + if (m_poweruptimeleft > 0) + m_poweruptimeleft -= (float)dt; + else + m_poweruptimeleft = 0; } void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -183,81 +187,85 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa Euler = glm::eulerAngles(transform->Orientation); bounds->VolumeVector.x = m_PlayerOriginalBounds.x * glm::cos(glm::radians(Euler.z)); } - - auto cameraEntity = m_World->GetProperty(entity, "Camera"); - auto cameracamera = m_World->GetComponent(cameraEntity, "Camera"); - cameracamera->FOV = glm::radians(45.f + transform->Velocity.z/3.f ); auto collision = m_World->GetComponent(entity, "Collision"); - if(collision != nullptr) + + // Obstacle collision + for(auto ent : collision->CollidingEntities) { - // Obstacle collision - for(auto ent : collision->CollidingEntities) + if(m_World->GetProperty(ent, "Name") == "Obstacle") { - if(m_World->GetProperty(ent, "Name") == "Obstacle") - { - m_World->RemoveEntity(entity); - } - - 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); - } + m_World->RemoveEntity(entity); } - //powerup - for(auto ent : collision->CollidingEntities) + if (m_World->GetProperty(ent, "Name") == "Obstacle_SoundTrigger") { - std::string name = m_World->GetProperty(ent, "Name"); - if(name == "PowerUp") - { - auto powerupComp = m_World->GetComponent(ent, "PowerUp"); - m_maxspeed = powerupComp->Speed; - m_poweruptimeleft = 5.f; - m_World->RemoveEntity(ent); - SetPlayerLightColor(entity, glm::vec3(0.0, 1.0, 0.0)); - auto soundSystem = m_World->GetSystem("SoundSystem"); - soundSystem->PlaySound(soundEmitter, "Sounds/boom.wav"); - } - } - if(m_poweruptimeleft <= 0) - { - m_maxspeed = m_basespeed; - SetPlayerLightColor(entity, glm::vec3(0.05f, 0.36f, 1.f)); - } - if(transform->Velocity.z < m_maxspeed) - { - transform->Velocity.z += 100.f*dt; - if(transform->Velocity.z >= m_maxspeed) - transform->Velocity.z = m_maxspeed; - } - else if(transform->Velocity.z > m_maxspeed) - { - transform->Velocity.z -= 50.f*dt; - if(transform->Velocity.z <= m_maxspeed) - transform->Velocity.z = m_maxspeed; + auto parent = m_World->GetEntityParent(ent); + auto parentTransform = m_World->GetComponent(parent, "Transform"); + 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; + swooshSound->Pitch = 1.f - (glm::length(parentTransform->Scale) / 12.f) * 0.5f; + auto soundSystem = m_World->GetSystem("SoundSystem"); + soundSystem->PlaySound(swooshSound.get(), "Sounds/swoosh.wav"); + m_World->RemoveEntity(ent); } } + //powerup + for(auto ent : collision->CollidingEntities) + { + std::string name = m_World->GetProperty(ent, "Name"); + if(name == "PowerUp") + { + auto powerupComp = m_World->GetComponent(ent, "PowerUp"); + m_maxspeed = powerupComp->Speed; + m_PowerUpTotalDuration = powerupComp->Duration; + m_poweruptimeleft = powerupComp->Duration; + m_World->RemoveEntity(ent); + SetPlayerLightColor(entity, glm::vec3(0.0, 1.0, 0.0)); + auto soundSystem = m_World->GetSystem("SoundSystem"); + soundSystem->PlaySound(soundEmitter, "Sounds/boom.wav"); + } + } + + if(m_poweruptimeleft <= 0) + { + m_maxspeed = m_basespeed; + } + + if(transform->Velocity.z < m_maxspeed) + { + transform->Velocity.z += 100.f*dt; + if(transform->Velocity.z >= m_maxspeed) + transform->Velocity.z = m_maxspeed; + } + else if(transform->Velocity.z > m_maxspeed) + { + transform->Velocity.z -= 50.f*dt; + if(transform->Velocity.z <= m_maxspeed) + transform->Velocity.z = m_maxspeed; + } + + float percentage = m_poweruptimeleft / m_PowerUpTotalDuration; + SetPlayerLightColor(entity, glm::vec3(0.0, 1.0, 0.0) * percentage + (1.f - percentage) * glm::vec3(0.05f, 0.36f, 1.f)); + // Update camera if(! freecamEnabled) { + auto cameraEntity = m_World->GetProperty(entity, "Camera"); + auto cameraTransform = m_World->GetComponent(cameraEntity, "Transform"); if (cameraTransform) { cameraTransform->Position = transform->Position + m_CameraOffset; cameraTransform->Orientation = m_CameraOrientation; } - + auto cameracamera = m_World->GetComponent(cameraEntity, "Camera"); + cameracamera->FOV = glm::radians(45.f + transform->Velocity.z / 3.f); } // Update ground diff --git a/Escape-the-Dawn/Systems/PlayerSystem.h b/Escape-the-Dawn/Systems/PlayerSystem.h index 5ebd28c..84fee4d 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.h +++ b/Escape-the-Dawn/Systems/PlayerSystem.h @@ -41,6 +41,7 @@ namespace Systems float m_basespeed; float m_maxspeed; + float m_PowerUpTotalDuration; float m_poweruptimeleft; void SetPlayerLightColor(EntityID player, glm::vec3 color);