adding register for getPlayer and getPlayerRound

This commit is contained in:
Bluub
2021-06-18 18:51:04 +02:00
parent 278cb9204f
commit 5565a15ab3
4 changed files with 46 additions and 6 deletions
+4 -6
View File
@@ -132,12 +132,10 @@ end
------ Update
function Update(mapinfo)
log("NEW FRAME")
x = getDanger()
p = getPath(0, 0, 16, 16);
for i, c in ipairs(p) do
print(c.x)
print(c.y)
end
local dangerMap = getDanger()
local path = getPath(0, 0, 16, 16);
local player = getPlayer();
local playerRound = getPlayerRound();
---- sjould send Map Danger and MaxX MaxY
--MaxX = 0
--MaxY = 0
+28
View File
@@ -192,6 +192,34 @@ namespace BBM
return 1;
}
int LuaMap::getPlayer(lua_State *L)
{
LuaG::State state(L);
const LuaMap *map = (const LuaMap *) lua_topointer(L, lua_upvalueindex(1));
lua_newtable(L);
lua_pushstring(L, "x");
lua_pushnumber(L, map->_player.x);
lua_settable(L, -3);
lua_pushstring(L, "y");
lua_pushnumber(L, map->_player.y);
lua_settable(L, -3);
return 1;
}
int LuaMap::getPlayerRound(lua_State *L)
{
LuaG::State state(L);
const LuaMap *map = (const LuaMap *) lua_topointer(L, lua_upvalueindex(1));
lua_newtable(L);
lua_pushstring(L, "x");
lua_pushnumber(L, map->_roundedPlayer.x);
lua_settable(L, -3);
lua_pushstring(L, "y");
lua_pushnumber(L, map->_roundedPlayer.y);
lua_settable(L, -3);
return 1;
}
int LuaMap::getClosestSafeSpace(lua_State *L)
{
LuaG::State state(L);
+6
View File
@@ -39,6 +39,12 @@ namespace BBM
//! @brief get array of nodes, path from a to b
static int getPath(lua_State *L);
//! @brief get player pos
static int getPlayer(lua_State *L);
//! @brief get rounded player pos
static int getPlayerRound(lua_State *L);
//! @brief get closest safe space of player
static int getClosestSafeSpace(lua_State *L);
@@ -83,6 +83,14 @@ namespace BBM
lua_pushlightuserdata(state.getState(), &_luamap);
lua_pushcclosure(state.getState(), LuaMap::getPath, 1);
lua_setglobal(state.getState(), "getPath");
lua_pushlightuserdata(state.getState(), &_luamap);
lua_pushcclosure(state.getState(), LuaMap::getPlayer, 1);
lua_setglobal(state.getState(), "getPlayer");
lua_pushlightuserdata(state.getState(), &_luamap);
lua_pushcclosure(state.getState(), LuaMap::getPlayerRound, 1);
lua_setglobal(state.getState(), "getPlayerRound");
}
void IAControllableSystem::onFixedUpdate(WAL::ViewEntity<PositionComponent, ControllableComponent, IAControllableComponent, BombHolderComponent> &entity)