diff --git a/sources/Component/BombHolder/BombHolderComponent.cpp b/sources/Component/BombHolder/BombHolderComponent.cpp new file mode 100644 index 00000000..3be639cf --- /dev/null +++ b/sources/Component/BombHolder/BombHolderComponent.cpp @@ -0,0 +1,39 @@ +// +// 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 "BombHolderComponent.hpp" + +namespace Bomberman +{ + BombHolderComponent::BombHolderComponent(WAL::Entity &entity) + : WAL::Component(entity), + _bombCount() + {} + + BombHolderComponent::BombHolderComponent(WAL::Entity &entity, unsigned int maxBombCount) + : WAL::Component(entity), + _bombCount(), + _maxBombCount(maxBombCount) + {} + + WAL::Component *BombHolderComponent::clone(WAL::Entity &entity) const + { + return new BombHolderComponent(entity); + } + + void BombHolderComponent::addBomb(unsigned int bombCount) + { + this->_bombCount += bombCount; + } + + void BombHolderComponent::removeBomb(unsigned int damage) + { + if (damage >= this->_bombCount) { + this->_bombCount = 0; + } else + this->_bombCount -= damage; + } +} \ No newline at end of file diff --git a/sources/Component/BombHolder/BombHolderComponent.hpp b/sources/Component/BombHolder/BombHolderComponent.hpp new file mode 100644 index 00000000..1d9c8570 --- /dev/null +++ b/sources/Component/BombHolder/BombHolderComponent.hpp @@ -0,0 +1,54 @@ +// +// 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 "lib/wal/sources/Component/Component.hpp" +#include "lib/wal/sources/Entity/Entity.hpp" + +namespace Bomberman +{ + class BombHolderComponent : public WAL::Component + { + + private: + //! @brief bomb count of an entity + unsigned int _bombCount; + //! @brief max bomb count of an entity + unsigned int _maxBombCount; + + public: + //! @brief add bomb to the entity + void addBomb(unsigned int bombCount); + + //! @brief add bomb bax of the entity + void addMaxBombCount(unsigned int maxBombCount); + + //! @brief reduce bomb max of the entity + void removeMaxBombCount(unsigned int bombCount); + + //! @brief reduce bomb + void removeBomb(unsigned int bombCount); + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief A component can't be instantiated, it should be derived. + explicit BombHolderComponent(WAL::Entity &entity); + + //! @brief Constructor + BombHolderComponent(WAL::Entity &entity, unsigned int maxBombCount); + + //! @brief A component can't be instantiated, it should be derived. + BombHolderComponent(const BombHolderComponent &) = default; + + //! @brief default destructor + ~BombHolderComponent() override = default; + + //! @brief A component can't be assigned + BombHolderComponent &operator=(const BombHolderComponent &) = delete; + }; +} \ No newline at end of file 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..cae6f480 --- /dev/null +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -0,0 +1,45 @@ +// +// 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 Bomberman +{ + class ControllableComponent : public WAL::Component + { + public: + //! @brief input value for X axe + float moveX = 0; + //! @brief input value for Z axe + float moveZ = 0; + //! @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 A Controllable 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 Controllable component can't be instantiated, it should be derived. + ControllableComponent(const ControllableComponent &) = default; + + //! @brief default destructor + ~ControllableComponent() override = default; + + //! @brief A Controllable omponent can't be assigned + ControllableComponent &operator=(const ControllableComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Component/Health/HealthComponent.cpp b/sources/Component/Health/HealthComponent.cpp new file mode 100644 index 00000000..0a336336 --- /dev/null +++ b/sources/Component/Health/HealthComponent.cpp @@ -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 Bomberman +{ + 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); + } +} \ No newline at end of file diff --git a/sources/Component/Health/HealthComponent.hpp b/sources/Component/Health/HealthComponent.hpp new file mode 100644 index 00000000..f0492fb4 --- /dev/null +++ b/sources/Component/Health/HealthComponent.hpp @@ -0,0 +1,49 @@ +// +// 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 "lib/wal/sources/Component/Component.hpp" +#include "lib/wal/sources/Entity/Entity.hpp" + +namespace Bomberman +{ + class HealthComponent : public WAL::Component + { + + private: + //! @brief life of an entity + unsigned int _healthPoint; + + public: + //! @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; + }; +} \ 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..2fb8b71b --- /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 Bomberman +{ + 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..435ebdfe --- /dev/null +++ b/sources/Component/Keyboard/KeyboardComponent.hpp @@ -0,0 +1,50 @@ +// +// 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 Bomberman +{ + 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 Keyboard 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 Keyboard component can't be instantiated, it should be derived. + KeyboardComponent(const KeyboardComponent &) = default; + + //! @brief default destructor + ~KeyboardComponent() override = default; + + //! @brief A Keyboard component can't be assigned + KeyboardComponent &operator=(const KeyboardComponent &) = delete; + }; +} \ 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..d9a02fb0 --- /dev/null +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -0,0 +1,25 @@ +// +// 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 Bomberman +{ + const std::type_info &ControllableSystem::getComponent() const + { + return typeid(ControllableComponent); + } + + void ControllableSystem::onFixedUpdate(WAL::Entity &entity) + { + auto &controllable = entity.getComponent(); + auto &movable = entity.getComponent(); + + movable.addForce(WAL::Vector3f(controllable._moveX, 0, controllable._moveZ)); + } +} \ 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..032ea244 --- /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 Bomberman +{ + //! @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/Health/HealthSystem.cpp b/sources/System/Health/HealthSystem.cpp new file mode 100644 index 00000000..4c72c83a --- /dev/null +++ b/sources/System/Health/HealthSystem.cpp @@ -0,0 +1,25 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// + +#include "HealthSystem.hpp" +#include "sources/Component/Health/HealthComponent.hpp" +#include "sources/Component/Controllable/ControllableComponent.hpp" +#include "lib/wal/sources/Entity/Entity.hpp" + +namespace Bomberman +{ + const std::type_info &HealthSystem::getComponent() const + { + return typeid(HealthComponent); + } + + void HealthSystem::onFixedUpdate(WAL::Entity &entity) + { + auto &health = entity.getComponent(); + + if (health.getHealthPoint() == 0); + entity.setDisable(true); + } +} \ No newline at end of file diff --git a/sources/System/Health/HealthSystem.hpp b/sources/System/Health/HealthSystem.hpp new file mode 100644 index 00000000..ebe67810 --- /dev/null +++ b/sources/System/Health/HealthSystem.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 Bomberman +{ + //! @brief A system to handle Health entities. + class HealthSystem : public WAL::System + { + public: + //! @inherit + const std::type_info &getComponent() const override; + //! @inherit + void onFixedUpdate(WAL::Entity &entity) override; + + //! @brief A default constructor + HealthSystem() = default; + //! @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; + }; +} diff --git a/sources/System/Keyboard/KeyboardSystem.cpp b/sources/System/Keyboard/KeyboardSystem.cpp new file mode 100644 index 00000000..e0b9a228 --- /dev/null +++ b/sources/System/Keyboard/KeyboardSystem.cpp @@ -0,0 +1,41 @@ +// +// 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 Bomberman +{ + const std::type_info &KeyboardSystem::getComponent() const + { + return typeid(KeyboardComponent); + } + + void KeyboardSystem::onFixedUpdate(WAL::Entity &entity) + { + auto &keyboard = entity.getComponent(); + auto &controllable= entity.getComponent(); + static const std::map keyPressedMap = { + {keyboard.keyJump, controllable.jump}, + {keyboard.keyBomb, controllable.bomb}, + {keyboard.keyPause, controllable.pause} + }; + + for (auto key : keyPressedMap) + key.second = RAY::IsKeyPressed(key.first); + controllable.moveX = 0; + controllable.moveZ = 0; + if (RAY::IsKeyPressed(keyboard.keyRight)) + controllable.moveX += 1; + if (RAY::IsKeyPressed(keyboard.keyLeft)) + controllable.moveX -= 1; + if (RAY::IsKeyPressed(keyboard.keyUp)) + controllable.moveX += 1; + if (RAY::IsKeyPressed(keyboard.keyDown)) + controllable.moveX -= 1; + } +} \ 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..0c43547d --- /dev/null +++ b/sources/System/Keyboard/KeyboardSystem.hpp @@ -0,0 +1,31 @@ +// +// 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" +#include + +namespace Bomberman +{ + //! @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; + }; +}