Merge remote-tracking branch 'origin/LevelSystemAndSuch' into Physics
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+26
-1
@@ -43,9 +43,11 @@
|
||||
#include "Game/PadSystem.h"
|
||||
#include "Game/CBall.h"
|
||||
#include "Game/CPad.h"
|
||||
#include "Game/CLifebuoy.h"
|
||||
#include "Game/CBrick.h"
|
||||
#include "Game/BallSystem.h"
|
||||
#include "Game/HitLagSystem.h"
|
||||
#include "Game/LifebuoySystem.h"
|
||||
#include "Game/Bricks/CPowerUpBrick.h"
|
||||
|
||||
#include "Physics/PhysicsSystem.h"
|
||||
@@ -110,6 +112,7 @@ 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::PowerUp>();
|
||||
m_World->ComponentFactory.Register<Components::PowerUpBrick>();
|
||||
@@ -126,6 +129,9 @@ 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::PhysicsSystem>(
|
||||
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::PhysicsSystem>();
|
||||
@@ -143,6 +149,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 +161,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,9 +176,20 @@ 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);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -229,6 +248,7 @@ public:
|
||||
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->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);
|
||||
@@ -247,6 +267,7 @@ 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;
|
||||
transform->Sticky = true;
|
||||
m_World->CommitEntity(BottomWall);
|
||||
}
|
||||
|
||||
@@ -266,6 +287,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 +309,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,6 +331,8 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "Game/EPause.h"
|
||||
#include "Game/EHitPad.h"
|
||||
#include "Game/EHitLag.h"
|
||||
#include "Game/EActionButton.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -89,6 +90,7 @@ private:
|
||||
int m_PastLives = 3;
|
||||
bool m_ReplaceBall = false;
|
||||
bool m_Pause = false;
|
||||
bool m_Waiting = true;
|
||||
EntityID m_LastCollision = 999999;
|
||||
|
||||
glm::vec3 m_SavedSpeed;
|
||||
@@ -104,7 +106,8 @@ private:
|
||||
dd::EventRelay<BallSystem, dd::Events::ResetBall> m_EResetBall;
|
||||
dd::EventRelay<BallSystem, dd::Events::MultiBall> m_EMultiBall;
|
||||
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);
|
||||
@@ -112,6 +115,7 @@ private:
|
||||
bool OnResetBall(const dd::Events::ResetBall &event);
|
||||
bool OnMultiBall(const dd::Events::MultiBall &event);
|
||||
bool OnPause(const dd::Events::Pause &event);
|
||||
bool OnActionButton(const dd::Events::ActionButton &event);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ struct Ball : Component
|
||||
float Speed = 5.f;
|
||||
int Combo = 0;
|
||||
bool Paused = false;
|
||||
bool Waiting = true;
|
||||
glm::vec3 SavedSpeed = glm::vec3(0, 0, 0);
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_CLIFEBUOY_H
|
||||
@@ -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
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_EACTIONBUTTON_H
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-17.
|
||||
//
|
||||
|
||||
#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
|
||||
@@ -9,13 +9,18 @@
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct StageCleared : Event
|
||||
{
|
||||
|
||||
int ClearedStage = 0;
|
||||
int StageCluster = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_ESTAGECLEARED_H
|
||||
|
||||
@@ -22,13 +22,14 @@
|
||||
#include "Game/EScoreEvent.h"
|
||||
#include "Game/EComboEvent.h"
|
||||
#include "Game/EHitPad.h"
|
||||
#include "Game/ELifebuoy.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"
|
||||
#include "Game/Bricks/CPowerUpBrick.h"
|
||||
//#include "Game/Bricks/CPowerUpBrick.h"
|
||||
#include "Physics/CPhysics.h"
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Physics/CRectangleShape.h"
|
||||
@@ -66,8 +67,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);
|
||||
|
||||
void OnEntityRemoved(EntityID entity);
|
||||
|
||||
@@ -123,6 +124,7 @@ private:
|
||||
const int EmptyBrickSpace = 0;
|
||||
const int StandardBrick = 1;
|
||||
const int MultiBallBrick = 2;
|
||||
const int LifebuoyBrick = 3;
|
||||
|
||||
EntityID m_BrickTemplate;
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// 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/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;
|
||||
|
||||
bool OnContact(const dd::Events::Contact &event);
|
||||
bool OnPause(const dd::Events::Pause &event);
|
||||
bool OnLifebuoy(const dd::Events::Lifebuoy &event);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_LIFEBUOYSYSTEM_H
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "Game/EStageCleared.h"
|
||||
#include "Game/EPause.h"
|
||||
#include "Game/EHitLag.h"
|
||||
#include "Game/EActionButton.h"
|
||||
|
||||
|
||||
namespace dd
|
||||
|
||||
@@ -9,27 +9,33 @@
|
||||
#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/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"
|
||||
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -95,6 +101,10 @@ 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);
|
||||
bool m_Travelling = false;
|
||||
float m_DistanceTravelled = 0;
|
||||
|
||||
//TODO: Fill struct with info needed.
|
||||
struct ParticleEmitter
|
||||
|
||||
@@ -59,7 +59,7 @@ void dd::Renderer::Initialize()
|
||||
}
|
||||
|
||||
// Create default camera
|
||||
m_DefaultCamera = std::unique_ptr<dd::Camera>(new dd::Camera((float)m_Resolution.Width / m_Resolution.Height, 45.f, 0.01f, 5000.f));
|
||||
m_DefaultCamera = std::unique_ptr<dd::Camera>(new dd::Camera((float)m_Resolution.Width / m_Resolution.Height, /*45.f*/ 46.f, 0.01f, 5000.f));
|
||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 0));
|
||||
if (m_Camera == nullptr) {
|
||||
m_Camera = m_DefaultCamera.get();
|
||||
|
||||
@@ -19,6 +19,7 @@ void dd::Systems::BallSystem::Initialize()
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &BallSystem::OnResetBall);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &BallSystem::OnActionButton);
|
||||
|
||||
//OctoBall
|
||||
{
|
||||
@@ -33,12 +34,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->Calculate = true;
|
||||
transform->Sticky = true;
|
||||
|
||||
//auto plight = m_World->AddComponent<Components::PointLight>(ent);
|
||||
//plight->Radius = 2.f;
|
||||
@@ -100,12 +103,23 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
if (templateCheck != nullptr){ return; }
|
||||
|
||||
if (ballComponent != nullptr) {
|
||||
if (ballComponent->Waiting) {
|
||||
if (m_Waiting == false) {
|
||||
ballComponent->Waiting = false;
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
transform->Velocity = glm::normalize(glm::vec3(0.5f, 1, 0.f)) * ballComponent->Speed;
|
||||
} else {
|
||||
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 (ReplaceBall()) {
|
||||
SetReplaceBall(false);
|
||||
|
||||
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);
|
||||
m_Waiting = true;
|
||||
ballComponent->Waiting = true;
|
||||
}
|
||||
|
||||
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
|
||||
@@ -321,6 +335,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;
|
||||
@@ -364,8 +379,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;
|
||||
}
|
||||
@@ -383,3 +400,9 @@ bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::BallSystem::OnActionButton(const dd::Events::ActionButton &event)
|
||||
{
|
||||
m_Waiting = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ void dd::Systems::LevelSystem::Initialize()
|
||||
cPhys->GravityScale = 0.f;
|
||||
cPhys->Category = CollisionLayer::Type::Brick;
|
||||
cPhys->Mask = CollisionLayer::Type::Ball;
|
||||
transform->Sticky = false;
|
||||
|
||||
model->ModelFile = "Models/Brick/WhiteBrick.obj";
|
||||
transform->Position = glm::vec3(50, 50, -10);
|
||||
@@ -48,7 +49,7 @@ void dd::Systems::LevelSystem::Update(double dt)
|
||||
{
|
||||
if (!m_Initialized) {
|
||||
GetNextLevel();
|
||||
CreateLevel();
|
||||
CreateLevel(0);
|
||||
m_Initialized = true;
|
||||
}
|
||||
}
|
||||
@@ -61,16 +62,32 @@ 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);
|
||||
}
|
||||
m_LooseBricks--;
|
||||
m_World->RemoveEntity(entity);
|
||||
}
|
||||
@@ -81,6 +98,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 +144,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);
|
||||
}
|
||||
if (num == 1)
|
||||
num = Lines();
|
||||
@@ -136,7 +155,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 +165,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]);
|
||||
getter++;
|
||||
}
|
||||
if (num == 1) {
|
||||
@@ -157,7 +176,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)
|
||||
{
|
||||
if (typeInt == EmptyBrickSpace) {
|
||||
SetNumberOfBricks(NumberOfBricks() - 1);
|
||||
@@ -171,13 +190,14 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
||||
if (typeInt == StandardBrick) {
|
||||
} 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -304,6 +324,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,7 +358,7 @@ bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &ev
|
||||
m_CurrentLevel++;
|
||||
if (m_CurrentLevel < 6) {
|
||||
GetNextLevel();
|
||||
CreateLevel();
|
||||
CreateLevel(12);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -399,7 +420,7 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
||||
1, 1, 1, 1, 1, 1, 1,
|
||||
1, 2, 1, 2, 1, 2, 1,
|
||||
1, 1, 0, 1, 0, 1, 1,
|
||||
1, 0, 0, 1, 0, 0, 1};
|
||||
1, 0, 0, 3, 0, 0, 1};
|
||||
} else if (m_CurrentLevel == 2) {
|
||||
level =
|
||||
{1, 0, 0, 0, 0, 0, 1,
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// 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);
|
||||
|
||||
//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(1.f, 0.1f);
|
||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->CollisionType = CollisionType::Type::Static;
|
||||
physics->Category = CollisionLayer::Type::Other;
|
||||
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Pad | CollisionLayer::Wall | CollisionLayer::Water);
|
||||
physics->Density = 0.001;
|
||||
physics->GravityScale = 1;
|
||||
ctransform->Sticky = true;
|
||||
auto cModel = m_World->AddComponent<Components::Model>(ent);
|
||||
cModel->ModelFile = "Models/Ship/Ship.obj";
|
||||
auto lifebuoy = m_World->AddComponent<Components::Lifebuoy>(ent);
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
|
||||
m_Template = ent;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void dd::Systems::LifebuoySystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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->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(event.Transform->Position.x, transform->Position.y, -10.f);
|
||||
return true;
|
||||
}
|
||||
@@ -28,6 +28,7 @@ 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();
|
||||
@@ -41,6 +42,7 @@ void dd::Systems::PadSystem::Initialize()
|
||||
physics->Category = CollisionLayer::Type::Pad;
|
||||
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::PowerUp);
|
||||
physics->Calculate = true;
|
||||
ctransform->Sticky = true;
|
||||
auto cModel = m_World->AddComponent<Components::Model>(ent);
|
||||
cModel->ModelFile = "Models/Ship/Ship.obj";
|
||||
|
||||
@@ -123,8 +125,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 +155,9 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
||||
e.Time = 0.2;
|
||||
e.Type = "All";
|
||||
EventBroker->Publish(e);
|
||||
} else if (val == GLFW_KEY_SPACE) {
|
||||
Events::ActionButton e;
|
||||
EventBroker->Publish(e);
|
||||
} else if (val == GLFW_KEY_D) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ void dd::Systems::PhysicsSystem::Initialize()
|
||||
InitializeWater();
|
||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PhysicsSystem::OnStageCleared);
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::InitializeWater()
|
||||
@@ -151,10 +152,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)
|
||||
@@ -204,7 +213,15 @@ 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 == true) {
|
||||
return;
|
||||
}
|
||||
transform->Position.y -= 6.0f * dt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
||||
@@ -273,6 +290,15 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
||||
}
|
||||
|
||||
|
||||
bool dd::Systems::PhysicsSystem::OnStageCleared(const dd::Events::StageCleared &event)
|
||||
{
|
||||
if (event.ClearedStage < 5) {
|
||||
m_Travelling = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
||||
{
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
|
||||
Reference in New Issue
Block a user