From 5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 13 May 2018 00:50:11 -0400 Subject: Started event handlers The AutomatingSystem has been renamed to the ScriptingSystem, since the automatic behavior script is just a special case of the scripts that an entity can exhibit. The AutomatableComponent has largely been moved to the new RunnableComponent (might not be the final name for it). The Lua state object, previously living on the singleton RealizableComponent, is now a member of the ScriptingSystem itself, because it A) doesn't really belong on the realizable entity, and B) a singleton entity seems weird and like a cumbersome attempt to apply the ECS rules to places they don't apply. In a similar vein, the RealizableComponent itself will probably soon be integrated into the RealizingSystem too. The attempt at using Lua environments in order to encapsulate the different behaviors that objects exhibit was scrapped in preference of just creating differently named Lua tables for each prototype. The new PrototypableComponent contains some information about entities which were prototyped. It is partially used by the ScriptingSystem to figure out what event handlers are appropriate, which may not be the best approach. It also has some data about automatic behavior, which also maybe does not belong in this component. The OnTouch event is raised by a player colliding with a physics body with the collider type "event", which may not be the best way to implement this. The result of all of this is that checkpoints now work, although no sound is played, and the result is not persistent across exiting the game. --- scripts/checkpoint.lua | 17 +++++++++++++++++ scripts/common.lua | 21 +++++++++++++++++++++ scripts/movplat.lua | 8 ++++++++ 3 files changed, 46 insertions(+) create mode 100644 scripts/checkpoint.lua create mode 100644 scripts/common.lua create mode 100644 scripts/movplat.lua (limited to 'scripts') diff --git a/scripts/checkpoint.lua b/scripts/checkpoint.lua new file mode 100644 index 0000000..452f81d --- /dev/null +++ b/scripts/checkpoint.lua @@ -0,0 +1,17 @@ +checkpoint = {} + +function checkpoint.OnTouch(id, player) + curMap = entity.new(realizing():singleton():realizable().activeMap) + + if not player:playable().checkpointMapObject or + not curMap:mappable().mapId == player:playable().checkpointMapId or + not id:prototypable().mapObjectIndex == + player:playable().checkpointMapObjectIndex then + + player:playable().checkpointMapObject = true + player:playable().checkpointMapId = curMap:mappable().mapId + player:playable().checkpointMapObjectIndex = + id:prototypable().mapObjectIndex + player:playable().checkpointPos = player:transformable().pos + end +end diff --git a/scripts/common.lua b/scripts/common.lua new file mode 100644 index 0000000..d84d97d --- /dev/null +++ b/scripts/common.lua @@ -0,0 +1,21 @@ +function waitForTick() + return coroutine.yield() +end + +function moveLeft(id, len, speed) + local remaining = len / speed + + while (remaining > 0) do + id:ponderable().vel.x = -speed + remaining = remaining - waitForTick() + end +end + +function moveRight(id, len, speed) + local remaining = len / speed + + while (remaining > 0) do + id:ponderable().vel.x = speed + remaining = remaining - waitForTick() + end +end diff --git a/scripts/movplat.lua b/scripts/movplat.lua new file mode 100644 index 0000000..21cc61a --- /dev/null +++ b/scripts/movplat.lua @@ -0,0 +1,8 @@ +movplat = {} + +function movplat.Behavior(id) + while true do + moveRight(id, 90, 30) + moveLeft(id, 90, 30) + end +end -- cgit 1.4.1