Merge remote-tracking branch 'origin/master' into water
Conflicts: include/Core/Engine.h src/game/Physics/PhysicsSystem.cpp
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+22
-3
@@ -143,6 +143,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 +155,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 +170,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);
|
||||
}
|
||||
|
||||
@@ -192,6 +205,7 @@ public:
|
||||
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
|
||||
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);
|
||||
@@ -200,7 +214,7 @@ public:
|
||||
//ParticleTest
|
||||
|
||||
|
||||
{
|
||||
/*{
|
||||
auto Pe = m_World->CreateEntity();
|
||||
auto transform = m_World->AddComponent<Components::Transform>(Pe);
|
||||
auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(Pe);
|
||||
@@ -231,7 +245,7 @@ public:
|
||||
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
|
||||
@@ -246,6 +260,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);
|
||||
}
|
||||
|
||||
@@ -265,6 +280,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);
|
||||
}
|
||||
@@ -286,6 +302,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);
|
||||
}
|
||||
@@ -307,6 +324,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 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
|
||||
@@ -9,13 +9,18 @@
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct StageCleared : Event
|
||||
{
|
||||
|
||||
int ClearedStage = 0;
|
||||
int StageCluster = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_ESTAGECLEARED_H
|
||||
|
||||
@@ -66,8 +66,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);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "Game/EStageCleared.h"
|
||||
#include "Game/EPause.h"
|
||||
#include "Game/EHitLag.h"
|
||||
#include "Game/EActionButton.h"
|
||||
|
||||
|
||||
namespace dd
|
||||
|
||||
@@ -9,28 +9,34 @@
|
||||
#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"
|
||||
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -104,6 +110,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_Timer = 0;
|
||||
|
||||
//TODO: Fill struct with info needed.
|
||||
struct ParticleEmitter //TODO CHANGE NAMES
|
||||
|
||||
@@ -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);
|
||||
@@ -324,6 +338,7 @@ void dd::Systems::BallSystem::CreateLife(int number)
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
|
||||
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
|
||||
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||
transform->Sticky = true;
|
||||
|
||||
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
|
||||
lifeNr->Number = number;
|
||||
@@ -367,8 +382,10 @@ bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event)
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
|
||||
auto ball1 = m_World->GetComponent<Components::Ball>(ent1);
|
||||
auto ball2 = m_World->GetComponent<Components::Ball>(ent2);
|
||||
ball1->Waiting = false;
|
||||
ball2->Waiting = false;
|
||||
auto padTransform = event.padTransform;
|
||||
float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2;
|
||||
float x1 = padTransform->Position.x/* - 2*/, x2 = padTransform->Position.x/* + 2*/;
|
||||
if (x1 < -m_EdgeX) {
|
||||
x1 = m_EdgeX - 0.2;
|
||||
}
|
||||
@@ -386,3 +403,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/TurquoiseBrick.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,6 +62,17 @@ 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);
|
||||
@@ -81,6 +93,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 +139,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 +150,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 +160,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 +171,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);
|
||||
@@ -177,7 +191,7 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
||||
}
|
||||
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 +318,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 +352,7 @@ bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &ev
|
||||
m_CurrentLevel++;
|
||||
if (m_CurrentLevel < 6) {
|
||||
GetNextLevel();
|
||||
CreateLevel();
|
||||
CreateLevel(12);
|
||||
}
|
||||
}
|
||||
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/Submarine2.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;
|
||||
}
|
||||
|
||||
@@ -156,10 +156,17 @@ void dd::Systems::PhysicsSystem::SyncBodiesWithEntities()
|
||||
|
||||
void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
{
|
||||
if (m_Pause) {
|
||||
return;
|
||||
}
|
||||
if (m_Pause) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Travelling) {
|
||||
m_Timer += dt;
|
||||
if (m_Timer >= 2) {
|
||||
m_Timer = 0;
|
||||
m_Travelling = false;
|
||||
}
|
||||
}
|
||||
m_Accumulator += dt;
|
||||
|
||||
while(m_Accumulator >= m_TimeStep)
|
||||
@@ -233,7 +240,16 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
|
||||
void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
||||
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;
|
||||
}
|
||||
}
|
||||
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
||||
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
|
||||
if (particle && !pTemplate) {
|
||||
particle->LifeTime -= dt;
|
||||
@@ -252,7 +268,6 @@ auto particle = m_World->GetComponent<Components::Particle>(entity);
|
||||
}
|
||||
m_World->RemoveEntity(entity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,6 +327,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