From e03683852cac9b31ca846fcf13ff53abf99232c7 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 27 Feb 2021 17:40:26 -0500 Subject: Added A* pathfinding --- res/scripts/common.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'res/scripts/common.lua') 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 = { DO_NOT_FADE = 1 -- Prevents fading to and from black } +PathfindingOptions = { + CARDINAL_DIRECTIONS_ONLY = 1 +} + gamestate = {} --- Yields until the specified amount of time has passed. @@ -127,6 +131,23 @@ function HideCutsceneBars(options) end end +--- Unpauses a sprite's movement. +-- Use this during cutscenes to allow the sprite's movement to be controlled +-- either by the InputSystem or the BehaviourSystem. +function UnpauseSprite(spriteName) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.paused = false +end + +--- Re-pauses a sprite's movement. +-- Use this after UnpauseSprite() when you are done moving the sprite. +function PauseSprite(spriteName) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.paused = true +end + function GetPosition(spriteName) local spriteId = getSpriteByAlias(spriteName) local sprite = getSprite(spriteId) @@ -216,6 +237,12 @@ function WaitForPan() end end +function CameraFollowSprite(spriteName) + local spriteId = getSpriteByAlias(spriteName) + camera():setFollowingSprite(spriteId) + camera():unlockCamera() +end + function ReturnCamera(length) local playerId = getPlayerSprite() camera():panToSprite(playerId, length) @@ -359,3 +386,30 @@ function SetAnimationSlowdown(spriteName, amount) local sprite = getSprite(spriteId) sprite.animSlowdown = amount end + +--- Removes the enclosure zone for the specified sprite. +-- This allows the sprite to move outside of the confines of the zone. +function RemoveEnclosureZone(spriteName) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.enclosureZone = "" +end + +--- Set a sprite on a path to the specified location. +function DirectSpriteToLocation(spriteName, warpPoint, options) + options = options or 0 + + local spriteId = getSpriteByAlias(spriteName) + local dest = getMap():getWarpPoint(warpPoint) + + behaviour():directSpriteToLocation(spriteId, dest, options) +end + +--- Blocks until the specified sprite has completed their path. +function WaitForSpritePath(spriteName) + local spriteId = getSpriteByAlias(spriteName) + + while (behaviour():isFollowingPath(spriteId)) do + coroutine.yield() + end +end -- cgit 1.4.1