From 7fa69be4e88f1fcf057871fec7e4503f50578465 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 1 Mar 2021 22:19:46 -0500 Subject: Started writing the Mixolydia scene! Looking pretty good so far. TODO: direction facing functions have inverted Y coordinate. confusion expression doesn't exist yet. rest of scene. --- res/scripts/common.lua | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'res/scripts/common.lua') diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 1b0c4a9..dad9c5d 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -30,6 +30,12 @@ SpriteLayer = { ABOVE = 1 } +BehaviourType = { + NONE = 0, + WANDER = 1, + PATH = 2 +} + CutsceneOptions = { DO_NOT_CHANGE_ANIMATION = 1 -- Prevents player party animation being set to "frozen" at the start of a cutscene or "still" at the end } @@ -426,6 +432,13 @@ function WaitForSpritePath(spriteName) end end +--- Turns off the sprite's behaviour. +function DisableBehaviour(spriteName) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.behaviourType = BehaviourType.NONE +end + --- Fades out the currently playing music. -- This does not block. If you want it to block, call Delay for the same amount -- of time. @@ -456,3 +469,49 @@ function EnablePlayerControl() local playerSprite = getSprite(playerId) playerSprite.controllable = true end + +--- Makes the specified sprite face toward the †arget sprite. +-- This version of the function uses the closest cardinal direction. +-- @param spriteName the name of the sprite to change the direction of +-- @param targetName the name of the sprite to face toward +function FaceTowardSpriteCardinally(spriteName, targetName) + local spriteId = getSpriteByAlias(spriteName) + local targetId = getSpriteByAlias(targetName) + local sprite = getSprite(spriteId) + local target = getSprite(targetId) + local diff = vec2i.new(target.loc:x() - sprite.loc:x(), target.loc:y() - sprite.loc:y()) + local dir = cardinalDirectionFacingPoint(diff) + + SetDirection(spriteName, dir) +end + +--- Detaches the sprite's followers and erases their following trails. +function BreakUpParty(spriteName) + local spriteId = getSpriteByAlias(spriteName) + character():breakUpParty(spriteId) +end + +--- Makes the specified sprite solid. +-- This means that other sprites will be blocked if they collide with this one. +function MakeSpriteSolid(spriteName) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.solid = true +end + +--- Makes the specified sprite not solid. +-- This means that other sprites will not be blocked if they collide with this +-- one. +function MakeSpriteNotSolid(spriteName) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.solid = false +end + +--- Sets the sprite's movement speed. +-- As a reference: 1 is slow (good for NPCs), 2 is Lucas's default walking speed +function SetMovementSpeed(spriteName, speed) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.movementSpeed = speed +end -- cgit 1.4.1