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
+3 -3
View File
@@ -5,7 +5,7 @@ void GameWorld::Initialize()
{
World::Initialize();
//AddSystem("LevelGenerationSystem");
AddSystem("LevelGenerationSystem");
AddSystem("InputSystem");
//AddSystem("CollisionSystem");
//AddSystem("ParticleSystem");
@@ -79,7 +79,7 @@ void GameWorld::Initialize()
//ground
ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(0.f, -4.f, 0.f);
transform->Position = glm::vec3(0.f, 0.f, 0.f);
model = AddComponent<Components::Model>(ent, "Model");
model->ModelFile = "Models/plane.obj";
@@ -122,7 +122,7 @@ void GameWorld::RegisterComponents()
void GameWorld::RegisterSystems()
{
//m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); });
//m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
@@ -0,0 +1,12 @@
# Blender MTL File: 'obstaclesandstuff.blend'
# Material Count: 1
newmtl Material.001
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd ObstacleTexture.png
@@ -0,0 +1,12 @@
# Blender MTL File: 'obstaclesandstuff.blend'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.559600 0.559600 0.559600
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd ObstacleTexture.png
@@ -0,0 +1,12 @@
# Blender MTL File: 'obstaclesandstuff.blend'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.559600 0.559600 0.559600
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd ObstacleTexture.png
@@ -0,0 +1,12 @@
# Blender MTL File: 'obstaclesandstuff.blend'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.559600 0.559600 0.559600
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd ObstacleTexture.png
@@ -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;
}
}
@@ -8,22 +8,32 @@
#include "Components/Collision.h"
#include "Components/Model.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
namespace Systems
{
class LevelGenerationSystem : public System
{
public:
LevelGenerationSystem(World* world)
: System(world) { }
LevelGenerationSystem(World* world);
void SpawnObstacle();
private:
void Update(double dt) override;
private:
int typeRandom;
int positionRandom;
glm::vec2 startyz;
double elapsedtime;
std::vector<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;
};
}
+1 -1
View File
@@ -18,7 +18,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;