From ce38d5d8317b6e4d95a7299d0e41449c094117b1 Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Thu, 20 May 2021 14:58:44 +0200 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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