diff --git a/sources/Component/Controllable/ControllableComponent.cpp b/sources/Component/Controllable/ControllableComponent.cpp new file mode 100644 index 00000000..e69de29b diff --git a/sources/Component/Controllable/ControllableComponent.hpp b/sources/Component/Controllable/ControllableComponent.hpp new file mode 100644 index 00000000..1a784db6 --- /dev/null +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -0,0 +1,46 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// + +#pragma once + +#include "lib/wal/sources/Component/Component.hpp" +#include "lib/wal/sources/Entity/Entity.hpp" + +namespace BBM +{ + class ControllableComponent : public WAL::Component + { + private: + bool _up; + bool _down; + bool _left; + bool _right; + bool _jump; + bool _bomb; + bool _pause; + public: + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief A component can't be instantiated, it should be derived. + explicit ControllableComponent(WAL::Entity &entity); + + //! @brief Constructor + ControllableComponent(WAL::Entity &entity, unsigned int maxBombCount); + + //! @brief A component can't be instantiated, it should be derived. + ControllableComponent(const ControllableComponent &) = default; + + //! @brief default destructor + ~ControllableComponent() override = default; + + //! @brief A component can't be assigned + ControllableComponent &operator=(const ControllableComponent &) = delete; + + friend class KeyboardSystem; + friend class ControllableSystem; + }; +} \ No newline at end of file diff --git a/sources/Component/Keyboard/KeyboardComponent.cpp b/sources/Component/Keyboard/KeyboardComponent.cpp new file mode 100644 index 00000000..b5460299 --- /dev/null +++ b/sources/Component/Keyboard/KeyboardComponent.cpp @@ -0,0 +1,14 @@ +// +// 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) + {} + +} // namespace BMM diff --git a/sources/Component/Keyboard/KeyboardComponent.hpp b/sources/Component/Keyboard/KeyboardComponent.hpp new file mode 100644 index 00000000..dc5c74c0 --- /dev/null +++ b/sources/Component/Keyboard/KeyboardComponent.hpp @@ -0,0 +1,52 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// + +#pragma once + +#include "lib/wal/sources/Component/Component.hpp" +#include "lib/wal/sources/Entity/Entity.hpp" + +namespace BBM +{ + class KeyboardComponent : public WAL::Component + { + public: + + //! @brief jump key + int keyJump; + //! @brief bomb key + int keyBomb; + //! @brief pause key + int keyPause; + //! @brief move right key + int keyRight; + //! @brief move left key + int keyLeft; + //! @brief move up key + int keyUp; + //! @brief move down key + int keyDown; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief A component can't be instantiated, it should be derived. + explicit KeyboardComponent(WAL::Entity &entity); + + //! @brief Constructor + KeyboardComponent(WAL::Entity &entity, unsigned int maxBombCount); + + //! @brief A component can't be instantiated, it should be derived. + KeyboardComponent(const KeyboardComponent &) = default; + + //! @brief default destructor + ~KeyboardComponent() override = default; + + //! @brief A component can't be assigned + KeyboardComponent &operator=(const KeyboardComponent &) = delete; + + friend class KeyboardSystem; + }; +} \ No newline at end of file diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp new file mode 100644 index 00000000..4658e61d --- /dev/null +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -0,0 +1,34 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// + +#include "ControllableSystem.hpp" +#include "lib/wal/sources/Component/Movable/MovableComponent.hpp" +#include "sources/Component/Controllable/ControllableComponent.hpp" +#include "lib/wal/sources/Entity/Entity.hpp" + +namespace BBM +{ + const std::type_info &ControllableSystem::getComponent() const + { + return typeid(ControllableComponent); + } + + void ControllableSystem::onFixedUpdate(WAL::Entity &entity) + { + auto &controllable= entity.getComponent(); + auto &movable= entity.getComponent(); + + if (controllable._left) + movable.addForce(WAL::Vector3f(-1, 0, 0)); + if (controllable._right) + movable.addForce(WAL::Vector3f(1, 0, 0)); + if (controllable._down) + movable.addForce(WAL::Vector3f(0, 0, -1)); + if (controllable._up) + movable.addForce(WAL::Vector3f(0, 0, 1)); + if (controllable._jump) + movable.addForce(WAL::Vector3f(0, 1, 0)); + } +} \ No newline at end of file diff --git a/sources/System/Controllable/ControllableSystem.hpp b/sources/System/Controllable/ControllableSystem.hpp new file mode 100644 index 00000000..7f81ae35 --- /dev/null +++ b/sources/System/Controllable/ControllableSystem.hpp @@ -0,0 +1,30 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// + +#pragma once + +#include "lib/wal/sources/System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle Controllable entities. + class ControllableSystem : public WAL::System + { + public: + //! @inherit + const std::type_info &getComponent() const override; + //! @inherit + void onFixedUpdate(WAL::Entity &entity) override; + + //! @brief A default constructor + ControllableSystem() = default; + //! @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; + }; +} diff --git a/sources/System/Keyboard/KeyboardSystem.cpp b/sources/System/Keyboard/KeyboardSystem.cpp new file mode 100644 index 00000000..3e4bd4aa --- /dev/null +++ b/sources/System/Keyboard/KeyboardSystem.cpp @@ -0,0 +1,38 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// + +#include "KeyboardSystem.hpp" +#include "sources/Component/Keyboard/KeyboardComponent.hpp" +#include "sources/Component/Controllable/ControllableComponent.hpp" +#include "lib/wal/sources/Entity/Entity.hpp" + +namespace BBM +{ + const std::type_info &KeyboardSystem::getComponent() const + { + return typeid(KeyboardComponent); + } + + void KeyboardSystem::onFixedUpdate(WAL::Entity &entity) + { + auto &keyboard = entity.getComponent(); + auto &controllable= entity.getComponent(); + + if (RAY::IsKeyPressed(keyboard.keyRight)) + controllable._right = true; + if (RAY::IsKeyPressed(keyboard.keyLeft)) + controllable._left = true; + if (RAY::IsKeyPressed(keyboard.keyUp)) + controllable._up = true; + if (RAY::IsKeyPressed(keyboard.keyDown)) + controllable._down = true; + if (RAY::IsKeyPressed(keyboard.keyBomb)) + controllable._bomb = true; + if (RAY::IsKeyPressed(keyboard.keyJump)) + controllable._jump = true; + if (RAY::IsKeyPressed(keyboard.keyPause)) + controllable._pause = true; + } +} \ No newline at end of file diff --git a/sources/System/Keyboard/KeyboardSystem.hpp b/sources/System/Keyboard/KeyboardSystem.hpp new file mode 100644 index 00000000..3127c2a6 --- /dev/null +++ b/sources/System/Keyboard/KeyboardSystem.hpp @@ -0,0 +1,30 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// + +#pragma once + +#include "lib/wal/sources/System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle keyboard entities. + class KeyboardSystem : public WAL::System + { + public: + //! @inherit + const std::type_info &getComponent() const override; + //! @inherit + void onFixedUpdate(WAL::Entity &entity) override; + + //! @brief A default constructor + KeyboardSystem() = default; + //! @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; + }; +}