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]") {