diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b75620d..07b2e9ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,10 @@ set(SOURCES sources/Component/Collision/CollisionComponent.hpp sources/System/Collision/CollisionSystem.hpp sources/System/Collision/CollisionSystem.cpp + sources/System/Levitate/LevitateSystem.hpp + sources/System/Levitate/LevitateSystem.cpp + sources/Component/Levitate/LevitateComponent.cpp + sources/Component/Levitate/LevitateComponent.cpp ) add_executable(bomberman diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index aab5fdc6..740514a8 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -80,9 +80,9 @@ namespace RAY::Drawables::Drawables3D { return this->_rotationAngle; } - Model &Model::setRotationAxis(const RAY::Vector3 &scale) + Model &Model::setRotationAxis(const RAY::Vector3 &rotationAxis) { - this->_scale = scale; + this->_rotationAxis = rotationAxis; return *this; } diff --git a/lib/Ray/sources/Model/Model.hpp b/lib/Ray/sources/Model/Model.hpp index 7a7e3fdf..813ef26c 100644 --- a/lib/Ray/sources/Model/Model.hpp +++ b/lib/Ray/sources/Model/Model.hpp @@ -66,7 +66,7 @@ namespace RAY::Drawables::Drawables3D { float getRotationAngle(void); //! @brief Set Rotation Axis - Model &setRotationAxis(const RAY::Vector3 &scale); + Model &setRotationAxis(const RAY::Vector3 &rotationAxis); //! @return rotation axis const RAY::Vector3 & getRotationAxis(void); diff --git a/sources/Component/Levitate/LevitateComponent.cpp b/sources/Component/Levitate/LevitateComponent.cpp new file mode 100644 index 00000000..1e6f3c5f --- /dev/null +++ b/sources/Component/Levitate/LevitateComponent.cpp @@ -0,0 +1,24 @@ +// +// Created by hbenjamin on 07/06/2021. +// + +#include "LevitateComponent.hpp" + +namespace BBM +{ + LevitateComponent::LevitateComponent(WAL::Entity &entity) + : WAL::Component(entity), + y() + {} + + LevitateComponent::LevitateComponent(WAL::Entity &entity, float y) + : WAL::Component(entity), + y(y) + {} + + WAL::Component *LevitateComponent::clone(WAL::Entity &entity) const + { + return new LevitateComponent(entity); + } + +} // namespace BMM \ No newline at end of file diff --git a/sources/Component/Levitate/LevitateComponent.hpp b/sources/Component/Levitate/LevitateComponent.hpp new file mode 100644 index 00000000..d2868956 --- /dev/null +++ b/sources/Component/Levitate/LevitateComponent.hpp @@ -0,0 +1,38 @@ +// +// Created by hbenjamin on 07/06/2021. +// + +#pragma once + +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" +#include "Models/Vector3.hpp" + +namespace BBM { + class LevitateComponent : public WAL::Component { + public: + + //! @brief Go down or up + bool up = true; + //! @brief Original y of the entity + float y; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Create a new levitate component. + explicit LevitateComponent(WAL::Entity &entity); + + //! @brief Create a new levitate component. + LevitateComponent(WAL::Entity &entity, float y); + + //! @brief A Levitate component is copy constructable. + LevitateComponent(const LevitateComponent &) = default; + + //! @brief default destructor + ~LevitateComponent() override = default; + + //! @brief A Levitate component can't be assigned + LevitateComponent &operator=(const LevitateComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/System/Health/HealthSystem.cpp b/sources/System/Health/HealthSystem.cpp index 82afdfeb..0005e9bd 100644 --- a/sources/System/Health/HealthSystem.cpp +++ b/sources/System/Health/HealthSystem.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "Component/Collision/CollisionComponent.hpp" #include "HealthSystem.hpp" #include "Component/Health/HealthComponent.hpp" @@ -19,7 +20,8 @@ namespace BBM { HealthSystem::HealthSystem(WAL::Wal &wal) : WAL::System({ - typeid(HealthComponent) + typeid(HealthComponent), + typeid(PositionComponent) }), _wal(wal) {} @@ -44,6 +46,7 @@ namespace BBM this->_wal.scene->addEntity("Bonus") .addComponent(position) .addComponent(1) + .addComponent(position.y) .addComponent([](WAL::Entity &bonus, const WAL::Entity &player) { //bonus.scheduleDeletion(true); }, func[bonusType - 1]) diff --git a/sources/System/Levitate/LevitateSystem.cpp b/sources/System/Levitate/LevitateSystem.cpp new file mode 100644 index 00000000..3d243ead --- /dev/null +++ b/sources/System/Levitate/LevitateSystem.cpp @@ -0,0 +1,32 @@ +// +// Created by hbenjamin on 07/06/2021. +// + +#include "LevitateSystem.hpp" + +namespace BBM { + LevitateSystem::LevitateSystem() + : WAL::System({ + typeid(LevitateComponent), + typeid(PositionComponent) + }) + {} + + void LevitateSystem::onFixedUpdate(WAL::Entity &entity) { + auto &levitate = entity.getComponent(); + auto &position = entity.getComponent(); + float &y = position.position.y; + + if (levitate.up) { + if (y < levitate.y + 0.1f) + y += 0.004f; + else + levitate.up = false; + return; + } + if (y > levitate.y - 0.1f) + y -= 0.004f; + else + levitate.up = true; + } +} \ No newline at end of file diff --git a/sources/System/Levitate/LevitateSystem.hpp b/sources/System/Levitate/LevitateSystem.hpp new file mode 100644 index 00000000..2b5a0fae --- /dev/null +++ b/sources/System/Levitate/LevitateSystem.hpp @@ -0,0 +1,29 @@ +// +// Created by hbenjamin on 07/06/2021. +// + +#pragma once + +#include "Component/Levitate/LevitateComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Wal.hpp" +#include "System/System.hpp" + +namespace BBM { + class LevitateSystem : public WAL::System + { + private: + public: + //! @inherit + void onFixedUpdate(WAL::Entity &entity) override; + + //! @brief A default constructor + LevitateSystem(); + //! @brief A Levitate system is copy constructable + LevitateSystem(const LevitateSystem &) = default; + //! @brief A default destructor + ~LevitateSystem() override = default; + //! @brief A Levitate system is assignable. + LevitateSystem &operator=(const LevitateSystem &) = default; + }; +} \ No newline at end of file