Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
Conflicts: Escape-the-Dawn/GameWorld.cpp
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
#include "LevelGenerationSystem.h"
|
||||
|
||||
Systems::LevelGenerationSystem::LevelGenerationSystem( World* world )
|
||||
: System(world)
|
||||
{
|
||||
elapsedtime = 0;
|
||||
startyz = glm::vec2(0, -1000);
|
||||
}
|
||||
|
||||
void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||
{
|
||||
|
||||
|
||||
|
||||
typeRandom = 0 + (rand() % 3);
|
||||
|
||||
|
||||
EntityID ent;
|
||||
|
||||
ent = m_World->CreateEntity();
|
||||
obstacles.push_back(ent);
|
||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||
transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
|
||||
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
|
||||
collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
|
||||
model = m_World->AddComponent<Components::Model>(ent, "Model");
|
||||
|
||||
positionRandom = -500 + (rand() % 1000);
|
||||
|
||||
switch (typeRandom)
|
||||
{
|
||||
case 0:
|
||||
transform->Position = glm::vec3( positionRandom, startyz); // fix position
|
||||
bounds->VolumeVector = glm::vec3(9, 12, 7);
|
||||
bounds->Origin = glm::vec3(1,11,-1);
|
||||
model->ModelFile = "Models/obstacle_mountain_1.obj";
|
||||
|
||||
break;
|
||||
case 1:
|
||||
transform->Position = glm::vec3( positionRandom, startyz); // fix position
|
||||
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
|
||||
bounds->Origin = glm::vec3(0,7.5f,0);
|
||||
model->ModelFile = "Models/obstacle_mountain_2.obj";
|
||||
|
||||
break;
|
||||
case 2:
|
||||
transform->Position = glm::vec3( positionRandom, startyz); // fix position
|
||||
bounds->VolumeVector = glm::vec3(1, 1, 1);
|
||||
bounds->Origin = glm::vec3(0,1,0);
|
||||
model->ModelFile = "Models/obstacle_cube_1.obj";
|
||||
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Systems::LevelGenerationSystem::Update( double dt )
|
||||
{
|
||||
|
||||
elapsedtime += dt;
|
||||
|
||||
if(elapsedtime > 0.1){
|
||||
SpawnObstacle();
|
||||
elapsedtime = 0;
|
||||
}
|
||||
|
||||
std::vector<EntityID> removethis;
|
||||
|
||||
for(auto ent : obstacles)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
||||
transformComponent->Position.z += 100.f * dt;
|
||||
|
||||
if(transformComponent->Position.z > 100)
|
||||
{
|
||||
removethis.push_back(ent);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for(auto ent : removethis)
|
||||
{
|
||||
m_World->RemoveEntity(ent);
|
||||
obstacles.remove(ent);
|
||||
}
|
||||
removethis.clear();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef LevelGenerationSystem_h__
|
||||
#define LevelGenerationSystem_h__
|
||||
|
||||
#include "System.h"
|
||||
#include "World.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/Model.h"
|
||||
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
class LevelGenerationSystem : public System
|
||||
{
|
||||
public:
|
||||
LevelGenerationSystem(World* world);
|
||||
|
||||
|
||||
void SpawnObstacle();
|
||||
|
||||
void Update(double dt) override;
|
||||
|
||||
private:
|
||||
int typeRandom;
|
||||
int positionRandom;
|
||||
glm::vec2 startyz;
|
||||
double elapsedtime;
|
||||
|
||||
std::list<EntityID> obstacles;
|
||||
|
||||
|
||||
std::shared_ptr<Components::Transform> transform;
|
||||
std::shared_ptr<Components::Bounds> bounds;
|
||||
std::shared_ptr<Components::Collision> collision;
|
||||
std::shared_ptr<Components::Model> model;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // LevelGenerationSystem_h__
|
||||
@@ -18,7 +18,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
if (input == nullptr)
|
||||
return;
|
||||
|
||||
float speed = 10.0f;
|
||||
float speed = 20.0f;
|
||||
|
||||
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
||||
if (name == "Camera") {
|
||||
@@ -26,7 +26,6 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
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);
|
||||
|
||||
|
||||
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
|
||||
speed *= 4.0f;
|
||||
}
|
||||
@@ -36,7 +35,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
if(input->KeyState[GLFW_KEY_A] || input->KeyState[GLFW_KEY_LEFT]) {
|
||||
transform->Position -= Camera_Right * (float)dt * speed;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_D] || input->KeyState[GLFW_KEY_RIGHT]) {
|
||||
else if(input->KeyState[GLFW_KEY_D] || input->KeyState[GLFW_KEY_RIGHT]) {
|
||||
transform->Position += Camera_Right * (float)dt * speed;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_W]) {
|
||||
@@ -77,27 +76,42 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
|
||||
float TurnSpeed = 2.0f;
|
||||
glm::vec3 Euler = glm::eulerAngles(transform->Orientation);
|
||||
LOG_DEBUG("Euler: %f", Euler.z);
|
||||
|
||||
if(input->KeyState[GLFW_KEY_LEFT]) {
|
||||
transform->Position -= Ship_Right * (float)dt * speed;
|
||||
|
||||
if(Euler.z < 25.f)
|
||||
if(Euler.z < 10.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed,glm::vec3(0,0,1));
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed,glm::vec3(0,0,1));
|
||||
}
|
||||
else if(Euler.z < 20.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed/2,glm::vec3(0,0,1));
|
||||
}
|
||||
else if (Euler.z < 25.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed/4,glm::vec3(0,0,1));
|
||||
}
|
||||
}
|
||||
else if(input->KeyState[GLFW_KEY_RIGHT]) {
|
||||
transform->Position += Ship_Right * (float)dt * speed;
|
||||
|
||||
if(Euler.z > -25.f)
|
||||
if(Euler.z > -10.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed,glm::vec3(0,0,-1));
|
||||
}
|
||||
else if(Euler.z > -20.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed/2,glm::vec3(0,0,-1));
|
||||
}
|
||||
else if (Euler.z > -25.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed/4,glm::vec3(0,0,-1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Euler.z < 0.5f && Euler.z > -0.5f)
|
||||
if(Euler.z < 1.5f && Euler.z > -1.5f)
|
||||
transform->Orientation = glm::angleAxis<float>(0,glm::vec3(0,0,1));
|
||||
else if(Euler.z < 0.f)
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt,glm::vec3(0,0,1));
|
||||
|
||||
@@ -32,7 +32,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
||||
#ifdef DEBUG
|
||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||
if (bounds != nullptr) {
|
||||
glm::vec3 origin = transformComponent->Position + bounds->Origin;
|
||||
glm::vec3 origin = transformComponent->Scale * (transformComponent->Position + bounds->Origin);
|
||||
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
|
||||
m_Renderer->AddAABBToDraw(origin, volumeVector);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Systems
|
||||
{
|
||||
public:
|
||||
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||
: System(world), m_Renderer(renderer) {}
|
||||
: System(world), m_Renderer(renderer){ }
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user