I developed a LevelSystem class, along with a CBrick component for use in it and an EStageCleared event that is triggered upon all the bricks being removed.
The class currently creates a 8x8 grid of entities with Transform components.
This commit is contained in:
+28
-24
@@ -33,6 +33,7 @@
|
||||
#include "Rendering/CModel.h"
|
||||
#include "CTemplate.h"
|
||||
#include "Transform/TransformSystem.h"
|
||||
#include "Game/LevelSystem.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -42,24 +43,26 @@ class Engine
|
||||
public:
|
||||
Engine(int argc, char* argv[])
|
||||
{
|
||||
// m_EventBroker = std::make_shared<EventBroker>();
|
||||
m_EventBroker = std::make_shared<EventBroker>();
|
||||
|
||||
m_Renderer = std::make_shared<BGFXRenderer>();
|
||||
m_Renderer->SetFullscreen(false);
|
||||
m_Renderer->SetResolution(Rectangle(0, 0, 1280, 720));
|
||||
m_Renderer->Initialize();
|
||||
|
||||
// m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
|
||||
//
|
||||
// m_World = std::make_shared<World>(m_EventBroker);
|
||||
//
|
||||
// //TODO: Move this out of engine.h
|
||||
// m_World->ComponentFactory.Register<Components::Transform>();
|
||||
// m_World->SystemFactory.Register<Systems::TransformSystem>([this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
|
||||
// m_World->AddSystem<Systems::TransformSystem>();
|
||||
// m_World->ComponentFactory.Register<Components::Model>();
|
||||
// m_World->ComponentFactory.Register<Components::Template>();
|
||||
// m_World->Initialize();
|
||||
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
|
||||
|
||||
m_World = std::make_shared<World>(m_EventBroker);
|
||||
|
||||
//TODO: Move this out of engine.h
|
||||
m_World->ComponentFactory.Register<Components::Transform>();
|
||||
m_World->SystemFactory.Register<Systems::TransformSystem>([this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::TransformSystem>();
|
||||
m_World->SystemFactory.Register<Systems::LevelSystem>([this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::LevelSystem>();
|
||||
m_World->ComponentFactory.Register<Components::Model>();
|
||||
m_World->ComponentFactory.Register<Components::Template>();
|
||||
m_World->Initialize();
|
||||
|
||||
// auto ent = m_World->CreateEntity();
|
||||
// std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
@@ -79,31 +82,32 @@ public:
|
||||
double dt = currentTime - m_LastTime;
|
||||
m_LastTime = currentTime;
|
||||
|
||||
// ResourceManager::Update();
|
||||
//
|
||||
// // Update input
|
||||
// m_InputManager->Update(dt);
|
||||
//
|
||||
// m_World->Update(dt);
|
||||
ResourceManager::Update();
|
||||
|
||||
// Update input
|
||||
m_InputManager->Update(dt);
|
||||
|
||||
m_World->Update(dt);
|
||||
//
|
||||
// if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) {
|
||||
// ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
|
||||
// }
|
||||
//
|
||||
// //TODO Fill up the renderQueue with models (Temp fix)
|
||||
//TODO Fill up the renderQueue with models (Temp fix)
|
||||
// TEMPAddToRenderQueue();
|
||||
//
|
||||
// // Render scene
|
||||
// //TODO send renderqueue to draw.
|
||||
m_Renderer->Draw(m_RendererQueue);
|
||||
|
||||
// Render scene
|
||||
//TODO send renderqueue to draw.
|
||||
// m_Renderer->Draw(m_RendererQueue);
|
||||
|
||||
// Swap event queues
|
||||
// m_EventBroker->Clear();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||
std::shared_ptr<Systems::LevelSystem> m_LevelSystem;
|
||||
|
||||
//TODO: Get this out of engine.h
|
||||
void TEMPAddToRenderQueue()
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-09.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_CBRICK_H
|
||||
#define DAYDREAM_CBRICK_H
|
||||
|
||||
#include "Core/Component.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Brick : Component
|
||||
{
|
||||
int Points = 10;
|
||||
int Hits = 1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_CBRICK_H
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-09.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_ESTAGECLEARED_H
|
||||
#define DAYDREAM_ESTAGECLEARED_H
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace Events
|
||||
{
|
||||
struct StageCleared : Event
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_ESTAGECLEARED_H
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-09.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_LEVELSYSTEM_H
|
||||
#define DAYDREAM_LEVELSYSTEM_H
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/CTransform.h"
|
||||
//#include "Rendering/CSprite.h"
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class LevelSystem : public System
|
||||
{
|
||||
public:
|
||||
LevelSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker)
|
||||
{ }
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void CreateBasicLevel(int, int, int, int);
|
||||
void CreateBrick(int, int, int, int);
|
||||
void ProcessCollision();
|
||||
|
||||
void OnEntityRemoved(EntityID entity);
|
||||
|
||||
void EndLevel();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
int numberOfBricks;
|
||||
EntityID bricks[];
|
||||
int tRows = 8;
|
||||
int tLines = 8;
|
||||
int tSpaceBetweenBricks = 30;
|
||||
int tSpaceToEdge = 30;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_LEVELSYSTEM_H
|
||||
Reference in New Issue
Block a user