diff --git a/Escape-the-Dawn/Components/Input.h b/Escape-the-Dawn/Components/Input.h index a565d47..b1c11b5 100644 --- a/Escape-the-Dawn/Components/Input.h +++ b/Escape-the-Dawn/Components/Input.h @@ -17,6 +17,7 @@ struct Input : Component std::array MouseState; std::array LastMouseState; float dX, dY; + float WheelDelta; }; } diff --git a/Escape-the-Dawn/Components/SoundEmitter.h b/Escape-the-Dawn/Components/SoundEmitter.h index d325dac..8e471d5 100644 --- a/Escape-the-Dawn/Components/SoundEmitter.h +++ b/Escape-the-Dawn/Components/SoundEmitter.h @@ -11,7 +11,7 @@ namespace Components struct SoundEmitter : Component { float Gain; - //float MaxDistance; + float MaxDistance; float ReferenceDistance; float Pitch; bool Loop; diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj b/Escape-the-Dawn/Escape-the-Dawn.vcxproj index 7fd3220..f5ecc5c 100644 --- a/Escape-the-Dawn/Escape-the-Dawn.vcxproj +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj @@ -82,7 +82,7 @@ MaxSpeed true true - GLEW_STATIC;DEBUG;%(PreprocessorDefinitions) + GLEW_STATIC;%(PreprocessorDefinitions) NotUsing ProgramDatabase true diff --git a/Escape-the-Dawn/GameWorld.cpp b/Escape-the-Dawn/GameWorld.cpp index 205148b..495ff02 100644 --- a/Escape-the-Dawn/GameWorld.cpp +++ b/Escape-the-Dawn/GameWorld.cpp @@ -39,26 +39,26 @@ void GameWorld::Initialize() pointLight->spotExponent = 0.0f; model = AddComponent(ent, "Model"); model->ModelFile = "Models/sphere.obj";*/ - ent = CreateEntity(); - SetProperty(ent, "Name", std::string("Sun")); - transform = AddComponent(ent, "Transform"); + auto sun = CreateEntity(); + SetProperty(sun, "Name", std::string("Sun")); + transform = AddComponent(sun, "Transform"); transform->Position = glm::vec3(0.f, 100.f, 30.f); - AddComponent(ent, "Input"); - pointLight = AddComponent(ent, "PointLight"); + AddComponent(sun, "Input"); + pointLight = AddComponent(sun, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); pointLight->Diffuse = glm::vec3(1.0, 0.45, 0.0); pointLight->constantAttenuation = 0.009f; pointLight->linearAttenuation = -0.0177f; pointLight->quadraticAttenuation = 0.00043f; pointLight->spotExponent = 0.0f; - model = AddComponent(ent, "Model"); + model = AddComponent(sun, "Model"); model->ModelFile = "Models/sphere.obj"; //ground - ent = CreateEntity(); - transform = AddComponent(ent, "Transform"); + auto ground = CreateEntity(); + transform = AddComponent(ground, "Transform"); transform->Position = glm::vec3(0.f, 0.f, 0.f); - model = AddComponent(ent, "Model"); + model = AddComponent(ground, "Model"); model->ModelFile = "Models/plane.obj"; // Camera @@ -77,6 +77,8 @@ void GameWorld::Initialize() m_Player = CreateEntity(); SetProperty(m_Player, "Name", std::string("Player")); SetProperty(m_Player, "Camera", entcamera); + SetProperty(m_Player, "Ground", ground); + SetProperty(m_Player, "Sun", sun); transform = AddComponent(m_Player, "Transform"); transform->Position = glm::vec3(0.f, 2.f, -5.f); transform->Velocity = glm::vec3(10.f, 0.f, 100.f); @@ -89,9 +91,12 @@ void GameWorld::Initialize() collision->Interested = true; bounds = AddComponent(m_Player, "Bounds"); bounds->Origin = glm::vec3(0, 0, 2.f); - bounds->VolumeVector = glm::vec3(3.4f, 0.7f, 1); + bounds->VolumeVector = glm::vec3(2.7f, 0.7f, 1); + soundEmitter = AddComponent(m_Player, "SoundEmitter"); + soundEmitter->Gain = 2.5f; // Player light auto playerLight = CreateEntity(m_Player); + SetProperty(m_Player, "LightLeft", playerLight); transform = AddComponent(playerLight, "Transform"); transform->Position = glm::vec3(1.5f, 0.25f, 2.5f); pointLight = AddComponent(playerLight, "PointLight"); @@ -104,6 +109,7 @@ void GameWorld::Initialize() bounds = AddComponent(playerLight, "Bounds"); bounds->VolumeVector = glm::vec3(0.5f); playerLight = CreateEntity(m_Player); + SetProperty(m_Player, "LightRight", playerLight); transform = AddComponent(playerLight, "Transform"); transform->Position = glm::vec3(-1.5f, 0.25f, 2.5f); pointLight = AddComponent(playerLight, "PointLight"); diff --git a/Escape-the-Dawn/Sounds/boom.wav b/Escape-the-Dawn/Sounds/boom.wav new file mode 100644 index 0000000..c59ceeb Binary files /dev/null and b/Escape-the-Dawn/Sounds/boom.wav differ diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp index de4e695..1bd30ab 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp @@ -7,7 +7,7 @@ Systems::LevelGenerationSystem::LevelGenerationSystem( World* world ) velocity = 0; startx = 0; - startyz = glm::vec2(0, -1000); + startyz = glm::vec2(0, -1500); spawnFrequency = 0.1f; } @@ -31,8 +31,9 @@ void Systems::LevelGenerationSystem::SpawnObstacle() sound->Loop = true; sound->Gain = 1.f; - sound->ReferenceDistance = 0.5f; - m_World->GetSystem("SoundSystem")->PlaySound(sound, "Sounds/hum.wav"); + sound->MaxDistance = 2.f; + sound->ReferenceDistance = 1.f; + m_World->GetSystem("SoundSystem")->PlaySound(sound.get(), "Sounds/hum.wav"); if(typeRandom >= 0 && typeRandom < 1) // Mountain stuff :D { diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 96cbc8f..eba8ad9 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -3,7 +3,7 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world) { - m_PlayerSpeed = 20; + m_PlayerSpeed = 35; m_PlayerOriginalBounds = glm::vec3(0); m_CameraOffset = glm::vec3(0.f, 5.f, 14.f); @@ -11,8 +11,8 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world) freecamEnabled = false; m_poweruptimeleft = 0; - m_basespeed = 100.f; - m_maxspeed = 100.f; + m_basespeed = 125.f; + m_maxspeed = 125.f; } void Systems::PlayerSystem::Update(double dt) @@ -29,18 +29,40 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa if (input == nullptr) return; - auto collision = m_World->GetComponent(entity, "Collision"); - auto name = m_World->GetProperty(entity, "Name"); - if(collision != nullptr) - { - for(auto ent : collision->CollidingEntities) + + if (name == "Sun") { + auto light = m_World->GetComponent(entity, "PointLight"); + + if (input->KeyState[GLFW_KEY_KP_ADD]) { - if(m_World->GetProperty(ent, "Name") == "Obstacle") - { - m_World->RemoveEntity(entity); + if (input->KeyState[GLFW_KEY_1]) { + light->constantAttenuation += 0.001; + } + if (input->KeyState[GLFW_KEY_2]) { + light->linearAttenuation += 0.001; + } + if (input->KeyState[GLFW_KEY_3]) { + light->quadraticAttenuation += 0.00001; } } + if (input->KeyState[GLFW_KEY_KP_SUBTRACT]) + { + if (input->KeyState[GLFW_KEY_1]) { + light->constantAttenuation -= 0.001; + + } + if (input->KeyState[GLFW_KEY_2]) { + light->linearAttenuation -= 0.001; + + } + if (input->KeyState[GLFW_KEY_3]) { + light->quadraticAttenuation -= 0.00001; + + } + } + + LOG_DEBUG("Constant: %f\nLinear: %f\nQuadratic: %f", light->constantAttenuation, light->linearAttenuation, light->quadraticAttenuation); } if (name == "Camera") { @@ -104,12 +126,15 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa m_PlayerOriginalBounds = bounds->VolumeVector; } + auto soundEmitter = m_World->GetComponent(entity, "SoundEmitter"); + glm::vec3 Ship_Right = glm::vec3(glm::vec4(1, 0, 0, 0)); glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 0)); float TurnSpeed = 1.0f; glm::vec3 Euler = glm::degrees(glm::eulerAngles(transform->Orientation)); + // Controls if(input->KeyState[GLFW_KEY_LEFT]) { transform->Position -= Ship_Right * (float)dt * (m_PlayerSpeed + Euler.z); @@ -158,46 +183,56 @@ 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)); } - - - - //powerup auto cameraEntity = m_World->GetProperty(entity, "Camera"); auto cameracamera = m_World->GetComponent(cameraEntity, "Camera"); - cameracamera->FOV = glm::radians(20.f + transform->Velocity.z/3 ); + cameracamera->FOV = glm::radians(45.f + transform->Velocity.z/3.f ); - auto collisionComponent = m_World->GetComponent(entity, "Collision"); - for(auto ent : collisionComponent->CollidingEntities) + auto collision = m_World->GetComponent(entity, "Collision"); + if(collision != nullptr) { - std::string name = m_World->GetProperty(ent, "Name"); - if(name == "PowerUp") + // Obstacle collision + for(auto ent : collision->CollidingEntities) { - auto powerupComp = m_World->GetComponent(ent, "PowerUp"); - m_maxspeed = powerupComp->Speed; - m_poweruptimeleft = 5.f; - m_World->RemoveEntity(ent); - + if(m_World->GetProperty(ent, "Name") == "Obstacle") + { + m_World->RemoveEntity(entity); + } + } + + //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_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; } } - 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; - } - - // Update camera if(! freecamEnabled) @@ -210,6 +245,32 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa } + + // Update ground + auto groundEntity = m_World->GetProperty(entity, "Ground"); + if (m_World->ValidEntity(groundEntity)) { + auto groundTransform = m_World->GetComponent(groundEntity, "Transform"); + groundTransform->Position.x = transform->Position.x; + } + + // Update Sun + auto sunEntity = m_World->GetProperty(entity, "Sun"); + if (m_World->ValidEntity(sunEntity)) { + auto sunTransform = m_World->GetComponent(sunEntity, "Transform"); + sunTransform->Position.x = transform->Position.x; + } } } +void Systems::PlayerSystem::SetPlayerLightColor(EntityID player, glm::vec3 color) +{ + auto light1 = m_World->GetProperty(player, "LightLeft"); + auto light2 = m_World->GetProperty(player, "LightRight"); + + auto lightComponent1 = m_World->GetComponent(light1, "PointLight"); + auto lightComponent2 = m_World->GetComponent(light2, "PointLight"); + + lightComponent1->Diffuse = color; + lightComponent2->Diffuse = color; +} + diff --git a/Escape-the-Dawn/Systems/PlayerSystem.h b/Escape-the-Dawn/Systems/PlayerSystem.h index 993ee20..5ebd28c 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.h +++ b/Escape-the-Dawn/Systems/PlayerSystem.h @@ -4,12 +4,15 @@ #include #include "System.h" +#include "Systems/SoundSystem.h" #include "Components/Transform.h" #include "Components/Input.h" #include "Components/Collision.h" #include "Components/Camera.h" #include "Components/Bounds.h" #include "Components/PowerUp.h" +#include "Components/PointLight.h" +#include "Components/SoundEmitter.h" #include "logging.h" @@ -39,6 +42,9 @@ namespace Systems float m_maxspeed; float m_poweruptimeleft; + + void SetPlayerLightColor(EntityID player, glm::vec3 color); + }; } diff --git a/Escape-the-Dawn/Systems/SoundSystem.h b/Escape-the-Dawn/Systems/SoundSystem.h index 07142f1..33b51d9 100644 --- a/Escape-the-Dawn/Systems/SoundSystem.h +++ b/Escape-the-Dawn/Systems/SoundSystem.h @@ -20,7 +20,7 @@ public: void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void OnComponentCreated(std::string type, std::shared_ptr component) override; void OnComponentRemoved(std::string type, Component* component) override; - void PlaySound(std::shared_ptr emitter, std::string path); // Use if you want to play a temporary .wav file not from component + void PlaySound(Components::SoundEmitter* emitter, std::string path); // Use if you want to play a temporary .wav file not from component void PlaySound(std::shared_ptr emitter); // Use if you want to play .wav file from component // imon no hate plx T.T void StopSound(std::shared_ptr emitter); diff --git a/Escape-the-Dawn/Systems/SoundsSystem.cpp b/Escape-the-Dawn/Systems/SoundsSystem.cpp index 8e1f6ed..864bff5 100644 --- a/Escape-the-Dawn/Systems/SoundsSystem.cpp +++ b/Escape-the-Dawn/Systems/SoundsSystem.cpp @@ -20,7 +20,7 @@ Systems::SoundSystem::SoundSystem(World* world) alGetError(); alSpeedOfSound(340.29f); // Speed of sound - alDistanceModel(AL_INVERSE_DISTANCE); + alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); } void Systems::SoundSystem::Update(double dt) @@ -75,15 +75,15 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par } } -void Systems::SoundSystem::PlaySound(std::shared_ptr emitter, std::string fileName) +void Systems::SoundSystem::PlaySound(Components::SoundEmitter* emitter, std::string fileName) { - if (m_Sources.find(emitter.get()) == m_Sources.end()) + if (m_Sources.find(emitter) == m_Sources.end()) return; ALuint buffer = LoadFile(fileName); - ALuint source = m_Sources[emitter.get()]; + ALuint source = m_Sources[emitter]; alSourcei(source, AL_BUFFER, buffer); - alSourcePlay(m_Sources[emitter.get()]); + alSourcePlay(m_Sources[emitter]); } void Systems::SoundSystem::PlaySound(std::shared_ptr emitter)