diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a3da03b..c736ea41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,8 @@ set(SOURCES sources/System/Collision/CollisionSystem.cpp sources/Component/IAControllable/IAControllableComponent.hpp sources/Component/IAControllable/IAControllableComponent.cpp + sources/System/IAControllable/IAControllableSystem.hpp + sources/System/IAControllable/IAControllableSystem.cpp ) add_executable(bomberman diff --git a/ai_scripts/john.lua b/ai_scripts/john.lua index a58b3496..3c74b31d 100644 --- a/ai_scripts/john.lua +++ b/ai_scripts/john.lua @@ -1,3 +1,7 @@ function sum(a,b) return a + b; end + +function update() + return 1; +end \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 73ff735c..835d6c2f 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -30,6 +30,7 @@ #include "Component/Animation/AnimationsComponent.hpp" #include "System/Animation/AnimationsSystem.hpp" #include "Map/Map.hpp" +#include "System/IAControllable/IAControllableSystem.hpp" namespace RAY2D = RAY::Drawables::Drawables2D; namespace RAY3D = RAY::Drawables::Drawables3D; @@ -50,6 +51,7 @@ namespace BBM { wal.addSystem() .addSystem() + .addSystem() .addSystem() .addSystem(wal) .addSystem(); diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp new file mode 100644 index 00000000..f020504d --- /dev/null +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -0,0 +1,33 @@ +// +// Created by Louis Auzuret on 06/07/21 +// + +#include "Component/Controllable/ControllableComponent.hpp" +#include "Component/IAControllable/IAControllableComponent.hpp" +#include "System/IAControllable/IAControllableSystem.hpp" + +namespace BBM +{ + IAControllableSystem::IAControllableSystem() + : WAL::System({ typeid(IAControllableComponent), + typeid(ControllableComponent)}) + { } + + void IAControllableSystem::onFixedUpdate(WAL::Entity &entity) + { + auto &ia = entity.getComponent(); + auto &controllable = entity.getComponent(); + + lua_getglobal(ia.state, "update"); + //push parameters + int nbParams = 0; + int nbReturn = 1; + lua_pcall(ia.state, nbParams, nbReturn, 0); + if (lua_isnil(ia.state, -1)) + return; + if (!lua_isnumber(ia.state, -1)) + return; + controllable.move.y = lua_tonumber(ia.state, -1); + lua_pop(ia.state, 1); + } +} \ No newline at end of file diff --git a/sources/System/IAControllable/IAControllableSystem.hpp b/sources/System/IAControllable/IAControllableSystem.hpp new file mode 100644 index 00000000..8528c01d --- /dev/null +++ b/sources/System/IAControllable/IAControllableSystem.hpp @@ -0,0 +1,27 @@ +// +// Created by Louis Auzuret on 06/07/21 +// + +#pragma once + +#include "System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle keyboard entities. + class IAControllableSystem : public WAL::System + { + public: + //! @inherit + void onFixedUpdate(WAL::Entity &entity) override; + + //! @brief A default constructor + IAControllableSystem(); + //! @brief A keyboard system is copy constructable + IAControllableSystem(const IAControllableSystem &) = default; + //! @brief A default destructor + ~IAControllableSystem() override = default; + //! @brief A keyboard system is assignable. + IAControllableSystem &operator=(const IAControllableSystem &) = default; + }; +}