mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-20 13:25:10 +00:00
alalalallalalllala
This commit is contained in:
@@ -21,11 +21,17 @@ set(SOURCES
|
|||||||
sources/System/Movable/MovableSystem.hpp
|
sources/System/Movable/MovableSystem.hpp
|
||||||
sources/System/Movable/MovableSystem.cpp
|
sources/System/Movable/MovableSystem.cpp
|
||||||
sources/Models/Vector3.hpp
|
sources/Models/Vector3.hpp
|
||||||
sources/Component/Drawable/Drawable3DComponent.hpp
|
sources/Models/Vector2.hpp
|
||||||
sources/Component/Drawable/Drawable2DComponent.hpp
|
sources/Component/Renderer/Drawable3DComponent.hpp
|
||||||
|
sources/Component/Renderer/Drawable2DComponent.hpp
|
||||||
sources/System/Renderer/Renderer3DSystem.hpp
|
sources/System/Renderer/Renderer3DSystem.hpp
|
||||||
sources/System/Renderer/Renderer2DSystem.hpp
|
sources/System/Renderer/Renderer2DSystem.hpp
|
||||||
sources/System/Renderer/RenderScreenSystem.hpp
|
sources/System/Renderer/RenderScreenSystem.hpp
|
||||||
|
sources/System/Renderer/RenderScreenSystem.cpp
|
||||||
|
sources/Component/Renderer/CameraComponent.cpp
|
||||||
|
sources/Component/Renderer/CameraComponent.hpp
|
||||||
|
sources/System/Renderer/Render2DScreenSystem.cpp
|
||||||
|
sources/System/Renderer/Render2DScreenSystem.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(bomberman
|
add_executable(bomberman
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace RAY::Camera {
|
|||||||
public:
|
public:
|
||||||
//! @brief 2D Camera constructor
|
//! @brief 2D Camera constructor
|
||||||
//! @param offset Camera offset (displacement from target)
|
//! @param offset Camera offset (displacement from target)
|
||||||
//! @param target Camera target (rotation and zoom origin
|
//! @param target Camera target (rotation and zoom origin)
|
||||||
//! @param rotation Camera rotation in degrees
|
//! @param rotation Camera rotation in degrees
|
||||||
//! @param zoom Camera zoom (scaling), should be 1.0f by default
|
//! @param zoom Camera zoom (scaling), should be 1.0f by default
|
||||||
Camera2D(const Vector2 &offset, const Vector2 &target, float rotation, float zoom = 1);
|
Camera2D(const Vector2 &offset, const Vector2 &target, float rotation, float zoom = 1);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "Drawables/ADrawable2D.hpp"
|
#include "Drawables/ADrawable2D.hpp"
|
||||||
|
|
||||||
namespace RAY::Drawables::Drawables2D {
|
namespace RAY::Drawables::Drawables2D {
|
||||||
//! @brief Rectangle in a two-dimensionnal space
|
//! @brief Rectangle in a two-dimensional space
|
||||||
class Rectangle: public ADrawable2D
|
class Rectangle: public ADrawable2D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -11,11 +11,22 @@
|
|||||||
#include "Drawables/ADrawable2D.hpp"
|
#include "Drawables/ADrawable2D.hpp"
|
||||||
#include "Drawables/ADrawable3D.hpp"
|
#include "Drawables/ADrawable3D.hpp"
|
||||||
|
|
||||||
RAY::Window &RAY::Window::getInstance(int width, int height, const std::string &title, unsigned flags, bool openNow)
|
std::optional<RAY::Window> RAY::Window::_instance = std::nullopt;
|
||||||
{
|
|
||||||
static RAY::Window window(width, height, title, flags, openNow);
|
|
||||||
|
|
||||||
return window;
|
RAY::Window &RAY::Window::getInstance()
|
||||||
|
{
|
||||||
|
if (!RAY::Window::_instance.has_value())
|
||||||
|
throw std::runtime_error("No window has been constructed.");
|
||||||
|
return RAY::Window::_instance.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
RAY::Window &RAY::Window::getInstance(int width, int height, const std::string &title, unsigned flags, bool openNow) noexcept
|
||||||
|
{
|
||||||
|
if (!RAY::Window::_instance.has_value()){
|
||||||
|
RAY::Window window(width, height, title, flags, openNow);
|
||||||
|
RAY::Window::_instance.emplace(std::move(window));
|
||||||
|
}
|
||||||
|
return RAY::Window::_instance.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
RAY::Window::Window(int width, int height, std::string title, unsigned flags, bool openNow):
|
RAY::Window::Window(int width, int height, std::string title, unsigned flags, bool openNow):
|
||||||
@@ -23,7 +34,7 @@ RAY::Window::Window(int width, int height, std::string title, unsigned flags, bo
|
|||||||
_title(std::move(title)),
|
_title(std::move(title)),
|
||||||
_isOpen(openNow),
|
_isOpen(openNow),
|
||||||
_flags(flags),
|
_flags(flags),
|
||||||
_drawingState(IDLE), _displayState(NONE)
|
_displayState(NONE)
|
||||||
{
|
{
|
||||||
if (openNow)
|
if (openNow)
|
||||||
this->open();
|
this->open();
|
||||||
@@ -95,20 +106,10 @@ void RAY::Window::clear(const RAY::Color &color)
|
|||||||
ClearBackground(color);
|
ClearBackground(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RAY::Window::setDrawingState(enum RAY::Window::drawingState state)
|
void RAY::Window::draw()
|
||||||
{
|
{
|
||||||
if (state == this->_drawingState)
|
|
||||||
return;
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case DRAWING:
|
|
||||||
BeginDrawing();
|
|
||||||
break;
|
|
||||||
case IDLE:
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
break;
|
BeginDrawing();
|
||||||
}
|
|
||||||
this->_drawingState = state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RAY::Window::useCamera(RAY::Camera::Camera2D &camera)
|
void RAY::Window::useCamera(RAY::Camera::Camera2D &camera)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
#include "Drawables/Image.hpp"
|
#include "Drawables/Image.hpp"
|
||||||
#include "Vector/Vector2.hpp"
|
#include "Vector/Vector2.hpp"
|
||||||
#include "Vector/Vector3.hpp"
|
#include "Vector/Vector3.hpp"
|
||||||
@@ -29,9 +30,18 @@ namespace RAY {
|
|||||||
class ADrawable3D;
|
class ADrawable3D;
|
||||||
}
|
}
|
||||||
class Window {
|
class Window {
|
||||||
|
private:
|
||||||
|
//! @brief The window's instance as an optional.
|
||||||
|
static std::optional<Window> _instance;
|
||||||
public:
|
public:
|
||||||
|
//! @brief Get The window's instance, if the window has not been already constructed a runtime exception is thrown.
|
||||||
|
static Window &getInstance();
|
||||||
|
|
||||||
//! @return A widow insta,ce. Only one window can be open at a time
|
//! @return A widow insta,ce. Only one window can be open at a time
|
||||||
static Window &getInstance(int width, int height, const std::string &title, unsigned flags = 0, bool openNow = true);
|
static Window &getInstance(int width, int height, const std::string &title, unsigned flags = 0, bool openNow = true) noexcept;
|
||||||
|
|
||||||
|
//! @brief A window is movable.
|
||||||
|
Window(Window &&) = default;
|
||||||
|
|
||||||
//! @brief A default copy constructor
|
//! @brief A default copy constructor
|
||||||
Window(const Window &window) = delete;
|
Window(const Window &window) = delete;
|
||||||
@@ -81,14 +91,6 @@ namespace RAY {
|
|||||||
//! @param color The color to clear the screen (default: black)
|
//! @param color The color to clear the screen (default: black)
|
||||||
void clear(const Color &color = BLACK);
|
void clear(const Color &color = BLACK);
|
||||||
|
|
||||||
//! @brief Different states of the draw-ability of the window
|
|
||||||
enum drawingState {
|
|
||||||
//! @brief Must be called after last draw of iteration
|
|
||||||
IDLE,
|
|
||||||
//! @brief Must be called before first draw of iteration
|
|
||||||
DRAWING,
|
|
||||||
};
|
|
||||||
|
|
||||||
//! @brief Different states of the view of the window
|
//! @brief Different states of the view of the window
|
||||||
enum displayState {
|
enum displayState {
|
||||||
//! @brief When a custom 2D camera is used
|
//! @brief When a custom 2D camera is used
|
||||||
@@ -99,8 +101,8 @@ namespace RAY {
|
|||||||
NONE,
|
NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
//! @brief Set drawing state of the window
|
//! @brief Draw the content of the buffer on the screen.
|
||||||
void setDrawingState(enum drawingState);
|
void draw();
|
||||||
|
|
||||||
//! @brief Initialize 2D mode with custom camera (2D)
|
//! @brief Initialize 2D mode with custom camera (2D)
|
||||||
void useCamera(Camera::Camera2D &camera);
|
void useCamera(Camera::Camera2D &camera);
|
||||||
@@ -149,9 +151,6 @@ namespace RAY {
|
|||||||
//! @brief flags for the window (ex: FLAG_WINDOW_RESIZABLE)
|
//! @brief flags for the window (ex: FLAG_WINDOW_RESIZABLE)
|
||||||
unsigned int _flags;
|
unsigned int _flags;
|
||||||
|
|
||||||
//! @brief Current window draw-state
|
|
||||||
enum drawingState _drawingState;
|
|
||||||
|
|
||||||
//! @brief Current window draw-state
|
//! @brief Current window draw-state
|
||||||
enum displayState _displayState;
|
enum displayState _displayState;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -75,11 +75,11 @@ namespace WAL
|
|||||||
//! @throw DuplicateError is thrown if a component with the same type already exist.
|
//! @throw DuplicateError is thrown if a component with the same type already exist.
|
||||||
//! @return This entity is returned
|
//! @return This entity is returned
|
||||||
template<typename T, typename ...Types>
|
template<typename T, typename ...Types>
|
||||||
Entity &addComponent(Types ...params)
|
Entity &addComponent(Types &&...params)
|
||||||
{
|
{
|
||||||
if (this->hasComponent<T>())
|
if (this->hasComponent<T>())
|
||||||
throw DuplicateError("A component of the type \"" + std::string(typeid(T).name()) + "\" already exists.");
|
throw DuplicateError("A component of the type \"" + std::string(typeid(T).name()) + "\" already exists.");
|
||||||
this->_components.push_back(std::make_unique<T>(*this, params...));
|
this->_components.push_back(std::make_unique<T>(*this, std::forward<Types>(params)...));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,9 @@ namespace WAL
|
|||||||
//! @brief Add a new entity to the scene, you can use this method with the same arguments as the entity's constructor.
|
//! @brief Add a new entity to the scene, you can use this method with the same arguments as the entity's constructor.
|
||||||
//! @return The current scene is returned to allow you to chain call.
|
//! @return The current scene is returned to allow you to chain call.
|
||||||
template <class ...Params>
|
template <class ...Params>
|
||||||
Scene &addEntity(Params ...params)
|
Entity &addEntity(Params &&...params)
|
||||||
{
|
{
|
||||||
this->_entities.emplace_back(params...);
|
return this->_entities.emplace_back(std::forward<Params>(params)...);
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! @brief A default constructor
|
//! @brief A default constructor
|
||||||
@@ -38,5 +37,6 @@ namespace WAL
|
|||||||
~Scene() = default;
|
~Scene() = default;
|
||||||
//! @brief A scene is assignable
|
//! @brief A scene is assignable
|
||||||
Scene &operator=(const Scene &) = default;
|
Scene &operator=(const Scene &) = default;
|
||||||
|
Scene(Scene &&) = default;
|
||||||
};
|
};
|
||||||
} // namespace WAL
|
} // namespace WAL
|
||||||
@@ -38,7 +38,7 @@ namespace WAL
|
|||||||
//! @return True if all dependencies are met, false otherwise.
|
//! @return True if all dependencies are met, false otherwise.
|
||||||
static bool _hasDependencies(const Entity &entity, const System &system);
|
static bool _hasDependencies(const Entity &entity, const System &system);
|
||||||
public:
|
public:
|
||||||
//! @brief The scene manager that allow multiple scene to work together.
|
//! @brief The scene that contains entities.
|
||||||
Scene scene;
|
Scene scene;
|
||||||
//! @brief The time between each fixed update.
|
//! @brief The time between each fixed update.
|
||||||
static std::chrono::nanoseconds timestep;
|
static std::chrono::nanoseconds timestep;
|
||||||
@@ -46,7 +46,7 @@ namespace WAL
|
|||||||
//! @brief Create a new system in place.
|
//! @brief Create a new system in place.
|
||||||
//! @return The wal instance used to call this function is returned. This allow method chaining.
|
//! @return The wal instance used to call this function is returned. This allow method chaining.
|
||||||
template<typename T, class ...Types>
|
template<typename T, class ...Types>
|
||||||
Wal &addSystem(Types ...params)
|
Wal &addSystem(Types &&...params)
|
||||||
{
|
{
|
||||||
const std::type_info &type = typeid(T);
|
const std::type_info &type = typeid(T);
|
||||||
auto existing = std::find_if(this->_systems.begin(), this->_systems.end(), [&type] (auto &sys) {
|
auto existing = std::find_if(this->_systems.begin(), this->_systems.end(), [&type] (auto &sys) {
|
||||||
@@ -54,7 +54,7 @@ namespace WAL
|
|||||||
});
|
});
|
||||||
if (existing != this->_systems.end())
|
if (existing != this->_systems.end())
|
||||||
throw DuplicateError("A system of the type \"" + std::string(type.name()) + "\" already exists.");
|
throw DuplicateError("A system of the type \"" + std::string(type.name()) + "\" already exists.");
|
||||||
this->_systems.push_back(std::make_unique<T>(params...));
|
this->_systems.push_back(std::make_unique<T>(std::forward<Types>(params)...));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
sources/Component/Renderer/CameraComponent.cpp
Normal file
17
sources/Component/Renderer/CameraComponent.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// Created by Zoe Roux on 5/27/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "CameraComponent.hpp"
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
CameraComponent::CameraComponent(WAL::Entity &entity)
|
||||||
|
: Component(entity)
|
||||||
|
{}
|
||||||
|
|
||||||
|
WAL::Component *BBM::CameraComponent::clone(WAL::Entity &entity) const
|
||||||
|
{
|
||||||
|
return new CameraComponent(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
28
sources/Component/Renderer/CameraComponent.hpp
Normal file
28
sources/Component/Renderer/CameraComponent.hpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Created by Zoe Roux on 5/27/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Component/Component.hpp>
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
//! @brief A class allowing one to place the camera in the scene.
|
||||||
|
//! @warning Only one CameraComponent is allowed on the scene. Using more than one result in undefined behaviors.
|
||||||
|
class CameraComponent : public WAL::Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! @inherit
|
||||||
|
Component *clone(WAL::Entity &entity) const override;
|
||||||
|
|
||||||
|
//! @brief Ctor
|
||||||
|
explicit CameraComponent(WAL::Entity &);
|
||||||
|
//! @brief A camera component is copy constructable.
|
||||||
|
CameraComponent(const CameraComponent &) = default;
|
||||||
|
//! @brief Default destructor.
|
||||||
|
~CameraComponent() override = default;
|
||||||
|
//! @brief A camera component can't be assigned.
|
||||||
|
CameraComponent &operator=(const CameraComponent &) = delete;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -17,11 +17,17 @@ namespace BBM
|
|||||||
T member;
|
T member;
|
||||||
|
|
||||||
//! ctor
|
//! ctor
|
||||||
explicit Drawable2DComponent(WAL::Entity &entity, T member)
|
Drawable2DComponent(WAL::Entity &entity, T member)
|
||||||
: WAL::Component(entity),
|
: WAL::Component(entity),
|
||||||
member(std::move(member))
|
member(std::move(member))
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
//! ctor
|
||||||
|
template<typename ...Params>
|
||||||
|
explicit Drawable2DComponent(WAL::Entity &entity, Params &&...params)
|
||||||
|
: WAL::Component(entity),
|
||||||
|
member(std::forward<Params>(params)...)
|
||||||
|
{}
|
||||||
|
|
||||||
//! @brief Clone a component for another or the same entity.
|
//! @brief Clone a component for another or the same entity.
|
||||||
//! @param entity The entity that owns the ne component.
|
//! @param entity The entity that owns the ne component.
|
||||||
@@ -17,11 +17,17 @@ namespace BBM
|
|||||||
T member;
|
T member;
|
||||||
|
|
||||||
//! @brief ctor
|
//! @brief ctor
|
||||||
explicit Drawable3DComponent(WAL::Entity &entity, T member)
|
Drawable3DComponent(WAL::Entity &entity, T member)
|
||||||
: WAL::Component(entity),
|
: WAL::Component(entity),
|
||||||
member(std::move(member))
|
member(std::move(member))
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
//! ctor
|
||||||
|
template<typename ...Params>
|
||||||
|
explicit Drawable3DComponent(WAL::Entity &entity, Params &&...params)
|
||||||
|
: WAL::Component(entity),
|
||||||
|
member(std::forward<Params>(params)...)
|
||||||
|
{}
|
||||||
|
|
||||||
//! @brief Clone a component for another or the same entity.
|
//! @brief Clone a component for another or the same entity.
|
||||||
//! @param entity The entity that owns the ne component.
|
//! @param entity The entity that owns the ne component.
|
||||||
166
sources/Models/Vector2.hpp
Normal file
166
sources/Models/Vector2.hpp
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
//
|
||||||
|
// Created by Zoe Roux on 5/17/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
|
#include "Vector/Vector2.hpp"
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
//! @brief A Vector2 data type. (templated to allow any kind of vector2)
|
||||||
|
template<typename T>
|
||||||
|
class Vector2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! @brief The x value of the vector
|
||||||
|
T x;
|
||||||
|
//! @brief The y value of the vector
|
||||||
|
T y;
|
||||||
|
|
||||||
|
//! @brief Create a new nil vector2.
|
||||||
|
Vector2()
|
||||||
|
: x(0), y(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//! @brief Create a new vector2 representing a specific coordinate.
|
||||||
|
Vector2(T x, T y)
|
||||||
|
: x(x), y(y)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//! @brief A default destructor
|
||||||
|
~Vector2() = default;
|
||||||
|
|
||||||
|
bool operator==(const Vector2<T> &other) const
|
||||||
|
{
|
||||||
|
return this->x == other.x && this->y == other.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Vector2<T> &other) const
|
||||||
|
{
|
||||||
|
return !this->operator==(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> &operator+=(const Vector2<T2> &vec)
|
||||||
|
{
|
||||||
|
this->x += vec.x;
|
||||||
|
this->y += vec.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> operator+(const Vector2<T2> &vec) const
|
||||||
|
{
|
||||||
|
return Vector2<T>(this->x + vec.x, this->y + vec.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> &operator-=(const Vector2<T2> &vec)
|
||||||
|
{
|
||||||
|
this->x -= vec.x;
|
||||||
|
this->y -= vec.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> &operator*=(T2 d)
|
||||||
|
{
|
||||||
|
this->x *= d;
|
||||||
|
this->y *= d;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> operator*(T2 d) const
|
||||||
|
{
|
||||||
|
return Vector2<T>(this->x * d, this->y * d);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> operator*(const Vector2<T2> &b) const
|
||||||
|
{
|
||||||
|
return Vector2<T>(this->x * b.x, this->y * b.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> operator/=(const Vector2<T2> &b)
|
||||||
|
{
|
||||||
|
this->x /= b.x;
|
||||||
|
this->y /= b.y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> operator/(const Vector2<T2> &b) const
|
||||||
|
{
|
||||||
|
return Vector2<T>(this->x / b.x, this->y / b.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> operator/=(T2 b)
|
||||||
|
{
|
||||||
|
this->x /= b;
|
||||||
|
this->y /= b;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
Vector2<T> operator/(T2 b) const
|
||||||
|
{
|
||||||
|
return Vector2<T>(this->x / b, this->y / b);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
double distance(const Vector2<T2> &o) const
|
||||||
|
{
|
||||||
|
return std::sqrt(std::pow(this->x - o.x, 2) + std::pow(this->y - o.y, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
double magnitude() const
|
||||||
|
{
|
||||||
|
return std::sqrt(std::pow(this->x, 2) + std::pow(this->y, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2<T> normalize()
|
||||||
|
{
|
||||||
|
double mag = this->magnitude();
|
||||||
|
|
||||||
|
this->x /= mag;
|
||||||
|
this->y /= mag;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2<T> normalized() const
|
||||||
|
{
|
||||||
|
T mag = this->magnitude();
|
||||||
|
|
||||||
|
return Vector2<T>(this->x / mag, this->y / mag);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2<T> projection(const Vector2<T> &point) const
|
||||||
|
{
|
||||||
|
return (point * this) / std::pow(this->magnitude(), 2) * this;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator RAY::Vector2() const requires(std::is_same_v<T, float>)
|
||||||
|
{
|
||||||
|
return RAY::Vector2(this->x, this->y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Vector2<float> Vector2f;
|
||||||
|
typedef Vector2<unsigned> Vector2u;
|
||||||
|
typedef Vector2<int> Vector2i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::ostream &operator<<(std::ostream &s, const BBM::Vector2<T> &v)
|
||||||
|
{
|
||||||
|
s << "Vector2<" << typeid(T).name() << ">("<< v.x << ", " << v.y << ")";
|
||||||
|
return s;
|
||||||
|
}
|
||||||
@@ -154,19 +154,18 @@ namespace BBM
|
|||||||
return (point * this) / std::pow(this->magnitude(), 2) * this;
|
return (point * this) / std::pow(this->magnitude(), 2) * this;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit operator RAY::Vector3() const { return {this->x, this->y, this->z};}
|
operator RAY::Vector3() const requires(std::is_same_v<T, float>)
|
||||||
|
{
|
||||||
|
return RAY::Vector3(this->x, this->y, this->z);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Vector3<float> Vector3f;
|
typedef Vector3<float> Vector3f;
|
||||||
typedef Vector3<unsigned> Vector3u;
|
typedef Vector3<unsigned> Vector3u;
|
||||||
typedef Vector3<int> Vector3i;
|
typedef Vector3<int> Vector3i;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::ostream &operator<<(std::ostream &s, const BBM::Vector3<T> &v)
|
std::ostream &operator<<(std::ostream &s, const BBM::Vector3<T> &v)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,12 @@
|
|||||||
|
|
||||||
#include <Wal.hpp>
|
#include <Wal.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <System/Movable/MovableSystem.hpp>
|
||||||
|
#include <System/Renderer/RenderScreenSystem.hpp>
|
||||||
|
#include <System/Renderer/Render2DScreenSystem.hpp>
|
||||||
|
#include <System/Renderer/Renderer2DSystem.hpp>
|
||||||
|
#include <Drawables/2D/Rectangle.hpp>
|
||||||
|
#include <Models/Vector2.hpp>
|
||||||
#include "Runner.hpp"
|
#include "Runner.hpp"
|
||||||
#include "Models/GameState.hpp"
|
#include "Models/GameState.hpp"
|
||||||
|
|
||||||
@@ -17,9 +23,36 @@ namespace BBM
|
|||||||
// If you don't need the scene anymore, remember to remove it from the loadedScene array.
|
// If you don't need the scene anymore, remember to remove it from the loadedScene array.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enableRaylib(WAL::Wal &wal)
|
||||||
|
{
|
||||||
|
RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
|
// wal.addSystem<>(); 3D elements here
|
||||||
|
|
||||||
|
wal.addSystem<Render2DScreenSystem>(window)
|
||||||
|
.addSystem<Renderer2DSystem<RAY::Drawables::Drawables2D::Rectangle>>();
|
||||||
|
wal.addSystem<RenderScreenSystem>(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
WAL::Scene loadGameScene()
|
||||||
|
{
|
||||||
|
WAL::Scene scene;
|
||||||
|
scene.addEntity("cube")
|
||||||
|
.addComponent<PositionComponent>()
|
||||||
|
.addComponent<Drawable2DComponent<RAY::Drawables::Drawables2D::Rectangle>>(Vector2f(), Vector2f(1, 1), RED);
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
int run()
|
int run()
|
||||||
{
|
{
|
||||||
WAL::Wal wal;
|
WAL::Wal wal;
|
||||||
|
wal.addSystem<MovableSystem>();
|
||||||
|
enableRaylib(wal);
|
||||||
|
WAL::Scene scene = loadGameScene();
|
||||||
|
wal.scene = scene;
|
||||||
|
|
||||||
|
|
||||||
|
// wal.scene = loadGameScene();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
wal.run<GameState>(updateState);
|
wal.run<GameState>(updateState);
|
||||||
|
|||||||
19
sources/System/Renderer/Render2DScreenSystem.cpp
Normal file
19
sources/System/Renderer/Render2DScreenSystem.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by Zoe Roux on 5/27/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Render2DScreenSystem.hpp"
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
Render2DScreenSystem::Render2DScreenSystem(RAY::Window &window)
|
||||||
|
: WAL::System({}),
|
||||||
|
_window(window),
|
||||||
|
_camera(RAY::Vector2(), RAY::Vector2(), 0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void Render2DScreenSystem::onSelfUpdate()
|
||||||
|
{
|
||||||
|
this->_window.useCamera(this->_camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
sources/System/Renderer/Render2DScreenSystem.hpp
Normal file
33
sources/System/Renderer/Render2DScreenSystem.hpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
//
|
||||||
|
// Created by Zoe Roux on 5/27/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <System/System.hpp>
|
||||||
|
#include <Window.hpp>
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
class Render2DScreenSystem : public WAL::System
|
||||||
|
{
|
||||||
|
//! @brief The window to render on
|
||||||
|
RAY::Window &_window;
|
||||||
|
|
||||||
|
//! @brief The camera used to render.
|
||||||
|
RAY::Camera::Camera2D _camera;
|
||||||
|
public:
|
||||||
|
//! @brief A method called after all entities that this system manage has been updated.
|
||||||
|
//! @note render on screen here
|
||||||
|
void onSelfUpdate() override;
|
||||||
|
|
||||||
|
//! @brief ctor
|
||||||
|
explicit Render2DScreenSystem(RAY::Window &window);
|
||||||
|
//! @brief Default copy ctor
|
||||||
|
Render2DScreenSystem(const Render2DScreenSystem &) = default;
|
||||||
|
//! @brief Default dtor
|
||||||
|
~Render2DScreenSystem() override = default;
|
||||||
|
//! @brief A render screen system can't be assigned.
|
||||||
|
Render2DScreenSystem &operator=(const Render2DScreenSystem &) = delete;
|
||||||
|
};
|
||||||
|
}
|
||||||
32
sources/System/Renderer/RenderScreenSystem.cpp
Normal file
32
sources/System/Renderer/RenderScreenSystem.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// Created by Zoe Roux on 5/27/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "RenderScreenSystem.hpp"
|
||||||
|
#include "Component/Renderer/CameraComponent.hpp"
|
||||||
|
#include "Component/Position/PositionComponent.hpp"
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
RenderScreenSystem::RenderScreenSystem(RAY::Window &window)
|
||||||
|
: WAL::System({
|
||||||
|
typeid(CameraComponent),
|
||||||
|
typeid(PositionComponent)
|
||||||
|
}),
|
||||||
|
_window(window),
|
||||||
|
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void RenderScreenSystem::onSelfUpdate()
|
||||||
|
{
|
||||||
|
this->_window.draw();
|
||||||
|
this->_window.clear();
|
||||||
|
this->_window.useCamera(this->_camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderScreenSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime)
|
||||||
|
{
|
||||||
|
const auto &pos = entity.getComponent<PositionComponent>();
|
||||||
|
_camera.setPosition(pos.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,39 +10,28 @@
|
|||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
template <class T>
|
|
||||||
class RenderScreenSystem : public WAL::System
|
class RenderScreenSystem : public WAL::System
|
||||||
{
|
{
|
||||||
//! @brief The window to render on
|
//! @brief The window to render on
|
||||||
RAY::Window &_window;
|
RAY::Window &_window;
|
||||||
//! @brief The camera
|
|
||||||
T &_camera;
|
|
||||||
public:
|
|
||||||
//! @brief ctor
|
|
||||||
explicit RenderScreenSystem(RAY::Window &window, T &camera)
|
|
||||||
: WAL::System({}),
|
|
||||||
_window(window),
|
|
||||||
_camera(camera)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//! @brief The camera used to render.
|
||||||
|
RAY::Camera::Camera3D _camera;
|
||||||
|
public:
|
||||||
//! @brief A method called after all entities that this system manage has been updated.
|
//! @brief A method called after all entities that this system manage has been updated.
|
||||||
//! @note render on screen here
|
//! @note render on screen here
|
||||||
void onSelfUpdate() override
|
void onSelfUpdate() override;
|
||||||
{
|
|
||||||
this->_window.unuseCamera();
|
|
||||||
this->_window.setDrawingState(RAY::Window::IDLE);
|
|
||||||
this->_window.setDrawingState(RAY::Window::DRAWING);
|
|
||||||
this->_window.clear();
|
|
||||||
this->_window.useCamera(_camera);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//! @inherit
|
||||||
|
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) override;
|
||||||
|
|
||||||
|
//! @brief ctor
|
||||||
|
explicit RenderScreenSystem(RAY::Window &window);
|
||||||
//! @brief Default copy ctor
|
//! @brief Default copy ctor
|
||||||
RenderScreenSystem(const RenderScreenSystem &) = default;
|
RenderScreenSystem(const RenderScreenSystem &) = default;
|
||||||
//! @brief Default dtor
|
//! @brief Default dtor
|
||||||
~RenderScreenSystem() override = default;
|
~RenderScreenSystem() override = default;
|
||||||
//! @brief Default assignment operator
|
//! @brief A render screen system can't be assigned.
|
||||||
RenderScreenSystem &operator=(const RenderScreenSystem &) = default;
|
RenderScreenSystem &operator=(const RenderScreenSystem &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "System/System.hpp"
|
#include "System/System.hpp"
|
||||||
#include "Entity/Entity.hpp"
|
#include "Entity/Entity.hpp"
|
||||||
#include "Component/Position/PositionComponent.hpp"
|
#include "Component/Position/PositionComponent.hpp"
|
||||||
#include "Component/Drawable/Drawable2DComponent.hpp"
|
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
@@ -20,9 +20,9 @@ namespace BBM
|
|||||||
//! @brief The class to render
|
//! @brief The class to render
|
||||||
RAY::Window &_window;
|
RAY::Window &_window;
|
||||||
public:
|
public:
|
||||||
explicit Renderer2DSystem(RAY::Window &window)
|
explicit Renderer2DSystem()
|
||||||
: WAL::System({typeid(PositionComponent), typeid(Drawable2DComponent<T>)}),
|
: WAL::System({typeid(PositionComponent), typeid(Drawable2DComponent<T>)}),
|
||||||
_window(window)
|
_window(RAY::Window::getInstance())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "System/System.hpp"
|
#include "System/System.hpp"
|
||||||
#include "Entity/Entity.hpp"
|
#include "Entity/Entity.hpp"
|
||||||
#include "Component/Position/PositionComponent.hpp"
|
#include "Component/Position/PositionComponent.hpp"
|
||||||
#include "Component/Drawable/Drawable3DComponent.hpp"
|
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
|
|||||||
100
sources/main.cpp
100
sources/main.cpp
@@ -24,8 +24,8 @@
|
|||||||
#include "Model/ModelAnimations.hpp"
|
#include "Model/ModelAnimations.hpp"
|
||||||
#include "System/Renderer/Renderer3DSystem.hpp"
|
#include "System/Renderer/Renderer3DSystem.hpp"
|
||||||
#include "System/Renderer/Renderer2DSystem.hpp"
|
#include "System/Renderer/Renderer2DSystem.hpp"
|
||||||
#include "Component/Drawable/Drawable3DComponent.hpp"
|
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||||
#include "Component/Drawable/Drawable2DComponent.hpp"
|
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||||
#include "System/Renderer/RenderScreenSystem.hpp"
|
#include "System/Renderer/RenderScreenSystem.hpp"
|
||||||
#include "Vector/Vector3.hpp"
|
#include "Vector/Vector3.hpp"
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
@@ -47,52 +47,52 @@ std::string get_full_path(const std::string &color)
|
|||||||
|
|
||||||
int demo()
|
int demo()
|
||||||
{
|
{
|
||||||
WAL::Wal wal;
|
// WAL::Wal wal;
|
||||||
const int screenWidth = 800;
|
// const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
// const int screenHeight = 450;
|
||||||
|
//
|
||||||
RAY::TraceLog::setLevel(LOG_WARNING);
|
// RAY::TraceLog::setLevel(LOG_WARNING);
|
||||||
RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE);
|
// RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE);
|
||||||
RAY::Image icon("assets/icon.png");
|
// RAY::Image icon("assets/icon.png");
|
||||||
window.setIcon(icon);
|
// window.setIcon(icon);
|
||||||
RAY::Camera::Camera3D camera(RAY::Vector3(10.0f, 10.0f, 10.0f),
|
// RAY::Camera::Camera3D camera(RAY::Vector3(10.0f, 10.0f, 10.0f),
|
||||||
RAY::Vector3(0.0f, 0.0f, 0.0f),
|
// RAY::Vector3(0.0f, 0.0f, 0.0f),
|
||||||
RAY::Vector3(0.0f, 1.0f, 0.0f),
|
// RAY::Vector3(0.0f, 1.0f, 0.0f),
|
||||||
45.0f, CAMERA_PERSPECTIVE
|
// 45.0f, CAMERA_PERSPECTIVE
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
RAY::Camera::Camera2D camera2D(RAY::Vector2(screenWidth / 2.0f, screenHeight / 2.0f),
|
// RAY::Camera::Camera2D camera2D(RAY::Vector2(screenWidth / 2.0f, screenHeight / 2.0f),
|
||||||
RAY::Vector2(20.0f, 20.0f),
|
// RAY::Vector2(20.0f, 20.0f),
|
||||||
0., 1);
|
// 0., 1);
|
||||||
WAL::Entity entityPlayer("roger");
|
// WAL::Entity entityPlayer("roger");
|
||||||
//RAY::Drawables::Drawables2D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0);
|
// //RAY::Drawables::Drawables2D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0);
|
||||||
RAY::Drawables::Drawables2D::Circle circle({0, 0}, 50, MAROON);
|
// RAY::Drawables::Drawables2D::Circle circle({0, 0}, 50, MAROON);
|
||||||
//RAY::Drawables::Drawables3D::Cube cube({0, 0, 0}, {2, 2, 2}, BLUE);
|
// //RAY::Drawables::Drawables3D::Cube cube({0, 0, 0}, {2, 2, 2}, BLUE);
|
||||||
BBM::Drawable2DComponent<RAY::Drawables::Drawables2D::Circle> circleComponent(entityPlayer, circle);
|
// BBM::Drawable2DComponent<RAY::Drawables::Drawables2D::Circle> circleComponent(entityPlayer, circle);
|
||||||
// BBM::Drawable3DComponent<RAY::Drawables::Drawables3D::Cube> cubeComponent(entityPlayer, cube);
|
//// BBM::Drawable3DComponent<RAY::Drawables::Drawables3D::Cube> cubeComponent(entityPlayer, cube);
|
||||||
BBM::PositionComponent posComponent(entityPlayer, {0, 0, 0});
|
// BBM::PositionComponent posComponent(entityPlayer, {0, 0, 0});
|
||||||
|
//
|
||||||
BBM::Renderer2DSystem<RAY::Drawables::Drawables2D::Circle> circleSystem(window);
|
// BBM::Renderer2DSystem<RAY::Drawables::Drawables2D::Circle> circleSystem(window);
|
||||||
//BBM::Renderer3DSystem<RAY::Drawables::Drawables3D::Cube> cubeSystem(window);
|
// //BBM::Renderer3DSystem<RAY::Drawables::Drawables3D::Cube> cubeSystem(window);
|
||||||
|
//
|
||||||
BBM::RenderScreenSystem<RAY::Camera::Camera2D> renderSystem(window, camera2D);
|
//// BBM::RenderScreenSystem<RAY::Camera::Camera2D> renderSystem(window, camera2D);
|
||||||
|
//
|
||||||
wal.addSystem(circleSystem);
|
// wal.addSystem(circleSystem);
|
||||||
wal.addSystem(renderSystem);
|
//// wal.addSystem(renderSystem);
|
||||||
//wal.addSystem(cubeSystem);
|
// //wal.addSystem(cubeSystem);
|
||||||
entityPlayer.addComponent(circleComponent);
|
// entityPlayer.addComponent(circleComponent);
|
||||||
//entityPlayer.addComponent(cubeComponent);
|
// //entityPlayer.addComponent(cubeComponent);
|
||||||
entityPlayer.addComponent(posComponent);
|
// entityPlayer.addComponent(posComponent);
|
||||||
wal.scene.addEntity(entityPlayer);
|
// wal.scene.addEntity(entityPlayer);
|
||||||
|
//
|
||||||
camera.setMode(CAMERA_FREE); // Set free camera mode
|
// camera.setMode(CAMERA_FREE); // Set free camera mode
|
||||||
|
//
|
||||||
float y_rotation = 0;
|
// float y_rotation = 0;
|
||||||
window.setFPS(60);
|
// window.setFPS(60);
|
||||||
|
//
|
||||||
wal.run<int>([](WAL::Wal &wal, int) {});
|
// wal.run<int>([](WAL::Wal &wal, int) {});
|
||||||
|
//
|
||||||
window.close();
|
// window.close();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -160,7 +160,7 @@ int demo()
|
|||||||
window.setDrawingState(RAY::Window::IDLE);
|
window.setDrawingState(RAY::Window::IDLE);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
window.close();
|
// window.close();
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -181,6 +181,6 @@ int main(int argc, char **argv)
|
|||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return demo();
|
// return demo();
|
||||||
return BBM::run();
|
return BBM::run();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user