mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-03 02:23:44 +00:00
add healthcomponent to breakable block
This commit is contained in:
+23
-1
@@ -20,9 +20,31 @@ set(SOURCES
|
||||
sources/Component/Position/PositionComponent.hpp
|
||||
sources/Component/Movable/MovableComponent.cpp
|
||||
sources/Component/Movable/MovableComponent.hpp
|
||||
sources/Component/Controllable/ControllableComponent.hpp
|
||||
sources/Component/Controllable/ControllableComponent.cpp
|
||||
sources/Component/Gamepad/GamepadComponent.cpp
|
||||
sources/Component/Gamepad/GamepadComponent.hpp
|
||||
sources/Component/Keyboard/KeyboardComponent.cpp
|
||||
sources/Component/Keyboard/KeyboardComponent.hpp
|
||||
sources/Component/Health/HealthComponent.cpp
|
||||
sources/Component/Health/HealthComponent.hpp
|
||||
sources/System/Movable/MovableSystem.hpp
|
||||
sources/System/Movable/MovableSystem.cpp
|
||||
sources/System/Controllable/ControllableSystem.cpp
|
||||
sources/System/Controllable/ControllableSystem.hpp
|
||||
sources/System/Gamepad/GamepadSystem.cpp
|
||||
sources/System/Gamepad/GamepadSystem.hpp
|
||||
sources/System/Health/HealthSystem.cpp
|
||||
sources/System/Health/HealthSystem.hpp
|
||||
sources/System/Keyboard/KeyboardSystem.cpp
|
||||
sources/System/Keyboard/KeyboardSystem.hpp
|
||||
sources/System/Movable/MovableSystem.cpp
|
||||
sources/System/Movable/MovableSystem.hpp
|
||||
sources/Models/Vector3.hpp
|
||||
sources/Component/GridCentered/GridCenteredComponent.cpp
|
||||
sources/Component/GridCentered/GridCenteredComponent.hpp
|
||||
sources/System/GridCentered/GridCenteredSystem.cpp
|
||||
sources/System/GridCentered/GridCenteredSystem.hpp
|
||||
sources/Models/Vector2.hpp
|
||||
sources/Component/Renderer/Drawable3DComponent.hpp
|
||||
sources/Component/Renderer/Drawable2DComponent.hpp
|
||||
@@ -49,7 +71,7 @@ add_executable(unit_tests EXCLUDE_FROM_ALL
|
||||
tests/MainTest.cpp
|
||||
tests/EngineTests.cpp
|
||||
tests/CallbackTest.cpp
|
||||
)
|
||||
tests/MoveTests.cpp)
|
||||
target_include_directories(unit_tests PUBLIC sources)
|
||||
target_link_libraries(unit_tests PUBLIC wal ray)
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
|
||||
@@ -102,7 +102,7 @@ void RAY::Window::setFPS(unsigned int fps)
|
||||
SetTargetFPS(fps);
|
||||
}
|
||||
|
||||
void RAY::Window::clear(const RAY::Color &color)
|
||||
void RAY::Window::clear(RAY::Color color)
|
||||
{
|
||||
ClearBackground(color);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace RAY {
|
||||
|
||||
//! @brief Set background color (framebuffer clear color)
|
||||
//! @param color The color to clear the screen (default: black)
|
||||
void clear(const Color &color = BLACK);
|
||||
void clear(Color color = BLACK);
|
||||
|
||||
//! @brief Different states of the view of the window
|
||||
enum displayState {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/24/21.
|
||||
//
|
||||
|
||||
#include "ControllableComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
ControllableComponent::ControllableComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity)
|
||||
{}
|
||||
|
||||
WAL::Component *ControllableComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new ControllableComponent(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Models/Vector2.hpp>
|
||||
#include "Component/Component.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class ControllableComponent : public WAL::Component
|
||||
{
|
||||
public:
|
||||
//! @brief The X and Z abscis of the movement.
|
||||
Vector2f move;
|
||||
//! @brief input value for jump
|
||||
bool jump = false;
|
||||
//! @brief input value for bomb
|
||||
bool bomb = false;
|
||||
//! @brief input value for pause
|
||||
bool pause = false;
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief Initialize a new controllable component.
|
||||
explicit ControllableComponent(WAL::Entity &entity);
|
||||
//! @brief A Controllable component is copy constructable.
|
||||
ControllableComponent(const ControllableComponent &) = default;
|
||||
//! @brief default destructor
|
||||
~ControllableComponent() override = default;
|
||||
//! @brief A Controllable component can't be assigned
|
||||
ControllableComponent &operator=(const ControllableComponent &) = delete;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "GamepadComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
GamepadComponent::GamepadComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity), _ID(0)
|
||||
{}
|
||||
|
||||
GamepadComponent::GamepadComponent(WAL::Entity &entity, int ID)
|
||||
: WAL::Component(entity), _ID(ID)
|
||||
{}
|
||||
|
||||
WAL::Component *GamepadComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new GamepadComponent(entity, _ID);
|
||||
}
|
||||
|
||||
GamepadComponent &GamepadComponent::setID(int ID)
|
||||
{
|
||||
this->_ID = ID;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int GamepadComponent::getID() const
|
||||
{
|
||||
return this->_ID;
|
||||
}
|
||||
|
||||
} // namespace BMM
|
||||
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Controllers/Gamepad.hpp"
|
||||
#include "Component/Component.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
using Button = RAY::Controller::GamePad::Button;
|
||||
using Gamepad = RAY::Controller::GamePad;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class GamepadComponent : public WAL::Component
|
||||
{
|
||||
private:
|
||||
//! @brief Identifier of the gamepad, used to fetch events
|
||||
int _ID;
|
||||
public:
|
||||
//! @brief jump key
|
||||
Button keyJump = GAMEPAD_BUTTON_RIGHT_FACE_DOWN;
|
||||
//! @brief bomb key
|
||||
Button keyBomb = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT;
|
||||
//! @brief pause key
|
||||
Button keyPause = GAMEPAD_BUTTON_MIDDLE;
|
||||
//! @brief move right key
|
||||
Button keyRight = GAMEPAD_BUTTON_LEFT_FACE_RIGHT;
|
||||
//! @brief move left key
|
||||
Button keyLeft = GAMEPAD_BUTTON_LEFT_FACE_LEFT;
|
||||
//! @brief move up key
|
||||
Button keyUp = GAMEPAD_BUTTON_LEFT_FACE_UP;
|
||||
//! @brief move down key
|
||||
Button keyDown = GAMEPAD_BUTTON_LEFT_FACE_DOWN;
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief Create a new gampad component using default keys.
|
||||
explicit GamepadComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief Create a new PositionComponent at a certain position
|
||||
GamepadComponent(WAL::Entity &entity, int id);
|
||||
|
||||
//! @brief A Gamepad component is copy constructable.
|
||||
GamepadComponent(const GamepadComponent &) = default;
|
||||
|
||||
//! @brief default destructor
|
||||
~GamepadComponent() override = default;
|
||||
|
||||
//! @brief A Gamepad component can't be assigned
|
||||
GamepadComponent &operator=(const GamepadComponent &) = delete;
|
||||
|
||||
//! @brief Set the ID of the Gamepad the events must be fetch from;
|
||||
GamepadComponent &setID(int ID);
|
||||
|
||||
//! @brief Get the ID of the Gamepad the events must be fetch from;
|
||||
int getID() const;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/24/21.
|
||||
//
|
||||
|
||||
#include "GridCenteredComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
GridCenteredComponent::GridCenteredComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity)
|
||||
{}
|
||||
|
||||
WAL::Component *GridCenteredComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new GridCenteredComponent(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/24/21.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Component/Component.hpp>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A component to slowly center entities to the middle of their current block.
|
||||
//! This allow flexibility in their movement will preventing them from getting stuck at every corner.
|
||||
class GridCenteredComponent : public WAL::Component
|
||||
{
|
||||
public:
|
||||
//! @brief The force factor applied at each frame.
|
||||
float force = 1;
|
||||
|
||||
//! @inherit
|
||||
Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief Create a new, default GridCenteredComponent.
|
||||
//! @param entity The entity attached to this component.
|
||||
explicit GridCenteredComponent(WAL::Entity &entity);
|
||||
//! @brief A GridCenteredComponent is copy constructable
|
||||
//! @param other The other GridCenteredComponent to copy.
|
||||
GridCenteredComponent(const GridCenteredComponent &other) = default;
|
||||
//! @brief A default destructor
|
||||
~GridCenteredComponent() override = default;
|
||||
//! @brief A GridCenteredComponent is not assignable
|
||||
GridCenteredComponent &operator=(const GridCenteredComponent &) = delete;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "HealthComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity),
|
||||
_healthPoint()
|
||||
{}
|
||||
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity, unsigned int healthPoint)
|
||||
: WAL::Component(entity),
|
||||
_healthPoint(healthPoint)
|
||||
{}
|
||||
|
||||
WAL::Component *HealthComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new HealthComponent(entity);
|
||||
}
|
||||
|
||||
void HealthComponent::addHealthPoint(unsigned int healthPoint)
|
||||
{
|
||||
this->_healthPoint += healthPoint;
|
||||
}
|
||||
|
||||
void HealthComponent::takeDmg(unsigned int damage)
|
||||
{
|
||||
if (damage >= this->_healthPoint) {
|
||||
this->_healthPoint = 0;
|
||||
} else
|
||||
this->_healthPoint -= damage;
|
||||
}
|
||||
|
||||
unsigned int HealthComponent::getHealthPoint(void) const
|
||||
{
|
||||
return (this->_healthPoint);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Models/Callback.hpp>
|
||||
#include "Component/Component.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class HealthComponent : public WAL::Component
|
||||
{
|
||||
|
||||
private:
|
||||
//! @brief life of an entity
|
||||
unsigned int _healthPoint;
|
||||
|
||||
public:
|
||||
//! @brief The callback invoked on this entity's death.
|
||||
WAL::Callback<WAL::Entity &> onDeath;
|
||||
|
||||
//! @brief add health to the entity
|
||||
void addHealthPoint(unsigned int healthPoint);
|
||||
|
||||
//! @brief reduce health
|
||||
void takeDmg(unsigned int damage);
|
||||
|
||||
//! @brief return health point of the entity
|
||||
unsigned int getHealthPoint(void) const;
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief A Health component can't be instantiated, it should be derived.
|
||||
explicit HealthComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief Constructor
|
||||
HealthComponent(WAL::Entity &entity, unsigned int healthPoint);
|
||||
|
||||
//! @brief A Health component can't be instantiated, it should be derived.
|
||||
HealthComponent(const HealthComponent &) = default;
|
||||
|
||||
//! @brief default destructor
|
||||
~HealthComponent() override = default;
|
||||
|
||||
//! @brief A Health component can't be assigned
|
||||
HealthComponent &operator=(const HealthComponent &) = delete;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "KeyboardComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
KeyboardComponent::KeyboardComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity)
|
||||
{}
|
||||
|
||||
WAL::Component *KeyboardComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new KeyboardComponent(entity);
|
||||
}
|
||||
|
||||
} // namespace BMM
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Controllers/Keyboard.hpp>
|
||||
#include "Component/Component.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
using Key = RAY::Controller::Keyboard::Key;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class KeyboardComponent : public WAL::Component
|
||||
{
|
||||
public:
|
||||
//! @brief jump key
|
||||
Key keyJump = KEY_SPACE;
|
||||
//! @brief bomb key
|
||||
Key keyBomb = KEY_E;
|
||||
//! @brief pause key
|
||||
Key keyPause = KEY_ESCAPE;
|
||||
//! @brief move right key
|
||||
Key keyRight = KEY_A;
|
||||
//! @brief move left key
|
||||
Key keyLeft = KEY_D;
|
||||
//! @brief move up key
|
||||
Key keyUp = KEY_W;
|
||||
//! @brief move down key
|
||||
Key keyDown = KEY_S;
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief Create a new keyboard component using default keys.
|
||||
explicit KeyboardComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief A Keyboard component is copy constructable.
|
||||
KeyboardComponent(const KeyboardComponent &) = default;
|
||||
|
||||
//! @brief default destructor
|
||||
~KeyboardComponent() override = default;
|
||||
|
||||
//! @brief A Keyboard component can't be assigned
|
||||
KeyboardComponent &operator=(const KeyboardComponent &) = delete;
|
||||
};
|
||||
}
|
||||
@@ -6,8 +6,9 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
CameraComponent::CameraComponent(WAL::Entity &entity)
|
||||
: Component(entity)
|
||||
CameraComponent::CameraComponent(WAL::Entity &entity, Vector3f target)
|
||||
: Component(entity),
|
||||
target(target)
|
||||
{}
|
||||
|
||||
WAL::Component *BBM::CameraComponent::clone(WAL::Entity &entity) const
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Component/Component.hpp>
|
||||
#include <Models/Vector3.hpp>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
@@ -13,11 +14,14 @@ namespace BBM
|
||||
class CameraComponent : public WAL::Component
|
||||
{
|
||||
public:
|
||||
//! @brief The camera's target, the cam will look at this position.
|
||||
Vector3f target;
|
||||
|
||||
//! @inherit
|
||||
Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief Ctor
|
||||
explicit CameraComponent(WAL::Entity &);
|
||||
explicit CameraComponent(WAL::Entity &, Vector3f target = Vector3f());
|
||||
//! @brief A camera component is copy constructable.
|
||||
CameraComponent(const CameraComponent &) = default;
|
||||
//! @brief Default destructor.
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ namespace BBM
|
||||
{
|
||||
scene->addEntity("Breakable Block")
|
||||
.addComponent<PositionComponent>(coords)
|
||||
//.addComponent<HealthComponent>(1)
|
||||
.addComponent<HealthComponent>(1)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/breakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/breakable_wall.png"));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "Model/Model.hpp"
|
||||
#include "Component/Component.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/Health/HealthComponent.hpp"
|
||||
#include "Component/Movable/MovableComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
|
||||
@@ -129,6 +129,11 @@ namespace BBM
|
||||
{
|
||||
double mag = this->magnitude();
|
||||
|
||||
if (mag == 0) {
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
return *this;
|
||||
}
|
||||
this->x /= mag;
|
||||
this->y /= mag;
|
||||
return *this;
|
||||
@@ -138,6 +143,8 @@ namespace BBM
|
||||
{
|
||||
T mag = this->magnitude();
|
||||
|
||||
if (mag == 0)
|
||||
return Vector2<T>();
|
||||
return Vector2<T>(this->x / mag, this->y / mag);
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,12 @@ namespace BBM
|
||||
{
|
||||
double mag = this->magnitude();
|
||||
|
||||
if (mag == 0) {
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
this->z = 0;
|
||||
return *this;
|
||||
}
|
||||
this->x /= mag;
|
||||
this->y /= mag;
|
||||
this->z /= mag;
|
||||
@@ -146,6 +152,8 @@ namespace BBM
|
||||
{
|
||||
T mag = this->magnitude();
|
||||
|
||||
if (mag == 0)
|
||||
return Vector3<T>();
|
||||
return Vector3<T>(this->x / mag, this->y / mag, this->z / mag);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
#include <Drawables/2D/Rectangle.hpp>
|
||||
#include <TraceLog.hpp>
|
||||
#include <System/Renderer/Renderer3DSystem.hpp>
|
||||
#include <System/Keyboard/KeyboardSystem.hpp>
|
||||
#include <System/Controllable/ControllableSystem.hpp>
|
||||
#include <Component/Movable/MovableComponent.hpp>
|
||||
#include <Component/Controllable/ControllableComponent.hpp>
|
||||
#include <Component/Keyboard/KeyboardComponent.hpp>
|
||||
#include <System/Gamepad/GamepadSystem.hpp>
|
||||
#include "Models/Vector2.hpp"
|
||||
#include "Component/Renderer/CameraComponent.hpp"
|
||||
#include "Runner.hpp"
|
||||
@@ -33,6 +39,14 @@ namespace BBM
|
||||
engine.shouldClose = true;
|
||||
}
|
||||
|
||||
void addSystems(WAL::Wal &wal)
|
||||
{
|
||||
wal.addSystem<KeyboardSystem>()
|
||||
.addSystem<GamepadSystem>()
|
||||
.addSystem<ControllableSystem>()
|
||||
.addSystem<MovableSystem>();
|
||||
}
|
||||
|
||||
void enableRaylib(WAL::Wal &wal)
|
||||
{
|
||||
RAY::TraceLog::setLevel(LOG_WARNING);
|
||||
@@ -41,7 +55,7 @@ namespace BBM
|
||||
wal.addSystem<Renderer3DSystem<RAY3D::Model>>();
|
||||
|
||||
wal.addSystem<Render2DScreenSystem>(window)
|
||||
.addSystem<Renderer2DSystem<RAY2D::Rectangle>>();
|
||||
.addSystem<Renderer2DSystem<RAY2D::Rectangle>>();
|
||||
wal.addSystem<RenderScreenSystem>(window);
|
||||
}
|
||||
|
||||
@@ -50,12 +64,18 @@ namespace BBM
|
||||
auto scene = std::make_shared<WAL::Scene>();
|
||||
scene->addEntity("cube")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable2DComponent<RAY2D::Rectangle>>(Vector2f(), Vector2f(10, 10), RED);
|
||||
/* scene->addEntity("player")
|
||||
.addComponent<Drawable2DComponent<RAY2D::Rectangle>>(Vector2f(), Vector2f(10, 10), RED)
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<MovableComponent>();;
|
||||
scene->addEntity("player")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")); */
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<MovableComponent>();
|
||||
scene->addEntity("camera")
|
||||
.addComponent<PositionComponent>(25, 50, 25)
|
||||
.addComponent<PositionComponent>(0, 20, -5)
|
||||
.addComponent<CameraComponent>();
|
||||
MapGenerator::generateMap(15, 15, rand(), scene);
|
||||
return scene;
|
||||
@@ -64,7 +84,7 @@ namespace BBM
|
||||
int run()
|
||||
{
|
||||
WAL::Wal wal;
|
||||
wal.addSystem<MovableSystem>();
|
||||
addSystems(wal);
|
||||
enableRaylib(wal);
|
||||
wal.scene = loadGameScene();
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "ControllableSystem.hpp"
|
||||
#include "Component/Movable/MovableComponent.hpp"
|
||||
#include "Component/Controllable/ControllableComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
float ControllableSystem::speed = .25f;
|
||||
|
||||
ControllableSystem::ControllableSystem()
|
||||
: WAL::System({
|
||||
typeid(ControllableComponent),
|
||||
typeid(MovableComponent)
|
||||
})
|
||||
{}
|
||||
|
||||
void ControllableSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
auto &controllable = entity.getComponent<ControllableComponent>();
|
||||
auto &movable = entity.getComponent<MovableComponent>();
|
||||
Vector2f move = controllable.move.normalized() * ControllableSystem::speed;
|
||||
|
||||
movable.addForce(Vector3f(move.x, controllable.jump, move.y));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "System/System.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A system to handle Controllable entities.
|
||||
class ControllableSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @brief The speed applied to every controllable entities.
|
||||
static float speed;
|
||||
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
ControllableSystem();
|
||||
//! @brief A Controllable system is copy constructable
|
||||
ControllableSystem(const ControllableSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~ControllableSystem() override = default;
|
||||
//! @brief A Controllable system is assignable.
|
||||
ControllableSystem &operator=(const ControllableSystem &) = default;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Created by Arthur Jamet on 2021-05-31.
|
||||
//
|
||||
|
||||
#include "GamepadSystem.hpp"
|
||||
#include "Component/Gamepad/GamepadComponent.hpp"
|
||||
#include "Component/Controllable/ControllableComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Controllers/Gamepad.hpp"
|
||||
|
||||
using Button = RAY::Controller::GamePad::Button;
|
||||
using Gamepad = RAY::Controller::GamePad;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
GamepadSystem::GamepadSystem()
|
||||
: WAL::System({
|
||||
typeid(GamepadComponent),
|
||||
typeid(ControllableComponent)
|
||||
})
|
||||
{}
|
||||
|
||||
void GamepadSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
const auto &gamepadComponent = entity.getComponent<GamepadComponent>();
|
||||
auto &controllable = entity.getComponent<ControllableComponent>();
|
||||
Gamepad gamepad(gamepadComponent.getID());
|
||||
|
||||
const std::map<Button, bool &> keyPressedMap = {
|
||||
{gamepadComponent.keyJump, controllable.jump},
|
||||
{gamepadComponent.keyBomb, controllable.bomb},
|
||||
{gamepadComponent.keyPause, controllable.pause}
|
||||
};
|
||||
|
||||
for (auto key : keyPressedMap)
|
||||
key.second = gamepad.isPressed(key.first);
|
||||
controllable.move = Vector2f();
|
||||
controllable.move.x += gamepad.isPressed(gamepadComponent.keyRight);
|
||||
controllable.move.x -= gamepad.isPressed(gamepadComponent.keyLeft);
|
||||
controllable.move.y += gamepad.isPressed(gamepadComponent.keyUp);
|
||||
controllable.move.y -= gamepad.isPressed(gamepadComponent.keyDown);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by Arthur Jamet on 2021-05-31.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "System/System.hpp"
|
||||
#include <map>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A system to handle Gamepad entities.
|
||||
class GamepadSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
GamepadSystem();
|
||||
//! @brief A Gamepad system is copy constructable
|
||||
GamepadSystem(const GamepadSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~GamepadSystem() override = default;
|
||||
//! @brief A Gamepad system is assignable.
|
||||
GamepadSystem &operator=(const GamepadSystem &) = default;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/24/21.
|
||||
//
|
||||
|
||||
#include "Component/Movable/MovableComponent.hpp"
|
||||
#include "Component/GridCentered/GridCenteredComponent.hpp"
|
||||
#include "GridCenteredSystem.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
GridCenteredSystem::GridCenteredSystem()
|
||||
: WAL::System({
|
||||
typeid(GridCenteredComponent),
|
||||
typeid(MovableComponent),
|
||||
// typeid(PositionComponent)
|
||||
})
|
||||
{}
|
||||
|
||||
void GridCenteredSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
auto &grid = entity.getComponent<GridCenteredComponent>();
|
||||
auto &movement = entity.getComponent<MovableComponent>();
|
||||
// movement.addForce(grid.force * )
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/24/21.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <System/System.hpp>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief The system handling GridCenteredComponent
|
||||
class GridCenteredSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
GridCenteredSystem();
|
||||
//! @brief A GridCenteredSystem is copyable.
|
||||
GridCenteredSystem(const GridCenteredSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~GridCenteredSystem() override = default;
|
||||
//! @brief A GridCenteredSystem is assignable
|
||||
GridCenteredSystem &operator=(const GridCenteredSystem &) = default;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "HealthSystem.hpp"
|
||||
#include "Component/Health/HealthComponent.hpp"
|
||||
#include "Component/Controllable/ControllableComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
HealthSystem::HealthSystem()
|
||||
: WAL::System({
|
||||
typeid(HealthComponent)
|
||||
})
|
||||
{}
|
||||
|
||||
void HealthSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
auto &health = entity.getComponent<HealthComponent>();
|
||||
|
||||
if (health.getHealthPoint() == 0)
|
||||
health.onDeath(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "System/System.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A system to handle Health entities.
|
||||
class HealthSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
HealthSystem();
|
||||
//! @brief A Health system is copy constructable
|
||||
HealthSystem(const HealthSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~HealthSystem() override = default;
|
||||
//! @brief A Health system is assignable.
|
||||
HealthSystem &operator=(const HealthSystem &) = default;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "KeyboardSystem.hpp"
|
||||
#include "Component/Keyboard/KeyboardComponent.hpp"
|
||||
#include "Component/Controllable/ControllableComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Controllers/Keyboard.hpp"
|
||||
|
||||
using Keyboard = RAY::Controller::Keyboard;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
KeyboardSystem::KeyboardSystem()
|
||||
: WAL::System({
|
||||
typeid(KeyboardComponent),
|
||||
typeid(ControllableComponent)
|
||||
})
|
||||
{}
|
||||
|
||||
void KeyboardSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
const auto &keyboard = entity.getComponent<KeyboardComponent>();
|
||||
auto &controllable = entity.getComponent<ControllableComponent>();
|
||||
|
||||
const std::map<KeyboardKey, bool &> keyPressedMap = {
|
||||
{keyboard.keyJump, controllable.jump},
|
||||
{keyboard.keyBomb, controllable.bomb},
|
||||
{keyboard.keyPause, controllable.pause}
|
||||
};
|
||||
|
||||
for (auto key : keyPressedMap)
|
||||
key.second = Keyboard::isDown(key.first);
|
||||
controllable.move = Vector2f();
|
||||
if (Keyboard::isDown(keyboard.keyRight))
|
||||
controllable.move.x += 1;
|
||||
if (Keyboard::isDown(keyboard.keyLeft))
|
||||
controllable.move.x -= 1;
|
||||
if (Keyboard::isDown(keyboard.keyUp))
|
||||
controllable.move.y += 1;
|
||||
if (Keyboard::isDown(keyboard.keyDown))
|
||||
controllable.move.y -= 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "System/System.hpp"
|
||||
#include <map>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A system to handle keyboard entities.
|
||||
class KeyboardSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
KeyboardSystem();
|
||||
//! @brief A keyboard system is copy constructable
|
||||
KeyboardSystem(const KeyboardSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~KeyboardSystem() override = default;
|
||||
//! @brief A keyboard system is assignable.
|
||||
KeyboardSystem &operator=(const KeyboardSystem &) = default;
|
||||
};
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "MovableSystem.hpp"
|
||||
#include "Component/Movable/MovableComponent.hpp"
|
||||
#include "Wal.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
@@ -21,8 +20,8 @@ namespace BBM
|
||||
auto &movable = entity.getComponent<MovableComponent>();
|
||||
auto &position = entity.getComponent<PositionComponent>();
|
||||
|
||||
position.position += movable._velocity * WAL::Wal::timestep.count();
|
||||
movable._velocity = movable._acceleration * WAL::Wal::timestep.count();
|
||||
position.position += movable._velocity;
|
||||
movable._velocity = movable._acceleration;
|
||||
movable._acceleration = Vector3f();
|
||||
}
|
||||
} // namespace WAL
|
||||
@@ -27,6 +27,8 @@ namespace BBM
|
||||
void RenderScreenSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
const auto &pos = entity.getComponent<PositionComponent>();
|
||||
const auto &cam = entity.getComponent<CameraComponent>();
|
||||
_camera.setPosition(pos.position);
|
||||
_camera.setTarget(cam.target);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/31/21.
|
||||
//
|
||||
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "System/Movable/MovableSystem.hpp"
|
||||
#include "System/Controllable/ControllableSystem.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
#include <Wal.hpp>
|
||||
#include <Component/Controllable/ControllableComponent.hpp>
|
||||
|
||||
#define private public
|
||||
#include <Component/Movable/MovableComponent.hpp>
|
||||
|
||||
using namespace WAL;
|
||||
using namespace BBM;
|
||||
|
||||
|
||||
TEST_CASE("Move test", "[Component][System]")
|
||||
{
|
||||
Scene scene;
|
||||
scene.addEntity("player")
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<PositionComponent>();
|
||||
Entity &entity = scene.getEntities()[0];
|
||||
|
||||
REQUIRE(entity.getComponent<PositionComponent>().position == Vector3f());
|
||||
|
||||
entity.getComponent<ControllableComponent>().move = Vector2f(1, 1);
|
||||
|
||||
ControllableSystem controllable;
|
||||
controllable.onUpdate(entity, std::chrono::nanoseconds(1));
|
||||
controllable.onFixedUpdate(entity);
|
||||
REQUIRE(entity.getComponent<MovableComponent>()._acceleration.x > 0);
|
||||
REQUIRE(entity.getComponent<MovableComponent>()._acceleration.z > 0);
|
||||
|
||||
MovableSystem movable;
|
||||
movable.onUpdate(entity, std::chrono::nanoseconds(1));
|
||||
movable.onFixedUpdate(entity);
|
||||
REQUIRE(entity.getComponent<MovableComponent>()._velocity.x > 0);
|
||||
REQUIRE(entity.getComponent<MovableComponent>()._velocity.z > 0);
|
||||
REQUIRE(entity.getComponent<MovableComponent>()._acceleration.x == 0);
|
||||
REQUIRE(entity.getComponent<MovableComponent>()._acceleration.z == 0);
|
||||
movable.onUpdate(entity, std::chrono::nanoseconds(1));
|
||||
movable.onFixedUpdate(entity);
|
||||
REQUIRE(entity.getComponent<PositionComponent>().position.x > 0);
|
||||
REQUIRE(entity.getComponent<PositionComponent>().position.z > 0);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user