Merge remote-tracking branch 'origin/master' into Benchmarking
Conflicts: include/Core/Engine.h src/game/Game/LevelSystem.cpp
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
# Blender MTL File: 'Brick.blend'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Brick
|
||||||
|
Ns 17.647059
|
||||||
|
Ka 0.000000 0.000000 0.000000
|
||||||
|
Kd 0.640000 0.154050 0.039202
|
||||||
|
Ks 0.000000 0.000000 0.000000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 1
|
||||||
|
map_Kd Brick_d.jpg
|
||||||
|
map_Bump Brick_n.jpg
|
||||||
|
map_Ks Brick_s.jpg
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1010 KiB |
@@ -0,0 +1,14 @@
|
|||||||
|
# Blender MTL File: 'None'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Material.001
|
||||||
|
Ns 96.078431
|
||||||
|
Ka 0.000000 0.000000 0.000000
|
||||||
|
Kd 0.640000 0.640000 0.640000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
||||||
|
map_Kd Test/Brick_Diffuse.png
|
||||||
|
map_Bump Test/Brick_Normal.png
|
||||||
|
map_Ks Test/Brick_Specular.png
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
# Blender v2.75 (sub 0) OBJ File: ''
|
||||||
|
# www.blender.org
|
||||||
|
mtllib Halfpipe.mtl
|
||||||
|
o Cylinder
|
||||||
|
v 0.000000 -2.908792 -1.000000
|
||||||
|
v 0.000000 2.908792 -1.000000
|
||||||
|
v 0.195090 -2.908792 -0.980785
|
||||||
|
v 0.195090 2.908792 -0.980785
|
||||||
|
v 0.382683 -2.908792 -0.923880
|
||||||
|
v 0.382683 2.908792 -0.923880
|
||||||
|
v 0.555570 -2.908792 -0.831470
|
||||||
|
v 0.555570 2.908792 -0.831470
|
||||||
|
v 0.707107 -2.908792 -0.707107
|
||||||
|
v 0.707107 2.908792 -0.707107
|
||||||
|
v 0.831470 -2.908792 -0.555570
|
||||||
|
v 0.831470 2.908792 -0.555570
|
||||||
|
v 0.923880 -2.908792 -0.382683
|
||||||
|
v 0.923880 2.908792 -0.382683
|
||||||
|
v 0.980785 -2.908792 -0.195090
|
||||||
|
v 0.980785 2.908792 -0.195090
|
||||||
|
v 1.000000 -2.908792 -0.000000
|
||||||
|
v 1.000000 2.908792 -0.000000
|
||||||
|
v -1.000000 -2.908792 -0.000001
|
||||||
|
v -1.000000 2.908792 -0.000001
|
||||||
|
v -0.980785 -2.908792 -0.195091
|
||||||
|
v -0.980785 2.908792 -0.195091
|
||||||
|
v -0.923879 -2.908792 -0.382684
|
||||||
|
v -0.923879 2.908792 -0.382684
|
||||||
|
v -0.831469 -2.908792 -0.555571
|
||||||
|
v -0.831469 2.908792 -0.555571
|
||||||
|
v -0.707106 -2.908792 -0.707108
|
||||||
|
v -0.707106 2.908792 -0.707108
|
||||||
|
v -0.555569 -2.908792 -0.831470
|
||||||
|
v -0.555569 2.908792 -0.831470
|
||||||
|
v -0.382682 -2.908792 -0.923880
|
||||||
|
v -0.382682 2.908792 -0.923880
|
||||||
|
v -0.195089 -2.908792 -0.980786
|
||||||
|
v -0.195089 2.908792 -0.980786
|
||||||
|
vt -1.156714 -1.419990
|
||||||
|
vt -1.158346 2.336063
|
||||||
|
vt -1.031779 2.336118
|
||||||
|
vt -1.283288 -1.420045
|
||||||
|
vt -1.284913 2.336008
|
||||||
|
vt -1.409862 -1.420100
|
||||||
|
vt -1.411480 2.335954
|
||||||
|
vt -1.536436 -1.420155
|
||||||
|
vt -1.538048 2.335899
|
||||||
|
vt 2.387354 -1.418355
|
||||||
|
vt 2.385534 2.337692
|
||||||
|
vt 2.512101 2.337753
|
||||||
|
vt 2.260782 -1.418416
|
||||||
|
vt 2.258967 2.337631
|
||||||
|
vt 2.134208 -1.418478
|
||||||
|
vt 2.132400 2.337570
|
||||||
|
vt 2.007634 -1.418538
|
||||||
|
vt 2.005832 2.337510
|
||||||
|
vt -0.144122 -1.419541
|
||||||
|
vt -0.145809 2.336510
|
||||||
|
vt -0.019241 2.336567
|
||||||
|
vt -0.270696 -1.419598
|
||||||
|
vt -0.272376 2.336454
|
||||||
|
vt -0.397270 -1.419654
|
||||||
|
vt -0.398943 2.336397
|
||||||
|
vt -0.523844 -1.419711
|
||||||
|
vt -0.525511 2.336341
|
||||||
|
vt -0.650418 -1.419767
|
||||||
|
vt -0.652078 2.336285
|
||||||
|
vt -0.776992 -1.419823
|
||||||
|
vt -0.778645 2.336229
|
||||||
|
vt -1.030140 -1.419935
|
||||||
|
vt -0.905212 2.336174
|
||||||
|
vt -0.903566 -1.419879
|
||||||
|
vt 2.513929 -1.418293
|
||||||
|
vt -0.017548 -1.419484
|
||||||
|
vn -0.098000 0.000000 0.995200
|
||||||
|
vn -0.290300 0.000000 0.956900
|
||||||
|
vn -0.471400 0.000000 0.881900
|
||||||
|
vn -0.634400 0.000000 0.773000
|
||||||
|
vn -0.773000 0.000000 0.634400
|
||||||
|
vn -0.881900 0.000000 0.471400
|
||||||
|
vn -0.956900 0.000000 0.290300
|
||||||
|
vn -0.995200 0.000000 0.098000
|
||||||
|
vn 0.995200 0.000000 0.098000
|
||||||
|
vn 0.956900 0.000000 0.290300
|
||||||
|
vn 0.881900 0.000000 0.471400
|
||||||
|
vn 0.773000 0.000000 0.634400
|
||||||
|
vn 0.634400 0.000000 0.773000
|
||||||
|
vn 0.471400 0.000000 0.881900
|
||||||
|
vn 0.098000 0.000000 0.995200
|
||||||
|
vn 0.290300 0.000000 0.956900
|
||||||
|
usemtl Material.001
|
||||||
|
s off
|
||||||
|
f 3/1/1 4/2/1 2/3/1
|
||||||
|
f 5/4/2 6/5/2 4/2/2
|
||||||
|
f 7/6/3 8/7/3 6/5/3
|
||||||
|
f 9/8/4 10/9/4 8/7/4
|
||||||
|
f 11/10/5 12/11/5 10/12/5
|
||||||
|
f 13/13/6 14/14/6 12/11/6
|
||||||
|
f 15/15/7 16/16/7 14/14/7
|
||||||
|
f 17/17/8 18/18/8 16/16/8
|
||||||
|
f 21/19/9 22/20/9 20/21/9
|
||||||
|
f 23/22/10 24/23/10 22/20/10
|
||||||
|
f 25/24/11 26/25/11 24/23/11
|
||||||
|
f 27/26/12 28/27/12 26/25/12
|
||||||
|
f 29/28/13 30/29/13 28/27/13
|
||||||
|
f 31/30/14 32/31/14 30/29/14
|
||||||
|
f 1/32/15 2/3/15 34/33/15
|
||||||
|
f 33/34/16 34/33/16 32/31/16
|
||||||
|
f 1/32/1 3/1/1 2/3/1
|
||||||
|
f 3/1/2 5/4/2 4/2/2
|
||||||
|
f 5/4/3 7/6/3 6/5/3
|
||||||
|
f 7/6/4 9/8/4 8/7/4
|
||||||
|
f 9/35/5 11/10/5 10/12/5
|
||||||
|
f 11/10/6 13/13/6 12/11/6
|
||||||
|
f 13/13/7 15/15/7 14/14/7
|
||||||
|
f 15/15/8 17/17/8 16/16/8
|
||||||
|
f 19/36/9 21/19/9 20/21/9
|
||||||
|
f 21/19/10 23/22/10 22/20/10
|
||||||
|
f 23/22/11 25/24/11 24/23/11
|
||||||
|
f 25/24/12 27/26/12 26/25/12
|
||||||
|
f 27/26/13 29/28/13 28/27/13
|
||||||
|
f 29/28/14 31/30/14 30/29/14
|
||||||
|
f 33/34/15 1/32/15 34/33/15
|
||||||
|
f 31/30/16 33/34/16 32/31/16
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Blender MTL File: 'submarine.blend'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Material
|
||||||
|
Ns 96.078431
|
||||||
|
Ka 0.000000 0.000000 0.000000
|
||||||
|
Kd 0.640000 0.640000 0.640000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
||||||
|
map_Kd SubmarineTexture.png
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 736 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.2 MiB |
+26
-30
@@ -42,8 +42,10 @@
|
|||||||
#include "Game/LevelSystem.h"
|
#include "Game/LevelSystem.h"
|
||||||
#include "Game/PadSystem.h"
|
#include "Game/PadSystem.h"
|
||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
#include "Game/CBrick.h"
|
|
||||||
#include "Game/CPad.h"
|
#include "Game/CPad.h"
|
||||||
|
#include "Game/CBrick.h"
|
||||||
|
#include "Game/BallSystem.h"
|
||||||
|
#include "Game/Bricks/CPowerUpBrick.h"
|
||||||
|
|
||||||
#include "Physics/PhysicsSystem.h"
|
#include "Physics/PhysicsSystem.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
@@ -63,8 +65,9 @@ public:
|
|||||||
|
|
||||||
m_Renderer = std::make_shared<Renderer>();
|
m_Renderer = std::make_shared<Renderer>();
|
||||||
m_Renderer->SetFullscreen(false);
|
m_Renderer->SetFullscreen(false);
|
||||||
m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
|
//m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
|
||||||
m_Renderer->Initialize();
|
m_Renderer->SetResolution(Rectangle(0, 0, 675, 1080));
|
||||||
|
m_Renderer->Initialize();
|
||||||
|
|
||||||
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
|
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
|
||||||
|
|
||||||
@@ -92,6 +95,10 @@ public:
|
|||||||
m_World->ComponentFactory.Register<Components::Brick>();
|
m_World->ComponentFactory.Register<Components::Brick>();
|
||||||
m_World->ComponentFactory.Register<Components::Pad>();
|
m_World->ComponentFactory.Register<Components::Pad>();
|
||||||
m_World->ComponentFactory.Register<Components::Life>();
|
m_World->ComponentFactory.Register<Components::Life>();
|
||||||
|
|
||||||
|
m_World->ComponentFactory.Register<Components::PowerUp>();
|
||||||
|
m_World->ComponentFactory.Register<Components::PowerUpBrick>();
|
||||||
|
|
||||||
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
|
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
|
||||||
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::PhysicsSystem>();
|
m_World->AddSystem<Systems::PhysicsSystem>();
|
||||||
@@ -100,6 +107,8 @@ public:
|
|||||||
m_World->AddSystem<Systems::LevelSystem>();
|
m_World->AddSystem<Systems::LevelSystem>();
|
||||||
m_World->SystemFactory.Register<Systems::PadSystem>([this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
|
m_World->SystemFactory.Register<Systems::PadSystem>([this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::PadSystem>();
|
m_World->AddSystem<Systems::PadSystem>();
|
||||||
|
m_World->SystemFactory.Register<Systems::BallSystem>([this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
|
||||||
|
m_World->AddSystem<Systems::BallSystem>();
|
||||||
|
|
||||||
m_World->ComponentFactory.Register<Components::Model>();
|
m_World->ComponentFactory.Register<Components::Model>();
|
||||||
m_World->ComponentFactory.Register<Components::Template>();
|
m_World->ComponentFactory.Register<Components::Template>();
|
||||||
@@ -115,15 +124,16 @@ public:
|
|||||||
{
|
{
|
||||||
auto ent = m_World->CreateEntity();
|
auto ent = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
transform->Position = glm::vec3(0.5f, 0.f, -9.9f);
|
transform->Position = glm::vec3(-0.f, 0.26f, -10.f);
|
||||||
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||||
|
transform->Velocity = glm::vec3(0.0f, -10.f, 0.f);
|
||||||
|
|
||||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||||
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||||
|
|
||||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||||
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
||||||
|
ball->Speed = 10.f;
|
||||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
physics->Static = false;
|
physics->Static = false;
|
||||||
|
|
||||||
@@ -132,11 +142,7 @@ public:
|
|||||||
|
|
||||||
m_World->CommitEntity(ent);
|
m_World->CommitEntity(ent);
|
||||||
|
|
||||||
Events::SetImpulse e;
|
|
||||||
e.Entity = ent;
|
|
||||||
e.Impulse = glm::vec2(0.f, -7.f);
|
|
||||||
e.Point = glm::vec2(0.5f, 0.f);
|
|
||||||
m_EventBroker->Publish(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//PointLightTest
|
//PointLightTest
|
||||||
@@ -152,28 +158,17 @@ public:
|
|||||||
{
|
{
|
||||||
auto t_halfPipe = m_World->CreateEntity();
|
auto t_halfPipe = m_World->CreateEntity();
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(t_halfPipe);
|
auto transform = m_World->AddComponent<Components::Transform>(t_halfPipe);
|
||||||
transform->Position = glm::vec3(0.f, 0.f, -15.f);
|
transform->Position = glm::vec3(0.f, 0.f, -13.f);
|
||||||
transform->Scale = glm::vec3(15.f);
|
transform->Scale = glm::vec3(5.f);
|
||||||
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
|
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
|
||||||
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Brick test model
|
|
||||||
{
|
|
||||||
auto t_Brick = m_World->CreateEntity();
|
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(t_Brick);
|
|
||||||
transform->Position = glm::vec3(0.f, 0.f, -12.f);
|
|
||||||
transform->Orientation = glm::rotate(glm::quat(), 0.5f, glm::vec3(0,-1,-1));
|
|
||||||
auto model = m_World->AddComponent<Components::Model>(t_Brick);
|
|
||||||
model->ModelFile = "Models/Test/Brick/Brick.obj";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto topWall = m_World->CreateEntity();
|
auto topWall = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
|
||||||
transform->Position = glm::vec3(0.f, 6.f, -10.f);
|
transform->Position = glm::vec3(0.f, 6.f, -10.f);
|
||||||
transform->Scale = glm::vec3(18.f, 0.5f, 1.f);
|
transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
@@ -188,8 +183,8 @@ public:
|
|||||||
{
|
{
|
||||||
auto leftWall = m_World->CreateEntity();
|
auto leftWall = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(leftWall);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(leftWall);
|
||||||
transform->Position = glm::vec3(-9.f, 1.f, -10.f);
|
transform->Position = glm::vec3(-4.f, 1.f, -10.f);
|
||||||
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
@@ -204,8 +199,8 @@ public:
|
|||||||
{
|
{
|
||||||
auto rightWall = m_World->CreateEntity();
|
auto rightWall = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(rightWall);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(rightWall);
|
||||||
transform->Position = glm::vec3(9.f, 1.f, -10.f);
|
transform->Position = glm::vec3(4.f, 1.f, -10.f);
|
||||||
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
@@ -223,9 +218,10 @@ public:
|
|||||||
m_World->SetProperty(ent, "Name", "Pad");
|
m_World->SetProperty(ent, "Name", "Pad");
|
||||||
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
|
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
ctransform->Position = glm::vec3(0.f, -5.f, -10.f);
|
ctransform->Position = glm::vec3(0.f, -5.f, -10.f);
|
||||||
ctransform->Scale = glm::vec3(3.2, 0.8, 0.);
|
ctransform->Scale = glm::vec3(1.6, 0.4, 0.);
|
||||||
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
|
physics->Static = false;
|
||||||
auto csprite = m_World->AddComponent<Components::Sprite>(ent);
|
auto csprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||||
auto pad = m_World->AddComponent<Components::Pad>(ent);
|
auto pad = m_World->AddComponent<Components::Pad>(ent);
|
||||||
csprite->SpriteFile = "Textures/Pad.png";
|
csprite->SpriteFile = "Textures/Pad.png";
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#ifndef DAYDREAM_BALLSYSTEM_H
|
||||||
|
#define DAYDREAM_BALLSYSTEM_H
|
||||||
|
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/World.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/CTransform.h"
|
||||||
|
#include "Physics/EContact.h"
|
||||||
|
#include "Game/CBall.h"
|
||||||
|
#include "Game/CPowerUp.h"
|
||||||
|
|
||||||
|
namespace dd {
|
||||||
|
|
||||||
|
namespace Systems {
|
||||||
|
|
||||||
|
class BallSystem : public System {
|
||||||
|
public:
|
||||||
|
BallSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
|
: System(world, eventBroker) { }
|
||||||
|
|
||||||
|
~BallSystem();
|
||||||
|
|
||||||
|
EventRelay<BallSystem, Events::Contact> m_Contact;
|
||||||
|
bool Contact(const Events::Contact &event);
|
||||||
|
|
||||||
|
void RegisterComponents(ComponentFactory *cf) override;
|
||||||
|
|
||||||
|
void Initialize() override;
|
||||||
|
|
||||||
|
// Called once per system every tick
|
||||||
|
void Update(double dt) override;
|
||||||
|
|
||||||
|
// Called once for every entity in the world every tick
|
||||||
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
|
// Called when components are committed to an entity
|
||||||
|
void OnEntityCommit(EntityID entity) override;
|
||||||
|
|
||||||
|
// Called when an entity is removed
|
||||||
|
void OnEntityRemoved(EntityID entity) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_CPOWERUPBRICK_H
|
||||||
|
#define DAYDREAM_CPOWERUPBRICK_H
|
||||||
|
|
||||||
|
#include "Core/Component.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct PowerUpBrick : Component
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_CPOWERUPBRICK_H
|
||||||
@@ -16,6 +16,7 @@ namespace Components
|
|||||||
struct Ball : Component
|
struct Ball : Component
|
||||||
{
|
{
|
||||||
int Number = 0;
|
int Number = 0;
|
||||||
|
float Speed = 5.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ struct Brick : Component
|
|||||||
int Points = 10;
|
int Points = 10;
|
||||||
int Hits = 1;
|
int Hits = 1;
|
||||||
int Score = 50;
|
int Score = 50;
|
||||||
|
bool Removed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -21,8 +21,8 @@ struct Pad : Component
|
|||||||
int Points;
|
int Points;
|
||||||
|
|
||||||
float SlowdownModifier = 5.f;
|
float SlowdownModifier = 5.f;
|
||||||
float AccelerationSpeed = 80.f;
|
float AccelerationSpeed = 40.f;
|
||||||
float MaxSpeed = 40.f;
|
float MaxSpeed = 20.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_CPOWERUP_H
|
||||||
|
#define DAYDREAM_CPOWERUP_H
|
||||||
|
|
||||||
|
#include "Core/Component.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct PowerUp : Component
|
||||||
|
{
|
||||||
|
int Type;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_CPOWERUP_H
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_ECREATEPOWERUP_H
|
||||||
|
#define DAYDREAM_ECREATEPOWERUP_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct CreatePowerUp : Event
|
||||||
|
{
|
||||||
|
glm::vec3 Position;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_ECREATEPOWERUP_H
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_EGAMEOVER_H
|
||||||
|
#define DAYDREAM_EGAMEOVER_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/Entity.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct GameOver : Event
|
||||||
|
{
|
||||||
|
EntityID Entity;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_EGAMEOVER_H
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_EMULTIBALL_H
|
||||||
|
#define DAYDREAM_EMULTIBALL_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/Entity.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct MultiBall : Event
|
||||||
|
{
|
||||||
|
Components::Transform* padTransform;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_EMULTIBALL_H
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_EPOWERUPTAKEN_H
|
||||||
|
#define DAYDREAM_EPOWERUPTAKEN_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct PowerUpTaken : Event
|
||||||
|
{
|
||||||
|
std::string Name = "Name";
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_EPOWERUPTAKEN_H
|
||||||
+42
-12
@@ -7,23 +7,30 @@
|
|||||||
|
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/CTransform.h"
|
#include "Core/CTransform.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/World.h"
|
||||||
#include "Rendering/CSprite.h"
|
#include "Rendering/CSprite.h"
|
||||||
#include "Rendering/CModel.h"
|
#include "Rendering/CModel.h"
|
||||||
#include "Game/CBrick.h"
|
#include "Game/CBrick.h"
|
||||||
#include "Core/EventBroker.h"
|
|
||||||
#include "Core/World.h"
|
|
||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
#include "Game/CLife.h"
|
#include "Game/CLife.h"
|
||||||
|
#include "Game/CPowerUp.h"
|
||||||
#include "Game/EStageCleared.h"
|
#include "Game/EStageCleared.h"
|
||||||
#include "Game/ELifeLost.h"
|
#include "Game/ELifeLost.h"
|
||||||
#include "Game/EResetBall.h"
|
#include "Game/EResetBall.h"
|
||||||
#include "Game/EScoreEvent.h"
|
#include "Game/EScoreEvent.h"
|
||||||
|
#include "Game/EMultiBall.h"
|
||||||
|
#include "Game/EGameOver.h"
|
||||||
|
#include "Game/ECreatePowerUp.h"
|
||||||
|
#include "Game/EPowerUpTaken.h"
|
||||||
|
#include "Game/Bricks/CPowerUpBrick.h"
|
||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CBoxShape.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
#include "Physics/CCircleShape.h"
|
#include "Physics/CCircleShape.h"
|
||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
#include "Physics/EContact.h"
|
#include "Physics/EContact.h"
|
||||||
#include "Sound/CCollisionSound.h"
|
#include "Sound/CCollisionSound.h"
|
||||||
|
#include "Game/PadSystem.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
@@ -54,11 +61,11 @@ public:
|
|||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
|
|
||||||
void CreateBasicLevel(int, int, glm::vec2, int);
|
void CreateBasicLevel(int, int, glm::vec2, float);
|
||||||
void CreateLife(int);
|
void CreateLife(int);
|
||||||
void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting.
|
void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting.
|
||||||
void LoadLevel(char[20]);
|
void LoadLevel(char[20]);
|
||||||
void CreateBrick(int, int, glm::vec2, int, int);
|
void CreateBrick(int, int, glm::vec2, float, int);
|
||||||
void ProcessCollision();
|
void ProcessCollision();
|
||||||
|
|
||||||
void OnEntityRemoved(EntityID entity);
|
void OnEntityRemoved(EntityID entity);
|
||||||
@@ -68,12 +75,18 @@ public:
|
|||||||
void Update(double dt) override;
|
void Update(double dt) override;
|
||||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
|
bool Restarting() const { return m_Restarting; }
|
||||||
|
void SetRestarting(const bool& restarting) { m_Restarting = restarting; }
|
||||||
bool Initialized() const { return m_Initialized; }
|
bool Initialized() const { return m_Initialized; }
|
||||||
void SetInitialized(const bool& initialized) { m_Initialized = initialized; }
|
void SetInitialized(const bool& initialized) { m_Initialized = initialized; }
|
||||||
int& Lives() { return m_Lives; }
|
int& Lives() { return m_Lives; }
|
||||||
void SetLives(const int& lives) { m_Lives = lives; }
|
void SetLives(const int& lives) { m_Lives = lives; }
|
||||||
int& PastLives() { return m_PastLives; }
|
int& PastLives() { return m_PastLives; }
|
||||||
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
|
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
|
||||||
|
int& MultiBalls() { return m_MultiBalls; }
|
||||||
|
void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
|
||||||
|
int& PowerUps() { return m_PowerUps; }
|
||||||
|
void SetPowerUps(const int& powerUps) { m_PowerUps = powerUps; }
|
||||||
int& Score() { return m_Score; }
|
int& Score() { return m_Score; }
|
||||||
void SetScore(const int& score) { m_Score = score; }
|
void SetScore(const int& score) { m_Score = score; }
|
||||||
int& NumberOfBricks() { return m_NumberOfBricks; }
|
int& NumberOfBricks() { return m_NumberOfBricks; }
|
||||||
@@ -82,30 +95,47 @@ public:
|
|||||||
void SetRows(const int& rows) { m_Rows = rows; }
|
void SetRows(const int& rows) { m_Rows = rows; }
|
||||||
int& Lines() { return m_Lines; }
|
int& Lines() { return m_Lines; }
|
||||||
void SetLines(const int& lines) { m_Lines = lines; }
|
void SetLines(const int& lines) { m_Lines = lines; }
|
||||||
int& SpaceToEdge() { return m_SpaceToEdge; }
|
float& SpaceToEdge() { return m_SpaceToEdge; }
|
||||||
void SetSpaceToEdge(const int& spaceToEdge) { m_SpaceToEdge = spaceToEdge; }
|
void SetSpaceToEdge(const float& spaceToEdge) { m_SpaceToEdge = spaceToEdge; }
|
||||||
|
|
||||||
glm::vec2& SpaceBetweenBricks() { return m_SpaceBetweenBricks; }
|
glm::vec2& SpaceBetweenBricks() { return m_SpaceBetweenBricks; }
|
||||||
void SetSpaceBetweenBricks(const glm::vec2& spaceBetweenBricks) { m_SpaceBetweenBricks = spaceBetweenBricks; }
|
void SetSpaceBetweenBricks(const glm::vec2& spaceBetweenBricks) { m_SpaceBetweenBricks = spaceBetweenBricks; }
|
||||||
|
float& EdgeX() { return m_EdgeX; }
|
||||||
|
void SetEdgeX(const float& edgeX) { m_EdgeX = edgeX; }
|
||||||
|
float& EdgeY() { return m_EdgeY; }
|
||||||
|
void SetEdgeY(const float& edgeY) { m_EdgeY = edgeY; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_Restarting = false;
|
||||||
bool m_Initialized = false;
|
bool m_Initialized = false;
|
||||||
int m_Lives = 3;
|
int m_Lives = 3;
|
||||||
int m_PastLives = 3;
|
int m_PastLives = 3;
|
||||||
|
int m_MultiBalls = 0;
|
||||||
|
int m_PowerUps = 0;
|
||||||
int m_Score = 0;
|
int m_Score = 0;
|
||||||
int m_NumberOfBricks;
|
int m_NumberOfBricks;
|
||||||
int m_Rows = 7;
|
int m_Rows = 6;
|
||||||
int m_Lines = 8;
|
int m_Lines = 7;
|
||||||
int m_SpaceToEdge = 0;
|
float m_SpaceToEdge = 0.25f;
|
||||||
glm::vec2 m_SpaceBetweenBricks = glm::vec2(2, 0.5);
|
glm::vec2 m_SpaceBetweenBricks = glm::vec2(1, 0.4);
|
||||||
|
float m_EdgeX = 3.2f;
|
||||||
|
float m_EdgeY = 5.2f;
|
||||||
|
|
||||||
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
||||||
dd::EventRelay<LevelSystem, dd::Events::LifeLost> m_ELifeLost;
|
dd::EventRelay<LevelSystem, dd::Events::LifeLost> m_ELifeLost;
|
||||||
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
|
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
|
||||||
|
dd::EventRelay<LevelSystem, dd::Events::MultiBall> m_EMultiBall;
|
||||||
|
dd::EventRelay<LevelSystem, dd::Events::CreatePowerUp> m_ECreatePowerUp;
|
||||||
|
dd::EventRelay<LevelSystem, dd::Events::PowerUpTaken> m_EPowerUpTaken;
|
||||||
|
dd::EventRelay<LevelSystem, dd::Events::StageCleared> m_EStageCleared;
|
||||||
|
|
||||||
bool OnContact(const dd::Events::Contact &event);
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
bool LifeLost(const dd::Events::LifeLost &event);
|
bool OnLifeLost(const dd::Events::LifeLost &event);
|
||||||
bool ScoreEvent(const dd::Events::ScoreEvent &event);
|
bool OnScoreEvent(const dd::Events::ScoreEvent &event);
|
||||||
|
bool OnMultiBall(const dd::Events::MultiBall &event);
|
||||||
|
bool OnCreatePowerUp(const dd::Events::CreatePowerUp &event);
|
||||||
|
bool OnPowerUpTaken(const dd::Events::PowerUpTaken &event);
|
||||||
|
bool OnStageCleared(const dd::Events::StageCleared &event);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,12 @@
|
|||||||
#include "Rendering/CSprite.h"
|
#include "Rendering/CSprite.h"
|
||||||
#include "Rendering/CModel.h"
|
#include "Rendering/CModel.h"
|
||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
|
#include "Game/CPad.h"
|
||||||
|
#include "Game/CPowerUp.h"
|
||||||
#include "Game/EResetBall.h"
|
#include "Game/EResetBall.h"
|
||||||
#include "CPad.h"
|
#include "Game/EMultiBall.h"
|
||||||
|
#include "Game/EPowerUpTaken.h"
|
||||||
|
#include "Game/EStageCleared.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
@@ -41,6 +45,8 @@ public:
|
|||||||
void Update(double dt) override;
|
void Update(double dt) override;
|
||||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
|
EntityID CreateBall();
|
||||||
|
|
||||||
EntityID& Entity() { return m_Entity; }
|
EntityID& Entity() { return m_Entity; }
|
||||||
void SetEntity(const EntityID& ent) { m_Entity = ent; }
|
void SetEntity(const EntityID& ent) { m_Entity = ent; }
|
||||||
glm::vec3 Acceleration() const { return m_Acceleration; }
|
glm::vec3 Acceleration() const { return m_Acceleration; }
|
||||||
@@ -52,29 +58,37 @@ public:
|
|||||||
void SetRight(const bool& right) { m_Right = right; }
|
void SetRight(const bool& right) { m_Right = right; }
|
||||||
bool ReplaceBall() const { return m_ReplaceBall; }
|
bool ReplaceBall() const { return m_ReplaceBall; }
|
||||||
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
|
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
|
||||||
|
bool MultiBall() const { return m_MultiBall; }
|
||||||
|
void SetMultiBall(const bool& multiBall) { m_MultiBall = multiBall; }
|
||||||
|
|
||||||
Components::Transform* Transform() const { return m_Transform; }
|
Components::Transform* Transform() const { return m_Transform; }
|
||||||
void SetTransform(const Components::Transform* transform) { m_Transform = transform; }
|
void SetTransform(Components::Transform* transform) { m_Transform = transform; }
|
||||||
Components::Pad* Pad() const { return m_Pad; }
|
Components::Pad* Pad() const { return m_Pad; }
|
||||||
void SetPad(const Components::Pad* pad) { m_Pad = pad; }
|
void SetPad(Components::Pad* pad) { m_Pad = pad; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EntityID m_Entity = 0;
|
EntityID m_Entity = 0;
|
||||||
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
|
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
|
||||||
bool m_Left = false, m_Right = false, m_ReplaceBall = false;
|
bool m_Left = false, m_Right = false, m_ReplaceBall = false, m_MultiBall = false;
|
||||||
Components::Transform* m_Transform;
|
Components::Transform* m_Transform;
|
||||||
Components::Pad* m_Pad;
|
Components::Pad* m_Pad;
|
||||||
|
|
||||||
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
|
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
|
||||||
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
|
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
|
||||||
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
|
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
|
||||||
|
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContactPowerUp;
|
||||||
dd::EventRelay<PadSystem, dd::Events::ResetBall> m_EResetBall;
|
dd::EventRelay<PadSystem, dd::Events::ResetBall> m_EResetBall;
|
||||||
|
dd::EventRelay<PadSystem, dd::Events::MultiBall> m_EMultiBall;
|
||||||
|
dd::EventRelay<PadSystem, dd::Events::StageCleared> m_EStageCleared;
|
||||||
|
|
||||||
bool OnKeyDown(const dd::Events::KeyDown &event);
|
bool OnKeyDown(const dd::Events::KeyDown &event);
|
||||||
bool OnKeyUp(const dd::Events::KeyUp &event);
|
bool OnKeyUp(const dd::Events::KeyUp &event);
|
||||||
|
|
||||||
bool OnContact(const dd::Events::Contact &event);
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
bool ResetBall(const dd::Events::ResetBall &event);
|
bool OnContactPowerUp(const dd::Events::Contact &event);
|
||||||
|
bool OnResetBall(const dd::Events::ResetBall &event);
|
||||||
|
bool OnMultiBall(const dd::Events::MultiBall &event);
|
||||||
|
bool OnStageCleared(const dd::Events::StageCleared &event);
|
||||||
|
|
||||||
class PadSteeringInputController;
|
class PadSteeringInputController;
|
||||||
std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers;
|
std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers;
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ struct Contact : Event
|
|||||||
{
|
{
|
||||||
EntityID Entity1;
|
EntityID Entity1;
|
||||||
EntityID Entity2;
|
EntityID Entity2;
|
||||||
glm::vec2 ContactPoint;
|
glm::vec2 Normal;
|
||||||
|
glm::vec2 SignificantNormal;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
#include "Physics/CCircleShape.h"
|
#include "Physics/CCircleShape.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Game/CPad.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
@@ -22,7 +23,6 @@ namespace dd
|
|||||||
namespace Systems
|
namespace Systems
|
||||||
{
|
{
|
||||||
|
|
||||||
//KOLLA http://box2d.org/manual.pdf p52 Pre-Solve Event
|
|
||||||
|
|
||||||
class PhysicsSystem : public System
|
class PhysicsSystem : public System
|
||||||
{
|
{
|
||||||
@@ -65,6 +65,16 @@ private:
|
|||||||
void CreateBody(EntityID entity);
|
void CreateBody(EntityID entity);
|
||||||
|
|
||||||
|
|
||||||
|
struct Impulse
|
||||||
|
{
|
||||||
|
b2Body* Body;
|
||||||
|
b2Vec2 Impulse;
|
||||||
|
b2Vec2 Point;
|
||||||
|
};
|
||||||
|
std::list<Impulse> m_Impulses;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ContactListener : public b2ContactListener
|
class ContactListener : public b2ContactListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -73,22 +83,40 @@ private:
|
|||||||
|
|
||||||
void BeginContact(b2Contact* contact)
|
void BeginContact(b2Contact* contact)
|
||||||
{
|
{
|
||||||
b2Vec2 contactPoint = contact->GetManifold()->localPoint;
|
b2WorldManifold worldManifold;
|
||||||
|
|
||||||
|
contact->GetWorldManifold(&worldManifold);
|
||||||
|
|
||||||
Events::Contact e;
|
Events::Contact e;
|
||||||
e.ContactPoint = glm::vec2(contactPoint.x, contactPoint.y);
|
|
||||||
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||||
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
||||||
|
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
|
||||||
|
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
|
||||||
|
|
||||||
m_PhysicsSystem->EventBroker->Publish(e);
|
m_PhysicsSystem->EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
void EndContact(b2Contact* contact)
|
void EndContact(b2Contact* contact)
|
||||||
{ /* handle end event */ }
|
{
|
||||||
|
|
||||||
|
}
|
||||||
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
|
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
|
||||||
{ /* handle pre-solve event */ }
|
{
|
||||||
|
EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||||
|
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||||
|
|
||||||
|
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
|
||||||
|
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
|
||||||
|
|
||||||
|
if (physicsComponentA != nullptr || physicsComponentB != nullptr) {
|
||||||
|
// Turn of collisions
|
||||||
|
contact->SetEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||||
{ /* handle post-solve event */ }
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PhysicsSystem* m_PhysicsSystem;
|
PhysicsSystem* m_PhysicsSystem;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ set(SOURCE_FILES
|
|||||||
${SOURCE_FILES_Transform}
|
${SOURCE_FILES_Transform}
|
||||||
${SOURCE_FILES_Physics}
|
${SOURCE_FILES_Physics}
|
||||||
${SOURCE_FILES_Game}
|
${SOURCE_FILES_Game}
|
||||||
${SOURCE_FILES_Sound})
|
${SOURCE_FILES_Sound} ../../include/Game/EGameOver.h ../../include/Game/Bricks/CPowerUpBrick.h ../../include/Game/CPowerUp.h ../../include/Game/ECreatePowerUp.h ../../include/Game/EPowerUpTaken.h)
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
#include "PrecompiledHeader.h"
|
||||||
|
#include "Game/BallSystem.h"
|
||||||
|
|
||||||
|
dd::Systems::BallSystem::~BallSystem() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::Initialize()
|
||||||
|
{
|
||||||
|
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_Contact, BallSystem::Contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (ballComponent != nullptr) {
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y));
|
||||||
|
glm::vec2 up = glm::vec2(0.f, 1.f);
|
||||||
|
float angle = glm::acos(glm::dot<float>(dir, up)) * glm::sign(dir.x);
|
||||||
|
transform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, -1.f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::OnEntityCommit(EntityID entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::OnEntityRemoved(EntityID entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||||
|
{
|
||||||
|
Components::PowerUp* power1 = m_World->GetComponent<Components::PowerUp>(event.Entity1);
|
||||||
|
Components::PowerUp* power2 = m_World->GetComponent<Components::PowerUp>(event.Entity2);
|
||||||
|
|
||||||
|
if (power1 != nullptr || power2 != nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Components::Ball* ballComponent1 = m_World->GetComponent<Components::Ball>(event.Entity1);
|
||||||
|
Components::Ball* ballComponent2 = m_World->GetComponent<Components::Ball>(event.Entity2);
|
||||||
|
Components::Ball* ballComponent;
|
||||||
|
|
||||||
|
if (ballComponent1 != nullptr && ballComponent2 != nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Which is the ball?
|
||||||
|
EntityID ballEntity, otherEntitiy;
|
||||||
|
|
||||||
|
if (ballComponent1 != nullptr) {
|
||||||
|
ballEntity = event.Entity1;
|
||||||
|
otherEntitiy = event.Entity2;
|
||||||
|
ballComponent = ballComponent1;
|
||||||
|
}
|
||||||
|
else if (ballComponent2 != nullptr) {
|
||||||
|
ballEntity = event.Entity2;
|
||||||
|
otherEntitiy = event.Entity1;
|
||||||
|
ballComponent = ballComponent2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
//TODO: Add support for power-up collisions
|
||||||
|
}
|
||||||
|
|
||||||
|
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"){
|
||||||
|
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
|
||||||
|
float x = ballTransform->Position.x - padTransform->Position.x;
|
||||||
|
|
||||||
|
float movementMultiplier = 5.0f;
|
||||||
|
float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f;
|
||||||
|
|
||||||
|
ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal);
|
||||||
|
ballTransform->Velocity = glm::vec3(reflectedVelocity, 0.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
+197
-44
@@ -10,8 +10,12 @@
|
|||||||
void dd::Systems::LevelSystem::Initialize()
|
void dd::Systems::LevelSystem::Initialize()
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::LifeLost);
|
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::OnLifeLost);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::ScoreEvent);
|
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::OnScoreEvent);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, LevelSystem::OnMultiBall);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, LevelSystem::OnCreatePowerUp);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, LevelSystem::OnPowerUpTaken);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, LevelSystem::OnStageCleared);
|
||||||
|
|
||||||
for (int i = 0; i < Lives(); i++) {
|
for (int i = 0; i < Lives(); i++) {
|
||||||
CreateLife(i);
|
CreateLife(i);
|
||||||
@@ -24,8 +28,8 @@ void dd::Systems::LevelSystem::CreateLife(int number)
|
|||||||
{
|
{
|
||||||
auto life = m_World->CreateEntity();
|
auto life = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
|
||||||
transform->Position = glm::vec3(-4.f + number * 0.5f, -2.f, -5.f);
|
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
|
||||||
transform->Scale = glm::vec3(0.25f, 0.25f, 0.25f);
|
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
|
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
|
||||||
lifeNr->Number = number;
|
lifeNr->Number = number;
|
||||||
@@ -33,8 +37,6 @@ void dd::Systems::LevelSystem::CreateLife(int number)
|
|||||||
auto model = m_World->AddComponent<Components::Model>(life);
|
auto model = m_World->AddComponent<Components::Model>(life);
|
||||||
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||||
|
|
||||||
/*std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(life);
|
|
||||||
sprite->SpriteFile = "Textures/Ball.png";*/
|
|
||||||
|
|
||||||
m_World->CommitEntity(life);
|
m_World->CommitEntity(life);
|
||||||
}
|
}
|
||||||
@@ -45,41 +47,111 @@ void dd::Systems::LevelSystem::Update(double dt)
|
|||||||
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
|
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
|
||||||
m_Initialized = true;
|
m_Initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Lives() < 0)
|
||||||
|
{
|
||||||
|
SetLives(3);
|
||||||
|
Events::GameOver e;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
{
|
{
|
||||||
auto ball = m_World->GetComponent<Components::Ball>(entity);
|
auto ball = m_World->GetComponent<Components::Ball>(entity);
|
||||||
|
|
||||||
if (ball != NULL) {
|
if (ball != nullptr) {
|
||||||
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
|
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
|
||||||
if (transformBall->Position.y < -10) {
|
if (glm::abs(transformBall->Velocity.y) < 2) {
|
||||||
if (Lives() == PastLives()) {
|
if (transformBall->Velocity.y > 0) {
|
||||||
|
transformBall->Velocity.y = 2;
|
||||||
|
} else {
|
||||||
|
transformBall->Velocity.y = -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (transformBall->Position.y < -EdgeY() - 4) {
|
||||||
|
if (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 if (Lives() == PastLives()) {
|
||||||
|
Events::ResetBall be;
|
||||||
|
EventBroker->Publish(be);
|
||||||
Events::LifeLost e;
|
Events::LifeLost e;
|
||||||
e.Entity = entity;
|
e.Entity = entity;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
Events::ResetBall be;
|
|
||||||
EventBroker->Publish(be);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (transformBall->Position.x > EdgeX()) {
|
||||||
|
if (transformBall->Velocity.x > 0) {
|
||||||
|
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(1, 0));
|
||||||
|
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
|
||||||
|
}
|
||||||
|
} else if (transformBall->Position.x < -EdgeX()) {
|
||||||
|
if (transformBall->Velocity.x < 0) {
|
||||||
|
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(-1, 0));
|
||||||
|
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
|
||||||
|
}
|
||||||
|
} else if (transformBall->Position.y > EdgeY()) {
|
||||||
|
if (transformBall->Velocity.y > 0) {
|
||||||
|
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(0, 1));
|
||||||
|
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Lives() != PastLives()) {
|
if (Lives() != PastLives()) {
|
||||||
auto life = m_World->GetComponent<Components::Life>(entity);
|
auto life = m_World->GetComponent<Components::Life>(entity);
|
||||||
if (life != NULL) {
|
if (life != nullptr) {
|
||||||
if (life->Number + 1 == PastLives()) {
|
if (life->Number + 1 == PastLives()) {
|
||||||
|
m_World->RemoveComponent<Components::Life>(entity);
|
||||||
|
m_World->RemoveComponent<Components::Transform>(entity);
|
||||||
m_World->RemoveEntity(entity);
|
m_World->RemoveEntity(entity);
|
||||||
SetPastLives(Lives());
|
SetPastLives(Lives());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (NumberOfBricks() <= 0) {
|
||||||
|
/*SetRestarting(true);
|
||||||
|
if (MultiBalls() <= 0 && PowerUps() <= 0) {
|
||||||
|
Events::ResetBall e;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
Events::ScoreEvent es;
|
||||||
|
es.Score = 500;
|
||||||
|
EventBroker->Publish(es);
|
||||||
|
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);
|
||||||
|
auto transformBall = m_World->GetComponent<Components::Transform>(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, int spaceToEdge)
|
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, float spaceToEdge)
|
||||||
{
|
{
|
||||||
int num = 0;
|
|
||||||
SetNumberOfBricks(rows * lines);
|
SetNumberOfBricks(rows * lines);
|
||||||
|
std::cout << "You're only doing this once, right?" << std::endl;
|
||||||
|
int num = 0;
|
||||||
for (int i = 0; i < rows; i++) {
|
for (int i = 0; i < rows; i++) {
|
||||||
num++;
|
num++;
|
||||||
for (int j = 0; j < Lines(); j++) {
|
for (int j = 0; j < Lines(); j++) {
|
||||||
@@ -89,10 +161,12 @@ void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 s
|
|||||||
num = 0;
|
num = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetNumberOfBricks(rows * lines);
|
||||||
|
SetRestarting(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, int spaceToEdge, int num)
|
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int num)
|
||||||
{
|
{
|
||||||
auto brick = m_World->CreateEntity();
|
auto brick = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
|
||||||
@@ -106,10 +180,13 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
|||||||
fileName.append(".png");
|
fileName.append(".png");
|
||||||
//sprite->SpriteFile = fileName;
|
//sprite->SpriteFile = fileName;
|
||||||
model->ModelFile = "Models/Test/Brick/Brick.obj";
|
model->ModelFile = "Models/Test/Brick/Brick.obj";
|
||||||
float x = spaceToEdge + line * spacesBetweenBricks.x;
|
if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 6 && row == 6)) {
|
||||||
float y = spaceToEdge + row * spacesBetweenBricks.y;
|
std::shared_ptr<Components::PowerUpBrick> cPow = m_World->AddComponent<Components::PowerUpBrick>(brick);
|
||||||
transform->Scale = glm::vec3(1.6, 0.35, 0.5);
|
}
|
||||||
transform->Position = glm::vec3(x - 7, y + 1, -10.f);
|
float x = line * spacesBetweenBricks.x;
|
||||||
|
float y = row * spacesBetweenBricks.y;
|
||||||
|
transform->Scale = glm::vec3(0.8, 0.2, 0.2);
|
||||||
|
transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y , -10.f);
|
||||||
cBrick->Score = 10 * num;
|
cBrick->Score = 10 * num;
|
||||||
|
|
||||||
//sound
|
//sound
|
||||||
@@ -128,59 +205,135 @@ void dd::Systems::LevelSystem::ProcessCollision()
|
|||||||
|
|
||||||
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
|
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
|
||||||
{
|
{
|
||||||
/*auto brick = m_World->GetComponent<Components::Brick>(entity);
|
auto brick = m_World->GetComponent<Components::Brick>(entity);
|
||||||
if (brick != NULL) {
|
if (brick != nullptr) {
|
||||||
numberOfBricks--;
|
SetNumberOfBricks(NumberOfBricks() - 1);
|
||||||
if (numberOfBricks < 1) {
|
Events::ScoreEvent es;
|
||||||
|
es.Score = brick->Score;
|
||||||
|
EventBroker->Publish(es);
|
||||||
|
/*if (numberOfBricks < 1) {
|
||||||
EndLevel();
|
EndLevel();
|
||||||
}
|
}*/
|
||||||
}*/
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||||
{
|
{
|
||||||
EntityID entityBrick = event.Entity1;
|
EntityID entityBrick;
|
||||||
auto brick = m_World->GetComponent<Components::Brick>(entityBrick);
|
EntityID entityBall;
|
||||||
if (brick == NULL) {
|
auto ball = m_World->GetComponent<Components::Ball>(event.Entity2);
|
||||||
|
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
|
||||||
|
if (brick != nullptr) {
|
||||||
|
entityBrick = event.Entity1;
|
||||||
|
} else {
|
||||||
|
brick = m_World->GetComponent<Components::Brick>(event.Entity2);
|
||||||
|
if (brick != nullptr) {
|
||||||
|
entityBrick = event.Entity2;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ball != nullptr) {
|
||||||
|
entityBall = event.Entity2;
|
||||||
|
} else {
|
||||||
|
ball = m_World->GetComponent<Components::Ball>(event.Entity1);
|
||||||
|
if (ball != nullptr) {
|
||||||
|
entityBall = event.Entity1;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
brick = m_World->GetComponent<Components::Brick>(entityBrick);
|
||||||
|
if (brick == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EntityID entityBall = event.Entity2;
|
|
||||||
|
|
||||||
m_World->RemoveEntity(entityBrick);
|
auto power = m_World->GetComponent<Components::PowerUpBrick>(entityBrick);
|
||||||
|
if (power != nullptr) {
|
||||||
SetNumberOfBricks(NumberOfBricks() - 1);
|
Events::CreatePowerUp e;
|
||||||
if (NumberOfBricks() == 0) {
|
auto transform = m_World->GetComponent<Components::Transform>(entityBrick);
|
||||||
Events::ScoreEvent es;
|
e.Position = transform->Position;
|
||||||
es.Score = 500;
|
|
||||||
EventBroker->Publish(es);
|
|
||||||
Events::ResetBall e;
|
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
|
|
||||||
}
|
}
|
||||||
Events::ScoreEvent es;
|
|
||||||
es.Score = brick->Score;
|
|
||||||
EventBroker->Publish(es);
|
|
||||||
|
|
||||||
//std::cout << "Score: " << Score() << std::endl;
|
if (ball != nullptr && Restarting() == false) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
SetNumberOfBricks(NumberOfBricks() - 1);
|
||||||
|
if (NumberOfBricks() <= 0) {
|
||||||
|
SetMultiBalls(MultiBalls() + 1);
|
||||||
|
}
|
||||||
|
Events::ScoreEvent es;
|
||||||
|
es.Score = brick->Score;
|
||||||
|
EventBroker->Publish(es);
|
||||||
|
|
||||||
|
//std::cout << NumberOfBricks() << std::endl;
|
||||||
|
//std::cout << "Score: " << Score() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::LevelSystem::LifeLost(const dd::Events::LifeLost &event)
|
bool dd::Systems::LevelSystem::OnLifeLost(const dd::Events::LifeLost &event)
|
||||||
{
|
{
|
||||||
SetLives(Lives() - 1);
|
SetLives(Lives() - 1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::LevelSystem::ScoreEvent(const dd::Events::ScoreEvent &event)
|
bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
|
||||||
{
|
{
|
||||||
SetScore(Score() += event.Score);
|
SetScore(Score() += event.Score);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::LevelSystem::OnMultiBall(const dd::Events::MultiBall &event)
|
||||||
|
{
|
||||||
|
SetMultiBalls(MultiBalls()+2);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &event)
|
||||||
|
{
|
||||||
|
SetPowerUps(PowerUps() + 1);
|
||||||
|
auto powerUp = m_World->CreateEntity();
|
||||||
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(powerUp);
|
||||||
|
auto model = m_World->AddComponent<Components::Model>(powerUp);
|
||||||
|
std::shared_ptr<Components::CircleShape> cRec = m_World->AddComponent<Components::CircleShape>(powerUp);
|
||||||
|
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(powerUp);
|
||||||
|
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
|
||||||
|
cPhys->Static = false;
|
||||||
|
|
||||||
|
transform->Position = event.Position;
|
||||||
|
transform->Scale = glm::vec3(0.2, 0.2, 0.2);
|
||||||
|
transform->Velocity = glm::vec3(0, -4, 0);
|
||||||
|
|
||||||
|
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||||
|
|
||||||
|
m_World->CommitEntity(powerUp);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::LevelSystem::OnPowerUpTaken(const dd::Events::PowerUpTaken &event)
|
||||||
|
{
|
||||||
|
SetPowerUps(PowerUps() - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &event)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void dd::Systems::LevelSystem::EndLevel()
|
void dd::Systems::LevelSystem::EndLevel()
|
||||||
{
|
{
|
||||||
Events::StageCleared e;
|
Events::StageCleared e;
|
||||||
|
|||||||
+139
-72
@@ -22,56 +22,25 @@ void dd::Systems::PadSystem::Initialize()
|
|||||||
l.Command = "left";
|
l.Command = "left";
|
||||||
EventBroker->Publish(l);
|
EventBroker->Publish(l);
|
||||||
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, PadSystem::OnKeyDown);
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &PadSystem::OnKeyDown);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, PadSystem::OnKeyUp);
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PadSystem::OnKeyUp);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, PadSystem::OnContact);
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, PadSystem::ResetBall);
|
EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &PadSystem::OnResetBall);
|
||||||
return;
|
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &PadSystem::OnMultiBall);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
{
|
{
|
||||||
auto ball = m_World->GetComponent<Components::Ball>(entity);
|
auto ball = m_World->GetComponent<Components::Ball>(entity);
|
||||||
if (ball != NULL) {
|
if (ball != nullptr) {
|
||||||
if (ReplaceBall() == true) {
|
if (ReplaceBall() == true) {
|
||||||
SetReplaceBall(false);
|
SetReplaceBall(false);
|
||||||
|
|
||||||
auto transformEntity = m_World->GetComponent<Components::Transform>(entity);
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
transformEntity->Position = glm::vec3(20, 20, -10);
|
transform->Position = glm::vec3(0.0f, 0.26f, -10.f);
|
||||||
|
transform->Velocity = glm::vec3(0.0f, -ball->Speed, 0.f);
|
||||||
//Temporary. Create new ball.
|
|
||||||
/*auto ent = m_World->CreateEntity();
|
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
|
||||||
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
|
|
||||||
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
|
||||||
sprite->SpriteFile = "Textures/Ball.png";
|
|
||||||
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;*/
|
|
||||||
|
|
||||||
auto ent = m_World->CreateEntity();
|
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
|
||||||
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
|
|
||||||
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
|
||||||
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;
|
|
||||||
|
|
||||||
m_World->RemoveEntity(entity);
|
|
||||||
m_World->CommitEntity(ent);
|
|
||||||
|
|
||||||
Events::SetImpulse e;
|
|
||||||
e.Entity = ent;
|
|
||||||
e.Impulse = glm::vec2(0.f, -7.f);
|
|
||||||
e.Point = glm::vec2(transform->Position.x, transform->Position.y);
|
|
||||||
EventBroker->Publish(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,16 +69,14 @@ void dd::Systems::PadSystem::Update(double dt)
|
|||||||
transform->Velocity.x = pad->MaxSpeed;
|
transform->Velocity.x = pad->MaxSpeed;
|
||||||
}
|
}
|
||||||
transform->Position += transform->Velocity * (float)dt;
|
transform->Position += transform->Velocity * (float)dt;
|
||||||
transform->Velocity += acceleration * (float)dt;
|
transform->Velocity += acceleration * (float)dt;
|
||||||
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
|
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
|
||||||
|
|
||||||
if (Left()) {
|
if (Left()) {
|
||||||
acceleration.x = -pad->AccelerationSpeed;
|
acceleration.x = -pad->AccelerationSpeed;
|
||||||
}
|
} else if (Right()) {
|
||||||
else if (Right()) {
|
|
||||||
acceleration.x = pad->AccelerationSpeed;
|
acceleration.x = pad->AccelerationSpeed;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
acceleration.x = 0.f;
|
acceleration.x = 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,9 +84,38 @@ void dd::Systems::PadSystem::Update(double dt)
|
|||||||
SetPad(pad);
|
SetPad(pad);
|
||||||
SetAcceleration(acceleration);
|
SetAcceleration(acceleration);
|
||||||
|
|
||||||
|
if (MultiBall() == true) {
|
||||||
|
SetMultiBall(false);
|
||||||
|
|
||||||
|
Events::MultiBall e;
|
||||||
|
e.padTransform = transform;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityID dd::Systems::PadSystem::CreateBall()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
cball->Speed = 10;
|
||||||
|
|
||||||
|
m_World->CommitEntity(ent);
|
||||||
|
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
||||||
{
|
{
|
||||||
int val = event.KeyCode;
|
int val = event.KeyCode;
|
||||||
@@ -137,6 +133,10 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
|||||||
SetRight(true);
|
SetRight(true);
|
||||||
} else if (val == GLFW_KEY_R) {
|
} else if (val == GLFW_KEY_R) {
|
||||||
SetReplaceBall(true);
|
SetReplaceBall(true);
|
||||||
|
} else if (val == GLFW_KEY_M) {
|
||||||
|
SetMultiBall(true);
|
||||||
|
} else if (val == GLFW_KEY_D) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -158,6 +158,7 @@ bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
|
|||||||
|
|
||||||
bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
EntityID entityBall = event.Entity2;
|
EntityID entityBall = event.Entity2;
|
||||||
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
|
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
|
||||||
if (ball == NULL) {
|
if (ball == NULL) {
|
||||||
@@ -171,10 +172,10 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
auto transformBall = m_World->GetComponent<Components::Transform>(entityBall);
|
auto transformBall = m_World->GetComponent<Components::Transform>(entityBall);
|
||||||
auto transformPad = m_World->GetComponent<Components::Transform>(entityPad);
|
auto transformPad = m_World->GetComponent<Components::Transform>(entityPad);
|
||||||
|
|
||||||
float movementMultiplier = 4.f;
|
float movementMultiplier = 0.5f;
|
||||||
|
|
||||||
float whatX = transformBall->Position.x - transformPad->Position.x;
|
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
|
||||||
float movementX;
|
//float movementY = glm::cos((abs(movementX) / (3.2f * movementMultiplier)) * 3.14159265359f / 2) * 2.f;
|
||||||
if (whatX > 0) {
|
if (whatX > 0) {
|
||||||
movementX = movementMultiplier * whatX;
|
movementX = movementMultiplier * whatX;
|
||||||
//std::cout << "Right!" << std::endl;
|
//std::cout << "Right!" << std::endl;
|
||||||
@@ -183,42 +184,108 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
//std::cout << "Left!" << std::endl;
|
//std::cout << "Left!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//float movementY = 1;
|
// std::cout << movementX << " " << movementY << std::endl;
|
||||||
|
|
||||||
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
|
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
|
||||||
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2) + 1;
|
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2)+ 0.2;
|
||||||
|
|
||||||
//std::cout << movementX << " " << movementY << std::endl;
|
//std::cout << movementX << " " << movementY << std::endl;
|
||||||
|
|
||||||
//Temporary solution. Add a new ball and delete the old one.
|
float len = glm::length<float>(transformBall->Velocity);
|
||||||
auto ent = m_World->CreateEntity();
|
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
|
||||||
transform->Position = glm::vec3(transformBall->Position.x, transformBall->Position.y + 0.01f, -10.f);
|
|
||||||
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
|
||||||
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;
|
|
||||||
|
|
||||||
m_World->RemoveEntity(entityBall);
|
|
||||||
m_World->CommitEntity(ent);
|
|
||||||
|
|
||||||
Events::SetImpulse e;
|
transformBall->Velocity += glm::vec3(transformPad->Velocity.x, 0, 0);
|
||||||
e.Entity = ent;
|
transformBall->Velocity = glm::normalize(transformBall->Velocity) * len;
|
||||||
e.Impulse = glm::vec2(movementX, movementY);
|
|
||||||
e.Point = glm::vec2(transform->Position.x, transform->Position.y);
|
|
||||||
EventBroker->Publish(e);
|
//transform->Velocity = glm::vec3(movementX, movementY, 0.f);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::PadSystem::ResetBall(const dd::Events::ResetBall &event)
|
bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
|
||||||
|
{
|
||||||
|
EntityID entityPower;
|
||||||
|
EntityID entityPad;
|
||||||
|
auto powerUp = m_World->GetComponent<Components::PowerUp>(event.Entity1);
|
||||||
|
auto pad = m_World->GetComponent<Components::Pad>(event.Entity2);
|
||||||
|
if (powerUp != nullptr) {
|
||||||
|
entityPower = event.Entity1;
|
||||||
|
} else {
|
||||||
|
powerUp = m_World->GetComponent<Components::PowerUp>(event.Entity2);
|
||||||
|
if (powerUp != nullptr) {
|
||||||
|
entityPower = event.Entity2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pad != nullptr) {
|
||||||
|
entityPad = event.Entity2;
|
||||||
|
} else {
|
||||||
|
pad = m_World->GetComponent<Components::Pad>(event.Entity1);
|
||||||
|
if (pad != nullptr) {
|
||||||
|
entityPad = event.Entity1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityPower == NULL || entityPad == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pad = m_World->GetComponent<Components::Pad>(entityPad);
|
||||||
|
if (pad == nullptr) {
|
||||||
|
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";
|
||||||
|
EventBroker->Publish(ep);
|
||||||
|
|
||||||
|
Events::MultiBall e;
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entityPad);
|
||||||
|
e.padTransform = transform;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::PadSystem::OnResetBall(const dd::Events::ResetBall &event)
|
||||||
{
|
{
|
||||||
SetReplaceBall(true);
|
SetReplaceBall(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::PadSystem::OnMultiBall(const dd::Events::MultiBall &event)
|
||||||
|
{
|
||||||
|
auto ent1 = CreateBall();
|
||||||
|
auto ent2 = CreateBall();
|
||||||
|
auto transform1 = m_World->GetComponent<Components::Transform>(ent1);
|
||||||
|
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
|
||||||
|
auto ball1 = m_World->GetComponent<Components::Ball>(ent1);
|
||||||
|
auto ball2 = m_World->GetComponent<Components::Ball>(ent2);
|
||||||
|
auto padTransform = event.padTransform;
|
||||||
|
float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2;
|
||||||
|
if (x1 < -3.1) {
|
||||||
|
x1 = 3;
|
||||||
|
}
|
||||||
|
if (x2 > 3.1) {
|
||||||
|
x2 = -3;
|
||||||
|
}
|
||||||
|
transform1->Position = glm::vec3(x1, -5.5, -10);
|
||||||
|
transform2->Position = glm::vec3(x2, -5.5, -10);
|
||||||
|
|
||||||
|
transform1->Velocity = glm::normalize(glm::vec3(5, 5 ,0.f)) * ball1->Speed;
|
||||||
|
transform2->Velocity = glm::normalize(glm::vec3(-5, 5 ,0.f)) * ball2->Speed;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::PadSystem::OnStageCleared(const dd::Events::StageCleared &event)
|
||||||
|
{
|
||||||
|
auto entity = CreateBall();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool dd::Systems::PadSystem::PadSteeringInputController::OnCommand(const Events::InputCommand &event)
|
bool dd::Systems::PadSystem::PadSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||||
{
|
{
|
||||||
std::string command = event.Command;
|
std::string command = event.Command;
|
||||||
|
|||||||
@@ -37,7 +37,13 @@ bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
|||||||
point.x = event.Point.x;
|
point.x = event.Point.x;
|
||||||
point.y = event.Point.y;
|
point.y = event.Point.y;
|
||||||
|
|
||||||
body->ApplyLinearImpulse(impulse, point, true);
|
|
||||||
|
Impulse i;
|
||||||
|
i.Body = body;
|
||||||
|
i.Impulse = impulse;
|
||||||
|
i.Point = point;
|
||||||
|
|
||||||
|
m_Impulses.push_back(i);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -57,8 +63,7 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_World->GetEntityParent(entity) == 0) { //TODO: Make this work with childs too
|
||||||
if (m_World->GetEntityParent(entity) == 0) {
|
|
||||||
b2Vec2 position;
|
b2Vec2 position;
|
||||||
position.x = transformComponent->Position.x;
|
position.x = transformComponent->Position.x;
|
||||||
position.y = transformComponent->Position.y;
|
position.y = transformComponent->Position.y;
|
||||||
@@ -66,10 +71,17 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
float angle = -glm::eulerAngles(transformComponent->Orientation).z;
|
float angle = -glm::eulerAngles(transformComponent->Orientation).z;
|
||||||
|
|
||||||
body->SetTransform(position, angle);
|
body->SetTransform(position, angle);
|
||||||
|
|
||||||
|
body->SetLinearVelocity(b2Vec2(transformComponent->Velocity.x, transformComponent->Velocity.y));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto i : m_Impulses) {
|
||||||
|
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
|
||||||
|
}
|
||||||
|
m_Impulses.clear();
|
||||||
|
|
||||||
|
|
||||||
m_Accumulator += dt;
|
m_Accumulator += dt;
|
||||||
@@ -80,13 +92,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (auto i : m_EntitiesToBodies) {
|
for (auto i : m_EntitiesToBodies) {
|
||||||
EntityID entity = i.first;
|
EntityID entity = i.first;
|
||||||
b2Body* body = i.second;
|
b2Body* body = i.second;
|
||||||
@@ -99,7 +104,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||||
if (! transformComponent)
|
if (! transformComponent)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (m_World->GetEntityParent(entity) == 0) {
|
if (m_World->GetEntityParent(entity) == 0) {
|
||||||
b2Vec2 position = body->GetPosition();
|
b2Vec2 position = body->GetPosition();
|
||||||
transformComponent->Position.x = position.x;
|
transformComponent->Position.x = position.x;
|
||||||
@@ -107,8 +111,13 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
|
|
||||||
float angle = body->GetAngle();
|
float angle = body->GetAngle();
|
||||||
|
|
||||||
//TODO: CHECK IF THIS IS CORRECT
|
|
||||||
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
|
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
|
||||||
|
|
||||||
|
b2Vec2 velocity = body->GetLinearVelocity();
|
||||||
|
transformComponent->Velocity.x = velocity.x;
|
||||||
|
transformComponent->Velocity.y = velocity.y;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,6 +178,7 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
|||||||
bodyDef.type = b2_staticBody;
|
bodyDef.type = b2_staticBody;
|
||||||
} else {
|
} else {
|
||||||
bodyDef.type = b2_dynamicBody;
|
bodyDef.type = b2_dynamicBody;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -205,7 +215,7 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
|||||||
fixtureDef.shape = pShape;
|
fixtureDef.shape = pShape;
|
||||||
fixtureDef.density = 1.f;
|
fixtureDef.density = 1.f;
|
||||||
fixtureDef.restitution = 1.0f;
|
fixtureDef.restitution = 1.0f;
|
||||||
fixtureDef.friction = 0.3f;
|
fixtureDef.friction = 0.0f;
|
||||||
body->CreateFixture(&fixtureDef);
|
body->CreateFixture(&fixtureDef);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user