work on script
[Tsunagari.git] / src / postMove.lua
blobd8ad24f20009036cd72293e7414b8a0e764035fc
1 #!/usr/bin/lua
2 --
3 -- This script is executed every time an Entity finishes walking onto a tile.
4 --
5 -- We are called from within Entity::postMove() in entity.cpp. There, we are
6 -- passed some game data. We pass three variables to this script from the
7 -- Entity object: x, y, and entity, which represents the Entity itself.
8 --
9 -- We also have a C function we can call, gotoRandomTile, which takes an Entity
10 -- object as a parameter.
13 -- Returns true if we are standing on the specified X,Y location.
14 function on(X, Y)
15 return x == X and y == Y
16 end
18 -- Returns true if we are standing on any of the specified locations.
19 function onAny(locations)
20 for _,loc in ipairs(locations) do
21 if on(loc.x, loc.y) then
22 return true
23 end
24 end
25 return false
26 end
28 local redPortalLocations = {
29 {x = 11, y = 4},
30 {x = 4, y = 11}
33 -- The red portals teleport us! *gasp* Excitement!
34 if onAny(redPortalLocations) then
35 print("Teleported!")
36 gotoRandomTile(entity)
37 end