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:
@@ -187,6 +187,7 @@ public:
|
||||
auto transform = m_World->AddComponent<Components::Transform>(t_halfPipe);
|
||||
transform->Position = glm::vec3(0.f, 34.6f, -15.f);
|
||||
transform->Scale = glm::vec3(6.f, 6.f, 10.f);
|
||||
transform->Sticky = false;
|
||||
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
|
||||
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
||||
model->Color = glm::vec4(0.8f, 0.8f, 0.8f, 0.3f);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "Game/EResetBall.h"
|
||||
#include "Game/EMultiBall.h"
|
||||
#include "Game/EMultiBallLost.h"
|
||||
#include "Game/EStickyPad.h"
|
||||
#include "Game/EGameOver.h"
|
||||
#include "Game/EPause.h"
|
||||
#include "Game/EHitPad.h"
|
||||
@@ -92,6 +93,8 @@ private:
|
||||
bool m_ReplaceBall = false;
|
||||
bool m_Pause = false;
|
||||
bool m_Waiting = true;
|
||||
bool m_Sticky = false;
|
||||
int m_StickyCounter = 5;
|
||||
EntityID m_LastCollision = 999999;
|
||||
|
||||
glm::vec3 m_SavedSpeed;
|
||||
@@ -106,6 +109,7 @@ private:
|
||||
dd::EventRelay<BallSystem, dd::Events::MultiBallLost> m_EMultiBallLost;
|
||||
dd::EventRelay<BallSystem, dd::Events::ResetBall> m_EResetBall;
|
||||
dd::EventRelay<BallSystem, dd::Events::MultiBall> m_EMultiBall;
|
||||
dd::EventRelay<BallSystem, dd::Events::StickyPad> m_EStickyPad;
|
||||
dd::EventRelay<BallSystem, dd::Events::Pause> m_EPause;
|
||||
dd::EventRelay<BallSystem, dd::Events::Contact> m_Contact;
|
||||
dd::EventRelay<BallSystem, dd::Events::ActionButton> m_EActionButton;
|
||||
@@ -115,6 +119,7 @@ private:
|
||||
bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
|
||||
bool OnResetBall(const dd::Events::ResetBall &event);
|
||||
bool OnMultiBall(const dd::Events::MultiBall &event);
|
||||
bool OnStickyPad(const dd::Events::StickyPad &event);
|
||||
bool OnPause(const dd::Events::Pause &event);
|
||||
bool OnActionButton(const dd::Events::ActionButton &event);
|
||||
};
|
||||
|
||||
@@ -20,6 +20,8 @@ struct Ball : Component
|
||||
int Combo = 0;
|
||||
bool Paused = false;
|
||||
bool Waiting = true;
|
||||
bool Sticky = false;
|
||||
glm::vec3 StickyPlacement = glm::vec3(0, 0, 0);
|
||||
glm::vec3 SavedSpeed = glm::vec3(0, 0, 0);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-10-08.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_ESTICKYPAD_H
|
||||
#define DAYDREAM_ESTICKYPAD_H
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct StickyPad : Event
|
||||
{
|
||||
Components::Transform* Transform;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_ESTICKYPAD_H
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "Game/EComboEvent.h"
|
||||
#include "Game/EHitPad.h"
|
||||
#include "Game/ELifebuoy.h"
|
||||
#include "Game/EStickyPad.h"
|
||||
#include "Game/EMultiBall.h"
|
||||
#include "Game/EMultiBallLost.h"
|
||||
#include "Game/EPause.h"
|
||||
@@ -109,7 +110,7 @@ private:
|
||||
bool m_Initialized = false;
|
||||
bool m_Pause = false;
|
||||
int m_LooseBricks = 0;
|
||||
int m_CurrentCluster = 2;
|
||||
int m_CurrentCluster = 1;
|
||||
int m_CurrentLevel = 1;
|
||||
int m_MultiBalls = 0;
|
||||
int m_PowerUps = 0;
|
||||
@@ -125,6 +126,7 @@ private:
|
||||
const int StandardBrick = 1;
|
||||
const int MultiBallBrick = 2;
|
||||
const int LifebuoyBrick = 3;
|
||||
const int StickyBrick = 4;
|
||||
|
||||
EntityID m_BrickTemplate;
|
||||
|
||||
|
||||
@@ -56,11 +56,11 @@ private:
|
||||
struct LifeBuoyInfo
|
||||
{
|
||||
EntityID Entity;
|
||||
float TimeToLive = 20.f;
|
||||
float TimeToLive = 15.f;
|
||||
};
|
||||
|
||||
float m_LeftEdge = -4.f;
|
||||
float m_RightEdge = 4.f;
|
||||
float m_LeftEdge = -3.8f;
|
||||
float m_RightEdge = 3.8f;
|
||||
std::list<LifeBuoyInfo> m_LifeBuoys;
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -65,7 +65,7 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
// Check the background.
|
||||
auto model = m_World->GetComponent<Components::Model>(entity);
|
||||
if (model != nullptr) {
|
||||
if (model->ModelFile == "Models/Test/halfpipe/Halfpipe.obj") {
|
||||
if (model->ModelFile == "Models/Test/halfpipe/Halfpipe.obj") {
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (transform->Position.y <= -34.6) {
|
||||
transform->Position.y = 34.6;
|
||||
@@ -87,6 +87,9 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
Events::Lifebuoy e;
|
||||
e.Transform = transform;
|
||||
EventBroker->Publish(e);
|
||||
} else if (brick->Type == StickyBrick) {
|
||||
Events::StickyPad e;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
m_LooseBricks--;
|
||||
m_World->RemoveEntity(entity);
|
||||
@@ -194,6 +197,12 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
||||
model->ModelFile = "Models/Brick/IceBrick.obj";
|
||||
} else if (typeInt == LifebuoyBrick) {
|
||||
cBrick->Type = LifebuoyBrick;
|
||||
auto model = m_World->GetComponent<Components::Model>(brick);
|
||||
model->Color = glm::vec4(1.f, 0.f, 0.f, .0f);
|
||||
} else if (typeInt == StickyBrick) {
|
||||
cBrick->Type = StickyBrick;
|
||||
auto model = m_World->GetComponent<Components::Model>(brick);
|
||||
model->Color = glm::vec4(0.f, 0.f, 1.f, .0f);
|
||||
}
|
||||
float x = line * spacesBetweenBricks.x;
|
||||
float y = row * spacesBetweenBricks.y;
|
||||
@@ -370,7 +379,9 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
||||
// 0 is empty space.
|
||||
// 1 is standard brick.
|
||||
// 2 is multiball brick.
|
||||
if (m_CurrentCluster == 1) {
|
||||
// 3 is lifebuoy brick.
|
||||
// 4 is sticky brick.
|
||||
if (m_CurrentCluster == 0) {
|
||||
if (m_CurrentLevel == 1) {
|
||||
level =
|
||||
{0, 0, 0, 0, 0, 0, 0,
|
||||
@@ -412,7 +423,7 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1};
|
||||
}
|
||||
} else if (m_CurrentCluster == 2) {
|
||||
} else if (m_CurrentCluster == 1) {
|
||||
if (m_CurrentLevel == 1) {
|
||||
level =
|
||||
{1, 1, 0, 1, 0, 1, 1,
|
||||
@@ -420,7 +431,7 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
||||
1, 1, 1, 1, 1, 1, 1,
|
||||
1, 2, 1, 2, 1, 2, 1,
|
||||
1, 1, 0, 1, 0, 1, 1,
|
||||
1, 3, 3, 3, 3, 3, 1};
|
||||
4, 0, 0, 3, 0, 0, 1};
|
||||
} else if (m_CurrentLevel == 2) {
|
||||
level =
|
||||
{1, 0, 0, 0, 0, 0, 1,
|
||||
|
||||
@@ -57,6 +57,16 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
{
|
||||
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
|
||||
if (templateCheck != nullptr){ return; }
|
||||
|
||||
auto ball = m_World->GetComponent<Components::Ball>(entity);
|
||||
if (ball != nullptr) {
|
||||
if (ball->Sticky) {
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
transform->Position = Transform()->Position;
|
||||
transform->Position -= ball->StickyPlacement;
|
||||
transform->Orientation = glm::quat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::PadSystem::Update(double dt)
|
||||
@@ -155,7 +165,10 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) {
|
||||
e.Time = 0.2;
|
||||
e.Type = "All";
|
||||
EventBroker->Publish(e);
|
||||
} else if (val == GLFW_KEY_SPACE) {
|
||||
} else if (val == GLFW_KEY_S) {
|
||||
Events::StageCleared e;
|
||||
EventBroker->Publish(e);
|
||||
} else if (val == GLFW_KEY_SPACE) {
|
||||
Events::ActionButton e;
|
||||
EventBroker->Publish(e);
|
||||
} else if (val == GLFW_KEY_D) {
|
||||
|
||||
@@ -22,8 +22,8 @@ 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);
|
||||
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::InitializeWater()
|
||||
@@ -253,12 +253,13 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
||||
if (m_Travelling) {
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (transform != nullptr) {
|
||||
if (transform->Sticky == true) {
|
||||
return;
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user