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

Conflicts:
	include/Core/Engine.h
	include/Physics/PhysicsSystem.h
	src/game/Game/BallSystem.cpp
	src/game/Game/LevelSystem.cpp
	src/game/Physics/PhysicsSystem.cpp
This commit is contained in:
viktorljung
2015-10-06 16:13:17 +02:00
17 changed files with 640 additions and 175 deletions
+4 -27
View File
@@ -45,6 +45,7 @@
#include "Game/CPad.h"
#include "Game/CBrick.h"
#include "Game/BallSystem.h"
#include "Game/HitLagSystem.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/PhysicsSystem.h"
@@ -122,6 +123,9 @@ public:
m_World->SystemFactory.Register<Systems::BallSystem>(
[this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::BallSystem>();
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::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>();
@@ -134,33 +138,6 @@ public:
m_World->ComponentFactory.Register<Components::ParticleEmitter>();
m_World->Initialize();
//OctoBall
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(-0.f, 0.26f, -10.f);
transform->Scale = glm::vec3(0.25f, 0.25f, 0.25f);
transform->Velocity = glm::vec3(0.0f, -10.f, 0.f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Sid.obj";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
circleShape->Radius = 0.25f;
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
ball->Speed = 5.f;
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->CollisionType = CollisionType::Type::Dynamic;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
//auto plight = m_World->AddComponent<Components::PointLight>(ent);
//plight->Radius = 2.f;
m_World->CommitEntity(ent);
}
//PointLightTest
{
auto t_Light = m_World->CreateEntity();
+14
View File
@@ -8,18 +8,23 @@
#include "Core/CTemplate.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/CRectangleShape.h"
#include "Physics/EContact.h"
#include "Rendering/CModel.h"
#include "Rendering/CPointLight.h"
#include "Game/CBall.h"
#include "Game/CPowerUp.h"
#include "Game/CLife.h"
#include "Game/CBrick.h"
#include "Game/ELifeLost.h"
#include "Game/EComboEvent.h"
#include "Game/EResetBall.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EGameOver.h"
#include "Game/EPause.h"
#include "Game/EHitPad.h"
#include "Game/EHitLag.h"
namespace dd
{
@@ -75,6 +80,8 @@ public:
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
bool MultiBall() const { return m_MultiBall; }
void SetMultiBall(const bool& multiBall) { m_MultiBall = multiBall; }
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
private:
float m_XMovementMultiplier = 2.f;
@@ -85,6 +92,11 @@ private:
int m_PastLives = 3;
bool m_ReplaceBall = false;
bool m_MultiBall = false;
bool m_Pause = false;
EntityID m_LastCollision = 999999;
glm::vec3 m_SavedSpeed;
bool m_InitializePause = false;
EntityID m_Ball;
@@ -92,11 +104,13 @@ 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::Pause> m_EPause;
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 OnPause(const dd::Events::Pause &event);
};
}
+2
View File
@@ -18,6 +18,8 @@ struct Ball : Component
int Number = 0;
float Speed = 5.f;
int Combo = 0;
bool Paused = false;
glm::vec3 SavedSpeed = glm::vec3(0, 0, 0);
};
}
-2
View File
@@ -15,8 +15,6 @@ namespace Components
struct Brick : Component
{
int Points = 10;
int Hits = 1;
int Score = 50;
bool Removed = false;
};
-3
View File
@@ -17,9 +17,6 @@ namespace Components
struct Pad : Component
{
int Lives;
int Points;
float SlowdownModifier = 5.f;
float AccelerationSpeed = 40.f;
float MaxSpeed = 5.f;
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Administrator on 2015-09-30.
//
#ifndef DAYDREAM_EHITLAG_H
#define DAYDREAM_EHITLAG_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct HitLag : Event
{
float Time;
std::string Type;
};
}
}
#endif //DAYDREAM_EHITLAG_H
+21
View File
@@ -0,0 +1,21 @@
//
// Created by Administrator on 2015-10-05.
//
#ifndef DAYDREAM_EHITPAD_H
#define DAYDREAM_EHITPAD_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct HitPad : Event
{
};
}
}
#endif //DAYDREAM_EHITPAD_H
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-09-30.
//
#ifndef DAYDREAM_EPAUSE_H
#define DAYDREAM_EPAUSE_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct Pause : Event
{
std::string Type;
};
}
}
#endif //DAYDREAM_EPAUSE_H
+91
View File
@@ -0,0 +1,91 @@
//
// Created by Adniklastrator on 2015-09-30.
//
#ifndef DAYDREAM_HITLAGSYSTEM_H
#define DAYDREAM_HITLAGSYSTEM_H
#include "Core/System.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Rendering/CSprite.h"
#include "Rendering/CModel.h"
#include "Game/CBrick.h"
#include "Game/CBall.h"
#include "Game/CLife.h"
#include "Game/CPowerUp.h"
#include "Game/EStageCleared.h"
#include "Game/ELifeLost.h"
#include "Game/EResetBall.h"
#include "Game/EScoreEvent.h"
#include "Game/EComboEvent.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EPause.h"
#include "Game/EHitLag.h"
#include "Game/EGameOver.h"
#include "Game/ECreatePowerUp.h"
#include "Game/EPowerUpTaken.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/CRectangleShape.h"
#include "Physics/ESetImpulse.h"
#include "Physics/EContact.h"
#include "Sound/CCollisionSound.h"
#include "Game/PadSystem.h"
#include <fstream>
#include <iostream>
namespace dd
{
namespace Systems
{
class HitLagSystem : public System
{
public:
HitLagSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker)
{ }
void Initialize() override;
void Update(double dt) override;
void FlipPause();
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
bool HitLag() const { return m_HitLag; }
void SetHitLag(const bool& hitLag) { m_HitLag = hitLag; }
float& HitLagDuration() { return m_HitLagDuration; }
void SetHitLagDuration(const float& hitLagDuration) { m_HitLagDuration = hitLagDuration; }
float& HitLagTimer() { return m_HitLagTimer; }
void SetHitLagTimer(const float& hitLagTimer) { m_HitLagTimer = hitLagTimer; }
std::string& CurrentType() { return m_CurrentType; }
void SetCurrentType(const std::string& currentType) { m_CurrentType = currentType; }
private:
bool m_Pause;
bool m_HitLag;
float m_HitLagDuration;
float m_HitLagTimer;
std::string m_CurrentType;
dd::EventRelay<HitLagSystem, dd::Events::Pause> m_EPause;
dd::EventRelay<HitLagSystem, dd::Events::HitLag> m_EHitLag;
bool OnPause(const dd::Events::Pause &event);
bool OnHitLag(const dd::Events::HitLag &event);
};
}
}
#endif //DAYDREAM_HITLAGSYSTEM_H
+28 -11
View File
@@ -21,8 +21,10 @@
#include "Game/EResetBall.h"
#include "Game/EScoreEvent.h"
#include "Game/EComboEvent.h"
#include "Game/EHitPad.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EPause.h"
#include "Game/EGameOver.h"
#include "Game/ECreatePowerUp.h"
#include "Game/EPowerUpTaken.h"
@@ -44,15 +46,15 @@ namespace Systems
{
// Me trying things out.
class Level
/*class Level
{
public:
int levelRows;
int levelLines;
int levelSpaceBetweenBricks;
int levelSpaceToEdge;
int bricks[];
};
int levelRows = 6;
int levelLines = 7;
glm::vec2 levelSpaceBetweenBricks = glm::vec2(1, 0.4);
float levelSpaceToEdge = 0.25f;
std::array<int, 42> bricks;
};*/
class LevelSystem : public System
{
@@ -64,10 +66,8 @@ public:
void Initialize() override;
void CreateBasicLevel(int, int, glm::vec2, float);
void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting.
void LoadLevel(char[20]);
void CreateBrick(int, int, glm::vec2, float, int);
void ProcessCollision();
void CreateLevel();
void CreateBrick(int, int, glm::vec2, float, int, int);
void OnEntityRemoved(EntityID entity);
@@ -80,6 +80,8 @@ public:
void SetRestarting(const bool& restarting) { m_Restarting = restarting; }
bool Initialized() const { return m_Initialized; }
void SetInitialized(const bool& initialized) { m_Initialized = initialized; }
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
int& MultiBalls() { return m_MultiBalls; }
void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
int& PowerUps() { return m_PowerUps; }
@@ -101,8 +103,13 @@ public:
void SetNotResettingTheStage(const float& notResettingTheStage) { m_NotResettingTheStage = notResettingTheStage; }
private:
bool m_Cleared = false;
bool m_Restarting = false;
bool m_Initialized = false;
bool m_Pause = false;
int m_LooseBricks = 0;
int m_CurrentCluster = 2;
int m_CurrentLevel = 1;
int m_MultiBalls = 0;
int m_PowerUps = 0;
int m_Score = 0;
@@ -113,6 +120,10 @@ private:
glm::vec2 m_SpaceBetweenBricks = glm::vec2(1, 0.4);
float m_NotResettingTheStage = 5.f;
EntityID m_BrickTemplate;
std::array<int, 42> m_Bricks;
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
dd::EventRelay<LevelSystem, dd::Events::MultiBall> m_EMultiBall;
@@ -120,6 +131,8 @@ private:
dd::EventRelay<LevelSystem, dd::Events::CreatePowerUp> m_ECreatePowerUp;
dd::EventRelay<LevelSystem, dd::Events::PowerUpTaken> m_EPowerUpTaken;
dd::EventRelay<LevelSystem, dd::Events::StageCleared> m_EStageCleared;
dd::EventRelay<LevelSystem, dd::Events::Pause> m_EPause;
dd::EventRelay<LevelSystem, dd::Events::HitPad> m_EHitPad;
bool OnContact(const dd::Events::Contact &event);
bool OnScoreEvent(const dd::Events::ScoreEvent &event);
@@ -128,6 +141,10 @@ private:
bool OnCreatePowerUp(const dd::Events::CreatePowerUp &event);
bool OnPowerUpTaken(const dd::Events::PowerUpTaken &event);
bool OnStageCleared(const dd::Events::StageCleared &event);
bool OnPause(const dd::Events::Pause &event);
bool OnHitPad(const dd::Events::HitPad &event);
void GetNextLevel();
};
}
+9 -1
View File
@@ -28,6 +28,8 @@
#include "Game/EMultiBall.h"
#include "Game/EPowerUpTaken.h"
#include "Game/EStageCleared.h"
#include "Game/EPause.h"
#include "Game/EHitLag.h"
namespace dd
@@ -63,6 +65,9 @@ public:
Components::Pad* Pad() const { return m_Pad; }
void SetPad(Components::Pad* pad) { m_Pad = pad; }
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
private:
EntityID m_Entity = 0;
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
@@ -74,18 +79,21 @@ private:
Components::Transform* m_Transform = nullptr;
Components::Pad* m_Pad = nullptr;
bool m_Pause = false;
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContactPowerUp;
dd::EventRelay<PadSystem, dd::Events::StageCleared> m_EStageCleared;
dd::EventRelay<PadSystem, dd::Events::Pause> m_EPause;
bool OnKeyDown(const dd::Events::KeyDown &event);
bool OnKeyUp(const dd::Events::KeyUp &event);
bool OnContact(const dd::Events::Contact &event);
bool OnContactPowerUp(const dd::Events::Contact &event);
bool OnStageCleared(const dd::Events::StageCleared &event);
bool OnPause(const dd::Events::Pause &event);
class PadSteeringInputController;
std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers;
+3
View File
@@ -29,6 +29,7 @@
#include "Transform/TransformSystem.h"
#include "Rendering/CSprite.h"
#include "Core/CTemplate.h"
#include "Game/EPause.h"
namespace dd
{
@@ -92,6 +93,8 @@ namespace dd
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &event);
dd::EventRelay<PhysicsSystem, dd::Events::Pause> m_EPause;
bool OnPause(const dd::Events::Pause &event);
//TODO: Fill struct with info needed.
struct ParticleEmitter
+97 -45
View File
@@ -18,26 +18,42 @@ 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_EPause, &BallSystem::OnPause);
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(-0.f, 50.f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
transform->Velocity = glm::vec3(0.0f, 0.f, 0.f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
ball->Speed = 5.f;
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
std::shared_ptr<Components::Template> ballTemplate = m_World->AddComponent<Components::Template>(ent);
//OctoBall
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(-0.f, 50.26f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
circleShape->Radius = 0.5f;
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
ball->Speed = 5.f;
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->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
m_World->CommitEntity(ent);
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
SetBall(ent);
//auto plight = m_World->AddComponent<Components::PointLight>(ent);
//plight->Radius = 2.f;
m_World->CommitEntity(ent);
SetBall(ent);
auto ent2 = CreateBall();
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
transform2->Position = glm::vec3(-0.f, 0.26f, -10.f);
transform2->Velocity = glm::vec3(0.0f, -10.f, 0.f);
m_World->CommitEntity(ent2);
}
for (int i = 0; i < Lives(); i++) {
CreateLife(i);
@@ -56,11 +72,34 @@ void dd::Systems::BallSystem::Update(double dt)
void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ballComponent = m_World->GetComponent<Components::Ball>(entity);
if (IsPaused()) {
if (ballComponent != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!ballComponent->Paused) {
ballComponent->Paused = true;
ballComponent->SavedSpeed = transform->Velocity;
transform->Velocity = glm::vec3(0, 0, 0);
}
}
return;
} else {
if (ballComponent != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (ballComponent->Paused) {
transform->Velocity = ballComponent->SavedSpeed;
ballComponent->Paused = false;
}
}
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
auto ballComponent = m_World->GetComponent<Components::Ball>(entity);
if (ballComponent != nullptr) {
if (ReplaceBall() == true) {
if (ReplaceBall()) {
SetReplaceBall(false);
auto transform = m_World->GetComponent<Components::Transform>(entity);
@@ -78,10 +117,6 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
}
if (transformBall->Position.y < -EdgeY() - 4) {
if (MultiBalls() != 0) {
// m_World->RemoveComponent<Components::Ball>(entity);
// m_World->RemoveComponent<Components::Transform>(entity);
// m_World->RemoveComponent<Components::CircleShape>(entity);
// m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity);
Events::MultiBallLost e;
EventBroker->Publish(e);
@@ -115,8 +150,6 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
auto life = m_World->GetComponent<Components::Life>(entity);
if (life != nullptr) {
if (life->Number + 1 == PastLives()) {
m_World->RemoveComponent<Components::Life>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
SetPastLives(Lives());
}
@@ -132,6 +165,20 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
}
}
bool dd::Systems::BallSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "BallSystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
void dd::Systems::BallSystem::OnEntityCommit(EntityID entity)
{
@@ -178,12 +225,36 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
//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 (otherEntitiy == m_LastCollision) {
if (brick != nullptr) {
return false;
}
} else {
m_LastCollision = otherEntitiy;
}*/
//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"){
Events::HitPad e;
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();
@@ -211,26 +282,7 @@ EntityID dd::Systems::BallSystem::CreateBall()
m_World->RemoveComponent<Components::Template>(ent);
/* auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.5f, 0.26f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
cball->Speed = 5.f;
auto plight = m_World->AddComponent<Components::PointLight>(ent);
plight->Radius = 2.f;*/
m_World->CommitEntity(ent);
//m_World->CommitEntity(ent);
return ent;
}
+57
View File
@@ -0,0 +1,57 @@
//
// Created by Adniklastrator on 2015-09-30.
//
#include "PrecompiledHeader.h"
#include "Game/HitLagSystem.h"
void dd::Systems::HitLagSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EPause, &HitLagSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EHitLag, &HitLagSystem::OnHitLag);
}
void dd::Systems::HitLagSystem::Update(double dt)
{
if (IsPaused()) {
if (HitLag()) {
SetHitLagTimer(HitLagTimer() += dt);
std::cout << HitLagTimer() << std::endl;
if (HitLagDuration() < HitLagTimer()) {
SetHitLagTimer(0);
SetHitLag(false);
FlipPause();
}
}
return;
}
}
void dd::Systems::HitLagSystem::FlipPause()
{
Events::Pause e;
e.Type = CurrentType();
EventBroker->Publish(e);
}
bool dd::Systems::HitLagSystem::OnPause(const dd::Events::Pause &event)
{
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
bool dd::Systems::HitLagSystem::OnHitLag(const dd::Events::HitLag &event)
{
if (HitLag()) {
FlipPause();
}
SetHitLag(true);
SetCurrentType(event.Type);
FlipPause();
SetHitLagDuration(event.Time);
return true;
}
+215 -81
View File
@@ -16,6 +16,30 @@ void dd::Systems::LevelSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &LevelSystem::OnMultiBallLost);
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, &LevelSystem::OnPowerUpTaken);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &LevelSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &LevelSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EHitPad, &LevelSystem::OnHitPad);
m_BrickTemplate = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(m_BrickTemplate);
auto model = m_World->AddComponent<Components::Model>(m_BrickTemplate);
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(m_BrickTemplate);
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(m_BrickTemplate);
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->GravityScale = 0.f;
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
model->ModelFile = "Models/Brick/TurquoiseBrick.obj";
transform->Position = glm::vec3(50, 50, -10);
//sound
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(m_BrickTemplate);
collisionSound->FilePath = "Sounds/Brick/shortbrickbreak.wav";
m_World->CommitEntity(m_BrickTemplate);
return;
}
@@ -23,54 +47,74 @@ void dd::Systems::LevelSystem::Initialize()
void dd::Systems::LevelSystem::Update(double dt)
{
if (!m_Initialized) {
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
//CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
GetNextLevel();
CreateLevel();
m_Initialized = true;
}
}
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (IsPaused()) {
return;
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
auto ball = m_World->GetComponent<Components::Ball>(entity);
SetNotResettingTheStage(NotResettingTheStage() + 0.01 * dt);
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) {
m_LooseBricks--;
std::cout << m_LooseBricks << std::endl;
m_World->RemoveEntity(entity);
}
}
if (NumberOfBricks() <= 0 && Restarting() == false) {
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (NumberOfBricks() <= 0 && m_LooseBricks <= 0 && !Restarting()) {
if (MultiBalls() <= 0 && PowerUps() <= 0) {
if (NotResettingTheStage() > 5) {
SetRestarting(true);
Events::ResetBall e;
EventBroker->Publish(e);
Events::ScoreEvent es;
es.Score = 500;
EventBroker->Publish(es);
Events::StageCleared ec;
EventBroker->Publish(ec);
SetNotResettingTheStage(0);
//CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
}
Events::StageCleared ec;
EventBroker->Publish(ec);
//CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
} else {
if (ball != nullptr && MultiBalls() > 0) {
SetMultiBalls(MultiBalls()-1);
m_World->RemoveComponent<Components::Ball>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveComponent<Components::CircleShape>(entity);
m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity);
} else {
auto powerUp = m_World->GetComponent<Components::PowerUp>(entity);
if (powerUp != nullptr) {
SetPowerUps(PowerUps() - 1);
m_World->RemoveComponent<Components::PowerUp>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
} else {
if (brick != nullptr) {
m_LooseBricks--;
std::cout << m_LooseBricks << std::endl;
m_World->RemoveEntity(entity);
}
}
}
}
}
}
bool dd::Systems::LevelSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "LevelSystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, float spaceToEdge)
{
SetNumberOfBricks(rows * lines);
@@ -79,7 +123,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);
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num, 1);
}
if (num == 1)
num = Lines();
@@ -90,27 +134,41 @@ void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 s
return;
}
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int num)
void dd::Systems::LevelSystem::CreateLevel()
{
auto brick = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
auto model = m_World->AddComponent<Components::Model>(brick);
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick);
std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(brick);
rectangleShape->Dimensions = glm::vec2(0.95f, 0.35f);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
cPhys->CollisionType = CollisionType::Type::Dynamic;
cPhys->GravityScale = 0.f;
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
std::cout << "Loading level: " << m_CurrentLevel << std::endl;
SetNumberOfBricks(Rows() * Lines());
int num = Lines();
int getter = 0;
/*std::string fileName = "Textures/Bricks/";
fileName.append(std::to_string(num));
fileName.append(".png");*/
//sprite->SpriteFile = fileName;
model->ModelFile = "Models/Brick/TurquoiseBrick.obj";
if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 5 && row == 2)) {
for (int i = 0; i < Rows(); i++) {
num--;
for (int j = 0; j < Lines(); j++) {
CreateBrick(i, j, SpaceBetweenBricks(), SpaceToEdge(), num, m_Bricks[getter]);
getter++;
}
if (num == 1)
num = Lines();
}
m_LooseBricks = NumberOfBricks();
SetRestarting(false);
}
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int num, int typeInt)
{
if (typeInt == 0) {
SetNumberOfBricks(NumberOfBricks() - 1);
return;
}
auto brick = m_World->CloneEntity(m_BrickTemplate);
m_World->RemoveComponent<Components::Template>(brick);
auto transform = m_World->GetComponent<Components::Transform>(brick);
auto cBrick = m_World->GetComponent<Components::Brick>(brick);
auto cPhys = m_World->GetComponent<Components::Physics>(brick);
if (typeInt == 2) {
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";
}
float x = line * spacesBetweenBricks.x;
@@ -118,33 +176,13 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y , -10.f);
cBrick->Score = 10 * num;
//sound
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(brick);
collisionSound->FilePath = "Sounds/Brick/shortbrickbreak.wav";
m_World->CommitEntity(brick);
return;
}
void dd::Systems::LevelSystem::ProcessCollision()
{
// Like, go into brick component and check what it does upon collision. Maybe not done here?
return;
}
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
{
/*auto brick = m_World->GetComponent<Components::Brick>(entity);
if (brick != nullptr) {
SetNumberOfBricks(NumberOfBricks() - 1);
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
if (numberOfBricks < 1) {
EndLevel();
}
}
return;*/
}
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
@@ -187,7 +225,9 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
EventBroker->Publish(e);
}
if (ball != nullptr && Restarting() == false) {
if (!Restarting() && !brick->Removed) {
brick->Removed = true;
// Hit brick with ball code.
ball->Combo += 1;
Events::ComboEvent ec;
ec.Combo = ball->Combo;
@@ -196,12 +236,6 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
auto ballTransform = m_World->GetComponent<Components::Transform>(entityBall);
// m_World->RemoveComponent<Components::Brick>(entityBrick);
// m_World->RemoveComponent<Components::Transform>(entityBrick);
// m_World->RemoveComponent<Components::RectangleShape>(entityBrick);
// m_World->RemoveComponent<Components::Physics>(entityBrick);
// m_World->RemoveEntity(entityBrick);
auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick);
physicsComponent->GravityScale = 1.f;
physicsComponent->Mask = CollisionLayer::Type::Water | CollisionLayer::Type::Wall;
@@ -222,17 +256,14 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
SetNumberOfBricks(NumberOfBricks() - 1);
if (NumberOfBricks() <= 0) {
//SetMultiBalls(MultiBalls() + 1);
}
Events::ScoreEvent es;
es.Score = brick->Score * ball->Combo;
EventBroker->Publish(es);
std::cout << "Combo: " << ball->Combo << std::endl;
//std::cout << "Combo: " << ball->Combo << std::endl;
//std::cout << NumberOfBricks() << std::endl;
//std::cout << "Brick Score: " << brick->Score << std::endl;
std::cout << "Score: " << Score() << std::endl;
//std::cout << "Score: " << Score() << std::endl;
}
return true;
@@ -248,14 +279,12 @@ bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
bool dd::Systems::LevelSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
SetMultiBalls(MultiBalls()+2);
std::cout << MultiBalls() << std::endl;
return true;
}
bool dd::Systems::LevelSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event)
{
SetMultiBalls(MultiBalls()-1);
std::cout << MultiBalls() << std::endl;
return true;
}
@@ -273,7 +302,6 @@ bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
transform->Position = event.Position;
transform->Scale = glm::vec3(0.2, 0.2, 0.2);
transform->Velocity = glm::vec3(0, -4, 0);
@@ -293,13 +321,119 @@ bool dd::Systems::LevelSystem::OnPowerUpTaken(const dd::Events::PowerUpTaken &ev
bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
if (!m_Cleared) {
m_Cleared = true;
SetRestarting(true);
Events::ResetBall e;
EventBroker->Publish(e);
Events::ScoreEvent es;
es.Score = 500;
EventBroker->Publish(es);
m_CurrentLevel++;
if (m_CurrentLevel < 6) {
GetNextLevel();
CreateLevel();
}
}
return true;
}
void dd::Systems::LevelSystem::EndLevel()
void dd::Systems::LevelSystem::GetNextLevel()
{
Events::StageCleared e;
EventBroker->Publish(e);
return;
std::array<int, 42> level;
if (m_CurrentCluster == 1) {
if (m_CurrentLevel == 1) {
level =
{0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 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};
} else if (m_CurrentLevel == 2) {
level =
{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, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0};
} else if (m_CurrentLevel == 3) {
level =
{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, 0, 0, 0, 0};
} else if (m_CurrentLevel == 4) {
level =
{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,
1, 0, 0, 0, 0, 0, 0};
} else if (m_CurrentLevel == 5) {
level =
{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, 1};
}
} else if (m_CurrentCluster == 2) {
if (m_CurrentLevel == 1) {
level =
{1, 1, 0, 1, 0, 1, 1,
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};
} 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};
} 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) {
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};
} else if (m_CurrentLevel == 5) {
level =
{1, 0, 1, 0, 1, 0, 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};
}
} else if (m_CurrentCluster == 3) {
}
std::copy(std::begin(level), std::end(level), std::begin(m_Bricks));
}
bool dd::Systems::LevelSystem::OnHitPad(const dd::Events::HitPad &event)
{
m_Cleared = false;
return true;
}
+27 -4
View File
@@ -27,13 +27,13 @@ void dd::Systems::PadSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause);
{
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->Scale = glm::vec3(1.0f, 1.0f, 1.f);
auto rectangleShape = m_World->AddComponent<Components::RectangleShape>(ent);
rectangleShape->Dimensions = glm::vec2(1.f, 0.5f);
auto physics = m_World->AddComponent<Components::Physics>(ent);
@@ -59,6 +59,9 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p
void dd::Systems::PadSystem::Update(double dt)
{
if (IsPaused()) {
return;
}
if (Entity() == 0) {
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") {
@@ -106,6 +109,20 @@ void dd::Systems::PadSystem::Update(double dt)
return;
}
bool dd::Systems::PadSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "PadSystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
{
int val = event.KeyCode;
@@ -128,6 +145,15 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
Events::MultiBall e;
e.padTransform = Transform();
EventBroker->Publish(e);
} else if (val == GLFW_KEY_P) {
Events::Pause e;
e.Type = "All";
EventBroker->Publish(e);
} else if (val == GLFW_KEY_H) {
Events::HitLag e;
e.Time = 0.2;
e.Type = "All";
EventBroker->Publish(e);
} else if (val == GLFW_KEY_D) {
return false;
}
@@ -226,9 +252,6 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
return false;
}
// m_World->RemoveComponent<Components::PowerUp>(entityPower);
// m_World->RemoveComponent<Components::CircleShape>(entityPower);
// m_World->RemoveComponent<Components::Physics>(entityPower);
m_World->RemoveEntity(entityPower);
Events::PowerUpTaken ep;
ep.Name = "Something";
+21 -1
View File
@@ -15,6 +15,7 @@ void dd::Systems::PhysicsSystem::Initialize()
m_PhysicsWorld->SetContactListener(m_ContactListener);
InitializeWater();
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause);
}
void dd::Systems::PhysicsSystem::InitializeWater()
@@ -197,6 +198,20 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
}
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "PhysicsSystem" && event.Type != "All") {
return false;
}
if (m_Pause) {
m_Pause = false;
} else {
m_Pause = true;
}
return true;
}
void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
{
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
@@ -213,7 +228,12 @@ void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
}
if (physicsComponent) {
CreateBody(entity);
auto it = m_EntitiesToBodies.find(entity);
if(it == m_EntitiesToBodies.end()) {
CreateBody(entity);
} else {
LOG_ERROR("Tried to commit a body that already exists");
}
} else if (waterComponent) {
CreateParticleGroup(entity);
} else if (particleEmitterComponent) {