summary refs log tree commit diff stats
path: root/res/scripts/common.lua
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-27 17:40:26 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-27 17:40:26 -0500
commite03683852cac9b31ca846fcf13ff53abf99232c7 (patch)
tree4f18e4f6d033547f8bf9210ff8466406ed6dbd49 /res/scripts/common.lua
parent4be70b7d55493cdc2d5e909d5101e70a16bee6f1 (diff)
downloadtanetane-e03683852cac9b31ca846fcf13ff53abf99232c7.tar.gz
tanetane-e03683852cac9b31ca846fcf13ff53abf99232c7.tar.bz2
tanetane-e03683852cac9b31ca846fcf13ff53abf99232c7.zip
Added A* pathfinding
Diffstat (limited to 'res/scripts/common.lua')
-rw-r--r--res/scripts/common.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 23b881a..123f2a0 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua
@@ -38,6 +38,10 @@ ChangeMapOptions = {
38 DO_NOT_FADE = 1 -- Prevents fading to and from black 38 DO_NOT_FADE = 1 -- Prevents fading to and from black
39} 39}
40 40
41PathfindingOptions = {
42 CARDINAL_DIRECTIONS_ONLY = 1
43}
44
41gamestate = {} 45gamestate = {}
42 46
43--- Yields until the specified amount of time has passed. 47--- Yields until the specified amount of time has passed.
@@ -127,6 +131,23 @@ function HideCutsceneBars(options)
127 end 131 end
128end 132end
129 133
134--- Unpauses a sprite's movement.
135-- Use this during cutscenes to allow the sprite's movement to be controlled
136-- either by the InputSystem or the BehaviourSystem.
137function UnpauseSprite(spriteName)
138 local spriteId = getSpriteByAlias(spriteName)
139 local sprite = getSprite(spriteId)
140 sprite.paused = false
141end
142
143--- Re-pauses a sprite's movement.
144-- Use this after UnpauseSprite() when you are done moving the sprite.
145function PauseSprite(spriteName)
146 local spriteId = getSpriteByAlias(spriteName)
147 local sprite = getSprite(spriteId)
148 sprite.paused = true
149end
150
130function GetPosition(spriteName) 151function GetPosition(spriteName)
131 local spriteId = getSpriteByAlias(spriteName) 152 local spriteId = getSpriteByAlias(spriteName)
132 local sprite = getSprite(spriteId) 153 local sprite = getSprite(spriteId)
@@ -216,6 +237,12 @@ function WaitForPan()
216 end 237 end
217end 238end
218 239
240function CameraFollowSprite(spriteName)
241 local spriteId = getSpriteByAlias(spriteName)
242 camera():setFollowingSprite(spriteId)
243 camera():unlockCamera()
244end
245
219function ReturnCamera(length) 246function ReturnCamera(length)
220 local playerId = getPlayerSprite() 247 local playerId = getPlayerSprite()
221 camera():panToSprite(playerId, length) 248 camera():panToSprite(playerId, length)
@@ -359,3 +386,30 @@ function SetAnimationSlowdown(spriteName, amount)
359 local sprite = getSprite(spriteId) 386 local sprite = getSprite(spriteId)
360 sprite.animSlowdown = amount 387 sprite.animSlowdown = amount
361end 388end
389
390--- Removes the enclosure zone for the specified sprite.
391-- This allows the sprite to move outside of the confines of the zone.
392function RemoveEnclosureZone(spriteName)
393 local spriteId = getSpriteByAlias(spriteName)
394 local sprite = getSprite(spriteId)
395 sprite.enclosureZone = ""
396end
397
398--- Set a sprite on a path to the specified location.
399function DirectSpriteToLocation(spriteName, warpPoint, options)
400 options = options or 0
401
402 local spriteId = getSpriteByAlias(spriteName)
403 local dest = getMap():getWarpPoint(warpPoint)
404
405 behaviour():directSpriteToLocation(spriteId, dest, options)
406end
407
408--- Blocks until the specified sprite has completed their path.
409function WaitForSpritePath(spriteName)
410 local spriteId = getSpriteByAlias(spriteName)
411
412 while (behaviour():isFollowingPath(spriteId)) do
413 coroutine.yield()
414 end
415end