diff --git a/include/Core/Engine.h.orig b/include/Core/Engine.h.orig
deleted file mode 100644
index f19102e..0000000
--- a/include/Core/Engine.h.orig
+++ /dev/null
@@ -1,562 +0,0 @@
-/*
- This file is part of Daydream Engine.
- Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
-
- Daydream Engine is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Daydream Engine is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with Daydream Engine. If not, see .
-*/
-
-#include
-#include
-#include
-
-#include "ResourceManager.h"
-#include "OBJ.h"
-#include "Model.h"
-#include "Texture.h"
-#include "EventBroker.h"
-#include "RenderQueue.h"
-#include "Renderer.h"
-#include "InputManager.h"
-//TODO: Remove includes that are only here for the temporary draw solution.
-#include "World.h"
-#include "CTransform.h"
-#include "Core/EventBroker.h"
-#include "Rendering/CModel.h"
-#include "Rendering/CSprite.h"
-#include "CTemplate.h"
-#include "Rendering/CPointLight.h"
-#include "Transform/TransformSystem.h"
-#include "Sound/SoundSystem.h"
-#include "Sound/CCollisionSound.h"
-#include "Game/LevelSystem.h"
-#include "Game/PadSystem.h"
-#include "Game/CBall.h"
-#include "Game/CPad.h"
-#include "Game/CBrick.h"
-#include "Game/BallSystem.h"
-#include "Game/Bricks/CPowerUpBrick.h"
-
-#include "Physics/PhysicsSystem.h"
-#include "Physics/CPhysics.h"
-#include "Physics/CRectangleShape.h"
-#include "Physics/ESetImpulse.h"
-#include "Physics/CWaterVolume.h"
-
-#include "Game/EGameStart.h"
-#include "Sound/EPlaySound.h"
-
-#include "GUI/Frame.h"
-#include "GUI/Button.h"
-#include "Game/MainMenu.h"
-#include "Game/HUD.h"
-
-namespace dd
-{
-
-class Engine
-{
-
-public:
- Engine(int argc, char* argv[]) {
- m_EventBroker = std::make_shared();
-
- m_Renderer = std::make_shared();
- m_Renderer->SetFullscreen(false);
- //m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
- m_Renderer->SetResolution(Rectangle(0, 0, 675, 1080));
- m_Renderer->Initialize();
-
- m_FrameStack = new GUI::Frame(m_EventBroker.get());
- m_FrameStack->Width = 675;
- m_FrameStack->Height = 1080;
- auto hud = new GUI::HUD(m_FrameStack, "HUD");
- auto menu = new GUI::MainMenu(m_FrameStack, "MainMenu");
-
- m_InputManager = std::make_shared(m_Renderer->Window(), m_EventBroker);
-
- m_World = std::make_shared(m_EventBroker);
-
- //TODO: Move this out of engine.h
- m_World->ComponentFactory.Register();
- m_World->SystemFactory.Register(
- [this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
- m_World->AddSystem();
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
-
- m_World->ComponentFactory.Register();
- m_World->SystemFactory.Register(
- [this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); });
- m_World->AddSystem();
-
- m_World->ComponentFactory.Register();
-
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
-
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
-
- m_World->SystemFactory.Register(
- [this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
- m_World->AddSystem();
-
- m_World->SystemFactory.Register(
- [this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
- m_World->AddSystem();
- m_World->SystemFactory.Register(
- [this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
- m_World->AddSystem();
- m_World->SystemFactory.Register(
- [this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
- m_World->AddSystem();
-
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
- m_World->ComponentFactory.Register();
- m_World->Initialize();
-
-
- //OctoBall
- {
- auto ent = m_World->CreateEntity();
- std::shared_ptr transform = m_World->AddComponent(ent);
- transform->Position = glm::vec3(-0.f, 0.26f, -9.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(ent);
- model->ModelFile = "Models/Test/Ball/Ballopus.obj";
- std::shared_ptr circleShape = m_World->AddComponent(ent);
- std::shared_ptr ball = m_World->AddComponent(ent);
- ball->Speed = 5.f;
-<<<<<<< HEAD
- std::shared_ptr physics = m_World->AddComponent(ent);
- physics->Static = false;
- physics->Category = CollisionLayer::Type::Ball;
- physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
- physics->Calculate = true;
-=======
- std::shared_ptr physics = m_World->AddComponent(ent);
- physics->Static = false;
->>>>>>> origin/master
-
- auto plight = m_World->AddComponent(ent);
- plight->Radius = 2.f;
-
- m_World->CommitEntity(ent);
- }
-
- //PointLightTest
- {
- auto t_Light = m_World->CreateEntity();
- auto transform = m_World->AddComponent(t_Light);
- transform->Position = glm::vec3(2.f, 1.5f, -9.f);
- auto pl = m_World->AddComponent(t_Light);
- pl->Radius = 8.f;
- m_World->CommitEntity(t_Light);
- }
-
- //Halfpipe background test model.
- {
- auto t_halfPipe = m_World->CreateEntity();
- auto transform = m_World->AddComponent(t_halfPipe);
- transform->Position = glm::vec3(0.f, 0.f, -15.f);
- transform->Scale = glm::vec3(15.f);
- auto model = m_World->AddComponent(t_halfPipe);
- model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
- model->Color = glm::vec4(1.f, 1.f, 1.f, 0.3f);
- m_World->CommitEntity(t_halfPipe);
- }
-
- //Background
- {
- auto background = m_World->CreateEntity();
- auto transform = m_World->AddComponent(background);
- transform->Position = glm::vec3(0.f, 0.f, -30.f);
- transform->Scale = glm::vec3(2681.f / 50.f, 1080.f / 50.f, 1.f);
- auto sprite = m_World->AddComponent(background);
- sprite->SpriteFile = "Textures/Background.png";
- m_World->CommitEntity(background);
- }
-
- //Water test
- {
- auto t_waterBody = m_World->CreateEntity();
- auto transform = m_World->AddComponent(t_waterBody);
- transform->Position = glm::vec3(0.f, -4.5f, -10.f);
- transform->Scale = glm::vec3(7.f, 1.5f, 1.f);
- auto water = m_World->AddComponent(t_waterBody);
- auto body = m_World->AddComponent(t_waterBody);
- m_World->CommitEntity(t_waterBody);
- }
- //TODO: Why does the ball not collide with these bricks?
- //BottomBox
- {
- auto topWall = m_World->CreateEntity();
- auto transform = m_World->AddComponent(topWall);
- transform->Position = glm::vec3(0.f, -6.f, -9.9f);
- transform->Scale = glm::vec3(10.f, 0.5f, 1.f);
- std::shared_ptr sprite = m_World->AddComponent(topWall);
- sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
- std::shared_ptr boxShape = m_World->AddComponent(
- topWall);
- std::shared_ptr physics = m_World->AddComponent(topWall);
- physics->Static = true;
- m_World->CommitEntity(topWall);
- }
- //SideBox
-// {
-// auto topWall = m_World->CreateEntity();
-// std::shared_ptr transform = m_World->AddComponent(topWall);
-// transform->Position = glm::vec3(3.f, -3.0f, -9.9f);
-// transform->Scale = glm::vec3(0.5f, 3.f, 1.f);
-// std::shared_ptr sprite = m_World->AddComponent(topWall);
-// sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
-// std::shared_ptr boxShape = m_World->AddComponent(
-// topWall);
-// std::shared_ptr physics = m_World->AddComponent(topWall);
-// physics->Static = true;
-// m_World->CommitEntity(topWall);
-// }
-// //OtherSideBox
-// {
-// auto topWall = m_World->CreateEntity();
-// std::shared_ptr transform = m_World->AddComponent(topWall);
-// transform->Position = glm::vec3(-4.f, -3.0f, -9.9f);
-// transform->Scale = glm::vec3(0.5f, 3.0f, 1.f);
-// std::shared_ptr sprite = m_World->AddComponent(topWall);
-// sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
-// std::shared_ptr boxShape = m_World->AddComponent(
-// topWall);
-// std::shared_ptr physics = m_World->AddComponent(topWall);
-// physics->Static = true;
-// m_World->CommitEntity(topWall);
-// }
-
- {
- auto topWall = m_World->CreateEntity();
- std::shared_ptr transform = m_World->AddComponent(
- topWall);
- transform->Position = glm::vec3(0.f, 6.f, -10.f);
- transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
-
- std::shared_ptr sprite = m_World->AddComponent(topWall);
- sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
-
- std::shared_ptr boxShape = m_World->AddComponent(
- topWall);
-
- std::shared_ptr physics = m_World->AddComponent(topWall);
- physics->Static = true;
- physics->Category = CollisionLayer::Type::Wall;
- physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
-
- m_World->CommitEntity(topWall);
- }
-
- {
- auto leftWall = m_World->CreateEntity();
- std::shared_ptr transform = m_World->AddComponent(
- leftWall);
- transform->Position = glm::vec3(-4.f, 1.f, -10.f);
- transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
-
- std::shared_ptr sprite = m_World->AddComponent(leftWall);
- sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
-
- std::shared_ptr boxShape = m_World->AddComponent(
- leftWall);
-
- std::shared_ptr physics = m_World->AddComponent(leftWall);
- physics->Static = true;
- physics->Category = CollisionLayer::Type::Wall;
- physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
-
- m_World->CommitEntity(leftWall);
- }
-
- {
- auto rightWall = m_World->CreateEntity();
- std::shared_ptr transform = m_World->AddComponent(
- rightWall);
- transform->Position = glm::vec3(4.f, 1.f, -10.f);
- transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
-
- std::shared_ptr sprite = m_World->AddComponent(rightWall);
- sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
-
- std::shared_ptr boxShape = m_World->AddComponent(
- rightWall);
-
- std::shared_ptr physics = m_World->AddComponent(rightWall);
- physics->Static = true;
- physics->Category = CollisionLayer::Type::Wall;
- physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
-
- m_World->CommitEntity(rightWall);
- }
-
- {
- auto ent = m_World->CreateEntity();
- m_World->SetProperty(ent, "Name", "Pad");
- auto ctransform = m_World->AddComponent(ent);
- ctransform->Position = glm::vec3(0.f, -5.f, -10.f);
- ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f);
- auto rectangle = m_World->AddComponent(ent);
- auto physics = m_World->AddComponent(ent);
- physics->Static = false;
- physics->Category = CollisionLayer::Type::Pad;
- physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::PowerUp;
- physics->Calculate = true;
- auto cModel = m_World->AddComponent(ent);
- cModel->ModelFile = "Models/Submarine2.obj";
-
- auto pad = m_World->AddComponent(ent);
- m_World->CommitEntity(ent);
- }
-
-
- //EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart);
- m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1));
- m_EventBroker->Subscribe(m_EGameStart);
-
- m_LastTime = glfwGetTime();
- }
-
- bool Running() const { return !glfwWindowShouldClose(m_Renderer->Window()); }
-
- void Tick()
- {
- double currentTime = glfwGetTime();
- double dt = currentTime - m_LastTime;
- m_LastTime = currentTime;
-
- // Update input
- m_InputManager->Update(dt);
- // Swap event queues to get fresh input data in the read queue
- //m_EventBroker->Swap();
-
- ResourceManager::Update();
- if (m_GameIsRunning) {
- m_World->Update(dt);
- }
- m_EventBroker->Process();
- m_FrameStack->UpdateLayered(dt);
-
- m_RendererQueue.Clear();
- m_FrameStack->DrawLayered(m_RendererQueue);
- //TODO Fill up the renderQueue with models (Temp fix)
- if (m_GameIsRunning) {
- TEMPAddToRenderQueue();
- }
-
- // Render scene
- //TODO send renderqueue to draw.
- m_Renderer->Draw(m_RendererQueue);
-
- m_EventBroker->Process();
- // Swap event queues
- m_EventBroker->Swap();
-
- glfwPollEvents();
- }
-
- std::shared_ptr m_TransformSystem;
- std::shared_ptr m_LevelSystem;
-
- //TODO: Get this out of engine.h
- void TEMPAddToRenderQueue()
- {
- if (!m_TransformSystem)
- m_TransformSystem = m_World->GetSystem();
-
- for (auto &pair : *m_World->GetEntities())
- {
- EntityID entity = pair.first;
-
- auto templateComponent = m_World->GetComponent(entity);
- if (templateComponent)
- continue;
-
- auto transform = m_World->GetComponent(entity);
- if (!transform)
- continue;
-
- auto modelComponent = m_World->GetComponent(entity);
- if (modelComponent)
- {
- Model* modelAsset = nullptr;
- modelAsset = ResourceManager::Load(modelComponent->ModelFile);
-
- if (modelAsset)
- {
- Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
- glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
- * glm::toMat4(absoluteTransform.Orientation)
- * glm::scale(absoluteTransform.Scale);
- EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color, modelComponent->ModelFile);
- }
- }
-
- auto pointLightComponent = m_World->GetComponent(entity);
- if (pointLightComponent)
- {
- Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
- EnqueuePointLight(absoluteTransform.Position,
- pointLightComponent->Diffuse,
- pointLightComponent->Specular,
- pointLightComponent->Radius);
- }
-
- auto parent = m_World->GetEntityParent(entity);
- if(parent != 0) {
- auto waterParticleComponent = m_World->GetComponent(parent);
- if (waterParticleComponent) {
- //TODO: Remove hardcoded color.
- //TODO: Do i even need modelMatrix?
- Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
- glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
- * glm::scale(absoluteTransform.Scale);
- EnqueueWaterParticles(absoluteTransform.Position, glm::vec4(1.f, 1.f, 1.f, 1.f), modelMatrix, absoluteTransform.Position.z);
- }
- }
-
-
- auto spriteComponent = m_World->GetComponent(entity);
- if (spriteComponent)
- {
-
- std::string normal = spriteComponent->NormalTexture;
- std::string spec = spriteComponent->SpecularTexture;
-
- if (normal.empty()) {
- normal = "Textures/Core/NeutralNormalMap.png";
- }
- if (spec.empty()) {
- spec = "Textures/Core/NeutralSpecularMap.png";
- }
- auto texturediff = ResourceManager::Load(spriteComponent->SpriteFile);
- auto texturenorm = ResourceManager::Load(normal);
- auto texturespec = ResourceManager::Load(spec);
-
-
- Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
- glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1));
- glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
- * glm::toMat4(orientation2D)
- * glm::scale(absoluteTransform.Scale);
- EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
- }
- }
-
- }
-
- //TODO: Get this out of engine.h
- void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color, std::string fileName)
- {
- for (auto texGroup : model->TextureGroups)
- {
- ModelJob job;
- job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
- job.DiffuseTexture = (texGroup.Texture) ? *texGroup.Texture : 0;
- job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0;
- job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0;
- job.VAO = model->VAO;
- job.ElementBuffer = model->ElementBuffer;
- job.StartIndex = texGroup.StartIndex;
- job.EndIndex = texGroup.EndIndex;
- job.ModelMatrix = modelMatrix;
- job.Color = color;
-
- m_RendererQueue.Deferred.Add(job);
- }
- }
-
- // TODO: Get this out of engine.h
- void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color, float depth)
- {
- SpriteJob job;
- job.TextureID = texture->ResourceID;
- job.DiffuseTexture = *texture;
- job.NormalTexture = *normalTexture;
- job.SpecularTexture = *specularTexture;
- job.ModelMatrix = modelMatrix;
- job.Color = color;
- job.Depth = depth;
-
-
- m_RendererQueue.Forward.Add(job);
- }
-
- void EnqueuePointLight(glm::vec3 position, glm::vec3 diffuseColor, glm::vec3 specularColor, float radius)
- {
- PointLightJob job;
- job.Position = position;
- job.DiffuseColor = diffuseColor;
- job.SpecularColor = specularColor;
- job.Radius = radius;
-
- m_RendererQueue.Lights.Add(job);
-
- }
-
- void EnqueueWaterParticles(glm::vec3 position, glm::vec4 color, glm::mat4 modelMatrix, float depth)
- {
- WaterParticleJob job;
- job.Position = position;
- job.Color = color;
- job.ModelMatrix = modelMatrix;
- job.Depth = depth;
-
- m_RendererQueue.Forward.Add(job);
- }
-
-private:
- std::shared_ptr m_EventBroker;
- GUI::Frame* m_FrameStack = nullptr;
- std::shared_ptr m_Renderer;
- RenderQueueCollection m_RendererQueue;
- std::shared_ptr m_InputManager;
- std::shared_ptr m_World;
-
- //TODO: Redo
- bool m_GameIsRunning = false;
- dd::EventRelay m_EGameStart;
- bool OnGameStart(const dd::Events::GameStart &event)
- {
- m_GameIsRunning = true;
- //Todo: Move this
- {
- dd::Events::PlaySound e;
- e.path = "Sounds/BGM/under-the-sea-instrumental.wav";
- e.isAmbient = true;
- m_EventBroker->Publish(e);
- }
- {
- dd::Events::PlaySound e;
- e.path = "Sounds/BGM/water-flowing.wav";
- e.volume = 0.3f;
- e.isAmbient = true;
- m_EventBroker->Publish(e);
- }
- };
- double m_LastTime;
-};
-
-}
diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h
index 1069ede..e838076 100644
--- a/include/Game/BallSystem.h
+++ b/include/Game/BallSystem.h
@@ -5,9 +5,17 @@
#include "Core/World.h"
#include "Core/EventBroker.h"
#include "Core/CTransform.h"
+#include "Physics/CPhysics.h"
+#include "Physics/CCircleShape.h"
#include "Physics/EContact.h"
+#include "Rendering/CModel.h"
#include "Game/CBall.h"
#include "Game/CPowerUp.h"
+#include "Game/ELifeLost.h"
+#include "Game/EResetBall.h"
+#include "Game/EMultiBall.h"
+#include "Game/EMultiBallLost.h"
+#include "Game/EGameOver.h"
namespace dd {
@@ -39,8 +47,41 @@ public:
// Called when an entity is removed
void OnEntityRemoved(EntityID entity) override;
-private:
+ EntityID CreateBall();
+ 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; }
+ int& MultiBalls() { return m_MultiBalls; }
+ void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
+ int& Lives() { return m_Lives; }
+ void SetLives(const int& lives) { m_Lives = lives; }
+ int& PastLives() { return m_PastLives; }
+ void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
+ bool ReplaceBall() const { return m_ReplaceBall; }
+ void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
+ bool MultiBall() const { return m_MultiBall; }
+ void SetMultiBall(const bool& multiBall) { m_MultiBall = multiBall; }
+
+private:
+ float m_EdgeX = 3.2f;
+ float m_EdgeY = 5.2f;
+ int m_MultiBalls = 0;
+ int m_Lives = 3;
+ int m_PastLives = 3;
+ bool m_ReplaceBall = false;
+ bool m_MultiBall = false;
+
+ dd::EventRelay m_ELifeLost;
+ dd::EventRelay m_EMultiBallLost;
+ dd::EventRelay m_EResetBall;
+ dd::EventRelay m_EMultiBall;
+
+ bool OnLifeLost(const dd::Events::LifeLost &event);
+ bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
+ bool OnResetBall(const dd::Events::ResetBall &event);
+ bool OnMultiBall(const dd::Events::MultiBall &event);
};
}
diff --git a/include/Game/EMultiBallLost.h b/include/Game/EMultiBallLost.h
new file mode 100644
index 0000000..3d9c6d4
--- /dev/null
+++ b/include/Game/EMultiBallLost.h
@@ -0,0 +1,26 @@
+//
+// Created by Adniklastrator on 2015-09-28.
+//
+
+#ifndef DAYDREAM_EMULTIBALLLOST_H
+#define DAYDREAM_EMULTIBALLLOST_H
+
+#include "Core/EventBroker.h"
+#include "Core/Entity.h"
+
+namespace dd
+{
+
+namespace Events
+{
+
+struct MultiBallLost : Event
+{
+
+};
+
+}
+
+}
+
+#endif //DAYDREAM_EMULTIBALLLOST_H
diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h
index 1d277ce..775d639 100755
--- a/include/Game/LevelSystem.h
+++ b/include/Game/LevelSystem.h
@@ -21,6 +21,7 @@
#include "Game/EScoreEvent.h"
#include "Physics/CRectangleShape.h"
#include "Game/EMultiBall.h"
+#include "Game/EMultiBallLost.h"
#include "Game/EGameOver.h"
#include "Game/ECreatePowerUp.h"
#include "Game/EPowerUpTaken.h"
@@ -79,10 +80,6 @@ public:
void SetRestarting(const bool& restarting) { m_Restarting = restarting; }
bool Initialized() const { return m_Initialized; }
void SetInitialized(const bool& initialized) { m_Initialized = initialized; }
- int& Lives() { return m_Lives; }
- void SetLives(const int& lives) { m_Lives = lives; }
- int& PastLives() { return m_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; }
@@ -100,18 +97,12 @@ public:
glm::vec2& SpaceBetweenBricks() { return m_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; }
float& NotResettingTheStage() { return m_NotResettingTheStage; }
void SetNotResettingTheStage(const float& notResettingTheStage) { m_NotResettingTheStage = notResettingTheStage; }
private:
bool m_Restarting = false;
bool m_Initialized = false;
- int m_Lives = 3;
- int m_PastLives = 3;
int m_MultiBalls = 0;
int m_PowerUps = 0;
int m_Score = 0;
@@ -120,22 +111,20 @@ private:
int m_Lines = 7;
float m_SpaceToEdge = 0.25f;
glm::vec2 m_SpaceBetweenBricks = glm::vec2(1, 0.4);
- float m_EdgeX = 3.2f;
- float m_EdgeY = 5.2f;
float m_NotResettingTheStage = 5.f;
dd::EventRelay m_EContact;
- dd::EventRelay m_ELifeLost;
dd::EventRelay m_EScoreEvent;
dd::EventRelay m_EMultiBall;
+ dd::EventRelay m_EMultiBallLost;
dd::EventRelay m_ECreatePowerUp;
dd::EventRelay m_EPowerUpTaken;
dd::EventRelay m_EStageCleared;
bool OnContact(const dd::Events::Contact &event);
- bool OnLifeLost(const dd::Events::LifeLost &event);
bool OnScoreEvent(const dd::Events::ScoreEvent &event);
bool OnMultiBall(const dd::Events::MultiBall &event);
+ bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
bool OnCreatePowerUp(const dd::Events::CreatePowerUp &event);
bool OnPowerUpTaken(const dd::Events::PowerUpTaken &event);
bool OnStageCleared(const dd::Events::StageCleared &event);
diff --git a/include/Game/PadSystem.h b/include/Game/PadSystem.h
index 4a53907..ef9d9ef 100755
--- a/include/Game/PadSystem.h
+++ b/include/Game/PadSystem.h
@@ -45,8 +45,6 @@ public:
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
- EntityID CreateBall();
-
EntityID& Entity() { return m_Entity; }
void SetEntity(const EntityID& ent) { m_Entity = ent; }
glm::vec3 Acceleration() const { return m_Acceleration; }
@@ -56,10 +54,6 @@ public:
void SetLeft(const bool& left) { m_Left = left; }
bool Right() const { return m_Right; }
void SetRight(const bool& right) { m_Right = right; }
- bool ReplaceBall() const { return m_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; }
void SetTransform(Components::Transform* transform) { m_Transform = transform; }
@@ -69,7 +63,8 @@ public:
private:
EntityID m_Entity = 0;
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
- bool m_Left = false, m_Right = false, m_ReplaceBall = false, m_MultiBall = false;
+ bool m_Left = false;
+ bool m_Right = false;
Components::Transform* m_Transform;
Components::Pad* m_Pad;
@@ -77,8 +72,6 @@ private:
dd::EventRelay m_EKeyUp;
dd::EventRelay m_EContact;
dd::EventRelay m_EContactPowerUp;
- dd::EventRelay m_EResetBall;
- dd::EventRelay m_EMultiBall;
dd::EventRelay m_EStageCleared;
bool OnKeyDown(const dd::Events::KeyDown &event);
@@ -86,8 +79,6 @@ private:
bool OnContact(const dd::Events::Contact &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;
diff --git a/include/Physics/PhysicsSystem.h.orig b/include/Physics/PhysicsSystem.h.orig
deleted file mode 100755
index f1465aa..0000000
--- a/include/Physics/PhysicsSystem.h.orig
+++ /dev/null
@@ -1,149 +0,0 @@
-#ifndef DAYDREAM_PHYSICSSYSTEM_H
-#define DAYDREAM_PHYSICSSYSTEM_H
-
-#include
-
-#include "Core/System.h"
-#include "Core/World.h"
-#include "CRectangleShape.h"
-#include "Physics/CPhysics.h"
-#include
-#include "Core/CTransform.h"
-#include "Transform/TransformSystem.h"
-#include "Physics/EContact.h"
-#include "Physics/ESetImpulse.h"
-#include "Physics/CCircleShape.h"
-#include "Core/EventBroker.h"
-#include "Game/CPad.h"
-<<<<<<< HEAD
-#include "Game/CBall.h"
-=======
-#include "Physics/CWaterVolume.h"
-#include "Rendering/CSprite.h"
->>>>>>> origin/master
-
-
-namespace dd
-{
-
-namespace Systems
-{
-
-
-class PhysicsSystem : public System
-{
- friend class ContractListener;
-
-public:
- PhysicsSystem(World* world, std::shared_ptr eventBroker)
- : System(world, eventBroker) {}
-
- ~PhysicsSystem();
-
- EventRelay m_SetImpulse;
- bool SetImpulse(const Events::SetImpulse &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:
- b2Vec2 m_Gravity;
- b2World* m_PhysicsWorld;
- float m_TimeStep;
- float m_Accumulator;
-
- int m_VelocityIterations, m_PositionIterations;
-
- std::unordered_map m_EntitiesToBodies;
- std::unordered_map m_BodiesToEntities;
-
- void CreateBody(EntityID entity);
-
- b2ParticleSystem *m_ParticleSystem;
- b2ParticleGroup* t_watergroup;
-
- std::unordered_map m_EntitiesToParticleHandle;
- std::unordered_map m_ParticleHandleToEntities;
-
- void InitializeWater();
- void SyncWater(); //TODO: Probably remove this
- void CreateParticleGroup(EntityID entity);
-
- struct Impulse
- {
- b2Body* Body;
- b2Vec2 Impulse;
- b2Vec2 Point;
- };
- std::list m_Impulses;
-
-
-
- class ContactListener : public b2ContactListener
- {
- public:
- ContactListener(PhysicsSystem* physicsSystem)
- : m_PhysicsSystem(physicsSystem) { }
-
- void BeginContact(b2Contact* contact)
- {
- b2WorldManifold worldManifold;
-
- contact->GetWorldManifold(&worldManifold);
-
- Events::Contact e;
- e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->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);
- }
- void EndContact(b2Contact* contact)
- {
-
- }
- void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
- {
- EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
- EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
-
- auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent(entityA);
- auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent(entityB);
-
- if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
- if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
- // Turn of collisions
- contact->SetEnabled(false);
- }
- }
-
-
- }
- void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
- {
-
- }
-
- private:
- PhysicsSystem* m_PhysicsSystem;
- };
-
- ContactListener* m_ContactListener;
-};
-
-}
-}
-
-#endif //DAYDREAM_PHYSICSSYSTEM_H
diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt
index 6834897..0c8978c 100755
--- a/src/game/CMakeLists.txt
+++ b/src/game/CMakeLists.txt
@@ -95,7 +95,7 @@ set(SOURCE_FILES
${SOURCE_FILES_Game}
${SOURCE_FILES_Sound}
${SOURCE_FILES_GUI}
-)
+ ../../include/Game/EMultiBallLost.h)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp
index 37df50a..2a54fc0 100644
--- a/src/game/Game/BallSystem.cpp
+++ b/src/game/Game/BallSystem.cpp
@@ -14,16 +14,89 @@ void dd::Systems::BallSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_Contact, BallSystem::Contact);
+ EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, BallSystem::OnLifeLost);
+ EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, BallSystem::OnMultiBallLost);
+ EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &BallSystem::OnResetBall);
+ EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall);
}
void dd::Systems::BallSystem::Update(double dt)
{
-
+ if (Lives() < 0)
+ {
+ SetLives(3);
+ Events::GameOver e;
+ EventBroker->Publish(e);
+ }
}
void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ballComponent = m_World->GetComponent(entity);
+ if (ballComponent != nullptr) {
+ if (ReplaceBall() == true) {
+ SetReplaceBall(false);
+
+ auto transform = m_World->GetComponent(entity);
+ transform->Position = glm::vec3(0.0f, 0.26f, -10.f);
+ transform->Velocity = glm::vec3(0.0f, -ballComponent->Speed, 0.f);
+ }
+
+ auto transformBall = m_World->GetComponent(entity);
+ if (glm::abs(transformBall->Velocity.y) < 2) {
+ if (transformBall->Velocity.y > 0) {
+ transformBall->Velocity.y = 2;
+ } else {
+ transformBall->Velocity.y = -2;
+ }
+ }
+ if (transformBall->Position.y < -EdgeY() - 4) {
+ if (MultiBalls() != 0) {
+// m_World->RemoveComponent(entity);
+// m_World->RemoveComponent(entity);
+// m_World->RemoveComponent(entity);
+// m_World->RemoveComponent(entity);
+ m_World->RemoveEntity(entity);
+ Events::MultiBallLost e;
+ EventBroker->Publish(e);
+ } else if (Lives() == PastLives()) {
+ Events::ResetBall be;
+ EventBroker->Publish(be);
+ Events::LifeLost e;
+ e.Entity = entity;
+ EventBroker->Publish(e);
+ 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()) {
+ /*auto life = m_World->GetComponent(entity);
+ if (life != nullptr) {
+ if (life->Number + 1 == PastLives()) {
+ /*m_World->RemoveComponent(entity);
+// m_World->RemoveComponent(entity);
+ m_World->RemoveEntity(entity);*/
+ SetPastLives(Lives());
+ // }
+ //}
+ }
+
if (ballComponent != nullptr) {
auto transform = m_World->GetComponent(entity);
glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y));
@@ -99,3 +172,72 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
return true;
}
+
+EntityID dd::Systems::BallSystem::CreateBall()
+{
+ auto ent = m_World->CreateEntity();
+ std::shared_ptr transform = m_World->AddComponent(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(ent);
+ model->ModelFile = "Models/Test/Ball/Ballopus.obj";
+ //auto pointlight = m_World->AddComponent(ent);
+ std::shared_ptr circleShape = m_World->AddComponent(ent);
+ std::shared_ptr cball = m_World->AddComponent(ent);
+ std::shared_ptr physics = m_World->AddComponent(ent);
+ physics->Static = false;
+ physics->Category = CollisionLayer::Type::Ball;
+ physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
+ physics->Calculate = true;
+ cball->Speed = 5.f;
+
+ m_World->CommitEntity(ent);
+
+ return ent;
+}
+
+bool dd::Systems::BallSystem::OnLifeLost(const dd::Events::LifeLost &event)
+{
+ SetLives(Lives() - 1);
+
+ return true;
+}
+
+bool dd::Systems::BallSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event)
+{
+ SetMultiBalls(MultiBalls()-1);
+ return true;
+}
+
+bool dd::Systems::BallSystem::OnResetBall(const dd::Events::ResetBall &event)
+{
+ SetReplaceBall(true);
+ return true;
+}
+
+bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event)
+{
+ auto ent1 = CreateBall();
+ auto ent2 = CreateBall();
+ auto transform1 = m_World->GetComponent(ent1);
+ auto transform2 = m_World->GetComponent(ent2);
+ auto ball1 = m_World->GetComponent(ent1);
+ auto ball2 = m_World->GetComponent(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;
+
+ SetMultiBalls(MultiBalls() + 2);
+
+ return true;
+}
diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp
index 52d0b0a..2b70d20 100755
--- a/src/game/Game/LevelSystem.cpp
+++ b/src/game/Game/LevelSystem.cpp
@@ -10,16 +10,16 @@
void dd::Systems::LevelSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
- EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::OnLifeLost);
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::OnScoreEvent);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, LevelSystem::OnMultiBall);
+ EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, LevelSystem::OnMultiBallLost);
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);
- }
+ }*/
return;
}
@@ -47,13 +47,6 @@ void dd::Systems::LevelSystem::Update(double dt)
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
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)
@@ -61,64 +54,10 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
auto ball = m_World->GetComponent(entity);
SetNotResettingTheStage(NotResettingTheStage() + 0.01 * dt);
- if (ball != nullptr) {
- auto transformBall = m_World->GetComponent(entity);
- if (glm::abs(transformBall->Velocity.y) < 2) {
- 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(entity);
-// m_World->RemoveComponent(entity);
-// m_World->RemoveComponent(entity);
-// m_World->RemoveComponent(entity);
- m_World->RemoveEntity(entity);
- } else if (Lives() == PastLives()) {
- Events::ResetBall be;
- EventBroker->Publish(be);
- Events::LifeLost e;
- e.Entity = entity;
- EventBroker->Publish(e);
- 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()) {
- /*auto life = m_World->GetComponent(entity);
- if (life != nullptr) {
- if (life->Number + 1 == PastLives()) {
- /*m_World->RemoveComponent(entity);
-// m_World->RemoveComponent(entity);
- m_World->RemoveEntity(entity);*/
- SetPastLives(Lives());
- // }
- //}
- }
- if (NumberOfBricks() <= 0) {
- /*SetRestarting(true);
+ if (NumberOfBricks() <= 0 && Restarting() == false) {
if (MultiBalls() <= 0 && PowerUps() <= 0) {
if (NotResettingTheStage() > 5) {
+ SetRestarting(true);
Events::ResetBall e;
EventBroker->Publish(e);
Events::ScoreEvent es;
@@ -127,11 +66,12 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
Events::StageCleared ec;
EventBroker->Publish(ec);
SetNotResettingTheStage(0);
- CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
+ //CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
}
} else {
if (ball != nullptr && MultiBalls() > 0) {
- SetMultiBalls(MultiBalls() - 1);
+ Events::MultiBallLost e;
+ EventBroker->Publish(e);
m_World->RemoveComponent(entity);
m_World->RemoveComponent(entity);
m_World->RemoveComponent(entity);
@@ -147,7 +87,7 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
m_World->RemoveEntity(entity);
}
}
- }*/
+ }
}
}
@@ -309,13 +249,6 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
return true;
}
-bool dd::Systems::LevelSystem::OnLifeLost(const dd::Events::LifeLost &event)
-{
- SetLives(Lives() - 1);
-
- return true;
-}
-
bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
{
SetScore(Score() += event.Score);
@@ -326,6 +259,13 @@ bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
bool dd::Systems::LevelSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
SetMultiBalls(MultiBalls()+2);
+ return true;
+}
+
+bool dd::Systems::LevelSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event)
+{
+ SetMultiBalls(MultiBalls()-1);
+ return true;
}
bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &event)
diff --git a/src/game/Game/LevelSystem.cpp.orig b/src/game/Game/LevelSystem.cpp.orig
deleted file mode 100644
index b1d1139..0000000
--- a/src/game/Game/LevelSystem.cpp.orig
+++ /dev/null
@@ -1,372 +0,0 @@
-//
-// Created by Adniklastrator on 2015-09-09.
-//
-
-
-#include "PrecompiledHeader.h"
-#include "Game/LevelSystem.h"
-
-
-void dd::Systems::LevelSystem::Initialize()
-{
- EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
- EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::OnLifeLost);
- 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++) {
- CreateLife(i);
- }
-
- return;
-}
-
-void dd::Systems::LevelSystem::CreateLife(int number)
-{
- auto life = m_World->CreateEntity();
- std::shared_ptr transform = m_World->AddComponent(life);
- transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
- transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
-
- std::shared_ptr lifeNr = m_World->AddComponent(life);
- lifeNr->Number = number;
-
- auto model = m_World->AddComponent(life);
- model->ModelFile = "Models/Test/Ball/Ballopus.obj";
-
-
- m_World->CommitEntity(life);
-}
-
-void dd::Systems::LevelSystem::Update(double dt)
-{
- if (!m_Initialized) {
- CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
- 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)
-{
- auto ball = m_World->GetComponent(entity);
-
- if (ball != nullptr) {
- auto transformBall = m_World->GetComponent(entity);
- if (glm::abs(transformBall->Velocity.y) < 2) {
- 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(entity);
-// m_World->RemoveComponent(entity);
-// m_World->RemoveComponent(entity);
-// m_World->RemoveComponent(entity);
- m_World->RemoveEntity(entity);
- } else if (Lives() == PastLives()) {
- Events::ResetBall be;
- EventBroker->Publish(be);
- Events::LifeLost e;
- e.Entity = entity;
- EventBroker->Publish(e);
- 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()) {
- auto life = m_World->GetComponent(entity);
- if (life != nullptr) {
- if (life->Number + 1 == PastLives()) {
-// m_World->RemoveComponent(entity);
-// m_World->RemoveComponent(entity);
- m_World->RemoveEntity(entity);
- 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(entity);
- m_World->RemoveComponent(entity);
- m_World->RemoveComponent(entity);
- m_World->RemoveComponent(entity);
- m_World->RemoveEntity(entity);
- auto transformBall = m_World->GetComponent(entity);
- } else {
- auto powerUp = m_World->GetComponent(entity);
- if (powerUp != nullptr) {
- SetPowerUps(PowerUps() - 1);
- m_World->RemoveComponent(entity);
- m_World->RemoveComponent(entity);
- m_World->RemoveEntity(entity);
- }
- }
- }*/
- }
-}
-
-void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, float spaceToEdge)
-{
- SetNumberOfBricks(rows * lines);
- std::cout << "You're only doing this once, right?" << std::endl;
- int num = 0;
- for (int i = 0; i < rows; i++) {
- num++;
- for (int j = 0; j < Lines(); j++) {
- CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num);
- }
- if (num == 7)
- num = 0;
- }
-
- SetNumberOfBricks(rows * lines);
- SetRestarting(false);
- return;
-}
-
-void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int num)
-{
- auto brick = m_World->CreateEntity();
- std::shared_ptr transform = m_World->AddComponent(brick);
- auto model = m_World->AddComponent(brick);
- std::shared_ptr cBrick = m_World->AddComponent(brick);
- std::shared_ptr cRec = m_World->AddComponent(brick);
- std::shared_ptr cPhys = m_World->AddComponent(brick);
- cPhys->Static = false;
- cPhys->GravityScale = 0.f;
- cPhys->Category = CollisionLayer::Type::Brick;
- cPhys->Mask = CollisionLayer::Type::Ball;
-
- std::string fileName = "Textures/Bricks/";
- fileName.append(std::to_string(num));
- fileName.append(".png");
- //sprite->SpriteFile = fileName;
- model->ModelFile = "Models/Test/Brick/Brick.obj";
- if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 6 && row == 6)) {
- std::shared_ptr cPow = m_World->AddComponent(brick);
- }
- 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;
-
- //sound
- auto collisionSound = m_World->AddComponent(brick);
- collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav";
-
- m_World->CommitEntity(brick);
- return;
-}
-
-void dd::Systems::LevelSystem::ProcessCollision()
-{
- // Like, go into brick component and check what it does upon collision. Maybe not done here?
- return;
-}
-
-void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
-{
- auto brick = m_World->GetComponent(entity);
- if (brick != nullptr) {
- SetNumberOfBricks(NumberOfBricks() - 1);
- Events::ScoreEvent es;
- es.Score = brick->Score;
- EventBroker->Publish(es);
- /*if (numberOfBricks < 1) {
- EndLevel();
- }*/
- }
- return;
-}
-
-bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
-{
- EntityID entityBrick;
- EntityID entityBall;
- auto ball = m_World->GetComponent(event.Entity2);
- auto brick = m_World->GetComponent(event.Entity1);
- if (brick != nullptr) {
- entityBrick = event.Entity1;
- } else {
- brick = m_World->GetComponent(event.Entity2);
- if (brick != nullptr) {
- entityBrick = event.Entity2;
- } else {
- return false;
- }
- }
- if (ball != nullptr) {
- entityBall = event.Entity2;
- } else {
- ball = m_World->GetComponent(event.Entity1);
- if (ball != nullptr) {
- entityBall = event.Entity1;
- } else {
- return false;
- }
- }
-
- brick = m_World->GetComponent(entityBrick);
- if (brick == nullptr) {
- return false;
- }
-
- auto power = m_World->GetComponent(entityBrick);
- if (power != nullptr) {
- Events::CreatePowerUp e;
- auto transform = m_World->GetComponent(entityBrick);
- e.Position = transform->Position;
- EventBroker->Publish(e);
- }
-
- if (ball != nullptr && Restarting() == false) {
- auto ballTransform = m_World->GetComponent(entityBall);
-
-// m_World->RemoveComponent(entityBrick);
-// m_World->RemoveComponent(entityBrick);
-// m_World->RemoveComponent(entityBrick);
-// m_World->RemoveComponent(entityBrick);
-// m_World->RemoveEntity(entityBrick);
-
- auto physicsComponent = m_World->GetComponent(entityBrick);
- physicsComponent->GravityScale = 1.f;
- physicsComponent->Mask = CollisionLayer::Type::Water | CollisionLayer::Type::Wall;
-
- auto transformComponentBrick = m_World->GetComponent(entityBrick);
- auto transformComponentBall = m_World->GetComponent(entityBall);
-
- Events::SetImpulse e;
- e.Entity = entityBrick;
-
- glm::vec2 point = glm::vec2(transformComponentBrick->Position.x + ((transformComponentBrick->Position.x - transformComponentBall->Position.x)/4), transformComponentBrick->Position.y + ((transformComponentBrick->Position.y - transformComponentBall->Position.y )/4));
-
- e.Impulse = glm::normalize(point)/2.f;
- e.Point = point;
- EventBroker->Publish(e);
- //TODO: Bricks dont collide with walls D=
-
- SetNumberOfBricks(NumberOfBricks() - 1);
- if (NumberOfBricks() <= 0) {
- SetMultiBalls(MultiBalls() + 1);
- }
- Events::ScoreEvent es;
- es.Score = brick->Score;
- EventBroker->Publish(es);
-
-<<<<<<< HEAD
- // std::cout << NumberOfBricks() << std::endl;
-=======
- //std::cout << NumberOfBricks() << std::endl;
->>>>>>> origin/master
- //std::cout << "Score: " << Score() << std::endl;
- }
-
- return true;
-}
-
-bool dd::Systems::LevelSystem::OnLifeLost(const dd::Events::LifeLost &event)
-{
- SetLives(Lives() - 1);
-
- return true;
-}
-
-bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
-{
- SetScore(Score() += event.Score);
-
- 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 transform = m_World->AddComponent(powerUp);
- auto model = m_World->AddComponent(powerUp);
- std::shared_ptr cRec = m_World->AddComponent(powerUp);
- std::shared_ptr cPhys = m_World->AddComponent(powerUp);
- cPhys->Static = false;
- cPhys->Category = CollisionLayer::Type::PowerUp;
- cPhys->Mask = CollisionLayer::Type::Pad;
-
- std::shared_ptr cPow = m_World->AddComponent(powerUp);
-
-
- 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()
-{
- Events::StageCleared e;
- EventBroker->Publish(e);
- return;
-}
-
diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp
index b72108b..b767c89 100755
--- a/src/game/Game/PadSystem.cpp
+++ b/src/game/Game/PadSystem.cpp
@@ -26,23 +26,12 @@ void dd::Systems::PadSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PadSystem::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp);
- EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &PadSystem::OnResetBall);
- 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)
{
- auto ball = m_World->GetComponent