diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-10 19:27:59 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-17 15:39:39 -0400 |
commit | 4bbfeae42a1245b1b84e8847787d7643e6a6f2cf (patch) | |
tree | 8dd65d9ab0cfffd0e79f670c94b035c5eebfa934 /res | |
parent | 67b24a8ddd89371cfb944c5b441c852f0edc23b1 (diff) | |
download | therapy-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.lua | 27 |
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 @@ | |||
1 | function 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 | ||
9 | end | ||
10 | |||
11 | function 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 | ||
19 | end | ||
20 | |||
21 | function run(entity) | ||
22 | print("yes") | ||
23 | while true do | ||
24 | moveRight(entity, 90, 30) | ||
25 | moveLeft(entity, 90, 30) | ||
26 | end | ||
27 | end \ No newline at end of file | ||