summary refs log tree commit diff stats
path: root/scripts
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-13 00:50:11 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:39:39 -0400
commit5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb (patch)
tree94a3f4ce0a0e54375cd2f27fb90d7c35295bda2e /scripts
parent59808c86bf0e4d5cf0b6ab3d6ed1d8bdcd303a37 (diff)
downloadtherapy-5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb.tar.gz
therapy-5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb.tar.bz2
therapy-5269e7c09a0b17c8c972c8ad996b04d42dbcd9cb.zip
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.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/checkpoint.lua17
-rw-r--r--scripts/common.lua21
-rw-r--r--scripts/movplat.lua8
3 files changed, 46 insertions, 0 deletions
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 @@
1checkpoint = {}
2
3function checkpoint.OnTouch(id, player)
4 curMap = entity.new(realizing():singleton():realizable().activeMap)
5
6 if not player:playable().checkpointMapObject or
7 not curMap:mappable().mapId == player:playable().checkpointMapId or
8 not id:prototypable().mapObjectIndex ==
9 player:playable().checkpointMapObjectIndex then
10
11 player:playable().checkpointMapObject = true
12 player:playable().checkpointMapId = curMap:mappable().mapId
13 player:playable().checkpointMapObjectIndex =
14 id:prototypable().mapObjectIndex
15 player:playable().checkpointPos = player:transformable().pos
16 end
17end
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 @@
1function waitForTick()
2 return coroutine.yield()
3end
4
5function moveLeft(id, len, speed)
6 local remaining = len / speed
7
8 while (remaining > 0) do
9 id:ponderable().vel.x = -speed
10 remaining = remaining - waitForTick()
11 end
12end
13
14function moveRight(id, len, speed)
15 local remaining = len / speed
16
17 while (remaining > 0) do
18 id:ponderable().vel.x = speed
19 remaining = remaining - waitForTick()
20 end
21end
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 @@
1movplat = {}
2
3function movplat.Behavior(id)
4 while true do
5 moveRight(id, 90, 30)
6 moveLeft(id, 90, 30)
7 end
8end