From 53c7609e1103e97aff7f0cb2488221a008829eab Mon Sep 17 00:00:00 2001 From: Tobias Dahl Date: Thu, 13 Mar 2014 20:13:28 +0100 Subject: [PATCH 1/9] Smoothare acceleration --- Escape-the-Dawn/Systems/PlayerSystem.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 6e44d64..377c227 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -108,6 +108,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa } else { + transform->Position -= Ship_Right * (float)dt * Euler.z; if(Euler.z < 1.5f && Euler.z > -1.5f) transform->Orientation = glm::angleAxis(0,glm::vec3(0,0,1)); else if(Euler.z < 0.f) From 8f18fc87e3225e3560af89a91fbe77c65c02e375 Mon Sep 17 00:00:00 2001 From: Tobias Dahl Date: Thu, 13 Mar 2014 20:59:25 +0100 Subject: [PATCH 2/9] [WIP] Frames --- Escape-the-Dawn/Frame.cpp | 91 ++++++++++++++++++++++++++++------ Escape-the-Dawn/Frame.h | 23 +++++---- Escape-the-Dawn/GUIManager.cpp | 4 +- Escape-the-Dawn/GUIManager.h | 5 +- Escape-the-Dawn/Rectangle.h | 8 +++ 5 files changed, 103 insertions(+), 28 deletions(-) diff --git a/Escape-the-Dawn/Frame.cpp b/Escape-the-Dawn/Frame.cpp index bf996ed..1c3c753 100644 --- a/Escape-the-Dawn/Frame.cpp +++ b/Escape-the-Dawn/Frame.cpp @@ -3,51 +3,74 @@ GUI::Frame::Frame() { rectangle = new Rectangle(); + texture = nullptr; } int GUI::Frame::GetWidth() { - return rectangle; + return rectangle->Width(); } int GUI::Frame::GetHeight() { - return rectangle.Height(); + return rectangle->Height(); } int GUI::Frame::GetX() { - return rectangle; + return rectangle->X(); } int GUI::Frame::GetY() { - return rectangle.Y(); + return rectangle->Y(); } -void GUI::Frame::SetWidth(int wid) +int GUI::Frame::GetRight() { - rectangle.width(wid); + return rectangle->Right(); } -void GUI::Frame::SetHeight(int hei) +int GUI::Frame::GetLeft() { - rectangle.height(hei); + return rectangle->Left(); } -void GUI::Frame::SetX(int xcord) +int GUI::Frame::GetBottom() { - rectangle.X(xcord) + return rectangle->Bottom(); } -void GUI::Frame::SetY(int ycord) +int GUI::Frame::GetTop() { - rectangle.Y(ycord) + return rectangle->Right(); } +void GUI::Frame::SetWidth(int _width) +{ + rectangle->Width(_width); +} + +void GUI::Frame::SetHeight(int _height) +{ + rectangle->Height(_height); +} + +void GUI::Frame::SetX(int _x) +{ + rectangle->X(_x); +} + +void GUI::Frame::SetY(int _y) +{ + rectangle->Y(_y); +} + + + Rectangle GUI::Frame::AbsouluteRectangle() { - + } bool GUI::Frame::Visible() @@ -85,8 +108,48 @@ void GUI::Frame::Update(double dt) } +void AddChild(GUI::Frame childFrame) +{ + childFrame.Parent = this; + if (!Children.Contains(childFrame)) + Children.Add(childFrame); +} + +/// +/// Remove a child frame from the frame. +/// +/// The child frame to remove. +void RemoveChild(GUI::Frame childFrame) +{ + if (Children.Contains(childFrame)) + Children.Remove(childFrame); +} + +/// +/// Destroys the frame and all its children. +/// +void Destroy() +{ + if (Parent != null) + Parent.RemoveChild(this); + + Manager.Remove(this); +} + +void GUI::Frame::SetTexture(std::string fileName) +{ + //texture == någonTextureIDunno; +} + void GUI::Frame::Draw() { - + if (Visible) + { + if (texture != nullptr) + { + //Drawshit + } + } } + */ \ No newline at end of file diff --git a/Escape-the-Dawn/Frame.h b/Escape-the-Dawn/Frame.h index 2e9a3f4..69dd6d7 100644 --- a/Escape-the-Dawn/Frame.h +++ b/Escape-the-Dawn/Frame.h @@ -1,4 +1,4 @@ -/*#ifndef Frame_h__ +#ifndef Frame_h__ #define Frame_h__ #include @@ -7,7 +7,7 @@ #include "GUIManager.h" #include "Texture.h" #include "Color.h" -//#include "Camera.h" +#include "Camera.h" namespace GUI { @@ -22,14 +22,19 @@ public: int GetHeight(); int GetX(); int GetY(); - void SetWidth(int wid); - void SetHeight(int hei); - void SetX( int xcord); - void SetY(int ycord); + int GetRight(); + int GetLeft(); + int GetBottom(); + int GetTop(); + void SetWidth(int _width); + void SetHeight(int _height); + void SetX( int _x); + void SetY(int _y); + void SetTexture(std::string fileName); Rectangle *rectangle; Rectangle AbsouluteRectangle(); - Texture texture; - Color color; + Texture* texture; + Color* color; bool _Visible; bool Visible(); int layer; @@ -48,4 +53,4 @@ protected: }; } -#endif*/ \ No newline at end of file +#endif \ No newline at end of file diff --git a/Escape-the-Dawn/GUIManager.cpp b/Escape-the-Dawn/GUIManager.cpp index 40b50d3..4956638 100644 --- a/Escape-the-Dawn/GUIManager.cpp +++ b/Escape-the-Dawn/GUIManager.cpp @@ -2,7 +2,7 @@ int GUI::GUIManager::Add(Frame frame) { - //Frame.Add(frame); - //return CreateUID(); + Frame.Add(frame); + return CreateUID(); } */ \ No newline at end of file diff --git a/Escape-the-Dawn/GUIManager.h b/Escape-the-Dawn/GUIManager.h index 7b8434a..57b66a7 100644 --- a/Escape-the-Dawn/GUIManager.h +++ b/Escape-the-Dawn/GUIManager.h @@ -1,4 +1,4 @@ -/*#ifndef GUIManager_h__ +#ifndef GUIManager_h__ #define GUIManager_h__ #include "Frame.h" @@ -18,9 +18,8 @@ private: static int uidIndex; }; - } -#endif */ \ No newline at end of file +#endif \ No newline at end of file diff --git a/Escape-the-Dawn/Rectangle.h b/Escape-the-Dawn/Rectangle.h index 2f6d0cd..d866955 100644 --- a/Escape-the-Dawn/Rectangle.h +++ b/Escape-the-Dawn/Rectangle.h @@ -22,6 +22,14 @@ public: int Y() const { return y; } void Y(int val) { y = val; } + + int Left() const { return x; } + + int Right() const { return x+width; } + + int Top() const { return y; } + + int Bottom() const { return y+height; } }; Rectangle::Rectangle() From 329262fe5a3d30331bd66eeecb2acbf56a8d3072 Mon Sep 17 00:00:00 2001 From: Tobias Dahl Date: Thu, 13 Mar 2014 21:38:29 +0100 Subject: [PATCH 3/9] [WIP] Colliderar saker --- Escape-the-Dawn/Systems/PlayerSystem.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index a55bdf3..1327bce 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -26,6 +26,15 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa if (input == nullptr) return; + auto collision = m_World->GetComponent(entity, "Collision"); + if(collision == nullptr) + return; + + if(collision->CollidingEntities.size() > 0) + { + m_World->RemoveEntity(entity); + } + auto name = m_World->GetProperty(entity, "Name"); if (name == "Camera" && freecamEnabled) { glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); From 759302b789b3eb66a0e2fb848b2a0cf3719735aa Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Thu, 13 Mar 2014 21:42:28 +0100 Subject: [PATCH 4/9] Powerups --- Escape-the-Dawn/Systems/CollisionSystem.cpp | 4 +- .../Systems/LevelGenerationSystem.cpp | 47 +++++++++++-------- .../Systems/LevelGenerationSystem.h | 9 +--- Escape-the-Dawn/Systems/PlayerSystem.cpp | 17 +++++++ Escape-the-Dawn/Systems/PlayerSystem.h | 2 + 5 files changed, 49 insertions(+), 30 deletions(-) diff --git a/Escape-the-Dawn/Systems/CollisionSystem.cpp b/Escape-the-Dawn/Systems/CollisionSystem.cpp index ab91656..4bd04bf 100644 --- a/Escape-the-Dawn/Systems/CollisionSystem.cpp +++ b/Escape-the-Dawn/Systems/CollisionSystem.cpp @@ -85,8 +85,8 @@ void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity) if (aMin.x <= bMax.x && bMin.x <= aMax.x) { if (aMin.y <= bMax.y && bMin.y <= aMax.y) { if (aMin.z <= bMax.z && bMin.z <= aMax.z) { - aCollisionComponent->CollidingEntities.push_back(aEntity); - bCollisionComponent->CollidingEntities.push_back(bEntity); + aCollisionComponent->CollidingEntities.push_back(bEntity); + bCollisionComponent->CollidingEntities.push_back(aEntity); return; } } diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp index 05fcf0a..931d524 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp @@ -18,11 +18,11 @@ void Systems::LevelGenerationSystem::SpawnObstacle() ent = m_World->CreateEntity(); obstacles.push_back(ent); - m_World->SetProperty(ent, "Name", std::string("Obstacle")); - transform = m_World->AddComponent(ent, "Transform"); - bounds = m_World->AddComponent(ent, "Bounds"); - collision = m_World->AddComponent(ent, "Collision"); - model = m_World->AddComponent(ent, "Model"); + + 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"); @@ -37,6 +37,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle() if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D { + m_World->SetProperty(ent, "Name", std::string("Obstacle")); float scale = (float)(rand() % 1000) / 250; transform->Scale = glm::vec3(scale); bounds->VolumeVector = glm::vec3(9, 12, 7); @@ -45,6 +46,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle() } else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D { + m_World->SetProperty(ent, "Name", std::string("Obstacle")); float scale = (float)(rand() % 1000) / 200; transform->Scale = glm::vec3(scale); bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f); @@ -53,6 +55,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle() } else if(typeRandom >= 5 && typeRandom < 8) { + m_World->SetProperty(ent, "Name", std::string("Obstacle")); float scale = (float)(rand() % 1000) / 100; transform->Scale = glm::vec3(scale); bounds->VolumeVector = glm::vec3(1, 1, 1); @@ -61,13 +64,14 @@ void Systems::LevelGenerationSystem::SpawnObstacle() } if(typeRandom >= 8 && typeRandom < 10) { + m_World->SetProperty(ent, "Name", std::string("PowerUp")); float scale = (float)(rand() % 1000) / 100; bounds->VolumeVector = glm::vec3(4, 4, 4); bounds->Origin = glm::vec3(0,4,0); - powerUp = m_World->AddComponent(ent, "PowerUp"); - powerUp->Speed = 10.f; + auto powerUp = m_World->AddComponent(ent, "PowerUp"); + powerUp->Speed = 200.f; model->ModelFile = "Models/powerup.obj"; } @@ -88,24 +92,26 @@ void Systems::LevelGenerationSystem::Update( double dt ) elapsedtime = 0; } - std::list removethis; + for(auto ent : obstacles) { auto transform = m_World->GetComponent(ent, "Transform"); - - transform->Velocity.z = velocity; - transform->Position += transform->Velocity * (float)dt; - - // Stop raising obstacles when they reach ground level - if (transform->Velocity.y > 0 && transform->Position.y >= 0) { - transform->Position.y = 0; - transform->Velocity.y = 0; - } - - if(transform->Position.z > 800) + if(transform != nullptr) { - removethis.push_back(ent); + transform->Velocity.z = velocity; + transform->Position += transform->Velocity * (float)dt; + + // Stop raising obstacles when they reach ground level + if (transform->Velocity.y > 0 && transform->Position.y >= 0) { + transform->Position.y = 0; + transform->Velocity.y = 0; + } + + if(transform->Position.z > 800) + { + removethis.push_back(ent); + } } } @@ -123,6 +129,7 @@ void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, E if( m_World->GetProperty(entity, "Name") == "Player") { auto transformComponent = m_World->GetComponent(entity, "Transform"); + startyz = glm::vec2(0, transformComponent->Position.z - 1000); startx = transformComponent->Position.x; velocity = transformComponent->Velocity.z; diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.h b/Escape-the-Dawn/Systems/LevelGenerationSystem.h index 864c047..c51e0b9 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.h +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.h @@ -31,18 +31,11 @@ namespace Systems int positionRandom; glm::vec2 startyz; float startx; - + std::list removethis; double elapsedtime; std::list obstacles; float velocity; - - std::shared_ptr transform; - std::shared_ptr bounds; - std::shared_ptr collision; - std::shared_ptr model; - std::shared_ptr pointLight; - std::shared_ptr powerUp; }; } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 7dc1959..7e2cc5d 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -136,6 +136,23 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa else freecamEnabled = true; } + + //powerup + auto collisionComponent = m_World->GetComponent(entity, "Collision"); + for(auto ent : collisionComponent->CollidingEntities) + { + std::string name = m_World->GetProperty(ent, "Name"); + if(name == "PowerUp") + { + auto powerupComp = m_World->GetComponent(ent, "PowerUp"); + if(powerupComp != nullptr) + { + transform->Velocity.z = powerupComp->Speed; + m_World->RemoveEntity(ent); + } + } + } + // Update camera diff --git a/Escape-the-Dawn/Systems/PlayerSystem.h b/Escape-the-Dawn/Systems/PlayerSystem.h index 12ea648..2774565 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.h +++ b/Escape-the-Dawn/Systems/PlayerSystem.h @@ -9,6 +9,8 @@ #include "Components/Collision.h" #include "Components/Camera.h" #include "Components/Bounds.h" +#include "Components/PowerUp.h" + #include "logging.h" From e3153fe13012600c78437720611732e3d317888a Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Thu, 13 Mar 2014 21:50:53 +0100 Subject: [PATCH 5/9] freecamfixed --- Escape-the-Dawn/Systems/PlayerSystem.cpp | 94 +++++++++++++----------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 7e2cc5d..60f4971 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -27,47 +27,58 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa return; auto name = m_World->GetProperty(entity, "Name"); - if (name == "Camera" && freecamEnabled) { - glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); - glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation); - - float speed = m_PlayerSpeed; - if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) { - speed *= 4.0f; - } - if(input->KeyState[GLFW_KEY_LEFT_ALT]) { - speed /= 4.0f; - } - if(input->KeyState[GLFW_KEY_A]) { - transform->Position -= Camera_Right * (float)dt * speed; - } - else if(input->KeyState[GLFW_KEY_D]) { - transform->Position += Camera_Right * (float)dt * speed; - } - if(input->KeyState[GLFW_KEY_W]) { - transform->Position -= Camera_Forward * (float)dt * speed; - } - if(input->KeyState[GLFW_KEY_S]) { - transform->Position += Camera_Forward * (float)dt * speed; - } - if(input->KeyState[GLFW_KEY_SPACE]) { - transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed; - } - if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) { - transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed; - } - - if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) { - // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS - //--------------------------------------------------------------------- - transform->Orientation = glm::angleAxis(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation; - - transform->Orientation = transform->Orientation * glm::angleAxis(input->dX/300.f,glm::vec3(0,1,0)); - //--------------------------------------------------------------------- - // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS + if (name == "Camera") { + if(input->KeyState[GLFW_KEY_F4] && !input->LastKeyState[GLFW_KEY_F4]) { + if(freecamEnabled) + freecamEnabled = false; + else + freecamEnabled = true; } + if(freecamEnabled) + { + glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); + glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation); + + float speed = m_PlayerSpeed; + if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) { + speed *= 4.0f; + } + if(input->KeyState[GLFW_KEY_LEFT_ALT]) { + speed /= 4.0f; + } + if(input->KeyState[GLFW_KEY_A]) { + transform->Position -= Camera_Right * (float)dt * speed; + } + else if(input->KeyState[GLFW_KEY_D]) { + transform->Position += Camera_Right * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_W]) { + transform->Position -= Camera_Forward * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_S]) { + transform->Position += Camera_Forward * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_SPACE]) { + transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) { + transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed; + } + + if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) { + // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS + //--------------------------------------------------------------------- + transform->Orientation = glm::angleAxis(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation; + + transform->Orientation = transform->Orientation * glm::angleAxis(input->dX/300.f,glm::vec3(0,1,0)); + //--------------------------------------------------------------------- + // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS + } + } + } + if (name == "Player") { auto bounds = m_World->GetComponent(entity, "Bounds"); @@ -130,12 +141,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa } - if(input->KeyState[GLFW_KEY_F4] && !input->LastKeyState[GLFW_KEY_F4]) { - if(freecamEnabled) - freecamEnabled = false; - else - freecamEnabled = true; - } + //powerup auto collisionComponent = m_World->GetComponent(entity, "Collision"); From fe1605a15836af12fe3f3995e574a5632ff72af1 Mon Sep 17 00:00:00 2001 From: Tobias Dahl Date: Thu, 13 Mar 2014 22:00:34 +0100 Subject: [PATCH 6/9] [WIP] Saker --- Escape-the-Dawn/Systems/PlayerSystem.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index d57f403..53b327d 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -36,13 +36,16 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa } auto name = m_World->GetProperty(entity, "Name"); + if (name == "Camera") { + if(input->KeyState[GLFW_KEY_F4] && !input->LastKeyState[GLFW_KEY_F4]) { if(freecamEnabled) freecamEnabled = false; else freecamEnabled = true; } + if(freecamEnabled) { glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); From c53913f63b0cc6921548790c273c5d224cb3a55d Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Thu, 13 Mar 2014 22:13:59 +0100 Subject: [PATCH 7/9] Powerup timer fixed --- .../Systems/LevelGenerationSystem.cpp | 24 ++++++++++--------- Escape-the-Dawn/Systems/PlayerSystem.cpp | 24 ++++++++++++------- Escape-the-Dawn/Systems/PlayerSystem.h | 4 +++- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp index 931d524..90a20e9 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp @@ -99,19 +99,21 @@ void Systems::LevelGenerationSystem::Update( double dt ) auto transform = m_World->GetComponent(ent, "Transform"); if(transform != nullptr) { - transform->Velocity.z = velocity; - transform->Position += transform->Velocity * (float)dt; - // Stop raising obstacles when they reach ground level - if (transform->Velocity.y > 0 && transform->Position.y >= 0) { - transform->Position.y = 0; - transform->Velocity.y = 0; - } + + transform->Velocity.z = velocity; + transform->Position += transform->Velocity * (float)dt; - if(transform->Position.z > 800) - { - removethis.push_back(ent); - } + // Stop raising obstacles when they reach ground level + if (transform->Velocity.y > 0 && transform->Position.y >= 0) { + transform->Position.y = 0; + transform->Velocity.y = 0; + } + + if(transform->Position.z > 800) + { + removethis.push_back(ent); + } } } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 60f4971..201d423 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -9,12 +9,14 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world) m_CameraOffset = glm::vec3(0.f, 5.f, 14.f); m_CameraOrientation = glm::angleAxis(glm::radians(15.0f),glm::vec3(1,0,0)); - freecamEnabled = false; - + m_freecamEnabled = false; + m_poweruptimeleft = 0; + m_basespeed = 100.f; } void Systems::PlayerSystem::Update(double dt) { + m_poweruptimeleft -= (float)dt; } void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -29,12 +31,12 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa auto name = m_World->GetProperty(entity, "Name"); if (name == "Camera") { if(input->KeyState[GLFW_KEY_F4] && !input->LastKeyState[GLFW_KEY_F4]) { - if(freecamEnabled) - freecamEnabled = false; + if(m_freecamEnabled) + m_freecamEnabled = false; else - freecamEnabled = true; + m_freecamEnabled = true; } - if(freecamEnabled) + if(m_freecamEnabled) { glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation); @@ -154,15 +156,19 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa if(powerupComp != nullptr) { transform->Velocity.z = powerupComp->Speed; + m_poweruptimeleft = 3.f; m_World->RemoveEntity(ent); } } } - - + if(m_poweruptimeleft <= 0) + { + transform->Velocity.z = m_basespeed; + } + // Update camera - if(! freecamEnabled) + if(! m_freecamEnabled) { auto cameraEntity = m_World->GetProperty(entity, "Camera"); auto cameraTransform = m_World->GetComponent(cameraEntity, "Transform"); diff --git a/Escape-the-Dawn/Systems/PlayerSystem.h b/Escape-the-Dawn/Systems/PlayerSystem.h index 2774565..c008caa 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.h +++ b/Escape-the-Dawn/Systems/PlayerSystem.h @@ -33,7 +33,9 @@ namespace Systems glm::vec3 m_CameraOffset; glm::quat m_CameraOrientation; - bool freecamEnabled; + bool m_freecamEnabled; + float m_basespeed; + float m_poweruptimeleft; }; } From 70135463146bf4dad996e877de5f2c0c4d8d0276 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Thu, 13 Mar 2014 23:01:55 +0100 Subject: [PATCH 8/9] powerup bugfix --- .../Systems/LevelGenerationSystem.cpp | 53 ++++++++----------- .../Systems/LevelGenerationSystem.h | 3 -- Escape-the-Dawn/Systems/PlayerSystem.cpp | 10 ++-- 3 files changed, 25 insertions(+), 41 deletions(-) diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp index 90a20e9..92a4ab6 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp @@ -17,7 +17,6 @@ void Systems::LevelGenerationSystem::SpawnObstacle() EntityID ent; ent = m_World->CreateEntity(); - obstacles.push_back(ent); auto transform = m_World->AddComponent(ent, "Transform"); auto bounds = m_World->AddComponent(ent, "Bounds"); @@ -28,7 +27,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle() positionRandom = -500 + startx + (rand() % 1000); transform->Position = glm::vec3(positionRandom, startyz); - //transform->Velocity = glm::vec3(0.f, 10.f, 100.f); + transform->Velocity = glm::vec3(0.f, 10.f, 0); sound->Loop = true; sound->Gain = 1.f; @@ -78,7 +77,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle() // Put it below ground level - //transform->Position.y -= bounds->VolumeVector.y * 2.f; + transform->Position.y -= bounds->VolumeVector.y * 2.f; } @@ -94,40 +93,30 @@ void Systems::LevelGenerationSystem::Update( double dt ) - for(auto ent : obstacles) - { - auto transform = m_World->GetComponent(ent, "Transform"); - if(transform != nullptr) - { - - - transform->Velocity.z = velocity; - transform->Position += transform->Velocity * (float)dt; - - // Stop raising obstacles when they reach ground level - if (transform->Velocity.y > 0 && transform->Position.y >= 0) { - transform->Position.y = 0; - transform->Velocity.y = 0; - } - - if(transform->Position.z > 800) - { - removethis.push_back(ent); - } - } - } - - for(auto ent : removethis) - { - m_World->RemoveEntity(ent); - obstacles.remove(ent); - } - removethis.clear(); + } void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, EntityID parent ) { + if( m_World->GetProperty(entity, "Name") == "Obstacle" || m_World->GetProperty(entity, "Name") == "PowerUp") + { + auto transform = m_World->GetComponent(entity, "Transform"); + transform->Velocity.z = velocity; + transform->Position += transform->Velocity * (float)dt; + + // Stop raising obstacles when they reach ground level + if (transform->Velocity.y > 0 && transform->Position.y >= 0) + { + transform->Position.y = 0; + transform->Velocity.y = 0; + } + + if(transform->Position.z > 800) + m_World->RemoveEntity(entity); + + } + if( m_World->GetProperty(entity, "Name") == "Player") { auto transformComponent = m_World->GetComponent(entity, "Transform"); diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.h b/Escape-the-Dawn/Systems/LevelGenerationSystem.h index c51e0b9..ab02fe3 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.h +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.h @@ -31,10 +31,7 @@ namespace Systems int positionRandom; glm::vec2 startyz; float startx; - std::list removethis; double elapsedtime; - - std::list obstacles; float velocity; }; } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 201d423..fcbce85 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -153,18 +153,16 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa if(name == "PowerUp") { auto powerupComp = m_World->GetComponent(ent, "PowerUp"); - if(powerupComp != nullptr) - { - transform->Velocity.z = powerupComp->Speed; - m_poweruptimeleft = 3.f; - m_World->RemoveEntity(ent); - } + transform->Velocity.z = powerupComp->Speed; + m_poweruptimeleft = 3.f; + m_World->RemoveEntity(ent); } } if(m_poweruptimeleft <= 0) { transform->Velocity.z = m_basespeed; } + //fixa FOV // Update camera From 28b83905e995f916e81cdba5791b34f153fe5069 Mon Sep 17 00:00:00 2001 From: Tobias Dahl Date: Thu, 13 Mar 2014 23:02:08 +0100 Subject: [PATCH 9/9] [WIP] Collisions and sun stuff --- Escape-the-Dawn/Shaders/Fragment.glsl | 4 ++-- Escape-the-Dawn/Systems/PlayerSystem.cpp | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Escape-the-Dawn/Shaders/Fragment.glsl b/Escape-the-Dawn/Shaders/Fragment.glsl index a16878d..ca7ef0b 100644 --- a/Escape-the-Dawn/Shaders/Fragment.glsl +++ b/Escape-the-Dawn/Shaders/Fragment.glsl @@ -23,7 +23,7 @@ in VertexData { vec3 ShadowCoord; } Input; -vec3 scene_ambient = vec3(0.3); +vec3 scene_ambient = vec3(0.98f, 0.95f, 0.8f); out vec4 fragmentColor; @@ -54,7 +54,7 @@ void main() { float bias = 0.0005; vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy); if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1)) { - visibility = 0.5; + visibility = 0.3; } } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 53b327d..02878b0 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -27,15 +27,18 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa return; auto collision = m_World->GetComponent(entity, "Collision"); - if(collision == nullptr) - return; - - if(collision->CollidingEntities.size() > 0) - { - m_World->RemoveEntity(entity); - } auto name = m_World->GetProperty(entity, "Name"); + if(collision != nullptr) + { + for(auto ent : collision->CollidingEntities) + { + if(m_World->GetProperty(ent, "Name") == "Obstacle") + { + m_World->RemoveEntity(entity); + } + } + } if (name == "Camera") {