|
@@ -0,0 +1,46 @@
|
|
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
|
+
|
|
12
|
+-- below here is created by the user
|
|
13
|
+floor.entity[1] = { x = 0, y = 0, character = "@" } -- entity drawing defaults: character="e",color={1,1,1,1},background={0,0,0,1}
|
|
14
|
+floor.global_functions = {}
|
|
15
|
+floor.global_functions.action = function(x, y)
|
|
16
|
+ local player = floor.entity[1]
|
|
17
|
+ local target, entities = floor:get(x, y)
|
|
18
|
+ if target == " " and #entities == 0 then
|
|
19
|
+ player.x = x
|
|
20
|
+ player.y = y
|
|
21
|
+ -- TODO elseif entities / other things
|
|
22
|
+ end
|
|
23
|
+end
|
|
24
|
+
|
|
25
|
+-- assumes engine will call it to initialize a floor before it is used
|
|
26
|
+floor.init = function()
|
|
27
|
+ for name, code in pairs(floor.global_functions) do
|
|
28
|
+ _G[name] = fn(code)
|
|
29
|
+ end
|
|
30
|
+ if not floor.generated then
|
|
31
|
+ -- TODO generate this floor!
|
|
32
|
+ end
|
|
33
|
+end
|
|
34
|
+
|
|
35
|
+floor.update = function(key)
|
|
36
|
+ local player = floor.entity[1]
|
|
37
|
+ if key == "up" then
|
|
38
|
+ action(player.x, player.y - 1)
|
|
39
|
+ elseif key == "left" then
|
|
40
|
+ action(player.x - 1, player.y)
|
|
41
|
+ elseif key == "down" then
|
|
42
|
+ action(player.x, player.y + 1)
|
|
43
|
+ elseif key == "right" then
|
|
44
|
+ action(player.x + 1, player.y)
|
|
45
|
+ end
|
|
46
|
+end
|