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 b06be45..81b327c 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 4589bfd..66f2174 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; @@ -18,7 +19,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) @@ -184,19 +188,14 @@ 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") - { auto deathSoundEntity = m_World->CreateEntity(ent); @@ -208,70 +207,79 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa auto deathSoundSystem = m_World->GetSystem("SoundSystem"); deathSoundSystem->PlaySound(deathSoundEmitter.get(), "Sounds/Explosion3.wav"); - m_World->RemoveEntity(entity); + m_World->RemoveEntity(entity); //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 - 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 9d37123..169a4d8 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.h +++ b/Escape-the-Dawn/Systems/PlayerSystem.h @@ -40,6 +40,7 @@ namespace Systems float m_basespeed; float m_maxspeed; + float m_PowerUpTotalDuration; float m_poweruptimeleft; void SetPlayerLightColor(EntityID player, glm::vec3 color);