Merge branch 'master' into gui

Conflicts:
	include/Game/GUI/HUD.h
	src/game/Core/Renderer.cpp
This commit is contained in:
2015-10-08 23:47:25 +02:00
73 changed files with 22402 additions and 302 deletions
+1 -4
View File
@@ -358,12 +358,10 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
{
// Forward-render semi-transparent objects on top of the current framebuffer
glDisable(GL_CULL_FACE);
glCullFace(GL_BACK);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
// glClearColor(1, 0.9, 0.8f, 1);
@@ -444,7 +442,6 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
glActiveTexture(GL_TEXTURE1);
+2 -1
View File
@@ -30,6 +30,7 @@ uniform vec3 LightPosition;
uniform float LightRadius;
uniform vec3 LightSpecular;
uniform vec3 LightDiffuse;
uniform vec4 Color;
in VertexData
{
@@ -86,5 +87,5 @@ void main()
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
//frag_Diffuse = light;
frag_Diffuse = diffuseTexel;
frag_Diffuse = diffuseTexel * Color;
}
+127 -43
View File
@@ -18,7 +18,11 @@ 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_EInkBlaster, &BallSystem::OnInkBlaster);
EVENT_SUBSCRIBE_MEMBER(m_EInkBlasterOver, &BallSystem::OnInkBlasterOver);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton);
//OctoBall
{
@@ -33,15 +37,14 @@ void dd::Systems::BallSystem::Initialize()
circleShape->Radius = 0.4f;
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
ball->Speed = 5.f;
ball->Waiting = true;
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
std::shared_ptr<Components::Template> ballTemplate = m_World->AddComponent<Components::Template>(ent);
physics->CollisionType = CollisionType::Type::Dynamic;
physics->CollisionType = CollisionType::Type::Dynamic;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall);
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall | CollisionLayer::LifeBuoy);
physics->Calculate = true;
//auto plight = m_World->AddComponent<Components::PointLight>(ent);
//plight->Radius = 2.f;
transform->Sticky = true;
m_World->CommitEntity(ent);
@@ -60,11 +63,17 @@ void dd::Systems::BallSystem::Initialize()
void dd::Systems::BallSystem::Update(double dt)
{
if (Lives() < 0)
if (Lives() == 0)
{
SetLives(3);
Events::GameOver e;
EventBroker->Publish(e);
Events::Pause p;
p.Type = "All";
EventBroker->Publish(p);
//TODO: Make this not so ugly
SetLives(-1);
}
ResolveContacts();
}
@@ -100,14 +109,38 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
if (templateCheck != nullptr){ return; }
if (ballComponent != nullptr) {
if (ReplaceBall()) {
SetReplaceBall(false);
if (ReplaceBall()) {
SetReplaceBall(false);
m_Waiting = true;
ballComponent->Waiting = true;
}
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(0.0f, 0.26f, -10.f);
transform->Velocity = glm::vec3(0.0f, -ballComponent->Speed, 0.f);
if (ballComponent->Waiting) {
if (!m_Waiting) {
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 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->Orientation = glm::quat();
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);
if (glm::abs(transformBall->Velocity.y) < 2) {
if (transformBall->Velocity.y > 0) {
@@ -116,7 +149,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;
@@ -224,44 +257,64 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
}
else {
return false;
//TODO: Add support for power-up collisions
}
auto brick = m_World->GetComponent<Components::Brick>(otherEntitiy);
if (brick != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(otherEntitiy);
auto physics = m_World->GetComponent<Components::Physics>(otherEntitiy);
auto rectangle = m_World->GetComponent<Components::RectangleShape>(otherEntitiy);
int hey = 5;
}
//if this is a brick thats dead do not collide :)
auto ballTransform = m_World->GetComponent<Components::Transform>(ballEntity);
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;
e.Ball = ballEntity;
e.Pad = otherEntitiy;
EventBroker->Publish(e);
// Events::HitLag el;
// el.Time = 0.1f;
//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_InkBlaster) {
if (!m_InkAttached) {
m_InkAttached = true;
m_Waiting = true;
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) {
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;
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;
EventBroker->Publish(ec);
//std::cout << "Combo: " << ballComponent->Combo << std::endl;
}
else {
} // Lifebuoy should always reflect the ball upwards
else if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Lifebuoy"){
ballTransform->Velocity = glm::vec3(ballTransform->Velocity.x, abs(ballTransform->Velocity.y), ballTransform->Velocity.z);
Events::LifebuoyHit e;
e.Lifebuoy = otherEntitiy;
EventBroker->Publish(e);
} else {
auto it = m_Contacts.find(ballEntity);
if (it == m_Contacts.end()) {
std::list<glm::vec2> normalList;
@@ -272,9 +325,6 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
normalList.push_back(event.Normal);
m_Contacts[ballEntity] = normalList;
}
//glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal);
//ballTransform->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
return true;
@@ -285,23 +335,18 @@ 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);
auto ballComponent = m_World->GetComponent<Components::Ball>(entity);
reflectedVelocity = glm::normalize(reflectedVelocity) * ballComponent->Speed;
transform->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
@@ -324,6 +369,7 @@ void dd::Systems::BallSystem::CreateLife(int number)
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
transform->Sticky = true;
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->Number = number;
@@ -367,8 +413,10 @@ bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event)
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
auto ball1 = m_World->GetComponent<Components::Ball>(ent1);
auto ball2 = m_World->GetComponent<Components::Ball>(ent2);
ball1->Waiting = false;
ball2->Waiting = false;
auto padTransform = event.padTransform;
float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2;
float x1 = padTransform->Position.x/* - 2*/, x2 = padTransform->Position.x/* + 2*/;
if (x1 < -m_EdgeX) {
x1 = m_EdgeX - 0.2;
}
@@ -386,3 +434,39 @@ 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::OnInkBlaster(const dd::Events::InkBlaster &event)
{
m_InkBlaster = 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)
{
if (!m_BlockedWaiting) {
m_Waiting = false;
}
return true;
}
+284 -59
View File
@@ -27,12 +27,13 @@ void dd::Systems::LevelSystem::Initialize()
cRec->Dimensions = glm::vec2(0.9f, 0.35f);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(m_BrickTemplate);
std::shared_ptr<Components::Template> cTemplate = m_World->AddComponent<Components::Template>(m_BrickTemplate);
cPhys->CollisionType = CollisionType::Type::Dynamic;
cPhys->CollisionType = CollisionType::Type::Static;
cPhys->GravityScale = 0.f;
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
cPhys->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Ball | CollisionLayer::Type::Projectile | CollisionLayer::Type::Wall | CollisionLayer::LifeBuoy);
transform->Sticky = false;
model->ModelFile = "Models/Brick/TurquoiseBrick.obj";
model->ModelFile = "Models/Brick/WhiteBrick.obj";
transform->Position = glm::vec3(50, 50, -10);
//sound
@@ -48,7 +49,7 @@ void dd::Systems::LevelSystem::Update(double dt)
{
if (!m_Initialized) {
GetNextLevel();
CreateLevel();
CreateLevel(0);
m_Initialized = true;
}
}
@@ -61,16 +62,38 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
// Check the background.
auto model = m_World->GetComponent<Components::Model>(entity);
if (model != nullptr) {
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;
}
}
}
auto brick = m_World->GetComponent<Components::Brick>(entity);
if (brick != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
//Removes bricks that falls out of the stage.
if (transform->Position.y < -10) {
if (brick->Type == MultiBallBrick) {
if (transform->Position.y < -10) {
if (brick->Type == StandardBrick) {
} else if (brick->Type == MultiBallBrick) {
Events::MultiBall e;
e.padTransform = transform;
EventBroker->Publish(e);
}
} else if (brick->Type == LifebuoyBrick) {
Events::Lifebuoy e;
e.Transform = transform;
EventBroker->Publish(e);
} else if (brick->Type == StickyBrick) {
Events::StickyPad e;
EventBroker->Publish(e);
} else if (brick->Type == InkBlasterBrick) {
Events::InkBlaster e;
EventBroker->Publish(e);
}
m_LooseBricks--;
m_World->RemoveEntity(entity);
}
@@ -81,6 +104,8 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
if (NumberOfBricks() <= 0 && m_LooseBricks <= 0 && !Restarting()) {
if (MultiBalls() <= 0 && PowerUps() <= 0) {
Events::StageCleared ec;
ec.ClearedStage = m_CurrentLevel;
ec.StageCluster = m_CurrentCluster;
EventBroker->Publish(ec);
} else {
if (ball != nullptr && MultiBalls() > 0) {
@@ -125,7 +150,7 @@ void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 s
for (int i = 0; i < rows; i++) {
num--;
for (int j = 0; j < Lines(); j++) {
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num, 1);
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, 0, num, 1, glm::vec4(0, 0, 0, 0));
}
if (num == 1)
num = Lines();
@@ -136,7 +161,7 @@ void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 s
return;
}
void dd::Systems::LevelSystem::CreateLevel()
void dd::Systems::LevelSystem::CreateLevel(int aboveBasicLevel)
{
std::cout << "Loading level: " << m_CurrentLevel << std::endl;
SetNumberOfBricks(Rows() * Lines());
@@ -146,7 +171,7 @@ void dd::Systems::LevelSystem::CreateLevel()
for (int i = 0; i < Rows(); i++) {
num--;
for (int j = 0; j < Lines(); j++) {
CreateBrick(i, j, SpaceBetweenBricks(), SpaceToEdge(), num, m_Bricks[getter]);
CreateBrick(i, j, SpaceBetweenBricks(), SpaceToEdge(), aboveBasicLevel, num, m_Bricks[getter], m_Colors[getter]);
getter++;
}
if (num == 1) {
@@ -157,7 +182,7 @@ void dd::Systems::LevelSystem::CreateLevel()
SetRestarting(false);
}
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, 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) {
SetNumberOfBricks(NumberOfBricks() - 1);
@@ -167,17 +192,27 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
m_World->RemoveComponent<Components::Template>(brick);
auto transform = m_World->GetComponent<Components::Transform>(brick);
auto cBrick = m_World->GetComponent<Components::Brick>(brick);
auto model = m_World->GetComponent<Components::Model>(brick);
if (typeInt == StandardBrick) {
model->Color = colorVec;
} else if (typeInt == MultiBallBrick) {
cBrick->Type = MultiBallBrick;
std::shared_ptr<Components::PowerUpBrick> cPow = m_World->AddComponent<Components::PowerUpBrick>(brick);
auto model = m_World->GetComponent<Components::Model>(brick);
model->ModelFile = "Models/Brick/IceBrick.obj";
}
} else if (typeInt == LifebuoyBrick) {
cBrick->Type = LifebuoyBrick;
model->ModelFile = "Models/Brick/LifeBuoyBrick.obj";
} else if (typeInt == StickyBrick) {
cBrick->Type = StickyBrick;
model->ModelFile = "Models/Brick/StickyBrick.obj";
} else if (typeInt == InkBlasterBrick) {
cBrick->Type = InkBlasterBrick;
model->Color = glm::vec4(0.1f, 0.1f, 0.1f, 1.0f);
}
float x = line * spacesBetweenBricks.x;
float y = row * spacesBetweenBricks.y;
transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y , -10.f);
transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y + aboveLevel, -10.f);
cBrick->Score = 10 * num;
return;
}
@@ -191,6 +226,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
{
EntityID entityBrick;
EntityID entityBall;
EntityID entityShot = 0;
auto ball = m_World->GetComponent<Components::Ball>(event.Entity2);
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
if (brick != nullptr) {
@@ -210,7 +246,17 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
if (ball != nullptr) {
entityBall = event.Entity1;
} else {
return false;
auto shot = m_World->GetComponent<Components::Projectile>(event.Entity1);
if (shot != nullptr) {
entityShot = event.Entity1;
} else {
shot = m_World->GetComponent<Components::Projectile>(event.Entity2);
if (shot != nullptr) {
entityShot = event.Entity2;
} else {
return false;
}
}
}
}
@@ -219,13 +265,54 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
return false;
}
/*auto power = m_World->GetComponent<Components::PowerUpBrick>(entityBrick);
if (power != nullptr && NumberOfBricks() > 1) {
Events::CreatePowerUp e;
auto transform = m_World->GetComponent<Components::Transform>(entityBrick);
e.Position = transform->Position;
EventBroker->Publish(e);
}*/
if (entityShot != 0) {
// For when a brick gets shot.
brick->Removed = true;
auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick);
physicsComponent->CollisionType = CollisionType::Type::Dynamic;
physicsComponent->GravityScale = 1.f;
physicsComponent->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Water | CollisionLayer::Wall);
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
auto transformComponentShot = m_World->GetComponent<Components::Transform>(entityShot);
auto brickModel = m_World->GetComponent<Components::Model>(entityBrick);
Events::SetImpulse e;
e.Entity = entityBrick;
glm::vec2 point = glm::vec2(transformComponentBrick->Position.x + ((transformComponentShot->Position.x - transformComponentBrick->Position.x) / 4),
transformComponentBrick->Position.y + ((transformComponentShot->Position.y - transformComponentBrick->Position.y) / 4));
e.Impulse = glm::normalize(point)*5.f;
e.Point = point;
EventBroker->Publish(e);
SetNumberOfBricks(NumberOfBricks() - 1);
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
m_World->RemoveEntity(entityShot);
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(0.3f);
ep.Speed = 50;
EventBroker->Publish(ep);
return true;
}
if (!Restarting() && !brick->Removed) {
brick->Removed = true;
@@ -239,11 +326,13 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
auto ballTransform = m_World->GetComponent<Components::Transform>(entityBall);
auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick);
physicsComponent->CollisionType = CollisionType::Type::Dynamic;
physicsComponent->GravityScale = 1.f;
physicsComponent->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Water | CollisionLayer::Wall);
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
auto brickModel = m_World->GetComponent<Components::Model>(entityBrick);
Events::SetImpulse e;
e.Entity = entityBrick;
@@ -262,6 +351,21 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
es.Score = brick->Score * ball->Combo;
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(0.3f);
ep.Speed = 50;
EventBroker->Publish(ep);
//std::cout << "Combo: " << ball->Combo << std::endl;
//std::cout << NumberOfBricks() << std::endl;
//std::cout << "Brick Score: " << brick->Score << std::endl;
@@ -304,6 +408,7 @@ bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &
cPhys->CollisionType = CollisionType::Type::Dynamic;
cPhys->Category = CollisionLayer::Type::PowerUp;
cPhys->Mask = CollisionLayer::Type::Pad;
transform->Sticky = false;
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
@@ -337,8 +442,16 @@ bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &ev
m_CurrentLevel++;
if (m_CurrentLevel < 6) {
GetNextLevel();
CreateLevel();
}
CreateLevel(12);
} else {
// Win
Events::ClusterClear e;
EventBroker->Publish(e);
Events::Pause p;
p.Type = "All";
EventBroker->Publish(p);
}
}
return true;
}
@@ -346,10 +459,51 @@ bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &ev
void dd::Systems::LevelSystem::GetNextLevel()
{
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.
// 2 is multiball brick.
if (m_CurrentCluster == 1) {
// 3 is lifebuoy brick.
// 4 is sticky 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);
//glm::vec4 p4 = glm::vec4(asd.f / 255.f, asd.f / 255.f, sad.f / 255.f, 1.f);
glm::vec4 br = glm::vec4(143.f / 255.f, 98.f / 255.f, 0.f / 255.f, 1.f);
glm::vec4 lb1 = glm::vec4(115.f / 255.f, 232.f / 255.f, 236.f / 255.f, 1.f);
glm::vec4 lb2 = glm::vec4(107.f / 255.f, 214.f / 255.f, 218.f / 255.f, 1.f);
glm::vec4 lb3 = glm::vec4(91.f / 255.f, 183.f / 255.f, 186.f / 255.f, 1.f);
glm::vec4 lb4 = glm::vec4(70.f / 255.f, 153.f / 255.f, 156.f / 255.f, 1.f);
glm::vec4 p1 = glm::vec4(255.f / 255.f, 184.f / 255.f, 254.f / 255.f, 1.f);
glm::vec4 p2 = glm::vec4(255.f / 255.f, 81.f / 255.f, 253.f / 255.f, 1.f);
glm::vec4 p3 = glm::vec4(189.f / 255.f, 0.f / 255.f, 187.f / 255.f, 1.f);
glm::vec4 p4 = glm::vec4(125.f / 255.f, 0.f / 255.f, 147.f / 255.f, 1.f);
if (m_CurrentCluster == 0) {
if (m_CurrentLevel == 1) {
level =
{0, 0, 0, 0, 0, 0, 0,
@@ -358,6 +512,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};
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) {
level =
{1, 0, 0, 0, 0, 0, 0,
@@ -366,6 +527,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};
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) {
level =
{0, 0, 0, 0, 0, 0, 1,
@@ -374,6 +542,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};
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) {
level =
{0, 0, 0, 0, 0, 0, 0,
@@ -382,6 +557,13 @@ void dd::Systems::LevelSystem::GetNextLevel()
0, 0, 0, 0, 0, 0, 0,
0, 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) {
level =
{0, 0, 0, 0, 0, 0, 0,
@@ -390,54 +572,97 @@ 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, 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 == 2) {
} else if (m_CurrentCluster == 1) {
if (m_CurrentLevel == 1) {
level =
{1, 1, 0, 1, 0, 1, 1,
{0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1,
1, 2, 1, 2, 1, 2, 1,
1, 1, 0, 1, 0, 1, 1,
1, 0, 0, 1, 0, 0, 1};
1, 0, 1, 2, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0};
color =
{w, w, w, w, w, w, w,
lb4, lb4, lb4, lb4, lb4, lb4, lb4,
lb3, lb3, lb3, lb3, lb3, lb3, lb3,
lb2, lb2, lb2, lb2, lb2, lb2, lb2,
lb1, lb1, lb1, lb1, lb1, lb1, lb1,
w, w, w, w, w, w, w};
} else if (m_CurrentLevel == 2) {
level =
{1, 0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 0, 1, 0,
0, 0, 2, 2, 2, 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, 1, 0, 1, 0, 0,
0, 1, 0, 1, 0, 1, 0,
0, 0, 1, 1, 1, 0, 0,
0, 0, 0, 3, 0, 0, 0,
1, 1, 1, 0, 1, 1, 1,
1, 0, 0, 0, 0, 0, 1};
color =
{w, w, r, w, r, w, w,
w, w, w, r, w, w, w,
w, w, r, w, r, w, w,
w, w, w, w, w, w, w,
w, r, w, w, w, r, w,
r, w, w, w, w, w, r};
} else if (m_CurrentLevel == 3) {
level =
{2, 0, 0, 0, 0, 0, 2,
0, 1, 0, 0, 0, 1, 0,
1, 2, 1, 1, 1, 2, 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) {
{0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 1, 1, 0, 0,
0, 1, 1, 1, 1, 1, 0,
1, 1, 1, 4, 1, 1, 1,
0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 1, 1, 0, 0};
color =
{g, g, g, g, g, g, g,
g, g, g, g, g, g, g,
g, g, g, g, g, g, g,
g, g, g, w, g, g, g,
w, w, w, br, w, w, w,
w, w, br, br, br, w, w};
} else if (m_CurrentLevel == 4) {
level =
{1, 2, 1, 1, 1, 2, 1,
1, 0, 1, 1, 1, 0, 1,
1, 2, 1, 1, 1, 2, 1,
1, 0, 1, 1, 1, 0, 1,
1, 0, 0, 0, 0, 0, 1,
0, 1, 1, 0, 1, 1, 0};
{0, 0, 1, 0, 1, 0, 0,
0, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 0,
0, 0, 1, 5, 1, 0, 0,
0, 0, 0, 1, 0, 0, 0};
color =
{w, w, p1, w, p1, w, w,
w, p2, p3, p2, p3, p2, w,
p1, p2, p3, p4, p3, p2, p1,
w, p1, p2, p3, p2, p1, w,
w, w, p1, w, p1, w, w,
w, w, w, p1, w, w, w};
} else if (m_CurrentLevel == 5) {
level =
{1, 0, 1, 0, 1, 0, 1,
{0, 1, 0, 0, 0, 1, 0,
1, 4, 1, 1, 1, 3, 1,
0, 1, 0, 1, 0, 1, 0,
2, 0, 1, 0, 1, 0, 2,
0, 1, 0, 2, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0};
0, 1, 0, 1, 0, 1, 0,
1, 5, 1, 1, 1, 2, 1,
0, 1, 0, 0, 0, 1, 0};
color =
{w, p3, w, w, w, r, w,
p2, w, p1, g, w, w, w,
w, p4, w, g, w, r, w,
w, br, w, g, w, lb1, w,
y, w, y, g, b, w, b,
w, br, w, w, w, lb1, w};
}
} 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)
+135
View File
@@ -0,0 +1,135 @@
//
// Created by Adniklastrator on 2015-10-08.
//
#include "PrecompiledHeader.h"
#include "Game/LifebuoySystem.h"
void dd::Systems::LifebuoySystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EContact, &LifebuoySystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &LifebuoySystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_ELifebuoy, &LifebuoySystem::OnLifebuoy);
EVENT_SUBSCRIBE_MEMBER(m_ELifebuoyHit, &LifebuoySystem::OnLifebuoyHit);
//Lifebuoy
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Lifebuoy");
std::shared_ptr<Components::Transform> ctransform = m_World->AddComponent<Components::Transform>(ent);
ctransform->Position = glm::vec3(50.f, -4.8f, -10.f);
auto rectangleShape = m_World->AddComponent<Components::RectangleShape>(ent);
auto lifebuoyTemplate = m_World->AddComponent<Components::Template>(ent);
rectangleShape->Dimensions = glm::vec2(0.9f, 0.19f);
auto physics = m_World->AddComponent<Components::Physics>(ent);
physics->CollisionType = CollisionType::Type::Static;
physics->Category = CollisionLayer::LifeBuoy;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Brick | CollisionLayer::LifeBuoy | CollisionLayer::Pad | CollisionLayer::Water);
physics->Density = 1.0f;
physics->GravityScale = 1;
ctransform->Sticky = true;
auto cModel = m_World->AddComponent<Components::Model>(ent);
cModel->ModelFile = "Models/Lifebuoy/Lifebuoy1.obj";
auto lifebuoy = m_World->AddComponent<Components::Lifebuoy>(ent);
m_World->CommitEntity(ent);
m_Template = ent;
}
return;
}
void dd::Systems::LifebuoySystem::Update(double dt)
{
for (auto it = m_Lifebuoys.begin(); it != m_Lifebuoys.end();) {
auto transformComponent = m_World->GetComponent<Components::Transform>(it->Entity);
auto lifebuoyComponent = m_World->GetComponent<Components::Lifebuoy>(it->Entity);
if (transformComponent->Position.y < m_DownEdge) {
m_World->RemoveEntity(it->Entity);
m_Lifebuoys.erase(it++);
}
else {
if (transformComponent->Position.x > m_RightEdge) {
transformComponent->Position = glm::vec3(m_LeftEdge + 0.1f, transformComponent->Position.y, transformComponent->Position.z);
} else if (transformComponent->Position.x < m_LeftEdge) {
transformComponent->Position = glm::vec3(m_RightEdge - 0.1f, transformComponent->Position.y, transformComponent->Position.z);
}
if (lifebuoyComponent->Hits <= 0) {
auto physicsComponent = m_World->GetComponent<Components::Physics>(it->Entity);
physicsComponent->Mask = CollisionLayer::Type::LifeBuoy;
physicsComponent->GravityScale = 10.f;
auto modelComponent = m_World->GetComponent<Components::Model>(it->Entity);
modelComponent->Color = glm::vec4(0.5f, 0.5f, 0.5f, 0.f);
}
if (transformComponent->Position.y < m_DownLimit && lifebuoyComponent->Hits > 0) {
transformComponent->Position.y = m_DownLimit;
}
++it;
}
}
}
void dd::Systems::LifebuoySystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (IsPaused()) {
return;
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
}
bool dd::Systems::LifebuoySystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "LifebuoySystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
bool dd::Systems::LifebuoySystem::OnContact(const dd::Events::Contact &event)
{
return true;
}
bool dd::Systems::LifebuoySystem::OnLifebuoy(const dd::Events::Lifebuoy &event)
{
auto ent = m_World->CloneEntity(m_Template);
m_World->SetProperty(ent, "Name", "Lifebuoy");
m_World->RemoveComponent<Components::Template>(ent);
auto transform = m_World->GetComponent<Components::Transform>(ent);
auto physics = m_World->GetComponent<Components::Physics>(ent);
physics->CollisionType = CollisionType::Type::Dynamic;
transform->Position = glm::vec3(0.f, 0.f, -10.f);
transform->Velocity = glm::vec3(20.f, 3.f, 0.f);
LifebuoyInfo info;
info.Entity = ent;
m_Lifebuoys.push_back(info);
return true;
}
bool dd::Systems::LifebuoySystem::OnLifebuoyHit(const dd::Events::LifebuoyHit &event)
{
auto lifebuoyComponent = m_World->GetComponent<Components::Lifebuoy>(event.Lifebuoy);
lifebuoyComponent->Hits -= 1;
auto modelComponent = m_World->GetComponent<Components::Model>(event.Lifebuoy);
modelComponent->ModelFile = "Models/Lifebuoy/Lifebuoy" + std::to_string(5 - lifebuoyComponent->Hits) + ".obj";
return true;
}
+24 -7
View File
@@ -28,21 +28,23 @@ void dd::Systems::PadSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause);
//EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &PadSystem::OnBindKey);
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Pad");
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
ctransform->Position = glm::vec3(0.f, -3.5f, -10.f);
ctransform->Position = glm::vec3(0.f, -4.8f, -10.f);
auto rectangleShape = m_World->AddComponent<Components::RectangleShape>(ent);
rectangleShape->Dimensions = glm::vec2(1.f, 0.5f);
rectangleShape->Dimensions = glm::vec2(1.f, 0.1f);
auto physics = m_World->AddComponent<Components::Physics>(ent);
physics->CollisionType = CollisionType::Type::Dynamic;
physics->CollisionType = CollisionType::Type::Kinematic;
physics->Category = CollisionLayer::Type::Pad;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::PowerUp);
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::PowerUp | CollisionLayer::LifeBuoy);
physics->Calculate = true;
ctransform->Sticky = true;
auto cModel = m_World->AddComponent<Components::Model>(ent);
cModel->ModelFile = "Models/Submarine2.obj";
cModel->ModelFile = "Models/Ship/Ship.obj";
auto pad = m_World->AddComponent<Components::Pad>(ent);
m_World->CommitEntity(ent);
@@ -55,6 +57,15 @@ 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;
}
}
}
void dd::Systems::PadSystem::Update(double dt)
@@ -123,8 +134,7 @@ bool dd::Systems::PadSystem::OnPause(const dd::Events::Pause &event)
return true;
}
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
{
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) {
int val = event.KeyCode;
if (val == GLFW_KEY_UP) {
//std::cout << "Up!" << std::endl;
@@ -154,6 +164,13 @@ 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_S) {
Events::StageCleared e;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_SPACE) {
Events::ActionButton e;
e.Position = Transform()->Position;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_D) {
return false;
}
+135
View File
@@ -0,0 +1,135 @@
//
// Created by Adniklastrator on 2015-10-08.
//
#include "PrecompiledHeader.h"
#include "Game/ProjectileSystem.h"
void dd::Systems::ProjectileSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EContact, &ProjectileSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &ProjectileSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EInkBlaster, &ProjectileSystem::OnInkBlaster);
EVENT_SUBSCRIBE_MEMBER(m_EHitPad, &ProjectileSystem::OnHitPad);
EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &ProjectileSystem::OnActionButton);
//Ink Blast
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Projectile");
std::shared_ptr<Components::Transform> ctransform = m_World->AddComponent<Components::Transform>(ent);
auto circleShape = m_World->AddComponent<Components::CircleShape>(ent);
auto inkBlastTemplate = m_World->AddComponent<Components::Template>(ent);
circleShape->Radius = 0.1f;
auto physics = m_World->AddComponent<Components::Physics>(ent);
physics->CollisionType = CollisionType::Type::Dynamic;
physics->Category = CollisionLayer::Type::Projectile;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall);
physics->Calculate = true;
ctransform->Sticky = true;
ctransform->Position = glm::vec3(0.f, 0.f, -10.f);
ctransform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
auto cModel = m_World->AddComponent<Components::Model>(ent);
cModel->ModelFile = "Models/Test/Ball/Sid.obj";
auto projectile = m_World->AddComponent<Components::Projectile>(ent);
m_World->CommitEntity(ent);
m_InkBlastTemplate = ent;
}
return;
}
void dd::Systems::ProjectileSystem::Update(double dt)
{
}
void dd::Systems::ProjectileSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (IsPaused()) {
return;
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
auto shot = m_World->GetComponent<Components::Projectile>(entity);
if (shot != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (transform->Position.y > 8) {
m_World->RemoveEntity(entity);
}
}
}
bool dd::Systems::ProjectileSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "ProjectileSystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
bool dd::Systems::ProjectileSystem::OnContact(const dd::Events::Contact &event)
{
return true;
}
bool dd::Systems::ProjectileSystem::OnInkBlaster(const dd::Events::InkBlaster &event)
{
m_InkBlaster = true;
m_Shots = 5;
return true;
}
bool dd::Systems::ProjectileSystem::OnHitPad(const dd::Events::HitPad &event)
{
if (m_InkBlaster) {
m_SquidLoaded = true;
m_AttachedSquid = event.Ball;
}
return true;
}
bool dd::Systems::ProjectileSystem::OnActionButton(const dd::Events::ActionButton &event)
{
if (m_InkBlaster && m_SquidLoaded) {
auto ent = m_World->CloneEntity(m_InkBlastTemplate);
m_World->RemoveComponent<Components::Template>(ent);
auto transform = m_World->GetComponent<Components::Transform>(ent);
transform->Position = event.Position;
transform->Velocity = glm::vec3(0, 5, 0);
m_Shots--;
if (m_Shots <= 0) {
auto ball = m_World->GetComponent<Components::Ball>(m_AttachedSquid);
m_InkBlaster = false;
m_SquidLoaded = false;
ball->InkBlaster = 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;
}
+13 -3
View File
@@ -12,8 +12,11 @@ void dd::Systems::PhysicsSystem::ContactListener::BeginContact(b2Contact* contac
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
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));
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)
@@ -29,10 +32,17 @@ void dd::Systems::PhysicsSystem::ContactListener::PreSolve(b2Contact* contact, c
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
std::string propertyA = m_PhysicsSystem->m_World->GetProperty<std::string>(entityA, "Name");
std::string propertyB = m_PhysicsSystem->m_World->GetProperty<std::string>(entityB, "Name");
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
// Turn of collisions
contact->SetEnabled(false);
if ((propertyA != "Lifebuoy" && propertyB != "Pad") || (propertyA != "Pad" && propertyB != "Lifebuoy")) {
contact->SetEnabled(false);
}
}
}
+328 -73
View File
@@ -10,19 +10,35 @@ void dd::Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
void dd::Systems::PhysicsSystem::Initialize()
{
std::random_device rd;
gen = std::mt19937(rd());
m_DestructionListener = new DestructionListener(this);
m_ContactListener = new ContactListener(this);
m_PhysicsWorld = new b2World(m_Gravity);
m_ParticleContactDisabler = new ParticleContactDisabler();
m_PhysicsWorld->SetContactListener(m_ContactListener);
m_PhysicsWorld->SetContactFilter(m_ParticleContactDisabler);
m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
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);
}
void dd::Systems::PhysicsSystem::InitializeWater()
{
float radius = 0.13f;
float gravityScale = 1.0f;
CreateParticleSystem(radius, gravityScale);
b2ParticleSystemDef m_ParticleSystemDef;
m_ParticleSystemDef.radius = radius;
m_ParticleSystemDef.gravityScale = gravityScale;
m_ParticleSystemDef.density = 4.f;
m_WaterParticleSystem = m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
}
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
@@ -89,6 +105,16 @@ void dd::Systems::PhysicsSystem::SyncEntitiesWithBodies()
filter.categoryBits = physicsComponent->Category;
filter.maskBits = physicsComponent->Mask;
body->GetFixtureList()->SetFilterData(filter);
if (physicsComponent->CollisionType == CollisionType::Type::Static) {
body->SetType(b2_staticBody);
}
else if (physicsComponent->CollisionType == CollisionType::Type::Dynamic) {
body->SetType(b2_dynamicBody);
}
else if (physicsComponent->CollisionType == CollisionType::Type::Kinematic) {
body->SetType(b2_dynamicBody);
}
}
}
}
@@ -141,10 +167,18 @@ void dd::Systems::PhysicsSystem::SyncBodiesWithEntities()
void dd::Systems::PhysicsSystem::Update(double dt)
{
if (m_Pause) {
return;
}
if (m_Pause) {
return;
}
if (m_Travelling) {
if (m_DistanceTravelled > 12.f) {
m_DistanceTravelled = 0;
m_Travelling = false;
}
m_DistanceTravelled += 6.0f * dt;
}
m_Accumulator += dt;
while(m_Accumulator >= m_TimeStep)
@@ -166,9 +200,34 @@ void dd::Systems::PhysicsSystem::Update(double dt)
SyncBodiesWithEntities();
//water
b2Vec2 *positionBuffer = m_WaterParticleSystem->GetPositionBuffer();
for (auto i : m_EntitiesToWaterParticleHandle){
EntityID entity = i.first;
const b2ParticleHandle *particleH = i.second;
b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()];
glm::vec2 position = glm::vec2(positionB2.x, positionB2.y);
EntityID entityParent = m_World->GetEntityParent(entity);
glm::vec3 parentTransform = glm::vec3(0.f);
if(entityParent) {
auto tp = m_World->GetComponent<Components::Transform>(entityParent);
parentTransform = tp->Position;
}
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(position.x - parentTransform.x, position.y - parentTransform.y, 0);
}
//Normal particles
for ( int e = 0; e < m_EntitiesToParticleHandle.size(); e++) {
b2Vec2 *positionBuffer = m_ParticleSystem[e]->GetPositionBuffer();
for (auto i : m_EntitiesToParticleHandle[e]) {
b2Vec2 *positionBuffer = m_ParticleEmitters.ParticleSystem[e]->GetPositionBuffer();
if(!positionBuffer) {
break;
}
for (auto i : m_EntitiesToParticleHandle[e]){
EntityID entity = i.first;
const b2ParticleHandle *particleH = i.second;
@@ -177,14 +236,13 @@ void dd::Systems::PhysicsSystem::Update(double dt)
EntityID entityParent = m_World->GetEntityParent(entity);
glm::vec3 parentTransform = glm::vec3(0.f);
if (entityParent) {
if(entityParent) {
auto tp = m_World->GetComponent<Components::Transform>(entityParent);
parentTransform = tp->Position;
}
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(position.x, position.y, -10) - parentTransform;
transform->Position = glm::vec3(position.x, position.y, transform->Position.z);
}
}
@@ -193,8 +251,55 @@ 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;
if (particle->LifeTime <= 0) {
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
const b2ParticleHandle* handle = m_EntitiesToParticleHandle[i][entity];
std::unordered_map<EntityID, const b2ParticleHandle*>::iterator iter1;
std::unordered_map<const b2ParticleHandle*,EntityID>::iterator iter2;
iter1 = m_EntitiesToParticleHandle[i].find(entity);
iter2 = m_ParticleHandleToEntities[i].find(handle);
if (iter1 != m_EntitiesToParticleHandle[i].end()) {
m_EntitiesToParticleHandle[i].erase(iter1);
}
if (iter2 != m_ParticleHandleToEntities[i].end()) {
m_ParticleHandleToEntities[i].erase(iter2);
}
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)
@@ -243,23 +348,22 @@ void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
{
/* auto physics = m_World->GetComponent<Components::Physics>(entity);
if (physics == nullptr) {
return;
}*/
auto it = m_EntitiesToBodies.find(entity);
if(it == m_EntitiesToBodies.end()) {
LOG_ERROR("Trying to remove non-exsisting body, Entity: %i", entity);
return;
if(it != m_EntitiesToBodies.end()) {
it->second->GetWorld()->DestroyBody(it->second);
m_BodiesToEntities.erase(it->second);
m_EntitiesToBodies.erase(entity);
}
//It told me I was removing a lot of objects, and I didn't need that information, so I commented it out.
//LOG_INFO("Removing entity %i", entity);
it->second->GetWorld()->DestroyBody(it->second);
m_BodiesToEntities.erase(it->second);
m_EntitiesToBodies.erase(entity);
//delete body;
}
bool dd::Systems::PhysicsSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
if (event.ClearedStage < 5) {
m_Travelling = true;
}
return true;
}
@@ -316,7 +420,7 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
fixtureDef.shape = pShape;
fixtureDef.density = 10.f;
fixtureDef.density = physicsComponent->Density;
fixtureDef.restitution = 1.0f;
fixtureDef.friction = 0.0f;
body->CreateFixture(&fixtureDef);
@@ -324,16 +428,12 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
delete pShape;
/* if(physicsComponent->Static) {
body->SetType(b2BodyType::b2_staticBody);
} else if (! physicsComponent->Static) {
body->SetType(b2BodyType::b2_dynamicBody);
}*/
body->SetGravityScale(physicsComponent->GravityScale);
m_EntitiesToBodies.insert(std::make_pair(entity, body));
m_BodiesToEntities.insert(std::make_pair(body, entity));
}
void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
{
auto transform = m_World->GetComponent<Components::Transform>(e);
@@ -349,19 +449,19 @@ void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
pd.shape = &shape;
pd.flags = b2_tensileParticle;
pd.position.Set(transform->Position.x, transform->Position.y);
t_ParticleGroup.push_back(m_ParticleSystem[0]->CreateParticleGroup(pd));
b2Vec2* t_ParticlePositions = m_ParticleSystem[0]->GetPositionBuffer();
for(int i = 0; i < m_ParticleSystem[0]->GetParticleCount(); i++){
t_ParticleGroup.push_back(m_WaterParticleSystem->CreateParticleGroup(pd));
b2Vec2* t_ParticlePositions = m_WaterParticleSystem->GetPositionBuffer();
for(int i = 0; i < m_WaterParticleSystem->GetParticleCount(); i++){
{
auto t_waterparticle = m_World->CreateEntity(e);
auto transformChild = m_World->AddComponent<Components::Transform>(t_waterparticle);
transformChild->Position = glm::vec3(t_ParticlePositions[i].x - transform->Position.x, t_ParticlePositions[i].y - transform->Position.y, -9.5f);
transformChild->Scale = glm::vec3(m_ParticleSystem[0]->GetRadius())/transform->Scale;
transformChild->Scale = glm::vec3(m_WaterParticleSystem->GetRadius())/transform->Scale;
m_World->CommitEntity(t_waterparticle);
m_EntitiesToParticleHandle[0].insert(std::make_pair(t_waterparticle, m_ParticleSystem[0]->GetParticleHandleFromIndex(i)));
m_ParticleHandleToEntities[0].insert(std::make_pair( m_ParticleSystem[0]->GetParticleHandleFromIndex(i), t_waterparticle));
m_EntitiesToWaterParticleHandle.insert(std::make_pair(t_waterparticle, m_WaterParticleSystem->GetParticleHandleFromIndex(i)));
m_WaterParticleHandleToEntities.insert(std::make_pair(m_WaterParticleSystem->GetParticleHandleFromIndex(i), t_waterparticle));
}
}
@@ -369,46 +469,166 @@ void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
}
}
void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
{
for (int i = 0; i < m_ParticleEmitters.System.size(); i++) {
auto e = m_ParticleEmitters.Emitter[i];
auto pt = m_ParticleEmitters.Template[i];
auto ps = m_ParticleEmitters.System[i];
std::vector<EntityID> emittersToDelete;
int pSizeTest = 0; //For debugging, delete this
int psListSize = 0;
for (int i = 0; i < m_ParticleEmitters.ParticleSystem.size(); i++) {
auto e = m_ParticleEmitters.ParticleEmitter[i];
auto pt = m_ParticleEmitters.ParticleTemplate[i];
auto ps = m_ParticleEmitters.ParticleSystem[i];
pSizeTest += ps->GetParticleCount();
psListSize++;
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(e);
auto particleTemplate = m_World->GetComponent<Components::Particle>(pt);
emitter->TimeSinceLastSpawn += dt;
if(emitter->TimeSinceLastSpawn < emitter->SpawnRate) {
if(!emitter) {
LOG_INFO("ParticleEmitter Component is nil");
continue;
}
if(!particleTemplate) {
LOG_INFO("ParticleTemplate Component is nil.");
continue;
}
auto emitterTransform = m_World->GetComponent<Components::Transform>(e);
emitterTransform->Orientation = glm::rotate(glm::quat(), 3.f, glm::vec3(0.f, 0.f, -1.f));
emitter->TimeSinceLastSpawn += dt;
emitter->LifeTime -= dt;
if (emitter->LifeTime <= 0 || emitter->NumberOfTicks <= 0) {
emittersToDelete.push_back(e);
continue;
}
if(emitter->TimeSinceLastSpawn < emitter->SpawnRate || emitter->NumberOfTicks < 1) {
continue;
}
emitter->NumberOfTicks--;
emitter->TimeSinceLastSpawn -= emitter->SpawnRate;
auto templateTransform = m_World->GetComponent<Components::Transform>(pt);
b2ParticleDef particleDef;
particleDef.flags = particleTemplate->Flags;
//particleDef.color TODO: Implement this if we want color mixing and shit.
particleDef.lifetime = particleTemplate->LifeTime;
particleDef.velocity = b2Vec2(templateTransform->Velocity.x, templateTransform->Velocity.y);
particleDef.position = b2Vec2(templateTransform->Position.x, templateTransform->Position.y);
for ( int j = 0; j < emitter->ParticlesPerTick; j++) {
particleDef.flags = particleTemplate->Flags;
//particleDef.color TODO: Implement this if we want color mixing and shit.
particleDef.lifetime = particleTemplate->LifeTime;
float eAngle = emitter->EmittingAngle;
float halfSpread = emitter->Spread / 2;
auto particle = m_World->CloneEntity(pt, 0);
m_World->RemoveComponent<Components::Template>(particle);
std::uniform_real_distribution<float> dis(eAngle - halfSpread, eAngle + halfSpread);
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 vel = unitVec * emitter->Speed * (float)dt * speedMultiplier * 0.5f;
particleDef.velocity = b2Vec2(vel.x, vel.y);
particleDef.position = b2Vec2(emitterTransform->Position.x, emitterTransform->Position.y);
auto b2Particle = ps->CreateParticle(particleDef);
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
//TODO: Ta bort detta
int particles = 0;
for (auto i : m_EntitiesToParticleHandle)
{
particles += i.size();
auto particle = m_World->CloneEntity(pt, 0);
m_World->RemoveComponent<Components::Template>(particle);
auto transform2 = m_World->GetComponent<Components::Transform>(particle);
std::uniform_real_distribution<float> dist(0, 1);
float zDistribution = dist(gen);
transform2->Position = glm::vec3(emitterTransform->Position.x, emitterTransform->Position.y, -9.5f + zDistribution);
transform2->Scale = glm::vec3(particleTemplate->Radius * 2.f / speedMultiplier, particleTemplate->Radius * 2.f / speedMultiplier, 1);
auto b2Particle = ps->CreateParticle(particleDef);
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
}
LOG_INFO("--I have %i particles.", particles);
}
// 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++)
{
EntityID ent = emittersToDelete[i];
int key;
for(key = 0; key < m_ParticleEmitters.ParticleEmitter.size(); key++) {
if (m_ParticleEmitters.ParticleEmitter[key] == ent) {
break;
}
}
if (m_ParticleEmitters.ParticleSystem[key]->GetParticleCount() == 0 && key <= m_ParticleEmitters.ParticleSystem.size()) {
m_World->RemoveEntity(ent);
m_PhysicsWorld->DestroyParticleSystem(m_ParticleEmitters.ParticleSystem[key]);
m_ParticleEmitters.ParticleSystem.erase(m_ParticleEmitters.ParticleSystem.begin() + key);
m_ParticleEmitters.ParticleEmitter.erase(m_ParticleEmitters.ParticleEmitter.begin() + key);
m_ParticleEmitters.ParticleTemplate.erase(m_ParticleEmitters.ParticleTemplate.begin() + key);
m_EntitiesToParticleHandle.erase(m_EntitiesToParticleHandle.begin() + key);
m_ParticleHandleToEntities.erase(m_ParticleHandleToEntities.begin() + key);
}
}
int stp = 0;
for (auto ts : m_EntitiesToParticleHandle)
{
stp += ts.size();
}
}
bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreateParticleSequence &event)
{
//Creating Emitter
EntityID emitter = m_World->CreateEntity();
auto emitterTransform = m_World->AddComponent<Components::Transform>(emitter);
auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(emitter);
if (event.parent != 0) {
particleEmitter->Parent = event.parent;
}
emitterTransform->Position = event.Position;
particleEmitter->GravityScale = event.GravityScale;
particleEmitter->SpawnRate = event.SpawnRate;
particleEmitter->NumberOfTicks = event.NumberOfTicks;
particleEmitter->Speed = event.Speed;
particleEmitter->ParticlesPerTick = event.ParticlesPerTick;
particleEmitter->Spread = event.Spread;
particleEmitter->EmittingAngle = event.EmittingAngle;
particleEmitter->LifeTime = event.EmitterLifeTime;
{
//Creating Particle Template
auto particle = m_World->CreateEntity(emitter);
auto particleTransform = m_World->AddComponent<Components::Transform>(particle);
auto sprite = m_World->AddComponent<Components::Sprite>(particle);
auto particleComponent = m_World->AddComponent<Components::Particle>(particle);
m_World->AddComponent<Components::Template>(particle);
particleTransform->Position = emitterTransform->Position;
sprite->SpriteFile = event.SpriteFile;
sprite->Color = event.Color;
particleComponent->LifeTime = event.ParticleLifeTime;
particleComponent->Flags = event.Flags;
particleComponent->Radius = event.Radius;
}
m_World->CommitEntity(emitter);
return true;
}
void dd::Systems::PhysicsSystem::CreateParticleEmitter(EntityID entity)
@@ -426,14 +646,14 @@ void dd::Systems::PhysicsSystem::CreateParticleEmitter(EntityID entity)
auto particleTemplate = m_World->GetComponent<Components::Template>(c);
if (!p) {
continue;
LOG_WARNING("--Emitter's Child is not a particle.");
LOG_WARNING("ParticleEmitter's Child is not a particle.");
}
if(!particleTemplate) {
LOG_ERROR("Emitter's particleChild is not a template.");
LOG_ERROR("ParticleEmitter's particleChild is not a template.");
continue;
}
if (pf != 0) {
LOG_WARNING("Emitter has more than one child that is a particleTemplate, only the first one is used.");
LOG_WARNING("ParticleEmitter has more than one child that is a particleTemplate, only the first one is used.");
break;
}
childEntity = c;
@@ -441,13 +661,14 @@ void dd::Systems::PhysicsSystem::CreateParticleEmitter(EntityID entity)
pf++;
}
//TODO: Skicka med fler flaggor till particlesystemet;
m_ParticleEmitters.System.push_back(CreateParticleSystem(particle->Radius, 0.f));
m_ParticleEmitters.Emitter.push_back(entity);
m_ParticleEmitters.Template.push_back(childEntity);
m_ParticleEmitters.ParticleSystem.push_back(CreateParticleSystem(particle->Radius, 0.f, 0));
m_ParticleEmitters.ParticleEmitter.push_back(entity);
m_ParticleEmitters.ParticleTemplate.push_back(childEntity);
}
b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius, float gravityScale)
b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius, float gravityScale, int maxCount)
{
std::unordered_map<EntityID, const b2ParticleHandle*> m1;
std::unordered_map<const b2ParticleHandle*, EntityID> m2;
@@ -455,14 +676,48 @@ b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius,
m_ParticleHandleToEntities.push_back(m2);
b2ParticleSystemDef m_ParticleSystemDef;
m_ParticleSystemDef.maxCount = maxCount;
m_ParticleSystemDef.radius = radius;
m_ParticleSystemDef.gravityScale = gravityScale;
m_ParticleSystemDef.destroyByAge = true;
m_ParticleSystem.push_back(m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef));
return m_ParticleSystem.back();
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(0.5f);
e.Speed = 100;
EventBroker->Publish(e);
return true;
}
dd::Systems::PhysicsSystem::~PhysicsSystem()
+11 -5
View File
@@ -4,7 +4,7 @@
dd::Systems::SoundSystem::~SoundSystem()
{
alcCloseDevice(m_Device);
};
}
void dd::Systems::SoundSystem::Initialize()
{
@@ -41,6 +41,8 @@ void dd::Systems::SoundSystem::Initialize()
e.IsAmbient = true;
EventBroker->Publish(e);
}
}
void dd::Systems::SoundSystem::Update(double dt)
@@ -165,10 +167,14 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
}
//Send play-sound event
dd::Events::PlaySound e;
e.FilePath = collisionSound->FilePath;
e.IsAmbient = false;
EventBroker->Publish(e);
{
dd::Events::PlaySound e;
e.FilePath = collisionSound->FilePath;
e.IsAmbient = false;
EventBroker->Publish(e);
}
return true;
}