summary refs log tree commit diff stats
path: root/res
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-10 19:27:59 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:39:39 -0400
commit4bbfeae42a1245b1b84e8847787d7643e6a6f2cf (patch)
tree8dd65d9ab0cfffd0e79f670c94b035c5eebfa934 /res
parent67b24a8ddd89371cfb944c5b441c852f0edc23b1 (diff)
downloadtherapy-4bbfeae42a1245b1b84e8847787d7643e6a6f2cf.tar.gz
therapy-4bbfeae42a1245b1b84e8847787d7643e6a6f2cf.tar.bz2
therapy-4bbfeae42a1245b1b84e8847787d7643e6a6f2cf.zip
Started integrating Lua as a scripting engine
Currently moving platforms are able to have their movement controlled by a script rather than by XML, which is probably a better implementation and scales better to other things. The scripts, instead of using the components as state, use the stack as state. In this way, they pretend to be multithreaded. For instance, the moving platform calls moveRight and then moveLeft. Both of those functions internally make calls that say to wait until the next tick. When the AutomatingSystem ticks, it continues execution of all scripts (sequentially, of course) until they ask for the next tick again. This is implemented using coroutines.
Diffstat (limited to 'res')
-rw-r--r--res/platform.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/res/platform.lua b/res/platform.lua new file mode 100644 index 0000000..31a7cba --- /dev/null +++ b/res/platform.lua
@@ -0,0 +1,27 @@
1function moveLeft(entity, len, speed)
2 local remaining = len / speed
3
4 while (remaining > 0) do
5 print("no")
6 --entity:ponderable().vel:x(-speed)
7 remaining = remaining - coroutine.yield()
8 end
9end
10
11function moveRight(entity, len, speed)
12 local remaining = len / speed
13
14 while (remaining > 0) do
15 print("no2")
16 --entity:ponderable().vel:x(speed)
17 remaining = remaining - coroutine.yield()
18 end
19end
20
21function run(entity)
22 print("yes")
23 while true do
24 moveRight(entity, 90, 30)
25 moveLeft(entity, 90, 30)
26 end
27end \ No newline at end of file