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
+3
View File
@@ -41,6 +41,9 @@ struct Transform : public Component
glm::vec3 Velocity;
/** Physical scale multiplier. */
glm::vec3 Scale;
// Sticky is if it sticks with the player or not. True means it will follow the camera.
bool Sticky;
};
}
+74 -42
View File
@@ -43,9 +43,13 @@
#include "Game/PadSystem.h"
#include "Game/CBall.h"
#include "Game/CPad.h"
#include "Game/CLifebuoy.h"
#include "Game/CProjectile.h"
#include "Game/CBrick.h"
#include "Game/BallSystem.h"
#include "Game/HitLagSystem.h"
#include "Game/LifebuoySystem.h"
#include "Game/ProjectileSystem.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/PhysicsSystem.h"
@@ -110,6 +114,8 @@ public:
m_World->ComponentFactory.Register<Components::Brick>();
m_World->ComponentFactory.Register<Components::Pad>();
m_World->ComponentFactory.Register<Components::Life>();
m_World->ComponentFactory.Register<Components::Lifebuoy>();
m_World->ComponentFactory.Register<Components::Projectile>();
m_World->ComponentFactory.Register<Components::PowerUp>();
m_World->ComponentFactory.Register<Components::PowerUpBrick>();
@@ -126,6 +132,12 @@ public:
m_World->SystemFactory.Register<Systems::HitLagSystem>(
[this]() { return new Systems::HitLagSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::HitLagSystem>();
m_World->SystemFactory.Register<Systems::LifebuoySystem>(
[this]() { return new Systems::LifebuoySystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::LifebuoySystem>();
m_World->SystemFactory.Register<Systems::ProjectileSystem>(
[this]() { return new Systems::ProjectileSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::ProjectileSystem>();
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>();
@@ -143,6 +155,7 @@ public:
auto t_Light = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_Light);
transform->Position = glm::vec3(-3.f, 6.f, -5.f);
transform->Sticky = true;
auto pl = m_World->AddComponent<Components::PointLight>(t_Light);
pl->Radius = 20.f;
pl->Diffuse = glm::vec3(0.8f, 0.7f, 0.05f);
@@ -154,6 +167,7 @@ public:
auto t_Light = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_Light);
transform->Position = glm::vec3(3.f, -5.f, -5.f);
transform->Sticky = true;
auto pl = m_World->AddComponent<Components::PointLight>(t_Light);
pl->Radius = 15.f;
pl->Diffuse = glm::vec3(0.1f, 0.5f, 0.8f);
@@ -168,13 +182,26 @@ public:
auto transform = m_World->AddComponent<Components::Transform>(t_halfPipe);
transform->Position = glm::vec3(0.f, 0.f, -15.f);
transform->Scale = glm::vec3(6.f, 6.f, 10.f);
transform->Sticky = false;
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
model->Color = glm::vec4(1.f, 0.f, 0.f, 0.3f);
model->Color = glm::vec4(0.8f, 0.8f, 0.8f, 0.3f);
m_World->CommitEntity(t_halfPipe);
}
{
auto t_halfPipe = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_halfPipe);
transform->Position = glm::vec3(0.f, 34.6f, -15.f);
transform->Scale = glm::vec3(6.f, 6.f, 10.f);
transform->Sticky = false;
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
model->Color = glm::vec4(0.8f, 0.8f, 0.8f, 0.3f);
m_World->CommitEntity(t_halfPipe);
}
//Background
{
auto background = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(background);
@@ -185,55 +212,55 @@ public:
m_World->CommitEntity(background);
}
//ParticleTest
// {
// auto Pe = m_World->CreateEntity();
// auto transform = m_World->AddComponent<Components::Transform>(Pe);
// auto particleEmitter= m_World->AddComponent<Components::Emitter>(Pe);
//
// transform->Position = glm::vec3(0.f, -5.f, -10.f);
// particleEmitter->GravityScale = 0.0f;
// particleEmitter->SpawnRate = 1.0f;
//
// {
// auto Pt = m_World->CreateEntity(Pe);
// auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
// auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
// //auto PtModel = m_World->AddComponent<Components::Model>(Pt);
// auto PtParticle = m_World->AddComponent<Components::Particle>(Pt);
// auto PtTemplate = m_World->AddComponent<Components::Template>(Pt);
//
// PtTransform->Velocity = glm::vec3(1.0f, 0.f, 0.f);
// PtTransform->Position = transform->Position;
// PtSprite->SpriteFile = "Textures/Ball.png";
//
// //PtModel->ModelFile = "Models/Brick/Brick.obj";
// PtParticle->LifeTime = 1000.f;
// PtParticle->Flags = ParticleFlags::Type::powderParticle;
// }
// m_World->CommitEntity(Pe);
// }
// {
// auto Pt = m_World->CreateEntity();
// auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
// auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
//
// PtTransform->Position = glm::vec3(2.f, 0.f, -10.f);
// PtSprite->SpriteFile = "Textures/Ball.png";
// }
//Water test
{
auto t_waterBody = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
transform->Position = glm::vec3(0.f, -5.5f, -10.f);
transform->Scale = glm::vec3(7.f, 1.5f, 1.f);
transform->Position = glm::vec3(0.f, -3.5f, -10.f);
transform->Scale = glm::vec3(7.0f, 1.5f, 1.f);
transform->Sticky = true;
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
m_World->CommitEntity(t_waterBody);
}
//ParticleTest
/*{
auto Pe = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(Pe);
auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(Pe);
auto emitteSprite = m_World->AddComponent<Components::Sprite>(Pe);
transform->Position = glm::vec3(0.f, 0.f, -10.f);
emitteSprite->SpriteFile = "Textures/Test/Brick_Normal.png";
particleEmitter->GravityScale = 0.0f;
particleEmitter->SpawnRate = 1.f;
particleEmitter->NumberOfTicks = 2;
particleEmitter->Speed = 1.f;
particleEmitter->ParticlesPerTick = 5;
particleEmitter->Spread = glm::pi<float>()*2;
particleEmitter->EmittingAngle = glm::pi<float>();
particleEmitter->LifeTime = 50;
{
auto Pt = m_World->CreateEntity(Pe);
auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
auto PtParticle = m_World->AddComponent<Components::Particle>(Pt);
auto PtTemplate = m_World->AddComponent<Components::Template>(Pt);
//PtTransform->Velocity = glm::vec3(1.0f, 0.f, 0.f);
PtTransform->Position = transform->Position;
PtSprite->SpriteFile = "Textures/Background.png";
PtParticle->LifeTime = 3.f;
PtParticle->Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Type::Powder | ParticleFlags::Type::ParticleContactFilter | ParticleFlags::Type::FixtureContactFilter);
}
m_World->CommitEntity(Pe);
}*/
//TODO: Why does the ball not collide with these bricks?
//BottomBox
{
@@ -247,6 +274,9 @@ public:
rectangleShape->Dimensions = glm::vec2(20.f, 0.5f);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(BottomWall);
physics->CollisionType = CollisionType::Type::Static;
physics->Category = CollisionLayer::Wall;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::LifeBuoy);
transform->Sticky = true;
m_World->CommitEntity(BottomWall);
}
@@ -266,6 +296,7 @@ public:
physics->CollisionType = CollisionType::Type::Static;
physics->Category = CollisionLayer::Wall;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Brick);
transform->Sticky = true;
m_World->CommitEntity(topWall);
}
@@ -287,6 +318,7 @@ public:
physics->CollisionType = CollisionType::Type::Static;
physics->Category = CollisionLayer::Wall;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Brick);
transform->Sticky = true;
m_World->CommitEntity(leftWall);
}
@@ -308,11 +340,11 @@ public:
physics->CollisionType = CollisionType::Type::Static;
physics->Category = CollisionLayer::Wall;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Brick);
transform->Sticky = true;
m_World->CommitEntity(rightWall);
}
//EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart);
m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1));
m_EventBroker->Subscribe(m_EGameStart);
+21 -2
View File
@@ -21,10 +21,16 @@
#include "Game/EResetBall.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EStickyPad.h"
#include "Game/EInkBlaster.h"
#include "Game/EInkBlasterOver.h"
#include "Game/EGameOver.h"
#include "Game/EPause.h"
#include "Game/EHitPad.h"
#include "Game/EHitLag.h"
#include "Game/EActionButton.h"
#include "Game/CLifebuoy.h"
#include "Game/ELifebuoyHit.h"
namespace dd
{
@@ -89,7 +95,12 @@ private:
int m_PastLives = 3;
bool m_ReplaceBall = false;
bool m_Pause = false;
EntityID m_LastCollision = 999999;
bool m_Waiting = true;
bool m_Sticky = false;
bool m_InkBlaster = false;
bool m_InkAttached = false;
bool m_BlockedWaiting = false;
int m_StickyCounter = 5;
glm::vec3 m_SavedSpeed;
bool m_InitializePause = false;
@@ -103,15 +114,23 @@ private:
dd::EventRelay<BallSystem, dd::Events::MultiBallLost> m_EMultiBallLost;
dd::EventRelay<BallSystem, dd::Events::ResetBall> m_EResetBall;
dd::EventRelay<BallSystem, dd::Events::MultiBall> m_EMultiBall;
dd::EventRelay<BallSystem, dd::Events::StickyPad> m_EStickyPad;
dd::EventRelay<BallSystem, dd::Events::InkBlaster> m_EInkBlaster;
dd::EventRelay<BallSystem, dd::Events::InkBlasterOver> m_EInkBlasterOver;
dd::EventRelay<BallSystem, dd::Events::Pause> m_EPause;
EventRelay<BallSystem, Events::Contact> m_Contact;
dd::EventRelay<BallSystem, dd::Events::Contact> m_Contact;
dd::EventRelay<BallSystem, dd::Events::ActionButton> m_EActionButton;
bool Contact(const Events::Contact &event);
bool OnLifeLost(const dd::Events::LifeLost &event);
bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
bool OnResetBall(const dd::Events::ResetBall &event);
bool OnMultiBall(const dd::Events::MultiBall &event);
bool OnStickyPad(const dd::Events::StickyPad &event);
bool OnInkBlaster(const dd::Events::InkBlaster &event);
bool OnInkBlasterOver(const dd::Events::InkBlasterOver &event);
bool OnPause(const dd::Events::Pause &event);
bool OnActionButton(const dd::Events::ActionButton &event);
};
}
+4
View File
@@ -19,6 +19,10 @@ struct Ball : Component
float Speed = 5.f;
int Combo = 0;
bool Paused = false;
bool Waiting = true;
bool InkBlaster = false;
bool Sticky = false;
glm::vec3 StickyPlacement = glm::vec3(0, 0, 0);
glm::vec3 SavedSpeed = glm::vec3(0, 0, 0);
};
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-10-08.
//
#ifndef DAYDREAM_CLIFEBUOY_H
#define DAYDREAM_CLIFEBUOY_H
#include "Core/Component.h"
namespace dd
{
namespace Components
{
struct Lifebuoy : Component
{
int Hits = 4;
};
}
}
#endif //DAYDREAM_CLIFEBUOY_H
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-10-08.
//
#ifndef DAYDREAM_CPROJECTILE_H
#define DAYDREAM_CPROJECTILE_H
#include "Core/Component.h"
namespace dd
{
namespace Components
{
struct Projectile : Component
{
};
}
}
#endif //DAYDREAM_CPROJECTILE_H
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Administrator on 2015-10-07.
//
#ifndef DAYDREAM_EACTIONBUTTON_H
#define DAYDREAM_EACTIONBUTTON_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct ActionButton : Event
{
glm::vec3 Position;
};
}
}
#endif //DAYDREAM_EACTIONBUTTON_H
+22
View File
@@ -0,0 +1,22 @@
#ifndef DAYDREAM_ECLUSTERCLEAR_H
#define DAYDREAM_ECLUSTERCLEAR_H
#include "Core/EventBroker.h"
#include "Core/Entity.h"
namespace dd
{
namespace Events
{
struct ClusterClear : Event
{
};
}
}
#endif //DAYDREAM_ECLUSTERCLEAR_H
+3 -1
View File
@@ -6,6 +6,7 @@
#define DAYDREAM_EHITPAD_H
#include "Core/EventBroker.h"
#include "Core/Entity.h"
namespace dd
{
@@ -13,7 +14,8 @@ namespace Events
{
struct HitPad : Event
{
EntityID Pad;
EntityID Ball;
};
}
}
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-10-08.
//
#ifndef DAYDREAM_EINKBLASTER_H
#define DAYDREAM_EINKBLASTER_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct InkBlaster : Event
{
Components::Transform* Transform;
};
}
}
#endif //DAYDREAM_EINKBLASTER_H
+25
View File
@@ -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
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-10-08.
//
#ifndef DAYDREAM_ELIFEBUOY_H
#define DAYDREAM_ELIFEBUOY_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct Lifebuoy : Event
{
Components::Transform* Transform;
};
}
}
#endif //DAYDREAM_ELIFEBUOY_H
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Adniklastrator on 2015-09-29.
//
#ifndef DAYDREAM_ELIFEBUOYHIT_H
#define DAYDREAM_ELIFEBUOYHIT_H
#include "Core/Entity.h"
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct LifebuoyHit : Event
{
EntityID Lifebuoy;
};
}
}
#endif //DAYDREAM_ELIFEBUOYHIT_H
+6 -1
View File
@@ -9,13 +9,18 @@
namespace dd
{
namespace Events
{
struct StageCleared : Event
{
int ClearedStage = 0;
int StageCluster = 0;
};
}
}
#endif //DAYDREAM_ESTAGECLEARED_H
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-10-08.
//
#ifndef DAYDREAM_ESTICKYPAD_H
#define DAYDREAM_ESTICKYPAD_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct StickyPad : Event
{
Components::Transform* Transform;
};
}
}
#endif //DAYDREAM_ESTICKYPAD_H
+22
View File
@@ -7,6 +7,8 @@
#include "Core/EKeyUp.h"
#include "Game/EScoreEvent.h"
#include "Game/GUI/FPSCounter.h"
#include "Game/EGameOver.h"
#include "Game/EClusterClear.h"
namespace dd
{
@@ -44,6 +46,8 @@ public:
m_FPSCounter = new GUI::FPSCounter(this, "FPSCounter");
EVENT_SUBSCRIBE_MEMBER(m_EScore, &HUD::OnScore);
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &HUD::OnGameOver);
EVENT_SUBSCRIBE_MEMBER(m_ClusterClear, &HUD::OnClusterClear);
}
private:
@@ -53,14 +57,32 @@ private:
NumberFrame* m_StageNumberFrame = nullptr;
NumberFrame* m_ScoreNumberFrame = nullptr;
FPSCounter* m_FPSCounter = nullptr;
TextureFrame* m_GameOverFrame = nullptr;
TextureFrame* m_ClusterClearFrame = nullptr;
EventRelay<Frame, Events::ScoreEvent> m_EScore;
EventRelay<Frame, Events::GameOver> m_EGameOver;
EventRelay<Frame, Events::ClusterClear> m_ClusterClear;
bool OnScore(const Events::ScoreEvent& event)
{
m_ScoreNumberFrame->SetNumber(m_ScoreNumberFrame->Number() + event.Score);
return true;
}
bool OnGameOver(const Events::GameOver& event)
{
m_GameOverFrame = new GUI::TextureFrame(this, "HUDGameOverFrame");
m_GameOverFrame->SetTexture("Textures/GUI/HUD/GameOverScreen.png");
return true;
}
bool OnClusterClear(const Events::ClusterClear& event)
{
m_ClusterClearFrame = new GUI::TextureFrame(this, "HUDGameOverFrame");
m_ClusterClearFrame->SetTexture("Textures/GUI/HUD/WinScreen.png");
return true;
}
};
}
+15 -4
View File
@@ -15,6 +15,7 @@
#include "Game/CBrick.h"
#include "Game/CBall.h"
#include "Game/CLife.h"
#include "Game/CProjectile.h"
#include "Game/CPowerUp.h"
#include "Game/EStageCleared.h"
#include "Game/ELifeLost.h"
@@ -22,13 +23,17 @@
#include "Game/EScoreEvent.h"
#include "Game/EComboEvent.h"
#include "Game/EHitPad.h"
#include "Game/ELifebuoy.h"
#include "Game/EStickyPad.h"
#include "Game/EInkBlaster.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EPause.h"
#include "Game/EGameOver.h"
#include "Game/EClusterClear.h"
#include "Game/ECreatePowerUp.h"
#include "Game/EPowerUpTaken.h"
#include "Game/Bricks/CPowerUpBrick.h"
//#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/CRectangleShape.h"
@@ -39,6 +44,8 @@
#include <fstream>
#include <iostream>
#include "Physics/ECreateParticleSequence.h"
namespace dd
{
@@ -66,8 +73,8 @@ public:
void Initialize() override;
void CreateBasicLevel(int, int, glm::vec2, float);
void CreateLevel();
void CreateBrick(int, int, glm::vec2, float, int, int);
void CreateLevel(int);
void CreateBrick(int, int, glm::vec2, float, int, int, int, glm::vec4);
void OnEntityRemoved(EntityID entity);
@@ -108,7 +115,7 @@ private:
bool m_Initialized = false;
bool m_Pause = false;
int m_LooseBricks = 0;
int m_CurrentCluster = 2;
int m_CurrentCluster = 1;
int m_CurrentLevel = 1;
int m_MultiBalls = 0;
int m_PowerUps = 0;
@@ -123,10 +130,14 @@ private:
const int EmptyBrickSpace = 0;
const int StandardBrick = 1;
const int MultiBallBrick = 2;
const int LifebuoyBrick = 3;
const int StickyBrick = 4;
const int InkBlasterBrick = 5;
EntityID m_BrickTemplate;
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::ScoreEvent> m_EScoreEvent;
+76
View File
@@ -0,0 +1,76 @@
//
// Created by Adniklastrator on 2015-09-09.
//
#ifndef DAYDREAM_LIFEBUOYSYSTEM_H
#define DAYDREAM_LIFEBUOYSYSTEM_H
#include "Core/System.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Physics/EContact.h"
#include "Rendering/CModel.h"
#include "Physics/CPhysics.h"
#include "Physics/CRectangleShape.h"
#include "Game/EPause.h"
#include "Game/ELifebuoy.h"
#include "Game/ELifebuoyHit.h"
#include "Game/CLifebuoy.h"
#include <fstream>
#include <iostream>
namespace dd
{
namespace Systems
{
class LifebuoySystem : public System
{
public:
LifebuoySystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker)
{ }
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
private:
bool m_Pause = false;
EntityID m_Template;
dd::EventRelay<LifebuoySystem, dd::Events::Contact> m_EContact;
dd::EventRelay<LifebuoySystem, dd::Events::Pause> m_EPause;
dd::EventRelay<LifebuoySystem, dd::Events::Lifebuoy> m_ELifebuoy;
dd::EventRelay<LifebuoySystem, dd::Events::LifebuoyHit> m_ELifebuoyHit;
bool OnContact(const dd::Events::Contact &event);
bool OnPause(const dd::Events::Pause &event);
bool OnLifebuoy(const dd::Events::Lifebuoy &event);
bool OnLifebuoyHit(const dd::Events::LifebuoyHit &event);
struct LifebuoyInfo
{
EntityID Entity;
//int Hits = 4;
};
float m_LeftEdge = -3.8f;
float m_RightEdge = 3.8f;
float m_DownLimit = -5.3f;
float m_DownEdge = -9.2f;
std::list<LifebuoyInfo> m_Lifebuoys;
};
}
}
#endif //DAYDREAM_LIFEBUOYSYSTEM_H
+1
View File
@@ -30,6 +30,7 @@
#include "Game/EStageCleared.h"
#include "Game/EPause.h"
#include "Game/EHitLag.h"
#include "Game/EActionButton.h"
namespace dd
+74
View File
@@ -0,0 +1,74 @@
//
// Created by Adniklastrator on 2015-09-09.
//
#ifndef DAYDREAM_PROJECTILESYSTEM_H
#define DAYDREAM_PROJECTILESYSTEM_H
#include "Core/System.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Core/EventBroker.h"
#include "Physics/EContact.h"
#include "Rendering/CModel.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Game/EPause.h"
#include "Game/EInkBlaster.h"
#include "Game/EInkBlasterOver.h"
#include "Game/EActionButton.h"
#include "Game/EHitPad.h"
#include "Game/CProjectile.h"
#include "Game/CBall.h"
#include <fstream>
#include <iostream>
namespace dd
{
namespace Systems
{
class ProjectileSystem : public System
{
public:
ProjectileSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker)
{ }
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
private:
bool m_Pause = false;
bool m_InkBlaster = false;
bool m_SquidLoaded = false;
int m_Shots = 0;
EntityID m_InkBlastTemplate;
EntityID m_AttachedSquid;
dd::EventRelay<ProjectileSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<ProjectileSystem, dd::Events::Pause> m_EPause;
dd::EventRelay<ProjectileSystem, dd::Events::InkBlaster> m_EInkBlaster;
dd::EventRelay<ProjectileSystem, dd::Events::HitPad> m_EHitPad;
dd::EventRelay<ProjectileSystem, dd::Events::ActionButton> m_EActionButton;
bool OnContact(const dd::Events::Contact &event);
bool OnPause(const dd::Events::Pause &event);
bool OnInkBlaster(const dd::Events::InkBlaster &event);
bool OnHitPad(const dd::Events::HitPad &event);
bool OnActionButton(const dd::Events::ActionButton &event);
};
}
}
#endif //DAYDREAM_PROJECTILESYSTEM_H
+11 -3
View File
@@ -9,10 +9,18 @@ namespace Components
struct ParticleEmitter : public Component
{
int Amount = 10.f;
EntityID Parent = 0;
int NumberOfTicks = 10.f;
float InitialSpeed = 1.f;
double SpawnRate = 1.f;
double TimeSinceLastSpawn = 0;
double SpawnRate = 1;
int ParticlesPerTick = 1;
//TODO: Refactor. Have cooldown instead of this
double TimeSinceLastSpawn = 100;
int MaxCount = 0;
float EmittingAngle = 0.f;
float Spread = 0.f;
float Speed = 2.f;
double LifeTime = 100;
//System variables
float GravityScale = 1.0f;
+21 -18
View File
@@ -9,13 +9,15 @@ namespace CollisionLayer
{
enum Type
{
Pad = 1 << 0,
Ball = 1 << 1,
Brick = 1 << 2,
Water = 1 << 3,
PowerUp = 1 << 4,
Other = 1 << 5,
Wall = 1 << 6
Pad = 1 << 0,
Ball = 1 << 1,
Brick = 1 << 2,
Water = 1 << 3,
PowerUp = 1 << 4,
Other = 1 << 5,
Wall = 1 << 6,
LifeBuoy = 1 << 7,
Projectile = 1 << 8
};
}
@@ -39,20 +41,21 @@ enum Type
bool Calculate = false;
float GravityScale = 0.f;
float Density = 20.f;
CollisionLayer::Type Category = CollisionLayer::Type::Other;
CollisionLayer::Type Mask = static_cast<CollisionLayer::Type>(
CollisionLayer::Pad
| CollisionLayer::Ball
| CollisionLayer::Brick
| CollisionLayer::Water
| CollisionLayer::PowerUp
| CollisionLayer::Wall
| CollisionLayer::Other
);
};
CollisionLayer::Type Mask = static_cast<CollisionLayer::Type>(
CollisionLayer::Pad
| CollisionLayer::Ball
| CollisionLayer::Brick
| CollisionLayer::Water
| CollisionLayer::PowerUp
| CollisionLayer::Wall
| CollisionLayer::LifeBuoy
| CollisionLayer::Other
);
};
}
}
+1
View File
@@ -19,6 +19,7 @@ struct Contact : Event
{
EntityID Entity1;
EntityID Entity2;
glm::vec2 IntersectionPoint;
glm::vec2 Normal;
glm::vec2 SignificantNormal;
};
+39
View File
@@ -0,0 +1,39 @@
#ifndef EVENTS_ECREATEPARTICLESEQUENCE_H__
#define EVENTS_ECREATEPARTICLESEQUENCE_H__
#include "Core/EventBroker.h"
#include "Physics/CParticle.h"
namespace dd
{
namespace Events
{
struct CreateParticleSequence : public Event
{
//Emitter
double EmitterLifeTime = 100;
glm::vec3 Position = glm::vec3(0);
float GravityScale = 0.f;
float SpawnRate = 1.f;
int NumberOfTicks = 100;
float Speed = 1.f;
int ParticlesPerTick = 1.f;
float Spread = 1.f;
float EmittingAngle = 0.f;
float MaxCount = 0;
glm::vec4 Color = glm::vec4(0);
EntityID parent = 0;
//Particle
std::string SpriteFile = "";
double ParticleLifeTime = 3.f;
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Powder | ParticleFlags::ParticleContactFilter | ParticleFlags::FixtureContactFilter);
float Radius = 1.f;
};
}
}
#endif
+108 -32
View File
@@ -2,6 +2,7 @@
#define DAYDREAM_PHYSICSSYSTEM_H
#include <unordered_map>
#include <random>
#include <Box2D/Box2D.h>
@@ -9,27 +10,35 @@
#include "Core/World.h"
#include "Core/EventBroker.h"
#include "Core/CTemplate.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Physics/EContact.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CRectangleShape.h"
#include "Physics/CCircleShape.h"
#include "Physics/CPhysics.h"
#include "Physics/CWaterVolume.h"
#include "Core/CTransform.h"
#include "Transform/TransformSystem.h"
#include "CRectangleShape.h"
#include "Physics/CPhysics.h"
#include "Physics/EContact.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CParticle.h"
#include "Physics/ECreateParticleSequence.h"
#include "Physics/CCircleShape.h"
#include "Physics/CParticleEmitter.h"
#include "Game/CPad.h"
#include "Game/CPad.h"
#include "Game/CBall.h"
#include "Transform/TransformSystem.h"
#include "Rendering/CSprite.h"
#include "Core/CTemplate.h"
#include "Transform/TransformSystem.h"
#include "CRectangleShape.h"
#include "Game/EStageCleared.h"
#include "Game/EPause.h"
#include "Game/CPad.h"
#include "Game/CBrick.h"
#include "Game/CBall.h"
#include "Rendering/CSprite.h"
#include "Rendering/CModel.h"
namespace dd
{
@@ -40,6 +49,7 @@ namespace dd
class PhysicsSystem : public System
{
friend class ContractListener;
friend class DestructionListener;
public:
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
@@ -47,6 +57,9 @@ namespace dd
~PhysicsSystem();
EventRelay<PhysicsSystem, Events::CreateParticleSequence> m_ECreateParticleSequence;
bool CreateParticleSequence(const Events::CreateParticleSequence &event);
void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override;
void Update(double dt) override;
@@ -62,6 +75,8 @@ namespace dd
b2Vec2 Point;
};
bool m_Pause = false;
std::mt19937 gen;
b2Vec2 m_Gravity = b2Vec2(0.f, -9.82f);
@@ -71,9 +86,11 @@ namespace dd
int m_VelocityIterations = 6;
int m_PositionIterations = 2;
std::vector<b2ParticleSystem*> m_ParticleSystem;
b2ParticleSystem* m_WaterParticleSystem;
std::vector<b2ParticleGroup*> t_ParticleGroup;
std::unordered_map<const b2ParticleHandle*, EntityID> m_WaterParticleHandleToEntities;
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToWaterParticleHandle;
std::vector<std::unordered_map<EntityID, const b2ParticleHandle*>> m_EntitiesToParticleHandle;
std::vector<std::unordered_map<const b2ParticleHandle*, EntityID>> m_ParticleHandleToEntities;
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
@@ -87,7 +104,7 @@ namespace dd
void InitializeWater();
void CreateParticleGroup(EntityID entity);
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale);
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale, int maxCount);
void CreateParticleEmitter(EntityID entity);
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed.
@@ -95,36 +112,95 @@ namespace dd
bool SetImpulse(const Events::SetImpulse &event);
dd::EventRelay<PhysicsSystem, dd::Events::Pause> m_EPause;
bool OnPause(const dd::Events::Pause &event);
dd::EventRelay<PhysicsSystem, dd::Events::StageCleared> m_EStageCleared;
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;
float m_DistanceTravelled = 0;
//TODO: Fill struct with info needed.
struct ParticleEmitter
{
std::vector<b2ParticleSystem*> System;
std::vector<EntityID> Emitter;
std::vector<EntityID> Template;
};
ParticleEmitter m_ParticleEmitters;
struct EmitterHandler //TODO CHANGE NAMES
{
std::vector<b2ParticleSystem*> ParticleSystem;
std::vector<EntityID> ParticleEmitter;
std::vector<EntityID> ParticleTemplate;
};
EmitterHandler m_ParticleEmitters;
std::list<Impulse> m_Impulses;
class DestructionListener : public b2DestructionListener
{
public:
DestructionListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
void SayGoodbye(b2Joint*) {LOG_INFO("joint körs");};
void SayGoodbye(b2Fixture*) {/*LOG_INFO("Fixture körs");*/};
void SayGoodbye(b2ParticleSystem* particleSystem, int32 index) override
{
LOG_INFO("Particle ded");
const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index);
for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) {
if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) {
std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle);
if(it != m_PhysicsSystem->m_ParticleHandleToEntities[i].end()) {
EntityID id = it->second;
m_PhysicsSystem->m_World->RemoveEntity(id);
m_PhysicsSystem->m_ParticleHandleToEntities[i].erase(it);
LOG_INFO("Removing from list");
}
}
}
}
private:
PhysicsSystem* m_PhysicsSystem;
};
class ParticleContactDisabler : public b2ContactFilter
{
public:
ParticleContactDisabler() { };
//Particles to particles
virtual bool ShouldCollide(b2ParticleSystem *particleSystem, int32 particleIndexA, int32 particleIndexB)
{
return false;
}
virtual bool ShouldCollide(b2Fixture* fixture, b2ParticleSystem* particleSystem, int32 particleIndex)
{
return false;
}
};
class ContactListener : public b2ContactListener
{
public:
ContactListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
private:
PhysicsSystem* m_PhysicsSystem;
};
class ContactListener : public b2ContactListener
{
public:
ContactListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
ContactListener* m_ContactListener;
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
private:
PhysicsSystem* m_PhysicsSystem;
};
DestructionListener* m_DestructionListener;
ParticleContactDisabler* m_ParticleContactDisabler;
ContactListener* m_ContactListener;
};
}
+1
View File
@@ -17,6 +17,7 @@
#include "Game/CBall.h"
#include "Game/CBrick.h"
#include "Game/CPad.h"
#include "Physics/ECreateParticleSequence.h"
namespace dd
{