From 4bbfeae42a1245b1b84e8847787d7643e6a6f2cf Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 10 May 2018 19:27:59 -0400 Subject: 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. --- res/platform.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 res/platform.lua (limited to 'res') 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 @@ +function moveLeft(entity, len, speed) + local remaining = len / speed + + while (remaining > 0) do + print("no") + --entity:ponderable().vel:x(-speed) + remaining = remaining - coroutine.yield() + end +end + +function moveRight(entity, len, speed) + local remaining = len / speed + + while (remaining > 0) do + print("no2") + --entity:ponderable().vel:x(speed) + remaining = remaining - coroutine.yield() + end +end + +function run(entity) + print("yes") + while true do + moveRight(entity, 90, 30) + moveLeft(entity, 90, 30) + end +end \ No newline at end of file -- cgit 1.4.1