Mer LevelGeneration

This commit is contained in:
ViktorLjung
2014-03-13 00:30:01 +01:00
parent ec25625b0a
commit 5629312960
8 changed files with 146 additions and 21 deletions
@@ -1,26 +1,93 @@
#include "LevelGenerationSystem.h"
Systems::LevelGenerationSystem::LevelGenerationSystem( World* world )
: System(world)
{
elapsedtime = 0;
startyz = glm::vec2(0, -200);
}
void Systems::LevelGenerationSystem::SpawnObstacle()
{
std::shared_ptr<Components::Transform> transform;
std::shared_ptr<Components::Bounds> bounds;
std::shared_ptr<Components::Collision> collision;
std::shared_ptr<Components::Model> model;
typeRandom = 0 + (rand() % 5);
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");
transform->Position = glm::vec3(0,0,0); // fix position
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
bounds->VolumeVector = glm::vec3(4, 4, 4);
collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
model = m_World->AddComponent<Components::Model>(ent, "Model");
switch (typeRandom)
{
case 0:
positionRandom = -500 + (rand() % 1000);
transform->Position = glm::vec3( positionRandom, startyz); // fix position
bounds->VolumeVector = glm::vec3(4, 4, 4);
model->ModelFile = "Models/obstacle_mountain_1.obj";
break;
case 1:
positionRandom = -100 + (rand() % 200);
transform->Position = glm::vec3( positionRandom, startyz); // fix position
bounds->VolumeVector = glm::vec3(4, 4, 4);
model->ModelFile = "Models/obstacle_mountain_2.obj";
break;
case 2:
positionRandom = -100 + (rand() % 200);
transform->Position = glm::vec3( positionRandom, startyz); // fix position
bounds->VolumeVector = glm::vec3(4, 4, 4);
model->ModelFile = "Models/obstacle_mountain_3.obj";
break;
case 3:
positionRandom = -100 + (rand() % 200);
transform->Position = glm::vec3( positionRandom, startyz); // fix position
bounds->VolumeVector = glm::vec3(4, 4, 4);
model->ModelFile = "Models/obstacle_mountain_4.obj";
break;
case 4:
positionRandom = -100 + (rand() % 200);
transform->Position = glm::vec3( positionRandom, startyz); // fix position
bounds->VolumeVector = glm::vec3(4, 4, 4);
model->ModelFile = "Models/obstacle_cube_1.obj";
break;
default:
break;
}
}
void Systems::LevelGenerationSystem::Update( double dt )
{
elapsedtime += dt;
if(elapsedtime > 1.0){
SpawnObstacle();
elapsedtime = 0;
}
for(auto ent : obstacles)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(ent, "Transform");
transformComponent->Position.z += 15.f * dt;
}
}