Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn

Conflicts:
	Escape-the-Dawn/Systems/LevelGenerationSystem.cpp
This commit is contained in:
2014-03-13 23:54:11 +01:00
11 changed files with 237 additions and 129 deletions
+76 -13
View File
@@ -3,48 +3,71 @@
GUI::Frame::Frame() GUI::Frame::Frame()
{ {
rectangle = new Rectangle(); rectangle = new Rectangle();
texture = nullptr;
} }
int GUI::Frame::GetWidth() int GUI::Frame::GetWidth()
{ {
return rectangle; return rectangle->Width();
} }
int GUI::Frame::GetHeight() int GUI::Frame::GetHeight()
{ {
return rectangle.Height(); return rectangle->Height();
} }
int GUI::Frame::GetX() int GUI::Frame::GetX()
{ {
return rectangle; return rectangle->X();
} }
int GUI::Frame::GetY() 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() Rectangle GUI::Frame::AbsouluteRectangle()
{ {
@@ -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);
}
/// <summary>
/// Remove a child frame from the frame.
/// </summary>
/// <param name="childFrame">The child frame to remove.</param>
void RemoveChild(GUI::Frame childFrame)
{
if (Children.Contains(childFrame))
Children.Remove(childFrame);
}
/// <summary>
/// Destroys the frame and all its children.
/// </summary>
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() void GUI::Frame::Draw()
{ {
if (Visible)
{
if (texture != nullptr)
{
//Drawshit
}
}
} }
*/ */
+14 -9
View File
@@ -1,4 +1,4 @@
/*#ifndef Frame_h__ #ifndef Frame_h__
#define Frame_h__ #define Frame_h__
#include <map> #include <map>
@@ -7,7 +7,7 @@
#include "GUIManager.h" #include "GUIManager.h"
#include "Texture.h" #include "Texture.h"
#include "Color.h" #include "Color.h"
//#include "Camera.h" #include "Camera.h"
namespace GUI namespace GUI
{ {
@@ -22,14 +22,19 @@ public:
int GetHeight(); int GetHeight();
int GetX(); int GetX();
int GetY(); int GetY();
void SetWidth(int wid); int GetRight();
void SetHeight(int hei); int GetLeft();
void SetX( int xcord); int GetBottom();
void SetY(int ycord); 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 *rectangle;
Rectangle AbsouluteRectangle(); Rectangle AbsouluteRectangle();
Texture texture; Texture* texture;
Color color; Color* color;
bool _Visible; bool _Visible;
bool Visible(); bool Visible();
int layer; int layer;
@@ -48,4 +53,4 @@ protected:
}; };
} }
#endif*/ #endif
+2 -2
View File
@@ -2,7 +2,7 @@
int GUI::GUIManager::Add(Frame frame) int GUI::GUIManager::Add(Frame frame)
{ {
//Frame.Add(frame); Frame.Add(frame);
//return CreateUID(); return CreateUID();
} }
*/ */
+2 -3
View File
@@ -1,4 +1,4 @@
/*#ifndef GUIManager_h__ #ifndef GUIManager_h__
#define GUIManager_h__ #define GUIManager_h__
#include "Frame.h" #include "Frame.h"
@@ -18,9 +18,8 @@ private:
static int uidIndex; static int uidIndex;
}; };
} }
#endif */ #endif
+8
View File
@@ -22,6 +22,14 @@ public:
int Y() const { return y; } int Y() const { return y; }
void Y(int val) { y = val; } 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() Rectangle::Rectangle()
+2 -2
View File
@@ -23,7 +23,7 @@ in VertexData {
vec3 ShadowCoord; vec3 ShadowCoord;
} Input; } Input;
vec3 scene_ambient = vec3(0.3); vec3 scene_ambient = vec3(0.98f, 0.95f, 0.8f);
out vec4 fragmentColor; out vec4 fragmentColor;
@@ -54,7 +54,7 @@ void main() {
float bias = 0.0005; float bias = 0.0005;
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy); vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1)) { if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1)) {
visibility = 0.5; visibility = 0.3;
} }
} }
+2 -2
View File
@@ -85,8 +85,8 @@ void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
if (aMin.x <= bMax.x && bMin.x <= aMax.x) { if (aMin.x <= bMax.x && bMin.x <= aMax.x) {
if (aMin.y <= bMax.y && bMin.y <= aMax.y) { if (aMin.y <= bMax.y && bMin.y <= aMax.y) {
if (aMin.z <= bMax.z && bMin.z <= aMax.z) { if (aMin.z <= bMax.z && bMin.z <= aMax.z) {
aCollisionComponent->CollidingEntities.push_back(aEntity); aCollisionComponent->CollidingEntities.push_back(bEntity);
bCollisionComponent->CollidingEntities.push_back(bEntity); bCollisionComponent->CollidingEntities.push_back(aEntity);
return; return;
} }
} }
@@ -17,18 +17,17 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
EntityID ent; EntityID ent;
ent = m_World->CreateEntity(); ent = m_World->CreateEntity();
obstacles.push_back(ent);
m_World->SetProperty(ent, "Name", std::string("Obstacle")); auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
transform = m_World->AddComponent<Components::Transform>(ent, "Transform"); auto bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds"); auto collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
collision = m_World->AddComponent<Components::Collision>(ent, "Collision"); auto model = m_World->AddComponent<Components::Model>(ent, "Model");
model = m_World->AddComponent<Components::Model>(ent, "Model");
auto sound = m_World->AddComponent<Components::SoundEmitter>(ent, "SoundEmitter"); auto sound = m_World->AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
positionRandom = -500 + startx + (rand() % 1000); positionRandom = -500 + startx + (rand() % 1000);
transform->Position = glm::vec3(positionRandom, startyz); 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->Loop = true;
sound->Gain = 1.f; sound->Gain = 1.f;
@@ -37,6 +36,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D
{ {
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = (float)(rand() % 1000) / 250; float scale = (float)(rand() % 1000) / 250;
transform->Scale = glm::vec3(scale); transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(9, 12, 7); bounds->VolumeVector = glm::vec3(9, 12, 7);
@@ -45,6 +45,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
} }
else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D
{ {
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = (float)(rand() % 1000) / 200; float scale = (float)(rand() % 1000) / 200;
transform->Scale = glm::vec3(scale); transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f); bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
@@ -53,6 +54,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
} }
else if(typeRandom >= 5 && typeRandom < 8) else if(typeRandom >= 5 && typeRandom < 8)
{ {
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = (float)(rand() % 1000) / 100; float scale = (float)(rand() % 1000) / 100;
transform->Scale = glm::vec3(scale); transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(1, 1, 1); bounds->VolumeVector = glm::vec3(1, 1, 1);
@@ -61,20 +63,21 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
} }
if(typeRandom >= 8 && typeRandom < 10) if(typeRandom >= 8 && typeRandom < 10)
{ {
m_World->SetProperty(ent, "Name", std::string("PowerUp"));
float scale = (float)(rand() % 1000) / 100; float scale = (float)(rand() % 1000) / 100;
bounds->VolumeVector = glm::vec3(4, 4, 4); bounds->VolumeVector = glm::vec3(4, 4, 4);
bounds->Origin = glm::vec3(0,4,0); bounds->Origin = glm::vec3(0,4,0);
powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp"); auto powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
powerUp->Speed = 10.f; powerUp->Speed = 200.f;
model->ModelFile = "Models/powerup.obj"; model->ModelFile = "Models/powerup.obj";
} }
// Put it below ground level // Put it below ground level
//transform->Position.y -= bounds->VolumeVector.y * 2.f; transform->Position.y -= bounds->VolumeVector.y * 2.f;
} }
@@ -88,47 +91,40 @@ void Systems::LevelGenerationSystem::Update( double dt )
elapsedtime = 0; elapsedtime = 0;
} }
std::list<EntityID> removethis;
for(auto ent : obstacles)
{
auto transform = m_World->GetComponent<Components::Transform>(ent, "Transform");
auto model = m_World->GetComponent<Components::Model>(ent, "Model");
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 > 10 && model->Visible)
{
model->Visible = false;
}
if(transform->Position.z > 2000)
{
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 ) void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
{ {
if( m_World->GetProperty<std::string>(entity, "Name") == "Obstacle" || m_World->GetProperty<std::string>(entity, "Name") == "PowerUp")
{
auto transform = m_World->GetComponent<Components::Transform>(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;
}
auto model = m_World->GetComponent<Components::Model>(entity, "Model");
if (transform->Position.z > 10 && model->Visible)
{
model->Visible = false;
}
if(transform->Position.z > 800) {
m_World->RemoveEntity(entity);
}
}
if( m_World->GetProperty<std::string>(entity, "Name") == "Player") if( m_World->GetProperty<std::string>(entity, "Name") == "Player")
{ {
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform"); auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
startyz = glm::vec2(0, transformComponent->Position.z - 1000); startyz = glm::vec2(0, transformComponent->Position.z - 1000);
startx = transformComponent->Position.x; startx = transformComponent->Position.x;
velocity = transformComponent->Velocity.z; velocity = transformComponent->Velocity.z;
@@ -31,18 +31,8 @@ namespace Systems
int positionRandom; int positionRandom;
glm::vec2 startyz; glm::vec2 startyz;
float startx; float startx;
double elapsedtime; double elapsedtime;
std::list<EntityID> obstacles;
float velocity; float velocity;
std::shared_ptr<Components::Transform> transform;
std::shared_ptr<Components::Bounds> bounds;
std::shared_ptr<Components::Collision> collision;
std::shared_ptr<Components::Model> model;
std::shared_ptr<Components::PointLight> pointLight;
std::shared_ptr<Components::PowerUp> powerUp;
}; };
} }
+87 -44
View File
@@ -10,11 +10,13 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
m_CameraOrientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0)); m_CameraOrientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
freecamEnabled = false; freecamEnabled = false;
m_poweruptimeleft = 0;
m_basespeed = 100.f;
} }
void Systems::PlayerSystem::Update(double dt) void Systems::PlayerSystem::Update(double dt)
{ {
m_poweruptimeleft -= (float)dt;
} }
void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
@@ -26,48 +28,74 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
if (input == nullptr) if (input == nullptr)
return; return;
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
auto name = m_World->GetProperty<std::string>(entity, "Name"); auto name = m_World->GetProperty<std::string>(entity, "Name");
if (name == "Camera" && freecamEnabled) { if(collision != nullptr)
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); for(auto ent : collision->CollidingEntities)
{
float speed = m_PlayerSpeed; if(m_World->GetProperty<std::string>(ent, "Name") == "Obstacle")
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) { {
speed *= 4.0f; m_World->RemoveEntity(entity);
} }
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<float>(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation;
transform->Orientation = transform->Orientation * glm::angleAxis<float>(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<float>(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation;
transform->Orientation = transform->Orientation * glm::angleAxis<float>(input->dX/300.f,glm::vec3(0,1,0));
//---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
}
}
}
if (name == "Player") if (name == "Player")
{ {
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds"); auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
@@ -115,6 +143,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
} }
else else
{ {
transform->Position -= Ship_Right * (float)dt * Euler.z;
if(Euler.z < 1.5f && Euler.z > -1.5f) if(Euler.z < 1.5f && Euler.z > -1.5f)
transform->Orientation = glm::angleAxis<float>(0,glm::vec3(0,0,1)); transform->Orientation = glm::angleAxis<float>(0,glm::vec3(0,0,1));
else if(Euler.z < 0.f) else if(Euler.z < 0.f)
@@ -130,12 +159,26 @@ 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; //powerup
else auto collisionComponent = m_World->GetComponent<Components::Collision>(entity, "Collision");
freecamEnabled = true; for(auto ent : collisionComponent->CollidingEntities)
{
std::string name = m_World->GetProperty<std::string>(ent, "Name");
if(name == "PowerUp")
{
auto powerupComp = m_World->GetComponent<Components::PowerUp>(ent, "PowerUp");
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 // Update camera
+4
View File
@@ -9,6 +9,8 @@
#include "Components/Collision.h" #include "Components/Collision.h"
#include "Components/Camera.h" #include "Components/Camera.h"
#include "Components/Bounds.h" #include "Components/Bounds.h"
#include "Components/PowerUp.h"
#include "logging.h" #include "logging.h"
@@ -32,6 +34,8 @@ namespace Systems
glm::quat m_CameraOrientation; glm::quat m_CameraOrientation;
bool freecamEnabled; bool freecamEnabled;
float m_basespeed;
float m_poweruptimeleft;
}; };
} }