Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
This commit is contained in:
@@ -85,8 +85,8 @@ void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
|
||||
if (aMin.x <= bMax.x && bMin.x <= aMax.x) {
|
||||
if (aMin.y <= bMax.y && bMin.y <= aMax.y) {
|
||||
if (aMin.z <= bMax.z && bMin.z <= aMax.z) {
|
||||
aCollisionComponent->CollidingEntities.push_back(aEntity);
|
||||
bCollisionComponent->CollidingEntities.push_back(bEntity);
|
||||
aCollisionComponent->CollidingEntities.push_back(bEntity);
|
||||
bCollisionComponent->CollidingEntities.push_back(aEntity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||
|
||||
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");
|
||||
|
||||
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");
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||
|
||||
if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D
|
||||
{
|
||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||
float scale = (float)(rand() % 1000) / 250;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(9, 12, 7);
|
||||
@@ -45,6 +46,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||
}
|
||||
else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D
|
||||
{
|
||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||
float scale = (float)(rand() % 1000) / 200;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
|
||||
@@ -53,6 +55,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||
}
|
||||
else if(typeRandom >= 5 && typeRandom < 8)
|
||||
{
|
||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||
float scale = (float)(rand() % 1000) / 100;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(1, 1, 1);
|
||||
@@ -61,13 +64,14 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||
}
|
||||
if(typeRandom >= 8 && typeRandom < 10)
|
||||
{
|
||||
m_World->SetProperty(ent, "Name", std::string("PowerUp"));
|
||||
float scale = (float)(rand() % 1000) / 100;
|
||||
bounds->VolumeVector = glm::vec3(4, 4, 4);
|
||||
bounds->Origin = glm::vec3(0,4,0);
|
||||
|
||||
|
||||
powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
|
||||
powerUp->Speed = 10.f;
|
||||
auto powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
|
||||
powerUp->Speed = 200.f;
|
||||
|
||||
model->ModelFile = "Models/powerup.obj";
|
||||
}
|
||||
@@ -88,24 +92,26 @@ void Systems::LevelGenerationSystem::Update( double dt )
|
||||
elapsedtime = 0;
|
||||
}
|
||||
|
||||
std::list<EntityID> removethis;
|
||||
|
||||
|
||||
for(auto ent : obstacles)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(ent, "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;
|
||||
}
|
||||
|
||||
if(transform->Position.z > 800)
|
||||
if(transform != nullptr)
|
||||
{
|
||||
removethis.push_back(ent);
|
||||
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 > 800)
|
||||
{
|
||||
removethis.push_back(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +129,7 @@ void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, E
|
||||
if( m_World->GetProperty<std::string>(entity, "Name") == "Player")
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
|
||||
startyz = glm::vec2(0, transformComponent->Position.z - 1000);
|
||||
startx = transformComponent->Position.x;
|
||||
velocity = transformComponent->Velocity.z;
|
||||
|
||||
@@ -31,18 +31,11 @@ namespace Systems
|
||||
int positionRandom;
|
||||
glm::vec2 startyz;
|
||||
float startx;
|
||||
|
||||
std::list<EntityID> removethis;
|
||||
double elapsedtime;
|
||||
|
||||
std::list<EntityID> obstacles;
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,47 +36,58 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
}
|
||||
|
||||
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
||||
if (name == "Camera" && 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 == "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")
|
||||
{
|
||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||
@@ -140,14 +151,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;
|
||||
else
|
||||
freecamEnabled = true;
|
||||
|
||||
|
||||
//powerup
|
||||
auto collisionComponent = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
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");
|
||||
if(powerupComp != nullptr)
|
||||
{
|
||||
transform->Velocity.z = powerupComp->Speed;
|
||||
m_World->RemoveEntity(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Update camera
|
||||
if(! freecamEnabled)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/Camera.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "Components/PowerUp.h"
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user