From ce38d5d8317b6e4d95a7299d0e41449c094117b1 Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Thu, 20 May 2021 14:58:44 +0200 Subject: [PATCH 01/18] Game Component Draft Draft of some game Component (Bomb, Character, PowerUp) + Camera --- .gitignore | 3 +- sources/Camera/Camera.cpp | 13 +++ sources/Camera/Camera.hpp | 29 ++++++ sources/Component/Bomb/BombComponent.cpp | 95 +++++++++++++++++++ sources/Component/Bomb/BombComponent.hpp | 95 +++++++++++++++++++ .../Character/CharacterComponent.cpp | 83 ++++++++++++++++ .../Character/CharacterComponent.hpp | 63 ++++++++++++ .../Component/PowerUp/PowerUpComponent.cpp | 50 ++++++++++ .../Component/PowerUp/PowerUpComponent.hpp | 56 +++++++++++ sources/main.cpp | 2 + 10 files changed, 488 insertions(+), 1 deletion(-) create mode 100644 sources/Camera/Camera.cpp create mode 100644 sources/Camera/Camera.hpp create mode 100644 sources/Component/Bomb/BombComponent.cpp create mode 100644 sources/Component/Bomb/BombComponent.hpp create mode 100644 sources/Component/Character/CharacterComponent.cpp create mode 100644 sources/Component/Character/CharacterComponent.hpp create mode 100644 sources/Component/PowerUp/PowerUpComponent.cpp create mode 100644 sources/Component/PowerUp/PowerUpComponent.hpp diff --git a/.gitignore b/.gitignore index a415037f..e27ebc19 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea cmake-build-debug -./bomberman \ No newline at end of file +./bomberman +.vscode \ No newline at end of file diff --git a/sources/Camera/Camera.cpp b/sources/Camera/Camera.cpp new file mode 100644 index 00000000..afcbe950 --- /dev/null +++ b/sources/Camera/Camera.cpp @@ -0,0 +1,13 @@ +// +// 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 "./Camera.hpp" + +Camera::Camera(std::string name) +: WAL::Entity(name) +{ + +} \ No newline at end of file diff --git a/sources/Camera/Camera.hpp b/sources/Camera/Camera.hpp new file mode 100644 index 00000000..333a9911 --- /dev/null +++ b/sources/Camera/Camera.hpp @@ -0,0 +1,29 @@ +// +// 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 +#include "lib/wal/sources/Entity/Entity.hpp" +#include "lib/wal/sources/Models/Vector3.hpp" + +class Camera : public WAL::Entity +{ + private: + std::string _name; + protected: + public: + Camera(std::string name); + ~Camera(); + + //! @brief camera zoom in + void zoomIn(WAL::Vector3f) const; + //! @brief camera zoom out + void zoomOut(WAL::Vector3f) const; + //! @brief camera zoom on + void zoomOn(WAL::Entity &) const; + +}; \ No newline at end of file diff --git a/sources/Component/Bomb/BombComponent.cpp b/sources/Component/Bomb/BombComponent.cpp new file mode 100644 index 00000000..e88f95e6 --- /dev/null +++ b/sources/Component/Bomb/BombComponent.cpp @@ -0,0 +1,95 @@ +// +// 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 "BombComponent.hpp" + +BombComponent::BombComponent(WAL::Entity &entity, BombType bombType, unsigned int ownerUid) +: WAL::Component(entity) +{ + this->_bombType = bombType; + this->_ownerUid = ownerUid; + this->_isGhosting = bombType == BombComponent::DANGEROUS ? true : false; + this->_isBreakingWall = false; + this->_explosionDist = 0; + this->_explosionHeight = 0; + this->_countdown = 0; + this->_explosionDamage = 0; +} + +BombComponent::~BombComponent() +{ + +} + +unsigned BombComponent::getCountdown() const +{ + return (this->_countdown); +} + +unsigned BombComponent::getExplosionDist() const +{ + return (this->_explosionDist); +} + +unsigned BombComponent::getExplosionHeight() const +{ + return (this->_explosionHeight); +} + +unsigned BombComponent::getExplosionDamage() const +{ + return (this->_explosionDamage); +} + +unsigned BombComponent::getOwnerUid() const +{ + return (this->_ownerUid); +} + +bool BombComponent::isBreakingWall() const +{ + return (this->_isBreakingWall); +} + +bool BombComponent::isGhosting() const +{ + return (this->_isGhosting); +} + +void BombComponent::setCountdown(unsigned countdown) +{ + this->_countdown = countdown; +} + +void BombComponent::setExplosionDist(unsigned explosionDist) +{ + this->_explosionDist = explosionDist; +} + +void BombComponent::setExplosionHeight(unsigned explosionHeight) +{ + this->_explosionHeight = explosionHeight; +} + +void BombComponent::setExplosionDamage(unsigned explosionDamage) +{ + this->_explosionDamage = explosionDamage; +} + +void BombComponent::setOwnerUid(unsigned ownerUid) +{ + this->_ownerUid = ownerUid; +} + +void BombComponent::setBreakingWall(bool isBreakingWall) +{ + this->_isBreakingWall = isBreakingWall; +} + +void BombComponent::setGhosting(bool isGhosting) +{ + this->_isBreakingWall = isBreakingWall; +} diff --git a/sources/Component/Bomb/BombComponent.hpp b/sources/Component/Bomb/BombComponent.hpp new file mode 100644 index 00000000..b235451c --- /dev/null +++ b/sources/Component/Bomb/BombComponent.hpp @@ -0,0 +1,95 @@ +// +// 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 +#include "lib/wal/sources/Component/Component.hpp" +#include "lib/wal/sources/Entity/Entity.hpp" +#include "lib/wal/sources/Models/Vector3.hpp" + +class BombComponent : public WAL::Component +{ + + public: + //! @brief Enum of bomb type + enum BombType { + CLASSIC, + REMOTE, + STICKY, + DANGEROUS, + THROWABLE + }; + //! @brief Constructor + BombComponent(WAL::Entity &entity, BombType bombType, unsigned int ownerUid); + ~BombComponent() override = default; + //! @brief A bomb component is copyable + BombComponent(const BombComponent &) = default; + //! @brief A bomb component is assignable + BombComponent &operator=(const BombComponent &) = delete; + + //! @brief Get the remaining time of the bomb + unsigned getCountdown() const; + //! @brief Get the explosion dist of the bomb + unsigned getExplosionDist() const; + //! @brief Get the explosion height of the bomb + unsigned getExplosionHeight() const; + //! @brief Get the damage of the bomb + unsigned getExplosionDamage() const; + //! @brief Get the owner uid + unsigned getOwnerUid() const; + //! @brief Is able to break wall + bool isBreakingWall() const; + //! @brief Is able to pass through wall + bool isGhosting() const; + + //! @brief Set the remaining time of the bomb + void setCountdown(unsigned countdown); + //! @brief Set the explosion dist of the bomb + void setExplosionDist(unsigned explosionDist); + //! @bries Set the explosion height of the bomb + void setExplosionHeight(unsigned explosionHeight); + //! @brief Set the damage of the bomb + void setExplosionDamage(unsigned explosionDamage); + //! @brief Set the owner uid + void setOwnerUid(unsigned isOwnerUid); + //! @brief Set ability to break wall + void setBreakingWall(bool isBreakingWall); + //! @brief set ability to pass through wall + void setGhosting(bool isGhosting); + + private: + //! @brief Direction enum + enum Direction { + UP, + RIGHT, + DOWN, + LEFT, + VERTICAL, // UP + DOWN + HORIZONTAL, // RIGHT + LEFT + CLASSIC, // UP + LEFT + RIGHT + DOWN + ALL, // SQUARE AROUND + }; + + //! @brief Pass through walls + bool _isGhosting; + //! @brief Is bomb breaking wall + bool _isBreakingWall; + //! @brief Explosion range of the bomb + unsigned _explosionDist; + //! @brief Explosion height + unsigned _explosionHeight; + //! @brief The time remaining before the explosion + unsigned _countdown; + //! @brief The damage of the bomb (on player) + unsigned _explosionDamage; + //! @brief The owner uid of the bomb + unsigned _ownerUid; + //! @brief bombType + BombComponent::BombType _bombType; + + protected: +}; \ No newline at end of file diff --git a/sources/Component/Character/CharacterComponent.cpp b/sources/Component/Character/CharacterComponent.cpp new file mode 100644 index 00000000..22c861f4 --- /dev/null +++ b/sources/Component/Character/CharacterComponent.cpp @@ -0,0 +1,83 @@ +// +// 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 "CharacterComponent.hpp" + +CharacterComponent::CharacterComponent(WAL::Entity &entity, BombComponent::BombType bombType) +: WAL::Component(entity) +{ + this->_bombType = bombType; + this->_canTriggerRemote = false; + this->_healthPoint = 1; + this->_isHuman = false; + this->_maxBombCount = 1; + this->_playerNumber = ++this->_nextPlayer; +} + +CharacterComponent::~CharacterComponent() +{ + +} + +unsigned CharacterComponent::getPlayerNumber() const +{ + return (this->_playerNumber); +} + +unsigned CharacterComponent::getHealthPoint() const +{ + return (this->_healthPoint); +} + +unsigned CharacterComponent::getMaxBombCount() const +{ + return(this->_maxBombCount); +} + +BombComponent::BombType CharacterComponent::getBombType() const +{ + return (this->_bombType); +} + +bool CharacterComponent::isHuman() const +{ + return (this->_isHuman); +} + +bool CharacterComponent::canTriggerRemote() const +{ + return (this->_canTriggerRemote); +} + +void CharacterComponent::setPlayerNumber(unsigned playerNumber) +{ + this->_playerNumber = playerNumber; +} + +void CharacterComponent::setHealthPoint(unsigned healthPoint) +{ + this->_healthPoint = healthPoint; +} + +unsigned CharacterComponent::setMaxBombCount(unsigned maxBombCount) +{ + this->_maxBombCount = maxBombCount; +} + +BombComponent::BombType CharacterComponent::setBombType(BombComponent::BombType bombType) +{ + this->_bombType = bombType; +} + +bool CharacterComponent::setIsHuman(bool isHuman) +{ + this->_isHuman = isHuman; +} + +bool CharacterComponent::setCanTriggerRemote(bool canTriggerRemote) +{ + this->_canTriggerRemote = canTriggerRemote; +} diff --git a/sources/Component/Character/CharacterComponent.hpp b/sources/Component/Character/CharacterComponent.hpp new file mode 100644 index 00000000..dc21f0ad --- /dev/null +++ b/sources/Component/Character/CharacterComponent.hpp @@ -0,0 +1,63 @@ +// +// 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 "lib/wal/sources/Component/Component.hpp" +#include "sources/Component/Bomb/BombComponent.hpp" +#include "lib/wal/sources/Models/Vector3.hpp" + +class CharacterComponent : public WAL::Component +{ + private: + //! @brief player number + unsigned _playerNumber; + //! @brief health point of the character + unsigned _healthPoint; + //! @brief maximum number of bombs a character can put + unsigned _maxBombCount; + //! @brief bomb type of the character + BombComponent::BombType _bombType; + //! @brief is player a human being + bool _isHuman; + //! @brief Remote bomb trigger available + bool _canTriggerRemote; + static unsigned _nextPlayer; + protected: + public: + + CharacterComponent(WAL::Entity &entity, BombComponent::BombType bombType); + ~CharacterComponent() override = default; + //! @brief A character component is copyable + CharacterComponent(const CharacterComponent &) = default; + //! @brief A character component is assignable + CharacterComponent &operator=(const CharacterComponent &) = delete; + + //! @brief get player number + unsigned getPlayerNumber() const; + //! @brief get health point of the character + unsigned getHealthPoint() const; + //! @brief get maximum number of bombs a character can put + unsigned getMaxBombCount() const; + //! @brief get bomb type of the character + BombComponent::BombType getBombType() const; + //! @brief is player a human being + bool isHuman() const; + //! @brief trigger can be remote + bool canTriggerRemote() const; + + //! @brief set player number + void setPlayerNumber(unsigned playerNumber); + //! @brief set health point of the character + void setHealthPoint(unsigned healthPoint); + //! @brief set maximum number of bombs a character can put + unsigned setMaxBombCount(unsigned maxBombCount); + //! @brief set bomb type of the character + BombComponent::BombType setBombType(BombComponent::BombType bombType); + //! @brief set if player is a human being + bool setIsHuman(bool isHuman); + //! @brief Remote bomb trigger available + bool setCanTriggerRemote(bool canTriggerRemote); + +}; \ No newline at end of file diff --git a/sources/Component/PowerUp/PowerUpComponent.cpp b/sources/Component/PowerUp/PowerUpComponent.cpp new file mode 100644 index 00000000..ca2d56e7 --- /dev/null +++ b/sources/Component/PowerUp/PowerUpComponent.cpp @@ -0,0 +1,50 @@ +// +// 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 "PowerUpComponent.hpp" + +PowerUpComponent::PowerUpComponent(WAL::Entity &entity, PowerUpType powerType, int duration, bool infinite) +: WAL::Component(entity) +{ + this->_duration = duration; + this->_isInfinite = infinite; + this->_powerUpType = powerType; +} + +PowerUpComponent::~PowerUpComponent() +{ + +} + +bool PowerUpComponent::getIsInfinite() const +{ + return (this->_isInfinite); +} + +unsigned PowerUpComponent::getDuration() const +{ + return (this->_duration); +} + +PowerUpComponent::PowerUpType PowerUpComponent::getPowerUpType() const +{ + return (this->_powerUpType); +} + +void PowerUpComponent::setIsInfinite(bool isInfinite) +{ + this->_isInfinite = isInfinite; +} + +void PowerUpComponent::setDuration(unsigned duration) +{ + this->_duration = duration; +} + +void PowerUpComponent::setPowerUpType(PowerUpType powerUpType) +{ + this->_powerUpType = powerUpType; +} \ No newline at end of file diff --git a/sources/Component/PowerUp/PowerUpComponent.hpp b/sources/Component/PowerUp/PowerUpComponent.hpp new file mode 100644 index 00000000..0173b80e --- /dev/null +++ b/sources/Component/PowerUp/PowerUpComponent.hpp @@ -0,0 +1,56 @@ +// +// 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" + +class PowerUpComponent : public WAL::Component +{ + public: + + enum PowerUpType { + SPEED, + FIREPOWER, + BOMBCOUNT, + BOMBKICK + }; + + PowerUpComponent(WAL::Entity &entity, PowerUpType powerType, int duration, bool infinite = false); + ~PowerUpComponent(); + //! @brief A power up component is copyable + PowerUpComponent(const PowerUpComponent &) = default; + //! @brief A power up component is assignable + PowerUpComponent &operator=(const PowerUpComponent &) = delete; + + //! @brief Get is the power up infinite + bool getIsInfinite() const; + //! @brief Get duration + unsigned getDuration() const; + //! @brief Get power up type + PowerUpType getPowerUpType() const; + + //! @brief Set if bomb duration infinite + void setIsInfinite(bool isInfinite); + //! @brief Set duration + void setDuration(unsigned duration); + //! @brief Set power up type + void setPowerUpType(PowerUpType powerUpType); + + protected: + private: + + + //! @brief Is the power up infinite + bool _isInfinite; + //! @brief Duration of the power up + unsigned _duration; + //! @brief Power up type + PowerUpType _powerUpType; + + +}; diff --git a/sources/main.cpp b/sources/main.cpp index 70491566..69749ce0 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -5,6 +5,8 @@ int main() { WAL::Wal wal; + auto sceneManager = wal.getSceneManager(); + //sceneManager.addScene(createGameScene); try { wal.run(); return 0; From b318442dc8ec065b0a6abdff2751bc0f6b1ffd99 Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Thu, 20 May 2021 16:28:10 +0200 Subject: [PATCH 02/18] HealthComponent / HealthSystem Component and system for health --- sources/Camera/Camera.cpp | 13 --- sources/Camera/Camera.hpp | 29 ------ sources/Component/Bomb/BombComponent.cpp | 95 ------------------- sources/Component/Bomb/BombComponent.hpp | 95 ------------------- .../Character/CharacterComponent.cpp | 83 ---------------- .../Character/CharacterComponent.hpp | 63 ------------ sources/Component/Health/HealthComponent.cpp | 43 +++++++++ sources/Component/Health/HealthComponent.hpp | 51 ++++++++++ .../Component/PowerUp/PowerUpComponent.cpp | 50 ---------- .../Component/PowerUp/PowerUpComponent.hpp | 56 ----------- sources/System/Health/HealthSystem.cpp | 19 ++++ sources/System/Health/HealthSystem.hpp | 30 ++++++ 12 files changed, 143 insertions(+), 484 deletions(-) delete mode 100644 sources/Camera/Camera.cpp delete mode 100644 sources/Camera/Camera.hpp delete mode 100644 sources/Component/Bomb/BombComponent.cpp delete mode 100644 sources/Component/Bomb/BombComponent.hpp delete mode 100644 sources/Component/Character/CharacterComponent.cpp delete mode 100644 sources/Component/Character/CharacterComponent.hpp create mode 100644 sources/Component/Health/HealthComponent.cpp create mode 100644 sources/Component/Health/HealthComponent.hpp delete mode 100644 sources/Component/PowerUp/PowerUpComponent.cpp delete mode 100644 sources/Component/PowerUp/PowerUpComponent.hpp create mode 100644 sources/System/Health/HealthSystem.cpp create mode 100644 sources/System/Health/HealthSystem.hpp diff --git a/sources/Camera/Camera.cpp b/sources/Camera/Camera.cpp deleted file mode 100644 index afcbe950..00000000 --- a/sources/Camera/Camera.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// 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 "./Camera.hpp" - -Camera::Camera(std::string name) -: WAL::Entity(name) -{ - -} \ No newline at end of file diff --git a/sources/Camera/Camera.hpp b/sources/Camera/Camera.hpp deleted file mode 100644 index 333a9911..00000000 --- a/sources/Camera/Camera.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// 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 -#include "lib/wal/sources/Entity/Entity.hpp" -#include "lib/wal/sources/Models/Vector3.hpp" - -class Camera : public WAL::Entity -{ - private: - std::string _name; - protected: - public: - Camera(std::string name); - ~Camera(); - - //! @brief camera zoom in - void zoomIn(WAL::Vector3f) const; - //! @brief camera zoom out - void zoomOut(WAL::Vector3f) const; - //! @brief camera zoom on - void zoomOn(WAL::Entity &) const; - -}; \ No newline at end of file diff --git a/sources/Component/Bomb/BombComponent.cpp b/sources/Component/Bomb/BombComponent.cpp deleted file mode 100644 index e88f95e6..00000000 --- a/sources/Component/Bomb/BombComponent.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// -// 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 "BombComponent.hpp" - -BombComponent::BombComponent(WAL::Entity &entity, BombType bombType, unsigned int ownerUid) -: WAL::Component(entity) -{ - this->_bombType = bombType; - this->_ownerUid = ownerUid; - this->_isGhosting = bombType == BombComponent::DANGEROUS ? true : false; - this->_isBreakingWall = false; - this->_explosionDist = 0; - this->_explosionHeight = 0; - this->_countdown = 0; - this->_explosionDamage = 0; -} - -BombComponent::~BombComponent() -{ - -} - -unsigned BombComponent::getCountdown() const -{ - return (this->_countdown); -} - -unsigned BombComponent::getExplosionDist() const -{ - return (this->_explosionDist); -} - -unsigned BombComponent::getExplosionHeight() const -{ - return (this->_explosionHeight); -} - -unsigned BombComponent::getExplosionDamage() const -{ - return (this->_explosionDamage); -} - -unsigned BombComponent::getOwnerUid() const -{ - return (this->_ownerUid); -} - -bool BombComponent::isBreakingWall() const -{ - return (this->_isBreakingWall); -} - -bool BombComponent::isGhosting() const -{ - return (this->_isGhosting); -} - -void BombComponent::setCountdown(unsigned countdown) -{ - this->_countdown = countdown; -} - -void BombComponent::setExplosionDist(unsigned explosionDist) -{ - this->_explosionDist = explosionDist; -} - -void BombComponent::setExplosionHeight(unsigned explosionHeight) -{ - this->_explosionHeight = explosionHeight; -} - -void BombComponent::setExplosionDamage(unsigned explosionDamage) -{ - this->_explosionDamage = explosionDamage; -} - -void BombComponent::setOwnerUid(unsigned ownerUid) -{ - this->_ownerUid = ownerUid; -} - -void BombComponent::setBreakingWall(bool isBreakingWall) -{ - this->_isBreakingWall = isBreakingWall; -} - -void BombComponent::setGhosting(bool isGhosting) -{ - this->_isBreakingWall = isBreakingWall; -} diff --git a/sources/Component/Bomb/BombComponent.hpp b/sources/Component/Bomb/BombComponent.hpp deleted file mode 100644 index b235451c..00000000 --- a/sources/Component/Bomb/BombComponent.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// -// 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 -#include "lib/wal/sources/Component/Component.hpp" -#include "lib/wal/sources/Entity/Entity.hpp" -#include "lib/wal/sources/Models/Vector3.hpp" - -class BombComponent : public WAL::Component -{ - - public: - //! @brief Enum of bomb type - enum BombType { - CLASSIC, - REMOTE, - STICKY, - DANGEROUS, - THROWABLE - }; - //! @brief Constructor - BombComponent(WAL::Entity &entity, BombType bombType, unsigned int ownerUid); - ~BombComponent() override = default; - //! @brief A bomb component is copyable - BombComponent(const BombComponent &) = default; - //! @brief A bomb component is assignable - BombComponent &operator=(const BombComponent &) = delete; - - //! @brief Get the remaining time of the bomb - unsigned getCountdown() const; - //! @brief Get the explosion dist of the bomb - unsigned getExplosionDist() const; - //! @brief Get the explosion height of the bomb - unsigned getExplosionHeight() const; - //! @brief Get the damage of the bomb - unsigned getExplosionDamage() const; - //! @brief Get the owner uid - unsigned getOwnerUid() const; - //! @brief Is able to break wall - bool isBreakingWall() const; - //! @brief Is able to pass through wall - bool isGhosting() const; - - //! @brief Set the remaining time of the bomb - void setCountdown(unsigned countdown); - //! @brief Set the explosion dist of the bomb - void setExplosionDist(unsigned explosionDist); - //! @bries Set the explosion height of the bomb - void setExplosionHeight(unsigned explosionHeight); - //! @brief Set the damage of the bomb - void setExplosionDamage(unsigned explosionDamage); - //! @brief Set the owner uid - void setOwnerUid(unsigned isOwnerUid); - //! @brief Set ability to break wall - void setBreakingWall(bool isBreakingWall); - //! @brief set ability to pass through wall - void setGhosting(bool isGhosting); - - private: - //! @brief Direction enum - enum Direction { - UP, - RIGHT, - DOWN, - LEFT, - VERTICAL, // UP + DOWN - HORIZONTAL, // RIGHT + LEFT - CLASSIC, // UP + LEFT + RIGHT + DOWN - ALL, // SQUARE AROUND - }; - - //! @brief Pass through walls - bool _isGhosting; - //! @brief Is bomb breaking wall - bool _isBreakingWall; - //! @brief Explosion range of the bomb - unsigned _explosionDist; - //! @brief Explosion height - unsigned _explosionHeight; - //! @brief The time remaining before the explosion - unsigned _countdown; - //! @brief The damage of the bomb (on player) - unsigned _explosionDamage; - //! @brief The owner uid of the bomb - unsigned _ownerUid; - //! @brief bombType - BombComponent::BombType _bombType; - - protected: -}; \ No newline at end of file diff --git a/sources/Component/Character/CharacterComponent.cpp b/sources/Component/Character/CharacterComponent.cpp deleted file mode 100644 index 22c861f4..00000000 --- a/sources/Component/Character/CharacterComponent.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// -// 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 "CharacterComponent.hpp" - -CharacterComponent::CharacterComponent(WAL::Entity &entity, BombComponent::BombType bombType) -: WAL::Component(entity) -{ - this->_bombType = bombType; - this->_canTriggerRemote = false; - this->_healthPoint = 1; - this->_isHuman = false; - this->_maxBombCount = 1; - this->_playerNumber = ++this->_nextPlayer; -} - -CharacterComponent::~CharacterComponent() -{ - -} - -unsigned CharacterComponent::getPlayerNumber() const -{ - return (this->_playerNumber); -} - -unsigned CharacterComponent::getHealthPoint() const -{ - return (this->_healthPoint); -} - -unsigned CharacterComponent::getMaxBombCount() const -{ - return(this->_maxBombCount); -} - -BombComponent::BombType CharacterComponent::getBombType() const -{ - return (this->_bombType); -} - -bool CharacterComponent::isHuman() const -{ - return (this->_isHuman); -} - -bool CharacterComponent::canTriggerRemote() const -{ - return (this->_canTriggerRemote); -} - -void CharacterComponent::setPlayerNumber(unsigned playerNumber) -{ - this->_playerNumber = playerNumber; -} - -void CharacterComponent::setHealthPoint(unsigned healthPoint) -{ - this->_healthPoint = healthPoint; -} - -unsigned CharacterComponent::setMaxBombCount(unsigned maxBombCount) -{ - this->_maxBombCount = maxBombCount; -} - -BombComponent::BombType CharacterComponent::setBombType(BombComponent::BombType bombType) -{ - this->_bombType = bombType; -} - -bool CharacterComponent::setIsHuman(bool isHuman) -{ - this->_isHuman = isHuman; -} - -bool CharacterComponent::setCanTriggerRemote(bool canTriggerRemote) -{ - this->_canTriggerRemote = canTriggerRemote; -} diff --git a/sources/Component/Character/CharacterComponent.hpp b/sources/Component/Character/CharacterComponent.hpp deleted file mode 100644 index dc21f0ad..00000000 --- a/sources/Component/Character/CharacterComponent.hpp +++ /dev/null @@ -1,63 +0,0 @@ -// -// 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 "lib/wal/sources/Component/Component.hpp" -#include "sources/Component/Bomb/BombComponent.hpp" -#include "lib/wal/sources/Models/Vector3.hpp" - -class CharacterComponent : public WAL::Component -{ - private: - //! @brief player number - unsigned _playerNumber; - //! @brief health point of the character - unsigned _healthPoint; - //! @brief maximum number of bombs a character can put - unsigned _maxBombCount; - //! @brief bomb type of the character - BombComponent::BombType _bombType; - //! @brief is player a human being - bool _isHuman; - //! @brief Remote bomb trigger available - bool _canTriggerRemote; - static unsigned _nextPlayer; - protected: - public: - - CharacterComponent(WAL::Entity &entity, BombComponent::BombType bombType); - ~CharacterComponent() override = default; - //! @brief A character component is copyable - CharacterComponent(const CharacterComponent &) = default; - //! @brief A character component is assignable - CharacterComponent &operator=(const CharacterComponent &) = delete; - - //! @brief get player number - unsigned getPlayerNumber() const; - //! @brief get health point of the character - unsigned getHealthPoint() const; - //! @brief get maximum number of bombs a character can put - unsigned getMaxBombCount() const; - //! @brief get bomb type of the character - BombComponent::BombType getBombType() const; - //! @brief is player a human being - bool isHuman() const; - //! @brief trigger can be remote - bool canTriggerRemote() const; - - //! @brief set player number - void setPlayerNumber(unsigned playerNumber); - //! @brief set health point of the character - void setHealthPoint(unsigned healthPoint); - //! @brief set maximum number of bombs a character can put - unsigned setMaxBombCount(unsigned maxBombCount); - //! @brief set bomb type of the character - BombComponent::BombType setBombType(BombComponent::BombType bombType); - //! @brief set if player is a human being - bool setIsHuman(bool isHuman); - //! @brief Remote bomb trigger available - bool setCanTriggerRemote(bool canTriggerRemote); - -}; \ 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..b08845d0 --- /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 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->die(); + else + this->_healthPoint -= damage; + } + + void HealthComponent::die(void) + { + this->setDisable(true); + } +} \ 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..131fc33d --- /dev/null +++ b/sources/Component/Health/HealthComponent.hpp @@ -0,0 +1,51 @@ +// +// 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 BBM +{ + 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 health to 0 + void die(void); + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief A 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 component can't be instantiated, it should be derived. + HealthComponent(const HealthComponent &) = default; + + //! @brief default destructor + ~HealthComponent() override = default; + + //! @brief A component can't be assigned + HealthComponent &operator=(const HealthComponent &) = delete; + + friend class HealthSystem; + }; +} \ No newline at end of file diff --git a/sources/Component/PowerUp/PowerUpComponent.cpp b/sources/Component/PowerUp/PowerUpComponent.cpp deleted file mode 100644 index ca2d56e7..00000000 --- a/sources/Component/PowerUp/PowerUpComponent.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// -// 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 "PowerUpComponent.hpp" - -PowerUpComponent::PowerUpComponent(WAL::Entity &entity, PowerUpType powerType, int duration, bool infinite) -: WAL::Component(entity) -{ - this->_duration = duration; - this->_isInfinite = infinite; - this->_powerUpType = powerType; -} - -PowerUpComponent::~PowerUpComponent() -{ - -} - -bool PowerUpComponent::getIsInfinite() const -{ - return (this->_isInfinite); -} - -unsigned PowerUpComponent::getDuration() const -{ - return (this->_duration); -} - -PowerUpComponent::PowerUpType PowerUpComponent::getPowerUpType() const -{ - return (this->_powerUpType); -} - -void PowerUpComponent::setIsInfinite(bool isInfinite) -{ - this->_isInfinite = isInfinite; -} - -void PowerUpComponent::setDuration(unsigned duration) -{ - this->_duration = duration; -} - -void PowerUpComponent::setPowerUpType(PowerUpType powerUpType) -{ - this->_powerUpType = powerUpType; -} \ No newline at end of file diff --git a/sources/Component/PowerUp/PowerUpComponent.hpp b/sources/Component/PowerUp/PowerUpComponent.hpp deleted file mode 100644 index 0173b80e..00000000 --- a/sources/Component/PowerUp/PowerUpComponent.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// -// 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" - -class PowerUpComponent : public WAL::Component -{ - public: - - enum PowerUpType { - SPEED, - FIREPOWER, - BOMBCOUNT, - BOMBKICK - }; - - PowerUpComponent(WAL::Entity &entity, PowerUpType powerType, int duration, bool infinite = false); - ~PowerUpComponent(); - //! @brief A power up component is copyable - PowerUpComponent(const PowerUpComponent &) = default; - //! @brief A power up component is assignable - PowerUpComponent &operator=(const PowerUpComponent &) = delete; - - //! @brief Get is the power up infinite - bool getIsInfinite() const; - //! @brief Get duration - unsigned getDuration() const; - //! @brief Get power up type - PowerUpType getPowerUpType() const; - - //! @brief Set if bomb duration infinite - void setIsInfinite(bool isInfinite); - //! @brief Set duration - void setDuration(unsigned duration); - //! @brief Set power up type - void setPowerUpType(PowerUpType powerUpType); - - protected: - private: - - - //! @brief Is the power up infinite - bool _isInfinite; - //! @brief Duration of the power up - unsigned _duration; - //! @brief Power up type - PowerUpType _powerUpType; - - -}; diff --git a/sources/System/Health/HealthSystem.cpp b/sources/System/Health/HealthSystem.cpp new file mode 100644 index 00000000..073f56e9 --- /dev/null +++ b/sources/System/Health/HealthSystem.cpp @@ -0,0 +1,19 @@ +// +// Edited by Benjamin Henry on 2021-05-20. +// Edited by Louis Auzuret on 2021-05-20. +// + +#include "HealthSystem.hpp" + +namespace BBM +{ + const std::type_info &HealthSystem::getComponent() const + { + return typeid(HealthComponent); + } + + void HealthSystem::onFixedUpdate(WAL::Entity &entity) + { + + } +} diff --git a/sources/System/Health/HealthSystem.hpp b/sources/System/Health/HealthSystem.hpp new file mode 100644 index 00000000..59215af0 --- /dev/null +++ b/sources/System/Health/HealthSystem.hpp @@ -0,0 +1,30 @@ +// +// Edited by Benjamin Henry on 2021-05-20. +// Edited by Louis Auzuret on 2021-05-20. +// + +#pragma once + +#include "Components/Health/HealthComponent.hpp" +#include "lib/wal/sources/System/System.hpp" + +namespace BBM +{ + class HealthSystem : public WAL::System + { + public: + //! @inherit + const std::type_info &getComponent() const override; + //! @inherit + void onFixedUpdate(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; + } +} \ No newline at end of file From a8cd709874cdece66410ee36f0ee723b3ab086a1 Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Thu, 20 May 2021 16:50:00 +0200 Subject: [PATCH 03/18] Fix HealthComponent --- sources/Component/Health/HealthComponent.cpp | 7 +++-- sources/System/Health/HealthSystem.cpp | 19 ------------- sources/System/Health/HealthSystem.hpp | 30 -------------------- 3 files changed, 4 insertions(+), 52 deletions(-) delete mode 100644 sources/System/Health/HealthSystem.cpp delete mode 100644 sources/System/Health/HealthSystem.hpp diff --git a/sources/Component/Health/HealthComponent.cpp b/sources/Component/Health/HealthComponent.cpp index b08845d0..28e93b1a 100644 --- a/sources/Component/Health/HealthComponent.cpp +++ b/sources/Component/Health/HealthComponent.cpp @@ -30,14 +30,15 @@ namespace BBM void HealthComponent::takeDmg(unsigned int damage) { - if (damage >= this->_healthPoint) + if (damage >= this->_healthPoint) { + this->_healthPoint = 0; this->die(); - else + } else this->_healthPoint -= damage; } void HealthComponent::die(void) { - this->setDisable(true); + this->_entity.setDisable(true) } } \ No newline at end of file diff --git a/sources/System/Health/HealthSystem.cpp b/sources/System/Health/HealthSystem.cpp deleted file mode 100644 index 073f56e9..00000000 --- a/sources/System/Health/HealthSystem.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Edited by Benjamin Henry on 2021-05-20. -// Edited by Louis Auzuret on 2021-05-20. -// - -#include "HealthSystem.hpp" - -namespace BBM -{ - const std::type_info &HealthSystem::getComponent() const - { - return typeid(HealthComponent); - } - - void HealthSystem::onFixedUpdate(WAL::Entity &entity) - { - - } -} diff --git a/sources/System/Health/HealthSystem.hpp b/sources/System/Health/HealthSystem.hpp deleted file mode 100644 index 59215af0..00000000 --- a/sources/System/Health/HealthSystem.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// -// Edited by Benjamin Henry on 2021-05-20. -// Edited by Louis Auzuret on 2021-05-20. -// - -#pragma once - -#include "Components/Health/HealthComponent.hpp" -#include "lib/wal/sources/System/System.hpp" - -namespace BBM -{ - class HealthSystem : public WAL::System - { - public: - //! @inherit - const std::type_info &getComponent() const override; - //! @inherit - void onFixedUpdate(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; - } -} \ No newline at end of file From da7694eb0b52c373bd493ccfc5dd0756a779bc69 Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Thu, 20 May 2021 16:55:28 +0200 Subject: [PATCH 04/18] Add BombHolder Component --- .../BombHolder/BombHolderComponent.cpp | 39 ++++++++++++++ .../BombHolder/BombHolderComponent.hpp | 54 +++++++++++++++++++ sources/Component/Health/HealthComponent.cpp | 2 +- sources/Component/Health/HealthComponent.hpp | 4 +- 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 sources/Component/BombHolder/BombHolderComponent.cpp create mode 100644 sources/Component/BombHolder/BombHolderComponent.hpp diff --git a/sources/Component/BombHolder/BombHolderComponent.cpp b/sources/Component/BombHolder/BombHolderComponent.cpp new file mode 100644 index 00000000..031dab8b --- /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 BBM +{ + 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..97e236d6 --- /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 BBM +{ + 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/Health/HealthComponent.cpp b/sources/Component/Health/HealthComponent.cpp index 28e93b1a..a129a24e 100644 --- a/sources/Component/Health/HealthComponent.cpp +++ b/sources/Component/Health/HealthComponent.cpp @@ -39,6 +39,6 @@ namespace BBM void HealthComponent::die(void) { - this->_entity.setDisable(true) + this->_entity.setDisable(true); } } \ No newline at end of file diff --git a/sources/Component/Health/HealthComponent.hpp b/sources/Component/Health/HealthComponent.hpp index 131fc33d..ecc67b12 100644 --- a/sources/Component/Health/HealthComponent.hpp +++ b/sources/Component/Health/HealthComponent.hpp @@ -25,7 +25,7 @@ namespace BBM //! @brief reduce health void takeDmg(unsigned int damage); - //! @brief health to 0 + //! @brief disable the entity void die(void); //! @inherit @@ -45,7 +45,5 @@ namespace BBM //! @brief A component can't be assigned HealthComponent &operator=(const HealthComponent &) = delete; - - friend class HealthSystem; }; } \ No newline at end of file From 7377301c4e71489c356cee5eb5ca5649605dcec9 Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Thu, 20 May 2021 17:59:34 +0200 Subject: [PATCH 05/18] Add basic controls components and system KeyboardComponents/System + ControllableComponents/ControllableSystem --- .../Controllable/ControllableComponent.cpp | 0 .../Controllable/ControllableComponent.hpp | 46 ++++++++++++++++ .../Component/Keyboard/KeyboardComponent.cpp | 14 +++++ .../Component/Keyboard/KeyboardComponent.hpp | 52 +++++++++++++++++++ .../Controllable/ControllableSystem.cpp | 34 ++++++++++++ .../Controllable/ControllableSystem.hpp | 30 +++++++++++ sources/System/Keyboard/KeyboardSystem.cpp | 38 ++++++++++++++ sources/System/Keyboard/KeyboardSystem.hpp | 30 +++++++++++ 8 files changed, 244 insertions(+) create mode 100644 sources/Component/Controllable/ControllableComponent.cpp create mode 100644 sources/Component/Controllable/ControllableComponent.hpp create mode 100644 sources/Component/Keyboard/KeyboardComponent.cpp create mode 100644 sources/Component/Keyboard/KeyboardComponent.hpp create mode 100644 sources/System/Controllable/ControllableSystem.cpp create mode 100644 sources/System/Controllable/ControllableSystem.hpp create mode 100644 sources/System/Keyboard/KeyboardSystem.cpp create mode 100644 sources/System/Keyboard/KeyboardSystem.hpp 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; + }; +} From 61e04f760a8a5e12827934fc511d1c86bab3e1ab Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Fri, 21 May 2021 14:15:42 +0200 Subject: [PATCH 06/18] Add healthSystem The component doesn't disable the entity anymore, the system does it by checking the component of the entity Co-Authored-By: Benjamin HENRY <44569175+EternalRat@users.noreply.github.com> --- sources/Component/Health/HealthComponent.cpp | 3 +- sources/Component/Health/HealthComponent.hpp | 2 ++ sources/System/Health/HealthSystem.cpp | 25 ++++++++++++++++ sources/System/Health/HealthSystem.hpp | 30 ++++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 sources/System/Health/HealthSystem.cpp create mode 100644 sources/System/Health/HealthSystem.hpp diff --git a/sources/Component/Health/HealthComponent.cpp b/sources/Component/Health/HealthComponent.cpp index a129a24e..bd3fff53 100644 --- a/sources/Component/Health/HealthComponent.cpp +++ b/sources/Component/Health/HealthComponent.cpp @@ -32,8 +32,7 @@ namespace BBM { if (damage >= this->_healthPoint) { this->_healthPoint = 0; - this->die(); - } else + } else this->_healthPoint -= damage; } diff --git a/sources/Component/Health/HealthComponent.hpp b/sources/Component/Health/HealthComponent.hpp index ecc67b12..41a8d920 100644 --- a/sources/Component/Health/HealthComponent.hpp +++ b/sources/Component/Health/HealthComponent.hpp @@ -45,5 +45,7 @@ namespace BBM //! @brief A component can't be assigned HealthComponent &operator=(const HealthComponent &) = delete; + + friend class HealthSystem; }; } \ No newline at end of file diff --git a/sources/System/Health/HealthSystem.cpp b/sources/System/Health/HealthSystem.cpp new file mode 100644 index 00000000..3b03337a --- /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 BBM +{ + const std::type_info &HealthSystem::getComponent() const + { + return typeid(HealthComponent); + } + + void HealthSystem::onFixedUpdate(WAL::Entity &entity) + { + auto &health = entity.getComponent(); + + if (health._healthPoint == 0); + health.die(); + } +} \ 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..8bf8eec5 --- /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 BBM +{ + //! @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; + }; +} From 54cb40aa0b220dd7dbfc1cabd4c7d9328ac50256 Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Fri, 21 May 2021 14:17:37 +0200 Subject: [PATCH 07/18] Modification on Controllable and Keyboard Add float variable instead of bool for the axes movement, and use of a map for classic keys Co-Authored-By: Benjamin HENRY <44569175+EternalRat@users.noreply.github.com> --- .../Controllable/ControllableComponent.hpp | 12 ++++------ .../Controllable/ControllableSystem.cpp | 15 +++--------- sources/System/Keyboard/KeyboardSystem.cpp | 23 +++++++++++-------- sources/System/Keyboard/KeyboardSystem.hpp | 1 + 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/sources/Component/Controllable/ControllableComponent.hpp b/sources/Component/Controllable/ControllableComponent.hpp index 1a784db6..fdab2cd8 100644 --- a/sources/Component/Controllable/ControllableComponent.hpp +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -13,13 +13,11 @@ namespace BBM class ControllableComponent : public WAL::Component { private: - bool _up; - bool _down; - bool _left; - bool _right; - bool _jump; - bool _bomb; - bool _pause; + float _moveX = 0; + float _moveZ = 0; + bool _jump = false; + bool _bomb = false; + bool _pause = false; public: //! @inherit diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp index 4658e61d..78044610 100644 --- a/sources/System/Controllable/ControllableSystem.cpp +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -17,18 +17,9 @@ namespace BBM void ControllableSystem::onFixedUpdate(WAL::Entity &entity) { - auto &controllable= entity.getComponent(); - auto &movable= entity.getComponent(); + 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)); + movable.addForce(WAL::Vector3f(controllable._moveX, 0, controllable._moveZ)); } } \ No newline at end of file diff --git a/sources/System/Keyboard/KeyboardSystem.cpp b/sources/System/Keyboard/KeyboardSystem.cpp index 3e4bd4aa..0c8216ba 100644 --- a/sources/System/Keyboard/KeyboardSystem.cpp +++ b/sources/System/Keyboard/KeyboardSystem.cpp @@ -19,20 +19,23 @@ namespace BBM { 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._right = true; + controllable._moveX += 1; if (RAY::IsKeyPressed(keyboard.keyLeft)) - controllable._left = true; + controllable._moveX -= 1; if (RAY::IsKeyPressed(keyboard.keyUp)) - controllable._up = true; + controllable._moveX += 1; 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; + controllable._moveX -= 1; } } \ No newline at end of file diff --git a/sources/System/Keyboard/KeyboardSystem.hpp b/sources/System/Keyboard/KeyboardSystem.hpp index 3127c2a6..5e0e6387 100644 --- a/sources/System/Keyboard/KeyboardSystem.hpp +++ b/sources/System/Keyboard/KeyboardSystem.hpp @@ -6,6 +6,7 @@ #pragma once #include "lib/wal/sources/System/System.hpp" +#include namespace BBM { From 80e9d674e9e638ef8f9130bc7fc2eecb54d8aa4d Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Fri, 21 May 2021 15:11:03 +0200 Subject: [PATCH 08/18] Fix documentation and remove friend keyword Remove friend keyword and put variables in public instead Fix documentation where the name of the component is not specified Co-Authored-By: Benjamin HENRY <44569175+EternalRat@users.noreply.github.com> --- .../Controllable/ControllableComponent.hpp | 47 ++++++++++--------- sources/Component/Health/HealthComponent.cpp | 4 +- sources/Component/Health/HealthComponent.hpp | 12 ++--- .../Component/Keyboard/KeyboardComponent.hpp | 8 ++-- sources/System/Health/HealthSystem.cpp | 4 +- sources/System/Keyboard/KeyboardSystem.cpp | 18 +++---- 6 files changed, 45 insertions(+), 48 deletions(-) diff --git a/sources/Component/Controllable/ControllableComponent.hpp b/sources/Component/Controllable/ControllableComponent.hpp index fdab2cd8..6a410802 100644 --- a/sources/Component/Controllable/ControllableComponent.hpp +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -11,34 +11,35 @@ namespace BBM { class ControllableComponent : public WAL::Component - { - private: - float _moveX = 0; - float _moveZ = 0; - bool _jump = false; - bool _bomb = false; - bool _pause = false; - public: + { + 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; + //! @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 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 Constructor + ControllableComponent(WAL::Entity &entity, unsigned int maxBombCount); - //! @brief A component can't be instantiated, it should be derived. - ControllableComponent(const ControllableComponent &) = default; + //! @brief A Controllable component can't be instantiated, it should be derived. + ControllableComponent(const ControllableComponent &) = default; - //! @brief default destructor - ~ControllableComponent() override = 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; + //! @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 index bd3fff53..fe81fabb 100644 --- a/sources/Component/Health/HealthComponent.cpp +++ b/sources/Component/Health/HealthComponent.cpp @@ -36,8 +36,8 @@ namespace BBM this->_healthPoint -= damage; } - void HealthComponent::die(void) + unsigned int HealthComponent::getHealthPoint(void) const { - this->_entity.setDisable(true); + return (this->_healthPoint); } } \ No newline at end of file diff --git a/sources/Component/Health/HealthComponent.hpp b/sources/Component/Health/HealthComponent.hpp index 41a8d920..f484d028 100644 --- a/sources/Component/Health/HealthComponent.hpp +++ b/sources/Component/Health/HealthComponent.hpp @@ -25,27 +25,25 @@ namespace BBM //! @brief reduce health void takeDmg(unsigned int damage); - //! @brief disable the entity - void die(void); + //! @brief return health point of the entity + unsigned int getHealthPoint(void) const; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; - //! @brief A component can't be instantiated, it should be derived. + //! @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 component can't be instantiated, it should be derived. + //! @brief A Health component can't be instantiated, it should be derived. HealthComponent(const HealthComponent &) = default; //! @brief default destructor ~HealthComponent() override = default; - //! @brief A component can't be assigned + //! @brief A Health component can't be assigned HealthComponent &operator=(const HealthComponent &) = delete; - - friend class HealthSystem; }; } \ No newline at end of file diff --git a/sources/Component/Keyboard/KeyboardComponent.hpp b/sources/Component/Keyboard/KeyboardComponent.hpp index dc5c74c0..b522296e 100644 --- a/sources/Component/Keyboard/KeyboardComponent.hpp +++ b/sources/Component/Keyboard/KeyboardComponent.hpp @@ -32,21 +32,19 @@ namespace BBM //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; - //! @brief A component can't be instantiated, it should be derived. + //! @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 component can't be instantiated, it should be derived. + //! @brief A Keyboard 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 + //! @brief A Keyboard component can't be assigned KeyboardComponent &operator=(const KeyboardComponent &) = delete; - - friend class KeyboardSystem; }; } \ No newline at end of file diff --git a/sources/System/Health/HealthSystem.cpp b/sources/System/Health/HealthSystem.cpp index 3b03337a..c0d435f8 100644 --- a/sources/System/Health/HealthSystem.cpp +++ b/sources/System/Health/HealthSystem.cpp @@ -19,7 +19,7 @@ namespace BBM { auto &health = entity.getComponent(); - if (health._healthPoint == 0); - health.die(); + if (health.getHealthPoint() == 0); + entity.setDisable(true); } } \ No newline at end of file diff --git a/sources/System/Keyboard/KeyboardSystem.cpp b/sources/System/Keyboard/KeyboardSystem.cpp index 0c8216ba..a994db01 100644 --- a/sources/System/Keyboard/KeyboardSystem.cpp +++ b/sources/System/Keyboard/KeyboardSystem.cpp @@ -20,22 +20,22 @@ namespace BBM 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} + {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; + controllable.moveX = 0; + controllable.moveZ = 0; if (RAY::IsKeyPressed(keyboard.keyRight)) - controllable._moveX += 1; + controllable.moveX += 1; if (RAY::IsKeyPressed(keyboard.keyLeft)) - controllable._moveX -= 1; + controllable.moveX -= 1; if (RAY::IsKeyPressed(keyboard.keyUp)) - controllable._moveX += 1; + controllable.moveX += 1; if (RAY::IsKeyPressed(keyboard.keyDown)) - controllable._moveX -= 1; + controllable.moveX -= 1; } } \ No newline at end of file From ee2f2d5befe5ccd5cad27eeb3b2dfad5cccd5e5b Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 24 May 2021 15:59:40 +0200 Subject: [PATCH 09/18] Adding components/systems to the cmake --- CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c6cf9dd..8c68e2e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,24 @@ 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/Keyboard/KeyboardComponent.cpp + sources/Component/Keyboard/KeyboardComponent.hpp + sources/Component/BombHolder/BombHolderComponent.cpp + sources/Component/BombHolder/BombHolderComponent.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/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 ) From 199b2869785de393acfe569b7a9450372f4c2e59 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 24 May 2021 16:58:11 +0200 Subject: [PATCH 10/18] Fixing compilation --- CMakeLists.txt | 2 +- lib/Ray/sources/Controllers/Keyboard.hpp | 1 - .../BombHolder/BombHolderComponent.cpp | 2 +- .../BombHolder/BombHolderComponent.hpp | 6 +-- .../Controllable/ControllableComponent.cpp | 17 +++++++++ .../Controllable/ControllableComponent.hpp | 18 +++------ sources/Component/Health/HealthComponent.cpp | 2 +- sources/Component/Health/HealthComponent.hpp | 6 +-- .../Component/Keyboard/KeyboardComponent.cpp | 11 ++++-- .../Component/Keyboard/KeyboardComponent.hpp | 31 ++++++++------- .../Component/Movable/MovableComponent.cpp | 2 +- .../Component/Movable/MovableComponent.hpp | 2 +- .../Component/Position/PositionComponent.cpp | 2 +- .../Component/Position/PositionComponent.hpp | 2 +- sources/Models/GameState.hpp | 2 +- sources/Models/Vector3.hpp | 4 +- sources/Runner/Runner.cpp | 2 +- sources/Runner/Runner.hpp | 2 +- .../Controllable/ControllableSystem.cpp | 22 ++++++----- .../Controllable/ControllableSystem.hpp | 8 ++-- sources/System/Health/HealthSystem.cpp | 17 +++++---- sources/System/Health/HealthSystem.hpp | 8 ++-- sources/System/Keyboard/KeyboardSystem.cpp | 38 +++++++++++-------- sources/System/Keyboard/KeyboardSystem.hpp | 8 ++-- sources/System/Movable/MovableSystem.cpp | 2 +- sources/System/Movable/MovableSystem.hpp | 2 +- sources/main.cpp | 2 +- tests/EngineTests.cpp | 2 +- tests/EntityTests.cpp | 2 +- 29 files changed, 121 insertions(+), 104 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c68e2e5..94c6d3e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ set(SOURCES add_executable(bomberman sources/main.cpp ${SOURCES} -) + sources/Component/Controllable/ControllableComponent.cpp) target_include_directories(bomberman PUBLIC sources) target_link_libraries(bomberman PUBLIC wal ray) diff --git a/lib/Ray/sources/Controllers/Keyboard.hpp b/lib/Ray/sources/Controllers/Keyboard.hpp index be5c54d2..dcb474ce 100644 --- a/lib/Ray/sources/Controllers/Keyboard.hpp +++ b/lib/Ray/sources/Controllers/Keyboard.hpp @@ -1,4 +1,3 @@ - /* ** EPITECH PROJECT, 2021 ** Bomberman diff --git a/sources/Component/BombHolder/BombHolderComponent.cpp b/sources/Component/BombHolder/BombHolderComponent.cpp index 3be639cf..031dab8b 100644 --- a/sources/Component/BombHolder/BombHolderComponent.cpp +++ b/sources/Component/BombHolder/BombHolderComponent.cpp @@ -6,7 +6,7 @@ #include "BombHolderComponent.hpp" -namespace Bomberman +namespace BBM { BombHolderComponent::BombHolderComponent(WAL::Entity &entity) : WAL::Component(entity), diff --git a/sources/Component/BombHolder/BombHolderComponent.hpp b/sources/Component/BombHolder/BombHolderComponent.hpp index 1d9c8570..049fd56c 100644 --- a/sources/Component/BombHolder/BombHolderComponent.hpp +++ b/sources/Component/BombHolder/BombHolderComponent.hpp @@ -6,10 +6,10 @@ #pragma once -#include "lib/wal/sources/Component/Component.hpp" -#include "lib/wal/sources/Entity/Entity.hpp" +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" -namespace Bomberman +namespace BBM { class BombHolderComponent : public WAL::Component { diff --git a/sources/Component/Controllable/ControllableComponent.cpp b/sources/Component/Controllable/ControllableComponent.cpp index e69de29b..959d372a 100644 --- a/sources/Component/Controllable/ControllableComponent.cpp +++ b/sources/Component/Controllable/ControllableComponent.cpp @@ -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); + } +} \ No newline at end of file diff --git a/sources/Component/Controllable/ControllableComponent.hpp b/sources/Component/Controllable/ControllableComponent.hpp index cae6f480..dffb1932 100644 --- a/sources/Component/Controllable/ControllableComponent.hpp +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -5,10 +5,10 @@ #pragma once -#include "lib/wal/sources/Component/Component.hpp" -#include "lib/wal/sources/Entity/Entity.hpp" +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" -namespace Bomberman +namespace BBM { class ControllableComponent : public WAL::Component { @@ -27,19 +27,13 @@ namespace Bomberman //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; - //! @brief A Controllable component can't be instantiated, it should be derived. + //! @brief Initialize a new controllable component. 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. + //! @brief A Controllable component is copy constructable. ControllableComponent(const ControllableComponent &) = default; - //! @brief default destructor ~ControllableComponent() override = default; - - //! @brief A Controllable omponent can't be assigned + //! @brief A Controllable component 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 index 0a336336..fe81fabb 100644 --- a/sources/Component/Health/HealthComponent.cpp +++ b/sources/Component/Health/HealthComponent.cpp @@ -6,7 +6,7 @@ #include "HealthComponent.hpp" -namespace Bomberman +namespace BBM { HealthComponent::HealthComponent(WAL::Entity &entity) : WAL::Component(entity), diff --git a/sources/Component/Health/HealthComponent.hpp b/sources/Component/Health/HealthComponent.hpp index f0492fb4..a7c72c7f 100644 --- a/sources/Component/Health/HealthComponent.hpp +++ b/sources/Component/Health/HealthComponent.hpp @@ -6,10 +6,10 @@ #pragma once -#include "lib/wal/sources/Component/Component.hpp" -#include "lib/wal/sources/Entity/Entity.hpp" +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" -namespace Bomberman +namespace BBM { class HealthComponent : public WAL::Component { diff --git a/sources/Component/Keyboard/KeyboardComponent.cpp b/sources/Component/Keyboard/KeyboardComponent.cpp index 2fb8b71b..de379862 100644 --- a/sources/Component/Keyboard/KeyboardComponent.cpp +++ b/sources/Component/Keyboard/KeyboardComponent.cpp @@ -5,10 +5,15 @@ #include "KeyboardComponent.hpp" -namespace Bomberman +namespace BBM { KeyboardComponent::KeyboardComponent(WAL::Entity &entity) - : WAL::Component(entity) + : WAL::Component(entity) {} - + + WAL::Component *KeyboardComponent::clone(WAL::Entity &entity) const + { + return new KeyboardComponent(entity); + } + } // namespace BMM diff --git a/sources/Component/Keyboard/KeyboardComponent.hpp b/sources/Component/Keyboard/KeyboardComponent.hpp index 435ebdfe..f18e54a4 100644 --- a/sources/Component/Keyboard/KeyboardComponent.hpp +++ b/sources/Component/Keyboard/KeyboardComponent.hpp @@ -5,40 +5,39 @@ #pragma once -#include "lib/wal/sources/Component/Component.hpp" -#include "lib/wal/sources/Entity/Entity.hpp" +#include +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" -namespace Bomberman +using Key = RAY::Controller::Keyboard::Key; + +namespace BBM { class KeyboardComponent : public WAL::Component { public: - //! @brief jump key - int keyJump; + Key keyJump = KEY_SPACE; //! @brief bomb key - int keyBomb; + Key keyBomb = KEY_E; //! @brief pause key - int keyPause; + Key keyPause = KEY_ESCAPE; //! @brief move right key - int keyRight; + Key keyRight = KEY_Q; //! @brief move left key - int keyLeft; + Key keyLeft = KEY_D; //! @brief move up key - int keyUp; + Key keyUp = KEY_Z; //! @brief move down key - int keyDown; + Key keyDown = KEY_S; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; - //! @brief A Keyboard component can't be instantiated, it should be derived. + //! @brief Create a new keyboard component using default keys. 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. + //! @brief A Keyboard component is copy constructable. KeyboardComponent(const KeyboardComponent &) = default; //! @brief default destructor diff --git a/sources/Component/Movable/MovableComponent.cpp b/sources/Component/Movable/MovableComponent.cpp index c0e9e52d..2bbbde92 100644 --- a/sources/Component/Movable/MovableComponent.cpp +++ b/sources/Component/Movable/MovableComponent.cpp @@ -4,7 +4,7 @@ #include "MovableComponent.hpp" -namespace Bomberman +namespace BBM { MovableComponent::MovableComponent(WAL::Entity &entity) : Component(entity) diff --git a/sources/Component/Movable/MovableComponent.hpp b/sources/Component/Movable/MovableComponent.hpp index 2f194378..5266232a 100644 --- a/sources/Component/Movable/MovableComponent.hpp +++ b/sources/Component/Movable/MovableComponent.hpp @@ -7,7 +7,7 @@ #include "Models/Vector3.hpp" #include "Entity/Entity.hpp" -namespace Bomberman +namespace BBM { //! @brief A component to place on entities that can move or be moved. class MovableComponent : public WAL::Component diff --git a/sources/Component/Position/PositionComponent.cpp b/sources/Component/Position/PositionComponent.cpp index d992a4a5..c237f845 100644 --- a/sources/Component/Position/PositionComponent.cpp +++ b/sources/Component/Position/PositionComponent.cpp @@ -4,7 +4,7 @@ #include "PositionComponent.hpp" -namespace Bomberman +namespace BBM { PositionComponent::PositionComponent(WAL::Entity &entity) : Component(entity), diff --git a/sources/Component/Position/PositionComponent.hpp b/sources/Component/Position/PositionComponent.hpp index 18c5faee..368934eb 100644 --- a/sources/Component/Position/PositionComponent.hpp +++ b/sources/Component/Position/PositionComponent.hpp @@ -7,7 +7,7 @@ #include "Models/Vector3.hpp" #include "Component/Component.hpp" -namespace Bomberman +namespace BBM { //! @brief A basic position component class PositionComponent : public WAL::Component diff --git a/sources/Models/GameState.hpp b/sources/Models/GameState.hpp index 7be6b723..883578bf 100644 --- a/sources/Models/GameState.hpp +++ b/sources/Models/GameState.hpp @@ -9,7 +9,7 @@ #include -namespace Bomberman +namespace BBM { //! @brief A class representing the current game state. This allow one to retain information between update calls. class GameState diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index ab642e94..094f6da9 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -8,7 +8,7 @@ #include #include -namespace Bomberman +namespace BBM { //! @brief A Vector3 data type. (templated to allow any kind of vector3) template @@ -160,7 +160,7 @@ namespace Bomberman } template -std::ostream &operator<<(std::ostream &s, const Bomberman::Vector3 &v) +std::ostream &operator<<(std::ostream &s, const BBM::Vector3 &v) { s << "Vector3<" << typeid(T).name() << ">("<< v.x << ", " << v.y << ", " << v.z << ")"; return s; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 837831cc..ff2dc933 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -7,7 +7,7 @@ #include "Runner.hpp" #include "Models/GameState.hpp" -namespace Bomberman +namespace BBM { void updateState(WAL::Wal &engine, GameState &state) { diff --git a/sources/Runner/Runner.hpp b/sources/Runner/Runner.hpp index 4531039a..0f622f11 100644 --- a/sources/Runner/Runner.hpp +++ b/sources/Runner/Runner.hpp @@ -4,7 +4,7 @@ #pragma once -namespace Bomberman +namespace BBM { //! @brief Start the game and run a Bomberman. //! @return 0 on success, another value on error. diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp index d9a02fb0..5b596d76 100644 --- a/sources/System/Controllable/ControllableSystem.cpp +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -4,22 +4,24 @@ // #include "ControllableSystem.hpp" -#include "lib/wal/sources/Component/Movable/MovableComponent.hpp" -#include "sources/Component/Controllable/ControllableComponent.hpp" -#include "lib/wal/sources/Entity/Entity.hpp" +#include "Component/Movable/MovableComponent.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Entity/Entity.hpp" -namespace Bomberman +namespace BBM { - const std::type_info &ControllableSystem::getComponent() const - { - return typeid(ControllableComponent); - } + ControllableSystem::ControllableSystem() + : WAL::System({ + typeid(ControllableComponent), + typeid(MovableComponent) + }) + {} void ControllableSystem::onFixedUpdate(WAL::Entity &entity) { auto &controllable = entity.getComponent(); - auto &movable = entity.getComponent(); + auto &movable = entity.getComponent(); - movable.addForce(WAL::Vector3f(controllable._moveX, 0, controllable._moveZ)); + movable.addForce(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 index 032ea244..576cb98a 100644 --- a/sources/System/Controllable/ControllableSystem.hpp +++ b/sources/System/Controllable/ControllableSystem.hpp @@ -5,21 +5,19 @@ #pragma once -#include "lib/wal/sources/System/System.hpp" +#include "System/System.hpp" -namespace Bomberman +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; + ControllableSystem(); //! @brief A Controllable system is copy constructable ControllableSystem(const ControllableSystem &) = default; //! @brief A default destructor diff --git a/sources/System/Health/HealthSystem.cpp b/sources/System/Health/HealthSystem.cpp index 4c72c83a..a3ecee88 100644 --- a/sources/System/Health/HealthSystem.cpp +++ b/sources/System/Health/HealthSystem.cpp @@ -4,16 +4,17 @@ // #include "HealthSystem.hpp" -#include "sources/Component/Health/HealthComponent.hpp" -#include "sources/Component/Controllable/ControllableComponent.hpp" -#include "lib/wal/sources/Entity/Entity.hpp" +#include "Component/Health/HealthComponent.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Entity/Entity.hpp" -namespace Bomberman +namespace BBM { - const std::type_info &HealthSystem::getComponent() const - { - return typeid(HealthComponent); - } + HealthSystem::HealthSystem() + : WAL::System({ + typeid(HealthComponent) + }) + {} void HealthSystem::onFixedUpdate(WAL::Entity &entity) { diff --git a/sources/System/Health/HealthSystem.hpp b/sources/System/Health/HealthSystem.hpp index ebe67810..15ca2062 100644 --- a/sources/System/Health/HealthSystem.hpp +++ b/sources/System/Health/HealthSystem.hpp @@ -5,21 +5,19 @@ #pragma once -#include "lib/wal/sources/System/System.hpp" +#include "System/System.hpp" -namespace Bomberman +namespace BBM { //! @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; + HealthSystem(); //! @brief A Health system is copy constructable HealthSystem(const HealthSystem &) = default; //! @brief A default destructor diff --git a/sources/System/Keyboard/KeyboardSystem.cpp b/sources/System/Keyboard/KeyboardSystem.cpp index e0b9a228..a9dd52d4 100644 --- a/sources/System/Keyboard/KeyboardSystem.cpp +++ b/sources/System/Keyboard/KeyboardSystem.cpp @@ -4,38 +4,44 @@ // #include "KeyboardSystem.hpp" -#include "sources/Component/Keyboard/KeyboardComponent.hpp" -#include "sources/Component/Controllable/ControllableComponent.hpp" -#include "lib/wal/sources/Entity/Entity.hpp" +#include "Component/Keyboard/KeyboardComponent.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Entity/Entity.hpp" +#include "Controllers/Keyboard.hpp" -namespace Bomberman +using Keyboard = RAY::Controller::Keyboard; + +namespace BBM { - const std::type_info &KeyboardSystem::getComponent() const - { - return typeid(KeyboardComponent); - } + KeyboardSystem::KeyboardSystem() + : WAL::System({ + typeid(KeyboardComponent), + typeid(ControllableComponent) + }) + {} void KeyboardSystem::onFixedUpdate(WAL::Entity &entity) { - auto &keyboard = entity.getComponent(); - auto &controllable= entity.getComponent(); - static const std::map keyPressedMap = { + const auto &keyboard = entity.getComponent(); + auto &controllable = entity.getComponent(); + + 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); + key.second = Keyboard::isPressed(key.first); controllable.moveX = 0; controllable.moveZ = 0; - if (RAY::IsKeyPressed(keyboard.keyRight)) + if (Keyboard::isPressed(keyboard.keyRight)) controllable.moveX += 1; - if (RAY::IsKeyPressed(keyboard.keyLeft)) + if (Keyboard::isPressed(keyboard.keyLeft)) controllable.moveX -= 1; - if (RAY::IsKeyPressed(keyboard.keyUp)) + if (Keyboard::isPressed(keyboard.keyUp)) controllable.moveX += 1; - if (RAY::IsKeyPressed(keyboard.keyDown)) + if (Keyboard::isPressed(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 index 0c43547d..f17c5f15 100644 --- a/sources/System/Keyboard/KeyboardSystem.hpp +++ b/sources/System/Keyboard/KeyboardSystem.hpp @@ -5,22 +5,20 @@ #pragma once -#include "lib/wal/sources/System/System.hpp" +#include "System/System.hpp" #include -namespace Bomberman +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; + KeyboardSystem(); //! @brief A keyboard system is copy constructable KeyboardSystem(const KeyboardSystem &) = default; //! @brief A default destructor diff --git a/sources/System/Movable/MovableSystem.cpp b/sources/System/Movable/MovableSystem.cpp index d8b88a48..2f699ece 100644 --- a/sources/System/Movable/MovableSystem.cpp +++ b/sources/System/Movable/MovableSystem.cpp @@ -7,7 +7,7 @@ #include "Component/Movable/MovableComponent.hpp" #include "Wal.hpp" -namespace Bomberman +namespace BBM { MovableSystem::MovableSystem() : System({ diff --git a/sources/System/Movable/MovableSystem.hpp b/sources/System/Movable/MovableSystem.hpp index 0bb89652..08555d26 100644 --- a/sources/System/Movable/MovableSystem.hpp +++ b/sources/System/Movable/MovableSystem.hpp @@ -7,7 +7,7 @@ #include "System/System.hpp" -namespace Bomberman +namespace BBM { //! @brief A system to handle movable entities. This system update velocity based on accelerations and positions based on velocity. class MovableSystem : public WAL::System diff --git a/sources/main.cpp b/sources/main.cpp index d29f7374..cd4efc41 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -107,5 +107,5 @@ int main(int argc, char **argv) return 1; } return demo(); - return Bomberman::run(); + return BBM::run(); } diff --git a/tests/EngineTests.cpp b/tests/EngineTests.cpp index 8c908dac..804b6050 100644 --- a/tests/EngineTests.cpp +++ b/tests/EngineTests.cpp @@ -8,7 +8,7 @@ #include using namespace WAL; -using namespace Bomberman; +using namespace BBM; TEST_CASE("Create system", "[Engine][System]") { diff --git a/tests/EntityTests.cpp b/tests/EntityTests.cpp index 3b009cad..f58fd0c1 100644 --- a/tests/EntityTests.cpp +++ b/tests/EntityTests.cpp @@ -7,7 +7,7 @@ #include using namespace WAL; -using namespace Bomberman; +using namespace BBM; TEST_CASE("Component", "[Entity]") { From 384e812c1932f104b193ce8f88d05cb195d4e7ff Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 24 May 2021 18:08:50 +0200 Subject: [PATCH 11/18] Adding a grid centered component --- CMakeLists.txt | 6 ++-- .../GridCentered/GridCenteredComponent.cpp | 17 ++++++++++ .../GridCentered/GridCenteredComponent.hpp | 33 +++++++++++++++++++ .../GridCentered/GridCenteredSystem.cpp | 5 +++ .../GridCentered/GridCenteredSystem.hpp | 15 +++++++++ 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 sources/Component/GridCentered/GridCenteredComponent.cpp create mode 100644 sources/Component/GridCentered/GridCenteredComponent.hpp create mode 100644 sources/System/GridCentered/GridCenteredSystem.cpp create mode 100644 sources/System/GridCentered/GridCenteredSystem.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 94c6d3e6..c948f529 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,12 +36,14 @@ set(SOURCES 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) add_executable(bomberman sources/main.cpp ${SOURCES} - sources/Component/Controllable/ControllableComponent.cpp) +) target_include_directories(bomberman PUBLIC sources) target_link_libraries(bomberman PUBLIC wal ray) diff --git a/sources/Component/GridCentered/GridCenteredComponent.cpp b/sources/Component/GridCentered/GridCenteredComponent.cpp new file mode 100644 index 00000000..d4b333b4 --- /dev/null +++ b/sources/Component/GridCentered/GridCenteredComponent.cpp @@ -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); + } +} \ No newline at end of file diff --git a/sources/Component/GridCentered/GridCenteredComponent.hpp b/sources/Component/GridCentered/GridCenteredComponent.hpp new file mode 100644 index 00000000..d4de0eed --- /dev/null +++ b/sources/Component/GridCentered/GridCenteredComponent.hpp @@ -0,0 +1,33 @@ +// +// Created by Zoe Roux on 5/24/21. +// + +#pragma once + +#include + +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; + }; +} diff --git a/sources/System/GridCentered/GridCenteredSystem.cpp b/sources/System/GridCentered/GridCenteredSystem.cpp new file mode 100644 index 00000000..133c2160 --- /dev/null +++ b/sources/System/GridCentered/GridCenteredSystem.cpp @@ -0,0 +1,5 @@ +// +// Created by Zoe Roux on 5/24/21. +// + +#include "GridCenteredSystem.hpp" diff --git a/sources/System/GridCentered/GridCenteredSystem.hpp b/sources/System/GridCentered/GridCenteredSystem.hpp new file mode 100644 index 00000000..0c33bc92 --- /dev/null +++ b/sources/System/GridCentered/GridCenteredSystem.hpp @@ -0,0 +1,15 @@ +// +// Created by Zoe Roux on 5/24/21. +// + +#pragma once + +#include + +namespace BBM +{ + class GridCenteredSystem : public WAL::System + { + + }; +} From c6ab6542e0458730de94cdfec14899a46c6750c7 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 27 May 2021 12:11:34 +0200 Subject: [PATCH 12/18] Starting the grid centered system --- .../GridCentered/GridCenteredSystem.cpp | 20 +++++++++++++++++++ .../GridCentered/GridCenteredSystem.hpp | 11 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/sources/System/GridCentered/GridCenteredSystem.cpp b/sources/System/GridCentered/GridCenteredSystem.cpp index 133c2160..5dcca1a9 100644 --- a/sources/System/GridCentered/GridCenteredSystem.cpp +++ b/sources/System/GridCentered/GridCenteredSystem.cpp @@ -2,4 +2,24 @@ // 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(); + auto &movement = entity.getComponent(); +// movement.addForce(grid.force * ) + } +} \ No newline at end of file diff --git a/sources/System/GridCentered/GridCenteredSystem.hpp b/sources/System/GridCentered/GridCenteredSystem.hpp index 0c33bc92..206e9eca 100644 --- a/sources/System/GridCentered/GridCenteredSystem.hpp +++ b/sources/System/GridCentered/GridCenteredSystem.hpp @@ -8,8 +8,19 @@ namespace BBM { + //! @brief The system handling GridCenteredComponent class GridCenteredSystem : public WAL::System { + public: + void onFixedUpdate(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; }; } From cbbde0bc0c6b33735c1ec12e7fd0dcf43c50886f Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 31 May 2021 12:48:59 +0200 Subject: [PATCH 13/18] gamepad ecs --- CMakeLists.txt | 4 ++ .../Component/Gamepad/GamepadComponent.cpp | 34 ++++++++++ .../Component/Gamepad/GamepadComponent.hpp | 62 +++++++++++++++++++ sources/System/Gamepad/GamepadSystem.cpp | 45 ++++++++++++++ sources/System/Gamepad/GamepadSystem.hpp | 29 +++++++++ .../GridCentered/GridCenteredSystem.hpp | 2 +- 6 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 sources/Component/Gamepad/GamepadComponent.cpp create mode 100644 sources/Component/Gamepad/GamepadComponent.hpp create mode 100644 sources/System/Gamepad/GamepadSystem.cpp create mode 100644 sources/System/Gamepad/GamepadSystem.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c948f529..f4efb796 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,8 @@ set(SOURCES 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/BombHolder/BombHolderComponent.cpp @@ -29,6 +31,8 @@ set(SOURCES 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 diff --git a/sources/Component/Gamepad/GamepadComponent.cpp b/sources/Component/Gamepad/GamepadComponent.cpp new file mode 100644 index 00000000..0b889b7a --- /dev/null +++ b/sources/Component/Gamepad/GamepadComponent.cpp @@ -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 diff --git a/sources/Component/Gamepad/GamepadComponent.hpp b/sources/Component/Gamepad/GamepadComponent.hpp new file mode 100644 index 00000000..be00a49b --- /dev/null +++ b/sources/Component/Gamepad/GamepadComponent.hpp @@ -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; + }; +} \ No newline at end of file diff --git a/sources/System/Gamepad/GamepadSystem.cpp b/sources/System/Gamepad/GamepadSystem.cpp new file mode 100644 index 00000000..2a12a11b --- /dev/null +++ b/sources/System/Gamepad/GamepadSystem.cpp @@ -0,0 +1,45 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// + +#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(); + auto &controllable = entity.getComponent(); + Gamepad gamepad(gamepadComponent.getID()); + + const std::map keyPressedMap = { + {gamepadComponent.keyJump, controllable.jump}, + {gamepadComponent.keyBomb, controllable.bomb}, + {gamepadComponent.keyPause, controllable.pause} + }; + + for (auto key : keyPressedMap) + key.second = gamepad.isPressed(key.first); + controllable.moveX = 0; + controllable.moveZ = 0; + controllable.moveX += gamepad.isPressed(gamepadComponent.keyRight); + controllable.moveX -= gamepad.isPressed(gamepadComponent.keyLeft); + controllable.moveX += gamepad.isPressed(gamepadComponent.keyUp); + controllable.moveX -= gamepad.isPressed(gamepadComponent.keyDown); + } +} \ No newline at end of file diff --git a/sources/System/Gamepad/GamepadSystem.hpp b/sources/System/Gamepad/GamepadSystem.hpp new file mode 100644 index 00000000..775248c1 --- /dev/null +++ b/sources/System/Gamepad/GamepadSystem.hpp @@ -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 + +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; + }; +} diff --git a/sources/System/GridCentered/GridCenteredSystem.hpp b/sources/System/GridCentered/GridCenteredSystem.hpp index 206e9eca..e84e65fb 100644 --- a/sources/System/GridCentered/GridCenteredSystem.hpp +++ b/sources/System/GridCentered/GridCenteredSystem.hpp @@ -12,7 +12,7 @@ namespace BBM class GridCenteredSystem : public WAL::System { public: - void onFixedUpdate(Entity &entity) override; + void onFixedUpdate(WAL::Entity &entity) override; //! @brief A default constructor GridCenteredSystem(); From e24ad0fa50a0812c093c1330d4157ca3b717065f Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 31 May 2021 11:42:39 +0200 Subject: [PATCH 14/18] Cleaning up movements --- .../Controllable/ControllableComponent.hpp | 7 +++---- sources/Component/Renderer/CameraComponent.cpp | 5 +++-- sources/Component/Renderer/CameraComponent.hpp | 6 +++++- sources/Models/Vector2.hpp | 7 +++++++ sources/Models/Vector3.hpp | 8 ++++++++ sources/Runner/Runner.cpp | 2 +- sources/System/Controllable/ControllableSystem.cpp | 5 ++++- sources/System/Controllable/ControllableSystem.hpp | 3 +++ sources/System/Gamepad/GamepadSystem.cpp | 13 ++++++------- sources/System/Keyboard/KeyboardSystem.cpp | 11 +++++------ sources/System/Renderer/RenderScreenSystem.cpp | 2 ++ 11 files changed, 47 insertions(+), 22 deletions(-) diff --git a/sources/Component/Controllable/ControllableComponent.hpp b/sources/Component/Controllable/ControllableComponent.hpp index dffb1932..8376d43f 100644 --- a/sources/Component/Controllable/ControllableComponent.hpp +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -5,6 +5,7 @@ #pragma once +#include #include "Component/Component.hpp" #include "Entity/Entity.hpp" @@ -13,10 +14,8 @@ namespace BBM 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 The X and Z abscis of the movement. + Vector2f move; //! @brief input value for jump bool jump = false; //! @brief input value for bomb diff --git a/sources/Component/Renderer/CameraComponent.cpp b/sources/Component/Renderer/CameraComponent.cpp index 3f6c1239..5934d527 100644 --- a/sources/Component/Renderer/CameraComponent.cpp +++ b/sources/Component/Renderer/CameraComponent.cpp @@ -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 diff --git a/sources/Component/Renderer/CameraComponent.hpp b/sources/Component/Renderer/CameraComponent.hpp index 1aa5cc38..3f8e7fc5 100644 --- a/sources/Component/Renderer/CameraComponent.hpp +++ b/sources/Component/Renderer/CameraComponent.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include 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. diff --git a/sources/Models/Vector2.hpp b/sources/Models/Vector2.hpp index 07904949..629a11b8 100644 --- a/sources/Models/Vector2.hpp +++ b/sources/Models/Vector2.hpp @@ -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(); return Vector2(this->x / mag, this->y / mag); } diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index 5579b382..def6d322 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -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(); return Vector3(this->x / mag, this->y / mag, this->z / mag); } diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 7e0dce41..f6d9439e 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -72,7 +72,7 @@ namespace BBM .addComponent() .addComponent(); scene->addEntity("camera") - .addComponent(10, 10, 10) + .addComponent(0, 20, -5) .addComponent(); return scene; } diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp index 3c6dc01c..0a9c789c 100644 --- a/sources/System/Controllable/ControllableSystem.cpp +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -10,6 +10,8 @@ namespace BBM { + float ControllableSystem::speed = .25f; + ControllableSystem::ControllableSystem() : WAL::System({ typeid(ControllableComponent), @@ -21,7 +23,8 @@ namespace BBM { auto &controllable = entity.getComponent(); auto &movable = entity.getComponent(); + Vector2f move = controllable.move.normalized() * ControllableSystem::speed; - movable.addForce(Vector3f(controllable.moveX, controllable.jump, controllable.moveZ)); + movable.addForce(Vector3f(move.x, controllable.jump, move.y)); } } \ No newline at end of file diff --git a/sources/System/Controllable/ControllableSystem.hpp b/sources/System/Controllable/ControllableSystem.hpp index 576cb98a..fac4db08 100644 --- a/sources/System/Controllable/ControllableSystem.hpp +++ b/sources/System/Controllable/ControllableSystem.hpp @@ -13,6 +13,9 @@ namespace BBM class ControllableSystem : public WAL::System { public: + //! @brief The speed applied to every controllable entities. + static float speed; + //! @inherit void onFixedUpdate(WAL::Entity &entity) override; diff --git a/sources/System/Gamepad/GamepadSystem.cpp b/sources/System/Gamepad/GamepadSystem.cpp index 2a12a11b..03851be2 100644 --- a/sources/System/Gamepad/GamepadSystem.cpp +++ b/sources/System/Gamepad/GamepadSystem.cpp @@ -27,7 +27,7 @@ namespace BBM auto &controllable = entity.getComponent(); Gamepad gamepad(gamepadComponent.getID()); - const std::map keyPressedMap = { + const std::map keyPressedMap = { {gamepadComponent.keyJump, controllable.jump}, {gamepadComponent.keyBomb, controllable.bomb}, {gamepadComponent.keyPause, controllable.pause} @@ -35,11 +35,10 @@ namespace BBM for (auto key : keyPressedMap) key.second = gamepad.isPressed(key.first); - controllable.moveX = 0; - controllable.moveZ = 0; - controllable.moveX += gamepad.isPressed(gamepadComponent.keyRight); - controllable.moveX -= gamepad.isPressed(gamepadComponent.keyLeft); - controllable.moveX += gamepad.isPressed(gamepadComponent.keyUp); - controllable.moveX -= gamepad.isPressed(gamepadComponent.keyDown); + 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); } } \ No newline at end of file diff --git a/sources/System/Keyboard/KeyboardSystem.cpp b/sources/System/Keyboard/KeyboardSystem.cpp index 686cd8bf..13ad9804 100644 --- a/sources/System/Keyboard/KeyboardSystem.cpp +++ b/sources/System/Keyboard/KeyboardSystem.cpp @@ -34,15 +34,14 @@ namespace BBM for (auto key : keyPressedMap) key.second = Keyboard::isDown(key.first); - controllable.moveX = 0; - controllable.moveZ = 0; + controllable.move = Vector2f(); if (Keyboard::isDown(keyboard.keyRight)) - controllable.moveX += 1; + controllable.move.x += 1; if (Keyboard::isDown(keyboard.keyLeft)) - controllable.moveX -= 1; + controllable.move.x -= 1; if (Keyboard::isDown(keyboard.keyUp)) - controllable.moveZ += 1; + controllable.move.y += 1; if (Keyboard::isDown(keyboard.keyDown)) - controllable.moveZ -= 1; + controllable.move.y -= 1; } } \ No newline at end of file diff --git a/sources/System/Renderer/RenderScreenSystem.cpp b/sources/System/Renderer/RenderScreenSystem.cpp index 5523ee48..8eba847a 100644 --- a/sources/System/Renderer/RenderScreenSystem.cpp +++ b/sources/System/Renderer/RenderScreenSystem.cpp @@ -27,6 +27,8 @@ namespace BBM void RenderScreenSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) { const auto &pos = entity.getComponent(); + const auto &cam = entity.getComponent(); _camera.setPosition(pos.position); + _camera.setTarget(cam.target); } } \ No newline at end of file From d034514e28c8a1a5aadbc961ea23521c5169d1a2 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 31 May 2021 12:02:19 +0200 Subject: [PATCH 15/18] Adding tests and cleaning up --- CMakeLists.txt | 2 +- sources/Runner/Runner.cpp | 2 + sources/System/Gamepad/GamepadSystem.cpp | 3 +- sources/System/Gamepad/GamepadSystem.hpp | 3 +- tests/MoveTests.cpp | 51 ++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 tests/MoveTests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2642b3ab..2371cd9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,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) diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index f6d9439e..c6a6c196 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "Models/Vector2.hpp" #include "Component/Renderer/CameraComponent.hpp" #include "Runner.hpp" @@ -40,6 +41,7 @@ namespace BBM void addSystems(WAL::Wal &wal) { wal.addSystem() + .addSystem() .addSystem() .addSystem(); } diff --git a/sources/System/Gamepad/GamepadSystem.cpp b/sources/System/Gamepad/GamepadSystem.cpp index 03851be2..5df6bd96 100644 --- a/sources/System/Gamepad/GamepadSystem.cpp +++ b/sources/System/Gamepad/GamepadSystem.cpp @@ -1,6 +1,5 @@ // -// Created by Tom Augier on 2021-05-20. -// Edited by Benjamin Henry on 2021-05-20. +// Created by Arthur Jamet on 2021-05-31. // #include "GamepadSystem.hpp" diff --git a/sources/System/Gamepad/GamepadSystem.hpp b/sources/System/Gamepad/GamepadSystem.hpp index 775248c1..9c8c705f 100644 --- a/sources/System/Gamepad/GamepadSystem.hpp +++ b/sources/System/Gamepad/GamepadSystem.hpp @@ -1,6 +1,5 @@ // -// Created by Tom Augier on 2021-05-20. -// Edited by Benjamin Henry on 2021-05-20. +// Created by Arthur Jamet on 2021-05-31. // #pragma once diff --git a/tests/MoveTests.cpp b/tests/MoveTests.cpp new file mode 100644 index 00000000..cd37d22a --- /dev/null +++ b/tests/MoveTests.cpp @@ -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 +#include +#include + +#define private public +#include + +using namespace WAL; +using namespace BBM; + + +TEST_CASE("Move test", "[Component][System]") +{ + Scene scene; + scene.addEntity("player") + .addComponent() + .addComponent() + .addComponent(); + Entity &entity = scene.getEntities()[0]; + + REQUIRE(entity.getComponent().position == Vector3f()); + + entity.getComponent().move = Vector2f(1, 1); + + ControllableSystem controllable; + controllable.onUpdate(entity, std::chrono::nanoseconds(1)); + controllable.onFixedUpdate(entity); + REQUIRE(entity.getComponent()._acceleration.x > 0); + REQUIRE(entity.getComponent()._acceleration.z > 0); + + MovableSystem movable; + movable.onUpdate(entity, std::chrono::nanoseconds(1)); + movable.onFixedUpdate(entity); + REQUIRE(entity.getComponent()._velocity.x > 0); + REQUIRE(entity.getComponent()._velocity.z > 0); + REQUIRE(entity.getComponent()._acceleration.x == 0); + REQUIRE(entity.getComponent()._acceleration.z == 0); + movable.onUpdate(entity, std::chrono::nanoseconds(1)); + movable.onFixedUpdate(entity); + REQUIRE(entity.getComponent().position.x > 0); + REQUIRE(entity.getComponent().position.z > 0); + +} \ No newline at end of file From ae1dc589951686acdb5f53a40392761f6f499239 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 31 May 2021 16:19:25 +0200 Subject: [PATCH 16/18] Removing the bomb holder component from this pr --- .../BombHolder/BombHolderComponent.cpp | 39 -------------- .../BombHolder/BombHolderComponent.hpp | 54 ------------------- 2 files changed, 93 deletions(-) delete mode 100644 sources/Component/BombHolder/BombHolderComponent.cpp delete mode 100644 sources/Component/BombHolder/BombHolderComponent.hpp diff --git a/sources/Component/BombHolder/BombHolderComponent.cpp b/sources/Component/BombHolder/BombHolderComponent.cpp deleted file mode 100644 index 031dab8b..00000000 --- a/sources/Component/BombHolder/BombHolderComponent.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// -// 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 BBM -{ - 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 deleted file mode 100644 index 049fd56c..00000000 --- a/sources/Component/BombHolder/BombHolderComponent.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// -// 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 "Component/Component.hpp" -#include "Entity/Entity.hpp" - -namespace BBM -{ - 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 From 345cc721f44b36c10bf222aeb83494edc13ecce4 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 31 May 2021 16:30:30 +0200 Subject: [PATCH 17/18] Fixing the cmake --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2371cd9e..763064ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,8 +24,6 @@ set(SOURCES sources/Component/Gamepad/GamepadComponent.hpp sources/Component/Keyboard/KeyboardComponent.cpp sources/Component/Keyboard/KeyboardComponent.hpp - sources/Component/BombHolder/BombHolderComponent.cpp - sources/Component/BombHolder/BombHolderComponent.hpp sources/Component/Health/HealthComponent.cpp sources/Component/Health/HealthComponent.hpp sources/System/Movable/MovableSystem.hpp From 87c5703c60b65f331c261e7dcb2b6f2a1112c78b Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 31 May 2021 20:14:07 +0200 Subject: [PATCH 18/18] Adding a on death callback --- sources/Component/Health/HealthComponent.hpp | 4 ++++ sources/Runner/Runner.cpp | 2 +- sources/System/Health/HealthSystem.cpp | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sources/Component/Health/HealthComponent.hpp b/sources/Component/Health/HealthComponent.hpp index a7c72c7f..2eadafc5 100644 --- a/sources/Component/Health/HealthComponent.hpp +++ b/sources/Component/Health/HealthComponent.hpp @@ -6,6 +6,7 @@ #pragma once +#include #include "Component/Component.hpp" #include "Entity/Entity.hpp" @@ -19,6 +20,9 @@ namespace BBM unsigned int _healthPoint; public: + //! @brief The callback invoked on this entity's death. + WAL::Callback onDeath; + //! @brief add health to the entity void addHealthPoint(unsigned int healthPoint); diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index c6a6c196..9e527fcb 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -41,7 +41,7 @@ namespace BBM void addSystems(WAL::Wal &wal) { wal.addSystem() - .addSystem() + .addSystem() .addSystem() .addSystem(); } diff --git a/sources/System/Health/HealthSystem.cpp b/sources/System/Health/HealthSystem.cpp index a3ecee88..90bbfbb9 100644 --- a/sources/System/Health/HealthSystem.cpp +++ b/sources/System/Health/HealthSystem.cpp @@ -20,7 +20,7 @@ namespace BBM { auto &health = entity.getComponent(); - if (health.getHealthPoint() == 0); - entity.setDisable(true); + if (health.getHealthPoint() == 0) + health.onDeath(entity); } } \ No newline at end of file