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

Conflicts:
	src/game/Game/BallSystem.cpp
	src/game/Game/LevelSystem.cpp
	src/game/Physics/PhysicsSystem.cpp
This commit is contained in:
viktorljung
2015-10-08 17:28:28 +02:00
10 changed files with 119 additions and 35 deletions
+45 -21
View File
@@ -18,6 +18,7 @@ void dd::Systems::BallSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &BallSystem::OnMultiBallLost);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &BallSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_EStickyPad, &BallSystem::OnStickyPad);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton);
@@ -103,12 +104,27 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
if (templateCheck != nullptr){ return; }
if (ballComponent != nullptr) {
if (ReplaceBall()) {
SetReplaceBall(false);
m_Waiting = true;
ballComponent->Waiting = true;
}
if (ballComponent->Waiting) {
if (m_Waiting == false) {
ballComponent->Waiting = false;
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Velocity = glm::normalize(glm::vec3(0.5f, 1, 0.f)) * ballComponent->Speed;
} else {
transform->Velocity = glm::normalize(glm::vec3(-0.5f, 1, 0.f)) * ballComponent->Speed;
if (ballComponent->Sticky) {
transform->Velocity = ballComponent->SavedSpeed;
m_StickyCounter--;
std::cout << m_StickyCounter << std::endl;
if (m_StickyCounter > 0) {
m_Sticky = true;
}
ballComponent->Sticky = false;
}
} 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);
@@ -116,12 +132,7 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
return;
}
}
if (ReplaceBall()) {
SetReplaceBall(false);
m_Waiting = true;
ballComponent->Waiting = true;
}
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (glm::abs(transformBall->Velocity.y) < 2) {
if (transformBall->Velocity.y > 0) {
@@ -130,7 +141,7 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
transformBall->Velocity.y = -2;
}
}
if (transformBall->Position.y < -EdgeY() - 4) {
if (transformBall->Position.y < -EdgeY() - 4 || transformBall->Position.y > EdgeY() + 4) {
if (MultiBalls() != 0) {
m_World->RemoveEntity(entity);
Events::MultiBallLost e;
@@ -245,7 +256,9 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y);
if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Pad"){
if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Pad") {
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
Events::HitPad e;
EventBroker->Publish(e);
// Events::HitLag el;
@@ -253,13 +266,24 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
//el.Type = "All";
// EventBroker->Publish(el);
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier();
float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier();
float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f;
ballComponent->Combo = 0;
if (m_Sticky) {
m_Sticky = false;
m_Waiting = true;
ballComponent->Sticky = true;
ballComponent->Waiting = true;
ballComponent->StickyPlacement = padTransform->Position - ballTransform->Position;
ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed;
ballTransform->Velocity *= -1;
return true;
}
ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed;
ballComponent->Combo = 0;
Events::ComboEvent ec;
ec.Combo = ballComponent->Combo;
ec.Ball = ballEntity;
@@ -297,20 +321,13 @@ void dd::Systems::BallSystem::ResolveContacts()
{
for (auto c : m_Contacts) {
int count = 0;
EntityID entity = c.first;
std::list<glm::vec2> contactNormals = c.second;
glm::vec2 finalNormal = glm::vec2(0.f);
for (auto it = contactNormals.begin(); it != contactNormals.end(); it++) {
finalNormal = finalNormal + (*it);
count++;
}
finalNormal = glm::normalize(finalNormal);
if (count > 1) {
LOG_INFO("MultiCollision %i", count);
}
auto transform = m_World->GetComponent<Components::Transform>(entity);
glm::vec2 velocity = glm::vec2(transform->Velocity.x, transform->Velocity.y);
glm::vec2 reflectedVelocity = glm::reflect(velocity, finalNormal);
@@ -403,6 +420,13 @@ bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event)
return true;
}
bool dd::Systems::BallSystem::OnStickyPad(const dd::Events::StickyPad &event)
{
m_Sticky = true;
m_StickyCounter = 5;
return true;
}
bool dd::Systems::BallSystem::OnActionButton(const dd::Events::ActionButton &event)
{
m_Waiting = false;