mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-28 00:31:50 +00:00
Finishing to rework the drawable system
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Models/TypeHolder.hpp>
|
||||
#include "Component/Component.hpp"
|
||||
#include "Drawables/ADrawable3D.hpp"
|
||||
#include "Model/Model.hpp"
|
||||
@@ -24,9 +25,9 @@ namespace BBM
|
||||
|
||||
//! ctor
|
||||
template<typename T, typename ...Params>
|
||||
explicit Drawable2DComponent(WAL::Entity &entity, Params &&...params)
|
||||
explicit Drawable2DComponent(WAL::Entity &entity, WAL::TypeHolder<T>, Params &&...params)
|
||||
: WAL::Component(entity),
|
||||
drawable(std::move(T(std::forward<Params>(params)...)))
|
||||
drawable(new T(std::forward<Params>(params)...))
|
||||
{}
|
||||
|
||||
//! @brief Clone a component for another or the same entity.
|
||||
|
||||
@@ -41,12 +41,10 @@ namespace BBM
|
||||
|
||||
std::shared_ptr<WAL::Scene> loadGameScene()
|
||||
{
|
||||
// Drawable2DComponent cmp = Drawable2DComponent(Vector2f(), Vector2f(), RED);
|
||||
|
||||
auto scene = std::make_shared<WAL::Scene>();
|
||||
// scene->addEntity("cube")
|
||||
// .addComponent<PositionComponent>()
|
||||
// .addComponent<Drawable2DComponent>(Vector2f(), Vector2f(10, 10), RED);
|
||||
scene->addEntity("cube")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(Vector2f(), Vector2f(10, 10), RED);
|
||||
scene->addEntity("player")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"));
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
|
||||
#undef INTERNAL
|
||||
#define INTERNAL public
|
||||
#include <Component/Renderer/Drawable2DComponent.hpp>
|
||||
#include <Component/Renderer/Drawable3DComponent.hpp>
|
||||
#include "Models/Vector2.hpp"
|
||||
#include "RenderSystem.hpp"
|
||||
#include "Component/Renderer/CameraComponent.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||
#include "Drawables/ADrawable2D.hpp"
|
||||
#include "Drawables/ADrawable3D.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
@@ -26,7 +30,21 @@ namespace BBM
|
||||
this->_camera.update();
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
BeginMode3D(this->_camera);
|
||||
for (auto &entity : this->_wal.scene->getEntities()) {
|
||||
if (!entity.hasComponent<Drawable3DComponent>()
|
||||
|| !entity.hasComponent<PositionComponent>())
|
||||
continue;
|
||||
auto &drawable = entity.getComponent<Drawable3DComponent>();
|
||||
auto &pos = entity.getComponent<PositionComponent>();
|
||||
|
||||
drawable.drawable->setPosition(pos.position);
|
||||
drawable.drawable->drawOn(this->_window);
|
||||
}
|
||||
EndMode3D();
|
||||
|
||||
// TODO sort entities based on the Z axis
|
||||
for (auto &entity : this->_wal.scene->getEntities()) {
|
||||
if (!entity.hasComponent<Drawable2DComponent>()
|
||||
|| !entity.hasComponent<PositionComponent>())
|
||||
@@ -34,10 +52,9 @@ namespace BBM
|
||||
auto &drawable = entity.getComponent<Drawable2DComponent>();
|
||||
auto &pos = entity.getComponent<PositionComponent>();
|
||||
|
||||
// drawable.drawable->setPosition(static_cast<RAY::Vector3>(pos.position));
|
||||
// drawable.drawable->drawOn(this->_window);
|
||||
drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y));
|
||||
drawable.drawable->drawOn(this->_window);
|
||||
}
|
||||
EndMode3D();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user