Merge remote-tracking branch 'origin/master' into Physics

This commit is contained in:
viktorljung
2015-10-13 18:03:15 +02:00
13 changed files with 297 additions and 89 deletions
+6
View File
@@ -72,6 +72,7 @@ void dd::Renderer::Initialize()
m_CurrentScreenBuffer = m_TFinal;
}
void dd::Renderer::LoadShaders()
{
/*
@@ -384,6 +385,11 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
DrawWater(objects);
}
void dd::Renderer::PlaceCamera(glm::vec3 position)
{
m_DefaultCamera->SetPosition(position);
}
void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
{
GLuint shaderProgramHandle = program;
+23 -21
View File
@@ -126,7 +126,7 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
} else if (!ballComponent->Sticky) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
transform->Position = glm::vec3(0.0f, -3.f, -10.f);
//transform->Position = glm::vec3(0.0f, -3.f, -10.f);
transform->Orientation = glm::quat();
return;
}
@@ -288,27 +288,29 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f;
ballComponent->Combo = 0;
if (m_InkBlaster) {
if (!m_InkAttached) {
m_InkAttached = true;
m_Waiting = true;
m_InkBlockedWaiting = true;
ballComponent->Sticky = true;
ballComponent->StickyPlacement = glm::vec3(0, 0.5f, 0);
ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed;
ballTransform->Velocity = glm::vec3(0.f, 0.f, 0.f);
if (!ballComponent->Waiting) {
if (m_InkBlaster) {
if (!m_InkAttached) {
m_InkAttached = true;
m_Waiting = true;
m_InkBlockedWaiting = true;
ballComponent->Sticky = true;
ballComponent->StickyPlacement = glm::vec3(0, 0.5f, 0);
ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed;
ballTransform->Velocity = glm::vec3(0.f, 0.f, 0.f);
}
}
else if (m_Sticky) {
m_Sticky = false;
m_Waiting = true;
ballComponent->Sticky = true;
ballComponent->StickyPlacement = ballTransform->Position - padTransform->Position;
ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed;
ballTransform->Velocity *= -1;
Events::StickyAttachedToPad e;
EventBroker->Publish(e);
return true;
}
} else if (m_Sticky) {
m_Sticky = false;
m_Waiting = true;
ballComponent->Sticky = true;
ballComponent->StickyPlacement = ballTransform->Position - padTransform->Position;
ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed;
ballTransform->Velocity *= -1;
Events::StickyAttachedToPad e;
EventBroker->Publish(e);
return true;
}
ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed;
+26 -3
View File
@@ -27,6 +27,7 @@ void dd::Systems::PadSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &PadSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttack, &PadSystem::OnKrakenAttack);
EVENT_SUBSCRIBE_MEMBER(m_EStickyPad, &PadSystem::OnStickyPad);
@@ -72,6 +73,8 @@ void dd::Systems::PadSystem::Initialize()
m_StickTransform = transform;
m_StickyAim = sticky;
}
m_ResetBall = true;
}
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
@@ -81,7 +84,12 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (ball != nullptr) {
if (ball->Sticky) {
if (ball->Waiting || ball->Sticky) {
if (m_ResetBall && ball->Waiting) {
ball->StickyPlacement = glm::vec3(0.f, 0.f, 0.f);
ball->StickyPlacement.y += 0.45f;
m_ResetBall = false;
}
auto ballTransform = m_World->GetComponent<Components::Transform>(entity);
ballTransform->Position = Transform()->Position;
ballTransform->Position += ball->StickyPlacement;
@@ -89,8 +97,10 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p
glm::vec2 up = glm::vec2(0.f, 1.f);
float angle = glm::acos(glm::dot<float>(dir, up)) * glm::sign(dir.x);
ballTransform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, -1.f));
m_StickTransform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, 1.f));
m_StickTransform->Position = ballTransform->Position;
if (ball->Sticky) {
m_StickTransform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, 1.f));
m_StickTransform->Position = ballTransform->Position;
}
}
if (!m_StickyAim->Aiming) {
m_StickTransform->Position = glm::vec3(30.f, 0.f, 0.f);
@@ -103,6 +113,7 @@ void dd::Systems::PadSystem::Update(double dt)
if (IsPaused()) {
return;
}
if (Entity() == 0) {
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") {
@@ -209,6 +220,11 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) {
} else if (val == GLFW_KEY_S) {
Events::StageCleared e;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_E) {
Events::ScreenShake e;
e.Intensity = 20;
e.Time = 3;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_Y) {
Events::StickyPad e;
EventBroker->Publish(e);
@@ -342,9 +358,16 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
bool dd::Systems::PadSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
//auto entity = CreateBall();
m_StickyAim->Aiming = false;
return true;
}
bool dd::Systems::PadSystem::OnResetBall(const dd::Events::ResetBall &event)
{
m_ResetBall = true;
return true;
}
bool dd::Systems::PadSystem::OnKrakenAttack(const dd::Events::KrakenAttack &event)
{
if (!m_KrakenAttack) {
+66
View File
@@ -0,0 +1,66 @@
//
// Created by Adniklastrator on 2015-10-13.
//
#include "PrecompiledHeader.h"
#include "Game/TravellingSystem.h"
void dd::Systems::TravellingSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EPause, &TravellingSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &TravellingSystem::OnStageCleared);
}
void dd::Systems::TravellingSystem::Update(double dt)
{
if (m_Pause) {
return;
}
if (m_Travelling) {
if (m_DistanceTravelled > 12.f) {
m_DistanceTravelled = 0;
m_Travelling = false;
Events::ArrivedAtNewStage e;
EventBroker->Publish(e);
}
m_DistanceTravelled += 6.0f * dt;
}
}
void dd::Systems::TravellingSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (m_Travelling) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (transform != nullptr) {
if (!transform->Sticky) {
transform->Position.y -= 6.0f * dt;
}
}
else {
transform->Position.y -= 6.0f * dt;
}
}
}
bool dd::Systems::TravellingSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "TravellingSystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
bool dd::Systems::TravellingSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
if (event.ClearedStage < 5) {
m_Travelling = true;
}
return true;
}
-33
View File
@@ -23,7 +23,6 @@ void dd::Systems::PhysicsSystem::Initialize()
InitializeWater();
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PhysicsSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_ECreateParticleSequence, &PhysicsSystem::CreateParticleSequence);
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PhysicsSystem::OnContact);
}
@@ -170,17 +169,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
if (m_Pause) {
return;
}
if (m_Travelling) {
if (m_DistanceTravelled > 12.f) {
m_DistanceTravelled = 0;
m_Travelling = false;
Events::ArrivedAtNewStage e;
EventBroker->Publish(e);
}
m_DistanceTravelled += 6.0f * dt;
}
m_Accumulator += dt;
while(m_Accumulator >= m_TimeStep)
@@ -254,20 +242,8 @@ void dd::Systems::PhysicsSystem::Update(double dt)
void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (m_Travelling) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (transform != nullptr) {
if (!transform->Sticky) {
transform->Position.y -= 6.0f * dt;
}
} else {
transform->Position.y -= 6.0f * dt;
}
}
auto particle = m_World->GetComponent<Components::Particle>(entity);
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
if (particle && !pTemplate) {
particle->LifeTime -= dt;
@@ -360,15 +336,6 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
}
bool dd::Systems::PhysicsSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
if (event.ClearedStage < 5) {
m_Travelling = true;
}
return true;
}
void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
{
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);