An idea for a dynamically re-programmable Roguelike.

wip.lua 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. -- assume that the engine will create these
  2. local floor = {}
  3. floor.entity = {}
  4. fn = function(code)
  5. -- TODO sandbox code appropriately
  6. end
  7. floor.get = function(self, x, y)
  8. -- TODO whatever is returned by this can be compared with a string to see if its character matches
  9. -- TODO this should return a second value, a table of entities! or empty table
  10. end
  11. -- below here is created by the user
  12. floor.entity[1] = { x = 0, y = 0, character = "@" } -- entity drawing defaults: character="e",color={1,1,1,1},background={0,0,0,1}
  13. floor.global_functions = {}
  14. floor.global_functions.action = function(x, y)
  15. local player = floor.entity[1]
  16. local target, entities = floor:get(x, y)
  17. if target == " " and #entities == 0 then
  18. player.x = x
  19. player.y = y
  20. -- TODO elseif entities / other things
  21. end
  22. end
  23. -- assumes engine will call it to initialize a floor before it is used
  24. floor.init = function()
  25. for name, code in pairs(floor.global_functions) do
  26. _G[name] = fn(code)
  27. end
  28. if not floor.generated then
  29. -- TODO generate this floor!
  30. end
  31. end
  32. floor.update = function(key)
  33. local player = floor.entity[1]
  34. if key == "up" then
  35. action(player.x, player.y - 1)
  36. elseif key == "left" then
  37. action(player.x - 1, player.y)
  38. elseif key == "down" then
  39. action(player.x, player.y + 1)
  40. elseif key == "right" then
  41. action(player.x + 1, player.y)
  42. end
  43. end