Grindling/wip.lua
2020-05-21 22:11:07 -07:00

47 lines
1.3 KiB
Lua

-- assume that the engine will create these
local floor = {}
floor.entity = {}
fn = function(code)
-- TODO sandbox code appropriately
end
floor.get = function(self, x, y)
-- TODO whatever is returned by this can be compared with a string to see if its character matches
-- TODO this should return a second value, a table of entities! or empty table
end
-- below here is created by the user
floor.entity[1] = { x = 0, y = 0, character = "@" } -- entity drawing defaults: character="e",color={1,1,1,1},background={0,0,0,1}
floor.global_functions = {}
floor.global_functions.action = function(x, y)
local player = floor.entity[1]
local target, entities = floor:get(x, y)
if target == " " and #entities == 0 then
player.x = x
player.y = y
-- TODO elseif entities / other things
end
end
-- assumes engine will call it to initialize a floor before it is used
floor.init = function()
for name, code in pairs(floor.global_functions) do
_G[name] = fn(code)
end
if not floor.generated then
-- TODO generate this floor!
end
end
floor.update = function(key)
local player = floor.entity[1]
if key == "up" then
action(player.x, player.y - 1)
elseif key == "left" then
action(player.x - 1, player.y)
elseif key == "down" then
action(player.x, player.y + 1)
elseif key == "right" then
action(player.x + 1, player.y)
end
end