Merge remote-tracking branch 'origin/master' into Physics
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 120 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 600 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
@@ -201,6 +201,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Background
|
//Background
|
||||||
|
|
||||||
{
|
{
|
||||||
auto background = m_World->CreateEntity();
|
auto background = m_World->CreateEntity();
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(background);
|
auto transform = m_World->AddComponent<Components::Transform>(background);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "Game/EMultiBallLost.h"
|
#include "Game/EMultiBallLost.h"
|
||||||
#include "Game/EStickyPad.h"
|
#include "Game/EStickyPad.h"
|
||||||
#include "Game/EInkBlaster.h"
|
#include "Game/EInkBlaster.h"
|
||||||
|
#include "Game/EInkBlasterOver.h"
|
||||||
#include "Game/EGameOver.h"
|
#include "Game/EGameOver.h"
|
||||||
#include "Game/EPause.h"
|
#include "Game/EPause.h"
|
||||||
#include "Game/EHitPad.h"
|
#include "Game/EHitPad.h"
|
||||||
@@ -97,6 +98,8 @@ private:
|
|||||||
bool m_Waiting = true;
|
bool m_Waiting = true;
|
||||||
bool m_Sticky = false;
|
bool m_Sticky = false;
|
||||||
bool m_InkBlaster = false;
|
bool m_InkBlaster = false;
|
||||||
|
bool m_InkAttached = false;
|
||||||
|
bool m_BlockedWaiting = false;
|
||||||
int m_StickyCounter = 5;
|
int m_StickyCounter = 5;
|
||||||
|
|
||||||
glm::vec3 m_SavedSpeed;
|
glm::vec3 m_SavedSpeed;
|
||||||
@@ -113,6 +116,7 @@ private:
|
|||||||
dd::EventRelay<BallSystem, dd::Events::MultiBall> m_EMultiBall;
|
dd::EventRelay<BallSystem, dd::Events::MultiBall> m_EMultiBall;
|
||||||
dd::EventRelay<BallSystem, dd::Events::StickyPad> m_EStickyPad;
|
dd::EventRelay<BallSystem, dd::Events::StickyPad> m_EStickyPad;
|
||||||
dd::EventRelay<BallSystem, dd::Events::InkBlaster> m_EInkBlaster;
|
dd::EventRelay<BallSystem, dd::Events::InkBlaster> m_EInkBlaster;
|
||||||
|
dd::EventRelay<BallSystem, dd::Events::InkBlasterOver> m_EInkBlasterOver;
|
||||||
dd::EventRelay<BallSystem, dd::Events::Pause> m_EPause;
|
dd::EventRelay<BallSystem, dd::Events::Pause> m_EPause;
|
||||||
dd::EventRelay<BallSystem, dd::Events::Contact> m_Contact;
|
dd::EventRelay<BallSystem, dd::Events::Contact> m_Contact;
|
||||||
dd::EventRelay<BallSystem, dd::Events::ActionButton> m_EActionButton;
|
dd::EventRelay<BallSystem, dd::Events::ActionButton> m_EActionButton;
|
||||||
@@ -124,6 +128,7 @@ private:
|
|||||||
bool OnMultiBall(const dd::Events::MultiBall &event);
|
bool OnMultiBall(const dd::Events::MultiBall &event);
|
||||||
bool OnStickyPad(const dd::Events::StickyPad &event);
|
bool OnStickyPad(const dd::Events::StickyPad &event);
|
||||||
bool OnInkBlaster(const dd::Events::InkBlaster &event);
|
bool OnInkBlaster(const dd::Events::InkBlaster &event);
|
||||||
|
bool OnInkBlasterOver(const dd::Events::InkBlasterOver &event);
|
||||||
bool OnPause(const dd::Events::Pause &event);
|
bool OnPause(const dd::Events::Pause &event);
|
||||||
bool OnActionButton(const dd::Events::ActionButton &event);
|
bool OnActionButton(const dd::Events::ActionButton &event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-10-08.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_EINKBLASTEROVER_H
|
||||||
|
#define DAYDREAM_EINKBLASTEROVER_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct InkBlasterOver : Event
|
||||||
|
{
|
||||||
|
EntityID Ball;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_EINKBLASTEROVER_H
|
||||||
@@ -44,6 +44,8 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "Physics/ECreateParticleSequence.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -72,7 +74,7 @@ public:
|
|||||||
|
|
||||||
void CreateBasicLevel(int, int, glm::vec2, float);
|
void CreateBasicLevel(int, int, glm::vec2, float);
|
||||||
void CreateLevel(int);
|
void CreateLevel(int);
|
||||||
void CreateBrick(int, int, glm::vec2, float, int, int, int);
|
void CreateBrick(int, int, glm::vec2, float, int, int, int, glm::vec4);
|
||||||
|
|
||||||
void OnEntityRemoved(EntityID entity);
|
void OnEntityRemoved(EntityID entity);
|
||||||
|
|
||||||
@@ -135,6 +137,7 @@ private:
|
|||||||
EntityID m_BrickTemplate;
|
EntityID m_BrickTemplate;
|
||||||
|
|
||||||
std::array<int, 42> m_Bricks;
|
std::array<int, 42> m_Bricks;
|
||||||
|
std::array<glm::vec4, 42> m_Colors;
|
||||||
|
|
||||||
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
||||||
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
|
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
|
||||||
|
|||||||
@@ -10,12 +10,14 @@
|
|||||||
#include "Core/CTemplate.h"
|
#include "Core/CTemplate.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
#include "Physics/EContact.h"
|
#include "Physics/EContact.h"
|
||||||
#include "Rendering/CModel.h"
|
#include "Rendering/CModel.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
#include "Physics/CCircleShape.h"
|
#include "Physics/CCircleShape.h"
|
||||||
#include "Game/EPause.h"
|
#include "Game/EPause.h"
|
||||||
#include "Game/EInkBlaster.h"
|
#include "Game/EInkBlaster.h"
|
||||||
|
#include "Game/EInkBlasterOver.h"
|
||||||
#include "Game/EActionButton.h"
|
#include "Game/EActionButton.h"
|
||||||
#include "Game/EHitPad.h"
|
#include "Game/EHitPad.h"
|
||||||
#include "Game/CProjectile.h"
|
#include "Game/CProjectile.h"
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ namespace Components
|
|||||||
|
|
||||||
struct ParticleEmitter : public Component
|
struct ParticleEmitter : public Component
|
||||||
{
|
{
|
||||||
|
EntityID Parent = 0;
|
||||||
int NumberOfTicks = 10.f;
|
int NumberOfTicks = 10.f;
|
||||||
float InitialSpeed = 1.f;
|
float InitialSpeed = 1.f;
|
||||||
double SpawnRate = 1;
|
double SpawnRate = 1;
|
||||||
int ParticlesPerTick = 1;
|
int ParticlesPerTick = 1;
|
||||||
double TimeSinceLastSpawn = 0;
|
//TODO: Refactor. Have cooldown instead of this
|
||||||
|
double TimeSinceLastSpawn = 100;
|
||||||
int MaxCount = 0;
|
int MaxCount = 0;
|
||||||
float EmittingAngle = 0.f;
|
float EmittingAngle = 0.f;
|
||||||
float Spread = 0.f;
|
float Spread = 0.f;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ struct Contact : Event
|
|||||||
{
|
{
|
||||||
EntityID Entity1;
|
EntityID Entity1;
|
||||||
EntityID Entity2;
|
EntityID Entity2;
|
||||||
|
glm::vec2 IntersectionPoint;
|
||||||
glm::vec2 Normal;
|
glm::vec2 Normal;
|
||||||
glm::vec2 SignificantNormal;
|
glm::vec2 SignificantNormal;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ struct CreateParticleSequence : public Event
|
|||||||
float Spread = 1.f;
|
float Spread = 1.f;
|
||||||
float EmittingAngle = 0.f;
|
float EmittingAngle = 0.f;
|
||||||
float MaxCount = 0;
|
float MaxCount = 0;
|
||||||
|
glm::vec4 Color = glm::vec4(0);
|
||||||
|
EntityID parent = 0;
|
||||||
|
|
||||||
//Particle
|
//Particle
|
||||||
std::string SpriteFile = "Texures/Core/ErrorTexture.png";
|
std::string SpriteFile = "";
|
||||||
double ParticleLifeTime = 3.f;
|
double ParticleLifeTime = 3.f;
|
||||||
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Powder | ParticleFlags::ParticleContactFilter | ParticleFlags::FixtureContactFilter);
|
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Powder | ParticleFlags::ParticleContactFilter | ParticleFlags::FixtureContactFilter);
|
||||||
float Radius = 1.f;
|
float Radius = 1.f;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
|
|
||||||
#include "Rendering/CSprite.h"
|
#include "Rendering/CSprite.h"
|
||||||
|
#include "Rendering/CModel.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
@@ -113,6 +114,8 @@ namespace dd
|
|||||||
bool OnPause(const dd::Events::Pause &event);
|
bool OnPause(const dd::Events::Pause &event);
|
||||||
dd::EventRelay<PhysicsSystem, dd::Events::StageCleared> m_EStageCleared;
|
dd::EventRelay<PhysicsSystem, dd::Events::StageCleared> m_EStageCleared;
|
||||||
bool OnStageCleared(const dd::Events::StageCleared &event);
|
bool OnStageCleared(const dd::Events::StageCleared &event);
|
||||||
|
dd::EventRelay<PhysicsSystem, dd::Events::Contact> m_EContact;
|
||||||
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
bool m_Travelling = false;
|
bool m_Travelling = false;
|
||||||
float m_DistanceTravelled = 0;
|
float m_DistanceTravelled = 0;
|
||||||
|
|
||||||
@@ -173,7 +176,7 @@ namespace dd
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -196,7 +199,7 @@ namespace dd
|
|||||||
};
|
};
|
||||||
|
|
||||||
DestructionListener* m_DestructionListener;
|
DestructionListener* m_DestructionListener;
|
||||||
ParticleContactDisabler m_ParticleContactDisabler;
|
ParticleContactDisabler* m_ParticleContactDisabler;
|
||||||
ContactListener* m_ContactListener;
|
ContactListener* m_ContactListener;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||||
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ uniform vec3 LightPosition;
|
|||||||
uniform float LightRadius;
|
uniform float LightRadius;
|
||||||
uniform vec3 LightSpecular;
|
uniform vec3 LightSpecular;
|
||||||
uniform vec3 LightDiffuse;
|
uniform vec3 LightDiffuse;
|
||||||
|
uniform vec4 Color;
|
||||||
|
|
||||||
in VertexData
|
in VertexData
|
||||||
{
|
{
|
||||||
@@ -86,5 +87,5 @@ void main()
|
|||||||
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
|
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
|
||||||
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||||
//frag_Diffuse = light;
|
//frag_Diffuse = light;
|
||||||
frag_Diffuse = diffuseTexel;
|
frag_Diffuse = diffuseTexel * Color;
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,7 @@ void dd::Systems::BallSystem::Initialize()
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall);
|
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EStickyPad, &BallSystem::OnStickyPad);
|
EVENT_SUBSCRIBE_MEMBER(m_EStickyPad, &BallSystem::OnStickyPad);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EInkBlaster, &BallSystem::OnInkBlaster);
|
EVENT_SUBSCRIBE_MEMBER(m_EInkBlaster, &BallSystem::OnInkBlaster);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EInkBlasterOver, &BallSystem::OnInkBlasterOver);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause);
|
EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton);
|
EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton);
|
||||||
|
|
||||||
@@ -115,19 +116,10 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ballComponent->Waiting) {
|
if (ballComponent->Waiting) {
|
||||||
if (m_Waiting == false) {
|
if (!m_Waiting) {
|
||||||
ballComponent->Waiting = false;
|
ballComponent->Waiting = false;
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
transform->Velocity = glm::normalize(glm::vec3(0.5f, 1, 0.f)) * ballComponent->Speed;
|
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) {
|
} else if (!ballComponent->Sticky) {
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
||||||
@@ -136,6 +128,18 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ballComponent->Sticky) {
|
||||||
|
if (!m_Waiting)
|
||||||
|
{
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
transform->Velocity = ballComponent->SavedSpeed;
|
||||||
|
m_StickyCounter--;
|
||||||
|
if (m_StickyCounter > 0) {
|
||||||
|
m_Sticky = true;
|
||||||
|
}
|
||||||
|
ballComponent->Sticky = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
|
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
|
||||||
if (glm::abs(transformBall->Velocity.y) < 2) {
|
if (glm::abs(transformBall->Velocity.y) < 2) {
|
||||||
@@ -279,15 +283,19 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
|||||||
ballComponent->Combo = 0;
|
ballComponent->Combo = 0;
|
||||||
|
|
||||||
if (m_InkBlaster) {
|
if (m_InkBlaster) {
|
||||||
m_InkBlaster = false;
|
if (!m_InkAttached) {
|
||||||
ballComponent->Sticky = true;
|
m_InkAttached = true;
|
||||||
ballComponent->StickyPlacement = glm::vec3(0, 0.5f, 0);
|
m_Waiting = true;
|
||||||
ballTransform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
m_BlockedWaiting = 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) {
|
} else if (m_Sticky) {
|
||||||
m_Sticky = false;
|
m_Sticky = false;
|
||||||
m_Waiting = true;
|
m_Waiting = true;
|
||||||
ballComponent->Sticky = true;
|
ballComponent->Sticky = true;
|
||||||
ballComponent->Waiting = true;
|
|
||||||
ballComponent->StickyPlacement = ballTransform->Position - padTransform->Position;
|
ballComponent->StickyPlacement = ballTransform->Position - padTransform->Position;
|
||||||
ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed;
|
ballComponent->SavedSpeed = glm::normalize(glm::vec3(x, y, 0.f)) * ballComponent->Speed;
|
||||||
ballTransform->Velocity *= -1;
|
ballTransform->Velocity *= -1;
|
||||||
@@ -439,9 +447,26 @@ bool dd::Systems::BallSystem::OnInkBlaster(const dd::Events::InkBlaster &event)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::BallSystem::OnInkBlasterOver(const dd::Events::InkBlasterOver &event)
|
||||||
|
{
|
||||||
|
auto ballComponent = m_World->GetComponent<Components::Ball>(event.Ball);
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(event.Ball);
|
||||||
|
|
||||||
|
m_InkBlaster = false;
|
||||||
|
m_InkAttached = false;
|
||||||
|
m_BlockedWaiting = false;
|
||||||
|
m_Sticky = true;
|
||||||
|
ballComponent->SavedSpeed = glm::normalize(glm::vec3(0.f, 1.f, 0.f)) * ballComponent->Speed;
|
||||||
|
m_Waiting = false;
|
||||||
|
transform->Velocity = glm::normalize(glm::vec3(0.f, 1, 0.f)) * ballComponent->Speed;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool dd::Systems::BallSystem::OnActionButton(const dd::Events::ActionButton &event)
|
bool dd::Systems::BallSystem::OnActionButton(const dd::Events::ActionButton &event)
|
||||||
{
|
{
|
||||||
m_Waiting = false;
|
if (!m_BlockedWaiting) {
|
||||||
|
m_Waiting = false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+117
-14
@@ -150,7 +150,7 @@ void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 s
|
|||||||
for (int i = 0; i < rows; i++) {
|
for (int i = 0; i < rows; i++) {
|
||||||
num--;
|
num--;
|
||||||
for (int j = 0; j < Lines(); j++) {
|
for (int j = 0; j < Lines(); j++) {
|
||||||
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, 0, num, 1);
|
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, 0, num, 1, glm::vec4(0, 0, 0, 0));
|
||||||
}
|
}
|
||||||
if (num == 1)
|
if (num == 1)
|
||||||
num = Lines();
|
num = Lines();
|
||||||
@@ -171,7 +171,7 @@ void dd::Systems::LevelSystem::CreateLevel(int aboveBasicLevel)
|
|||||||
for (int i = 0; i < Rows(); i++) {
|
for (int i = 0; i < Rows(); i++) {
|
||||||
num--;
|
num--;
|
||||||
for (int j = 0; j < Lines(); j++) {
|
for (int j = 0; j < Lines(); j++) {
|
||||||
CreateBrick(i, j, SpaceBetweenBricks(), SpaceToEdge(), aboveBasicLevel, num, m_Bricks[getter]);
|
CreateBrick(i, j, SpaceBetweenBricks(), SpaceToEdge(), aboveBasicLevel, num, m_Bricks[getter], m_Colors[getter]);
|
||||||
getter++;
|
getter++;
|
||||||
}
|
}
|
||||||
if (num == 1) {
|
if (num == 1) {
|
||||||
@@ -182,7 +182,7 @@ void dd::Systems::LevelSystem::CreateLevel(int aboveBasicLevel)
|
|||||||
SetRestarting(false);
|
SetRestarting(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int aboveLevel, int num, int typeInt)
|
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int aboveLevel, int num, int typeInt, glm::vec4 colorVec)
|
||||||
{
|
{
|
||||||
if (typeInt == EmptyBrickSpace) {
|
if (typeInt == EmptyBrickSpace) {
|
||||||
SetNumberOfBricks(NumberOfBricks() - 1);
|
SetNumberOfBricks(NumberOfBricks() - 1);
|
||||||
@@ -192,25 +192,24 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
|||||||
m_World->RemoveComponent<Components::Template>(brick);
|
m_World->RemoveComponent<Components::Template>(brick);
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(brick);
|
auto transform = m_World->GetComponent<Components::Transform>(brick);
|
||||||
auto cBrick = m_World->GetComponent<Components::Brick>(brick);
|
auto cBrick = m_World->GetComponent<Components::Brick>(brick);
|
||||||
|
auto model = m_World->GetComponent<Components::Model>(brick);
|
||||||
if (typeInt == StandardBrick) {
|
if (typeInt == StandardBrick) {
|
||||||
|
model->Color = colorVec;
|
||||||
} else if (typeInt == MultiBallBrick) {
|
} else if (typeInt == MultiBallBrick) {
|
||||||
cBrick->Type = MultiBallBrick;
|
cBrick->Type = MultiBallBrick;
|
||||||
auto model = m_World->GetComponent<Components::Model>(brick);
|
|
||||||
model->ModelFile = "Models/Brick/IceBrick.obj";
|
model->ModelFile = "Models/Brick/IceBrick.obj";
|
||||||
} else if (typeInt == LifebuoyBrick) {
|
} else if (typeInt == LifebuoyBrick) {
|
||||||
cBrick->Type = LifebuoyBrick;
|
cBrick->Type = LifebuoyBrick;
|
||||||
auto model = m_World->GetComponent<Components::Model>(brick);
|
|
||||||
model->ModelFile = "Models/Brick/LifeBuoyBrick.obj";
|
model->ModelFile = "Models/Brick/LifeBuoyBrick.obj";
|
||||||
} else if (typeInt == StickyBrick) {
|
} else if (typeInt == StickyBrick) {
|
||||||
cBrick->Type = StickyBrick;
|
cBrick->Type = StickyBrick;
|
||||||
auto model = m_World->GetComponent<Components::Model>(brick);
|
|
||||||
model->ModelFile = "Models/Brick/StickyBrick.obj";
|
model->ModelFile = "Models/Brick/StickyBrick.obj";
|
||||||
} else if (typeInt == InkBlasterBrick) {
|
} else if (typeInt == InkBlasterBrick) {
|
||||||
cBrick->Type = InkBlasterBrick;
|
cBrick->Type = InkBlasterBrick;
|
||||||
auto model = m_World->GetComponent<Components::Model>(brick);
|
|
||||||
model->Color = glm::vec4(0.1f, 0.1f, 0.1f, .0f);
|
model->Color = glm::vec4(0.1f, 0.1f, 0.1f, .0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float x = line * spacesBetweenBricks.x;
|
float x = line * spacesBetweenBricks.x;
|
||||||
float y = row * spacesBetweenBricks.y;
|
float y = row * spacesBetweenBricks.y;
|
||||||
transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y + aboveLevel, -10.f);
|
transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y + aboveLevel, -10.f);
|
||||||
@@ -225,7 +224,6 @@ void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
|
|||||||
|
|
||||||
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("Collision happened!");
|
|
||||||
EntityID entityBrick;
|
EntityID entityBrick;
|
||||||
EntityID entityBall;
|
EntityID entityBall;
|
||||||
EntityID entityShot = 0;
|
EntityID entityShot = 0;
|
||||||
@@ -250,12 +248,10 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
} else {
|
} else {
|
||||||
auto shot = m_World->GetComponent<Components::Projectile>(event.Entity1);
|
auto shot = m_World->GetComponent<Components::Projectile>(event.Entity1);
|
||||||
if (shot != nullptr) {
|
if (shot != nullptr) {
|
||||||
LOG_DEBUG("Entity1 is a shot!");
|
|
||||||
entityShot = event.Entity1;
|
entityShot = event.Entity1;
|
||||||
} else {
|
} else {
|
||||||
shot = m_World->GetComponent<Components::Projectile>(event.Entity2);
|
shot = m_World->GetComponent<Components::Projectile>(event.Entity2);
|
||||||
if (shot != nullptr) {
|
if (shot != nullptr) {
|
||||||
LOG_DEBUG("Entity2 is a shot!");
|
|
||||||
entityShot = event.Entity2;
|
entityShot = event.Entity2;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -319,6 +315,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
|
|
||||||
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
|
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
|
||||||
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
|
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
|
||||||
|
auto brickModel = m_World->GetComponent<Components::Model>(entityBrick);
|
||||||
|
|
||||||
Events::SetImpulse e;
|
Events::SetImpulse e;
|
||||||
e.Entity = entityBrick;
|
e.Entity = entityBrick;
|
||||||
@@ -337,6 +334,21 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
es.Score = brick->Score * ball->Combo;
|
es.Score = brick->Score * ball->Combo;
|
||||||
EventBroker->Publish(es);
|
EventBroker->Publish(es);
|
||||||
|
|
||||||
|
Events::CreateParticleSequence ep;
|
||||||
|
ep.parent = entityBrick;
|
||||||
|
ep.EmitterLifeTime = 1.f;
|
||||||
|
ep.ParticleLifeTime = 1.5f;
|
||||||
|
ep.ParticlesPerTick = 1;
|
||||||
|
ep.SpawnRate = 0.2;
|
||||||
|
ep.EmittingAngle = glm::half_pi<float>();
|
||||||
|
ep.Spread = 1.5f;
|
||||||
|
ep.Position = transformComponentBrick->Position;
|
||||||
|
ep.Radius = 0.05;
|
||||||
|
ep.SpriteFile = "Textures/Particles/FadeBall.png";
|
||||||
|
ep.Color = brickModel->Color + glm::vec4(1);
|
||||||
|
ep.Speed = 50;
|
||||||
|
EventBroker->Publish(ep);
|
||||||
|
|
||||||
//std::cout << "Combo: " << ball->Combo << std::endl;
|
//std::cout << "Combo: " << ball->Combo << std::endl;
|
||||||
//std::cout << NumberOfBricks() << std::endl;
|
//std::cout << NumberOfBricks() << std::endl;
|
||||||
//std::cout << "Brick Score: " << brick->Score << std::endl;
|
//std::cout << "Brick Score: " << brick->Score << std::endl;
|
||||||
@@ -426,12 +438,33 @@ bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &ev
|
|||||||
void dd::Systems::LevelSystem::GetNextLevel()
|
void dd::Systems::LevelSystem::GetNextLevel()
|
||||||
{
|
{
|
||||||
std::array<int, 42> level;
|
std::array<int, 42> level;
|
||||||
// 0 is empty space.
|
std::array<glm::vec4, 42> color;
|
||||||
|
// Level array indicates type of brick.
|
||||||
|
// 0 is empty space.
|
||||||
// 1 is standard brick.
|
// 1 is standard brick.
|
||||||
// 2 is multiball brick.
|
// 2 is multiball brick.
|
||||||
// 3 is lifebuoy brick.
|
// 3 is lifebuoy brick.
|
||||||
// 4 is sticky brick.
|
// 4 is sticky brick.
|
||||||
// 5 is ink blaster brick.
|
// 5 is ink blaster brick.
|
||||||
|
|
||||||
|
// wolor array determines the color of standard bricks.
|
||||||
|
// w is white.
|
||||||
|
// r is red.
|
||||||
|
// g is green.
|
||||||
|
// b is blue.
|
||||||
|
// y is yellow.
|
||||||
|
// c is cyan.
|
||||||
|
// m is magenta.
|
||||||
|
// d is dark.
|
||||||
|
// Feel free to make your own.
|
||||||
|
glm::vec4 w = glm::vec4(1, 1, 1, 0);
|
||||||
|
glm::vec4 r = glm::vec4(1, 0, 0, 0);
|
||||||
|
glm::vec4 g = glm::vec4(0, 1, 0, 0);
|
||||||
|
glm::vec4 b = glm::vec4(0, 0, 1, 0);
|
||||||
|
glm::vec4 y = glm::vec4(1, 1, 0, 0);
|
||||||
|
glm::vec4 c = glm::vec4(0, 1, 1, 0);
|
||||||
|
glm::vec4 m = glm::vec4(1, 0, 1, 0);
|
||||||
|
glm::vec4 d = glm::vec4(0, 0, 0, 0);
|
||||||
if (m_CurrentCluster == 0) {
|
if (m_CurrentCluster == 0) {
|
||||||
if (m_CurrentLevel == 1) {
|
if (m_CurrentLevel == 1) {
|
||||||
level =
|
level =
|
||||||
@@ -441,6 +474,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0};
|
0, 0, 0, 0, 0, 0, 0};
|
||||||
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
} else if (m_CurrentLevel == 2) {
|
} else if (m_CurrentLevel == 2) {
|
||||||
level =
|
level =
|
||||||
{1, 0, 0, 0, 0, 0, 0,
|
{1, 0, 0, 0, 0, 0, 0,
|
||||||
@@ -449,6 +489,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0};
|
0, 0, 0, 0, 0, 0, 0};
|
||||||
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
} else if (m_CurrentLevel == 3) {
|
} else if (m_CurrentLevel == 3) {
|
||||||
level =
|
level =
|
||||||
{0, 0, 0, 0, 0, 0, 1,
|
{0, 0, 0, 0, 0, 0, 1,
|
||||||
@@ -457,6 +504,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0};
|
0, 0, 0, 0, 0, 0, 0};
|
||||||
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
} else if (m_CurrentLevel == 4) {
|
} else if (m_CurrentLevel == 4) {
|
||||||
level =
|
level =
|
||||||
{0, 0, 0, 0, 0, 0, 0,
|
{0, 0, 0, 0, 0, 0, 0,
|
||||||
@@ -465,6 +519,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 0, 0, 0, 0, 0, 0};
|
1, 0, 0, 0, 0, 0, 0};
|
||||||
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
} else if (m_CurrentLevel == 5) {
|
} else if (m_CurrentLevel == 5) {
|
||||||
level =
|
level =
|
||||||
{0, 0, 0, 0, 0, 0, 0,
|
{0, 0, 0, 0, 0, 0, 0,
|
||||||
@@ -473,6 +534,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 1};
|
0, 0, 0, 0, 0, 0, 1};
|
||||||
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
}
|
}
|
||||||
} else if (m_CurrentCluster == 1) {
|
} else if (m_CurrentCluster == 1) {
|
||||||
if (m_CurrentLevel == 1) {
|
if (m_CurrentLevel == 1) {
|
||||||
@@ -483,6 +551,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
1, 2, 1, 2, 1, 2, 1,
|
1, 2, 1, 2, 1, 2, 1,
|
||||||
1, 1, 0, 1, 0, 1, 1,
|
1, 1, 0, 1, 0, 1, 1,
|
||||||
4, 0, 0, 3, 0, 0, 5};
|
4, 0, 0, 3, 0, 0, 5};
|
||||||
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
r, g, b, y, c, m, d,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
} else if (m_CurrentLevel == 2) {
|
} else if (m_CurrentLevel == 2) {
|
||||||
level =
|
level =
|
||||||
{1, 0, 0, 0, 0, 0, 1,
|
{1, 0, 0, 0, 0, 0, 1,
|
||||||
@@ -491,6 +566,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
0, 0, 0, 1, 0, 0, 0,
|
0, 0, 0, 1, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0};
|
0, 0, 0, 0, 0, 0, 0};
|
||||||
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
} else if (m_CurrentLevel == 3) {
|
} else if (m_CurrentLevel == 3) {
|
||||||
level =
|
level =
|
||||||
{2, 0, 0, 0, 0, 0, 2,
|
{2, 0, 0, 0, 0, 0, 2,
|
||||||
@@ -499,7 +581,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
1, 0, 1, 1, 1, 0, 1,
|
1, 0, 1, 1, 1, 0, 1,
|
||||||
1, 0, 1, 1, 1, 0, 1,
|
1, 0, 1, 1, 1, 0, 1,
|
||||||
1, 0, 1, 1, 1, 0, 1};
|
1, 0, 1, 1, 1, 0, 1};
|
||||||
} else if (m_CurrentLevel == 4) {
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
level =
|
level =
|
||||||
{1, 2, 1, 1, 1, 2, 1,
|
{1, 2, 1, 1, 1, 2, 1,
|
||||||
1, 0, 1, 1, 1, 0, 1,
|
1, 0, 1, 1, 1, 0, 1,
|
||||||
@@ -507,6 +595,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
1, 0, 1, 1, 1, 0, 1,
|
1, 0, 1, 1, 1, 0, 1,
|
||||||
1, 0, 0, 0, 0, 0, 1,
|
1, 0, 0, 0, 0, 0, 1,
|
||||||
0, 1, 1, 0, 1, 1, 0};
|
0, 1, 1, 0, 1, 1, 0};
|
||||||
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
} else if (m_CurrentLevel == 5) {
|
} else if (m_CurrentLevel == 5) {
|
||||||
level =
|
level =
|
||||||
{1, 0, 1, 0, 1, 0, 1,
|
{1, 0, 1, 0, 1, 0, 1,
|
||||||
@@ -515,12 +610,20 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
|||||||
0, 1, 0, 2, 0, 1, 0,
|
0, 1, 0, 2, 0, 1, 0,
|
||||||
1, 0, 1, 0, 1, 0, 1,
|
1, 0, 1, 0, 1, 0, 1,
|
||||||
0, 1, 0, 1, 0, 1, 0};
|
0, 1, 0, 1, 0, 1, 0};
|
||||||
|
color =
|
||||||
|
{w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w,
|
||||||
|
w, w, w, w, w, w, w};
|
||||||
}
|
}
|
||||||
} else if (m_CurrentCluster == 3) {
|
} else if (m_CurrentCluster == 3) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::copy(std::begin(level), std::end(level), std::begin(m_Bricks));
|
std::copy(std::begin(level), std::end(level), std::begin(m_Bricks));
|
||||||
|
std::copy(std::begin(color), std::end(color), std::begin(m_Colors));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::LevelSystem::OnHitPad(const dd::Events::HitPad &event)
|
bool dd::Systems::LevelSystem::OnHitPad(const dd::Events::HitPad &event)
|
||||||
|
|||||||
@@ -118,6 +118,17 @@ bool dd::Systems::ProjectileSystem::OnActionButton(const dd::Events::ActionButto
|
|||||||
m_SquidLoaded = false;
|
m_SquidLoaded = false;
|
||||||
ball->InkBlaster = false;
|
ball->InkBlaster = false;
|
||||||
ball->Sticky = false;
|
ball->Sticky = false;
|
||||||
|
ball->Waiting = true;
|
||||||
|
|
||||||
|
{
|
||||||
|
Events::InkBlasterOver e;
|
||||||
|
e.Ball = m_AttachedSquid;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
Events::ActionButton e;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ void dd::Systems::PhysicsSystem::ContactListener::BeginContact(b2Contact* contac
|
|||||||
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
||||||
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
|
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
|
||||||
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
|
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
|
||||||
m_PhysicsSystem->EventBroker->Publish(e);
|
//contact->GetManifold()->points
|
||||||
|
b2Vec2 pos = worldManifold.points[0];
|
||||||
|
glm::vec2 glmPos = glm::vec2(pos.x, pos.y);
|
||||||
|
e.IntersectionPoint = glmPos;
|
||||||
|
m_PhysicsSystem->EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::PhysicsSystem::ContactListener::EndContact(b2Contact* contact)
|
void dd::Systems::PhysicsSystem::ContactListener::EndContact(b2Contact* contact)
|
||||||
|
|||||||
@@ -15,15 +15,17 @@ void dd::Systems::PhysicsSystem::Initialize()
|
|||||||
m_DestructionListener = new DestructionListener(this);
|
m_DestructionListener = new DestructionListener(this);
|
||||||
m_ContactListener = new ContactListener(this);
|
m_ContactListener = new ContactListener(this);
|
||||||
m_PhysicsWorld = new b2World(m_Gravity);
|
m_PhysicsWorld = new b2World(m_Gravity);
|
||||||
|
m_ParticleContactDisabler = new ParticleContactDisabler();
|
||||||
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
||||||
m_PhysicsWorld->SetContactFilter(&m_ParticleContactDisabler);
|
m_PhysicsWorld->SetContactFilter(m_ParticleContactDisabler);
|
||||||
m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
||||||
|
|
||||||
InitializeWater();
|
InitializeWater();
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause);
|
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PhysicsSystem::OnStageCleared);
|
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PhysicsSystem::OnStageCleared);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ECreateParticleSequence, &PhysicsSystem::CreateParticleSequence);
|
EVENT_SUBSCRIBE_MEMBER(m_ECreateParticleSequence, &PhysicsSystem::CreateParticleSequence);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PhysicsSystem::OnContact);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::PhysicsSystem::InitializeWater()
|
void dd::Systems::PhysicsSystem::InitializeWater()
|
||||||
@@ -261,7 +263,10 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
||||||
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
|
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (particle && !pTemplate) {
|
if (particle && !pTemplate) {
|
||||||
particle->LifeTime -= dt;
|
particle->LifeTime -= dt;
|
||||||
if (particle->LifeTime <= 0) {
|
if (particle->LifeTime <= 0) {
|
||||||
@@ -280,7 +285,21 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
|||||||
m_World->RemoveEntity(entity);
|
m_World->RemoveEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auto sprite = m_World->GetComponent<Components::Sprite>(entity);
|
||||||
|
sprite->Color.w = particle->LifeTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
||||||
|
if (emitter) {
|
||||||
|
EntityID emitterParent = emitter->Parent;
|
||||||
|
if (emitterParent != 0) {
|
||||||
|
auto emitterTransform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
auto parentTransform = m_World->GetComponent<Components::Transform>(emitterParent);
|
||||||
|
if (emitterTransform && parentTransform) {
|
||||||
|
emitterTransform->Position = parentTransform->Position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
||||||
@@ -335,6 +354,7 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
|||||||
m_BodiesToEntities.erase(it->second);
|
m_BodiesToEntities.erase(it->second);
|
||||||
m_EntitiesToBodies.erase(entity);
|
m_EntitiesToBodies.erase(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -453,14 +473,14 @@ void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
|
|||||||
void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||||
{
|
{
|
||||||
std::vector<EntityID> emittersToDelete;
|
std::vector<EntityID> emittersToDelete;
|
||||||
int pSizeTest = 0;
|
int pSizeTest = 0; //For debugging, delete this
|
||||||
|
int psListSize = 0;
|
||||||
for (int i = 0; i < m_ParticleEmitters.ParticleSystem.size(); i++) {
|
for (int i = 0; i < m_ParticleEmitters.ParticleSystem.size(); i++) {
|
||||||
auto e = m_ParticleEmitters.ParticleEmitter[i];
|
auto e = m_ParticleEmitters.ParticleEmitter[i];
|
||||||
auto pt = m_ParticleEmitters.ParticleTemplate[i];
|
auto pt = m_ParticleEmitters.ParticleTemplate[i];
|
||||||
auto ps = m_ParticleEmitters.ParticleSystem[i];
|
auto ps = m_ParticleEmitters.ParticleSystem[i];
|
||||||
pSizeTest += ps->GetParticleCount();
|
pSizeTest += ps->GetParticleCount();
|
||||||
|
psListSize++;
|
||||||
|
|
||||||
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(e);
|
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(e);
|
||||||
auto particleTemplate = m_World->GetComponent<Components::Particle>(pt);
|
auto particleTemplate = m_World->GetComponent<Components::Particle>(pt);
|
||||||
if(!emitter) {
|
if(!emitter) {
|
||||||
@@ -471,8 +491,8 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
LOG_INFO("ParticleTemplate Component is nil.");
|
LOG_INFO("ParticleTemplate Component is nil.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto TempTransform = m_World->GetComponent<Components::Transform>(e);
|
auto emitterTransform = m_World->GetComponent<Components::Transform>(e);
|
||||||
TempTransform->Orientation = glm::rotate(glm::quat(), 3.f, glm::vec3(0.f, 0.f, -1.f));
|
emitterTransform->Orientation = glm::rotate(glm::quat(), 3.f, glm::vec3(0.f, 0.f, -1.f));
|
||||||
|
|
||||||
emitter->TimeSinceLastSpawn += dt;
|
emitter->TimeSinceLastSpawn += dt;
|
||||||
emitter->LifeTime -= dt;
|
emitter->LifeTime -= dt;
|
||||||
@@ -497,20 +517,22 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
|
|
||||||
std::uniform_real_distribution<float> dis(eAngle - halfSpread, eAngle + halfSpread);
|
std::uniform_real_distribution<float> dis(eAngle - halfSpread, eAngle + halfSpread);
|
||||||
float pAngle = dis(gen);
|
float pAngle = dis(gen);
|
||||||
|
std::uniform_real_distribution<float> dis2(0.3, 1.5);
|
||||||
|
float speedMultiplier = dis2(gen);
|
||||||
glm::vec2 unitVec = glm::normalize(glm::vec2(glm::cos(pAngle), glm::sin(pAngle)));
|
glm::vec2 unitVec = glm::normalize(glm::vec2(glm::cos(pAngle), glm::sin(pAngle)));
|
||||||
glm::vec2 vel = unitVec * emitter->Speed;
|
glm::vec2 vel = unitVec * emitter->Speed * (float)dt * speedMultiplier * 0.5f;
|
||||||
particleDef.velocity = b2Vec2(vel.x, vel.y);
|
particleDef.velocity = b2Vec2(vel.x, vel.y);
|
||||||
particleDef.position = b2Vec2(templateTransform->Position.x, templateTransform->Position.y);
|
particleDef.position = b2Vec2(emitterTransform->Position.x, emitterTransform->Position.y);
|
||||||
|
|
||||||
|
|
||||||
auto particle = m_World->CloneEntity(pt, 0);
|
auto particle = m_World->CloneEntity(pt, 0);
|
||||||
m_World->RemoveComponent<Components::Template>(particle);
|
m_World->RemoveComponent<Components::Template>(particle);
|
||||||
auto transform2 = m_World->GetComponent<Components::Transform>(particle);
|
auto transform2 = m_World->GetComponent<Components::Transform>(particle);
|
||||||
|
|
||||||
std::uniform_real_distribution<float> dist(0, 1);
|
std::uniform_real_distribution<float> dist(0, 1);
|
||||||
float zDistribution = dist(gen);
|
float zDistribution = dist(gen);
|
||||||
transform2->Position = glm::vec3(transform2->Position.x, transform2->Position.y, -9.5f + zDistribution);
|
transform2->Position = glm::vec3(emitterTransform->Position.x, emitterTransform->Position.y, -9.5f + zDistribution);
|
||||||
transform2->Scale = glm::vec3(particleTemplate->Radius * 2.f, particleTemplate->Radius * 2.f, 1);
|
transform2->Scale = glm::vec3(particleTemplate->Radius * 2.f / speedMultiplier, particleTemplate->Radius * 2.f / speedMultiplier, 1);
|
||||||
|
|
||||||
|
|
||||||
auto b2Particle = ps->CreateParticle(particleDef);
|
auto b2Particle = ps->CreateParticle(particleDef);
|
||||||
@@ -518,8 +540,25 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
|
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
|
||||||
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
||||||
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// system("cls");
|
||||||
|
// std::cout << "Particles living: " << pSizeTest << std::endl;
|
||||||
|
// std::cout << "particle systems: " << psListSize << std::endl;
|
||||||
|
// int entHandles = 0;
|
||||||
|
// for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++)
|
||||||
|
// entHandles += m_EntitiesToParticleHandle[i].size();
|
||||||
|
// std::cout << "Entities and handles: " << entHandles << std::endl;
|
||||||
|
// LOG_INFO("Particles living: %i", pSizeTest);
|
||||||
|
// LOG_INFO("Particle systems: %i", psListSize);
|
||||||
|
// int entHandles = 0;
|
||||||
|
// for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++)
|
||||||
|
// entHandles += m_EntitiesToParticleHandle[i].size();
|
||||||
|
// LOG_INFO("Entities and handles: %i", entHandles);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < emittersToDelete.size(); i++)
|
for (int i = 0; i < emittersToDelete.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -542,6 +581,8 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int stp = 0;
|
int stp = 0;
|
||||||
for (auto ts : m_EntitiesToParticleHandle)
|
for (auto ts : m_EntitiesToParticleHandle)
|
||||||
{
|
{
|
||||||
@@ -552,10 +593,15 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreateParticleSequence &event)
|
bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreateParticleSequence &event)
|
||||||
{
|
{
|
||||||
//Creating Emitter
|
//Creating Emitter
|
||||||
auto emitter = m_World->CreateEntity();
|
EntityID emitter = m_World->CreateEntity();
|
||||||
|
|
||||||
auto emitterTransform = m_World->AddComponent<Components::Transform>(emitter);
|
auto emitterTransform = m_World->AddComponent<Components::Transform>(emitter);
|
||||||
auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(emitter);
|
auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(emitter);
|
||||||
|
|
||||||
|
if (event.parent != 0) {
|
||||||
|
particleEmitter->Parent = event.parent;
|
||||||
|
}
|
||||||
|
|
||||||
emitterTransform->Position = event.Position;
|
emitterTransform->Position = event.Position;
|
||||||
particleEmitter->GravityScale = event.GravityScale;
|
particleEmitter->GravityScale = event.GravityScale;
|
||||||
particleEmitter->SpawnRate = event.SpawnRate;
|
particleEmitter->SpawnRate = event.SpawnRate;
|
||||||
@@ -576,6 +622,7 @@ bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreatePart
|
|||||||
|
|
||||||
particleTransform->Position = emitterTransform->Position;
|
particleTransform->Position = emitterTransform->Position;
|
||||||
sprite->SpriteFile = event.SpriteFile;
|
sprite->SpriteFile = event.SpriteFile;
|
||||||
|
sprite->Color = event.Color;
|
||||||
particleComponent->LifeTime = event.ParticleLifeTime;
|
particleComponent->LifeTime = event.ParticleLifeTime;
|
||||||
particleComponent->Flags = event.Flags;
|
particleComponent->Flags = event.Flags;
|
||||||
particleComponent->Radius = event.Radius;
|
particleComponent->Radius = event.Radius;
|
||||||
@@ -637,6 +684,40 @@ b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius,
|
|||||||
return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||||
|
{
|
||||||
|
//Check if it is a brick colliding
|
||||||
|
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
|
||||||
|
Components::Model* model;
|
||||||
|
|
||||||
|
if (!brick) {
|
||||||
|
brick = m_World->GetComponent<Components::Brick>(event.Entity2);
|
||||||
|
if (!brick) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
model = m_World->GetComponent<Components::Model>(event.Entity2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
model = m_World->GetComponent<Components::Model>(event.Entity1);
|
||||||
|
}
|
||||||
|
Events::CreateParticleSequence e;
|
||||||
|
e.EmitterLifeTime = 4;
|
||||||
|
//- glm::atan(event.Normal.x, event.Normal.y
|
||||||
|
e.EmittingAngle = glm::half_pi<float>();
|
||||||
|
e.Spread = 0.5f;
|
||||||
|
e.NumberOfTicks = 1;
|
||||||
|
e.ParticleLifeTime = 1.f;
|
||||||
|
e.ParticlesPerTick = 15;
|
||||||
|
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -10);
|
||||||
|
e.Radius = 0.2f;
|
||||||
|
e.SpriteFile = "Textures/Particles/Cloud_Particle.png";
|
||||||
|
e.Color = model->Color + glm::vec4(1);
|
||||||
|
e.Speed = 100;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
dd::Systems::PhysicsSystem::~PhysicsSystem()
|
dd::Systems::PhysicsSystem::~PhysicsSystem()
|
||||||
|
|||||||
Reference in New Issue
Block a user