Conflicts:
	Escape-the-Dawn/Systems/CollisionSystem.cpp
This commit is contained in:
Tleety
2015-06-01 23:30:05 +02:00
5 changed files with 83 additions and 54 deletions
@@ -15,69 +15,80 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
{
typeRandom = 0 + (rand() % 10);
EntityID ent;
auto ent = m_World->CreateEntity();
{
auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
auto bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
auto collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
auto model = m_World->AddComponent<Components::Model>(ent, "Model");
ent = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
auto bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
auto collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
auto model = m_World->AddComponent<Components::Model>(ent, "Model");
auto sound = m_World->AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
positionRandom = -500 + startx + (rand() % 1000);
transform->Position = glm::vec3(positionRandom, startyz);
transform->Velocity = glm::vec3(0.f, 30.f, 0);
positionRandom = -500 + startx + (rand() % 1000);
transform->Position = glm::vec3(positionRandom, startyz);
transform->Velocity = glm::vec3(0.f, 30.f, 0);
sound->Loop = true;
sound->Gain = 1.f;
sound->MaxDistance = 2.f;
sound->ReferenceDistance = 1.f;
m_World->GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(sound.get(), "Sounds/hum.wav");
// Obstacle
if (typeRandom >= 0 && typeRandom < 9)
{
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
if(typeRandom >= 0 && typeRandom < 1) // Mountain stuff :D
{
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = 1.0f + (float)(rand() % 1000) / 250;
transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(8.5f, 12, 5);
bounds->Origin = glm::vec3(1,11,-1);
model->ModelFile = "Models/obstacle_mountain_1.obj";
if (typeRandom >= 0 && typeRandom < 1) // Mountain stuff :D
{
float scale = 1.0f + (float)(rand() % 1000) / 250;
transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(8.5f, 12, 5);
bounds->Origin = glm::vec3(1, 11, -1);
model->ModelFile = "Models/obstacle_mountain_1.obj";
}
else if (typeRandom >= 1 && typeRandom < 5) // Single Mountain :D
{
float scale = 1.0f + (float)(rand() % 1000) / 200;
transform->Scale = glm::vec3(scale);
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";
}
else if (typeRandom >= 5 && typeRandom < 9)
{
float scale = 2.f + (float)(rand() % 1000) / 100;
transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(1, 1, 1);
bounds->Origin = glm::vec3(0, 1, 0);
model->ModelFile = "Models/obstacle_cube_1.obj";
}
auto soundTrigger = m_World->CreateEntity(ent);
{
auto obstacleTransform = m_World->GetComponent<Components::Transform>(ent, "Transform");
auto obstacleBounds = m_World->GetComponent<Components::Bounds>(ent, "Bounds");
m_World->SetProperty(soundTrigger, "Name", std::string("Obstacle_SoundTrigger"));
auto transform = m_World->AddComponent<Components::Transform>(soundTrigger, "Transform");
auto bounds = m_World->AddComponent<Components::Bounds>(soundTrigger, "Bounds");
auto collision = m_World->AddComponent<Components::Collision>(soundTrigger, "Collision");
bounds->VolumeVector = obstacleBounds->VolumeVector * obstacleTransform->Scale + glm::vec3(25, 0, 50);
bounds->Origin = obstacleBounds->Origin;
}
}
else if(typeRandom >= 1 && typeRandom < 5) // Single Mountain :D
{
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = 1.0f + (float)(rand() % 1000) / 200;
transform->Scale = glm::vec3(scale);
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";
}
else if(typeRandom >= 5 && typeRandom < 9)
{
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = 2.f + (float)(rand() % 1000) / 100;
transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(1, 1, 1);
bounds->Origin = glm::vec3(0,1,0);
model->ModelFile = "Models/obstacle_cube_1.obj";
}
if(typeRandom >= 9 && typeRandom < 10)
// PowerUp
if (typeRandom >= 9 && typeRandom < 10)
{
m_World->SetProperty(ent, "Name", std::string("PowerUp"));
bounds->VolumeVector = glm::vec3(4, 4, 4);
bounds->Origin = glm::vec3(0,4,0);
bounds->Origin = glm::vec3(0, 4, 0);
auto powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
powerUp->Speed = 200.f;
model->ModelFile = "Models/powerup.obj";
}
// Put it below ground level
transform->Position.y -= transform->Scale.y * bounds->VolumeVector.y * 2.f;
// Put it below ground level
transform->Position.y -= transform->Scale.y * bounds->VolumeVector.y * 2.f;
}
}
@@ -100,6 +111,9 @@ void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, E
transform->Velocity.z = velocity;
transform->Position += transform->Velocity * (float)dt;
auto name = m_World->GetProperty<std::string>(entity, "Name");
auto pname = m_World->GetProperty<std::string>(parent, "Name");
// Stop raising obstacles when they reach ground level
if (transform->Velocity.y > 0 && transform->Position.y >= 0)
{