mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-25 15:39:50 +00:00
moving player up with the lua script
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
function sum(a,b)
|
||||
return a + b;
|
||||
end
|
||||
|
||||
function update()
|
||||
return 1;
|
||||
end
|
||||
@@ -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<KeyboardSystem>()
|
||||
.addSystem<GamepadSystem>()
|
||||
.addSystem<IAControllableSystem>()
|
||||
.addSystem<ControllableSystem>()
|
||||
.addSystem<CollisionSystem>(wal)
|
||||
.addSystem<MovableSystem>();
|
||||
|
||||
@@ -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<IAControllableComponent>();
|
||||
auto &controllable = entity.getComponent<ControllableComponent>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user