Fulhack.
This commit is contained in:
@@ -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<Systems::SoundSystem>("SoundSystem")->PlaySound(sound, "Sounds/hum.wav");
|
||||
sound->MaxDistance = 2.f;
|
||||
sound->ReferenceDistance = 1.f;
|
||||
m_World->GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(sound.get(), "Sounds/hum.wav");
|
||||
|
||||
if(typeRandom >= 0 && typeRandom < 1) // Mountain stuff :D
|
||||
{
|
||||
|
||||
@@ -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<Components::Collision>(entity, "Collision");
|
||||
|
||||
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
||||
if(collision != nullptr)
|
||||
{
|
||||
for(auto ent : collision->CollidingEntities)
|
||||
|
||||
if (name == "Sun") {
|
||||
auto light = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
|
||||
|
||||
if (input->KeyState[GLFW_KEY_KP_ADD])
|
||||
{
|
||||
if(m_World->GetProperty<std::string>(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<Components::SoundEmitter>(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<EntityID>(entity, "Camera");
|
||||
auto cameracamera = m_World->GetComponent<Components::Camera>(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<Components::Collision>(entity, "Collision");
|
||||
for(auto ent : collisionComponent->CollidingEntities)
|
||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
if(collision != nullptr)
|
||||
{
|
||||
std::string name = m_World->GetProperty<std::string>(ent, "Name");
|
||||
if(name == "PowerUp")
|
||||
// Obstacle collision
|
||||
for(auto ent : collision->CollidingEntities)
|
||||
{
|
||||
auto powerupComp = m_World->GetComponent<Components::PowerUp>(ent, "PowerUp");
|
||||
m_maxspeed = powerupComp->Speed;
|
||||
m_poweruptimeleft = 5.f;
|
||||
m_World->RemoveEntity(ent);
|
||||
|
||||
if(m_World->GetProperty<std::string>(ent, "Name") == "Obstacle")
|
||||
{
|
||||
m_World->RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
//powerup
|
||||
for(auto ent : collision->CollidingEntities)
|
||||
{
|
||||
std::string name = m_World->GetProperty<std::string>(ent, "Name");
|
||||
if(name == "PowerUp")
|
||||
{
|
||||
auto powerupComp = m_World->GetComponent<Components::PowerUp>(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<Systems::SoundSystem>("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<EntityID>(entity, "Ground");
|
||||
if (m_World->ValidEntity(groundEntity)) {
|
||||
auto groundTransform = m_World->GetComponent<Components::Transform>(groundEntity, "Transform");
|
||||
groundTransform->Position.x = transform->Position.x;
|
||||
}
|
||||
|
||||
// Update Sun
|
||||
auto sunEntity = m_World->GetProperty<EntityID>(entity, "Sun");
|
||||
if (m_World->ValidEntity(sunEntity)) {
|
||||
auto sunTransform = m_World->GetComponent<Components::Transform>(sunEntity, "Transform");
|
||||
sunTransform->Position.x = transform->Position.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::PlayerSystem::SetPlayerLightColor(EntityID player, glm::vec3 color)
|
||||
{
|
||||
auto light1 = m_World->GetProperty<EntityID>(player, "LightLeft");
|
||||
auto light2 = m_World->GetProperty<EntityID>(player, "LightRight");
|
||||
|
||||
auto lightComponent1 = m_World->GetComponent<Components::PointLight>(light1, "PointLight");
|
||||
auto lightComponent2 = m_World->GetComponent<Components::PointLight>(light2, "PointLight");
|
||||
|
||||
lightComponent1->Diffuse = color;
|
||||
lightComponent2->Diffuse = color;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
#include <array>
|
||||
|
||||
#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);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
void PlaySound(std::shared_ptr<Components::SoundEmitter> 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<Components::SoundEmitter> emitter); // Use if you want to play .wav file from component // imon no hate plx T.T
|
||||
void StopSound(std::shared_ptr<Components::SoundEmitter> emitter);
|
||||
|
||||
|
||||
@@ -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<Components::SoundEmitter> 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<Components::SoundEmitter> emitter)
|
||||
|
||||
Reference in New Issue
Block a user