From 6dab458c5fcd97aca871b46a43a2b46c80d1ed3c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 6 Mar 2021 23:41:40 -0500 Subject: Idling in front of the mirror faces you toward it --- res/maps/hallucination_mirror.tmx | 3 ++- res/scripts/common.lua | 10 ++++++++++ res/scripts/hallucination_mirror.lua | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'res') diff --git a/res/maps/hallucination_mirror.tmx b/res/maps/hallucination_mirror.tmx index a9aadff..1c5eee2 100644 --- a/res/maps/hallucination_mirror.tmx +++ b/res/maps/hallucination_mirror.tmx @@ -1,5 +1,5 @@ - + @@ -113,6 +113,7 @@ + diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 2a2ce35..d0ea6b5 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -542,3 +542,13 @@ function ExitAreaTransition() effect():circleTransition(1, 0.0) Delay(1000) end + +--- Checks whether a sprite is in a zone. +-- @param spriteName the name of the sprite to locate +-- @param zoneName the name of the zone on the current map to use as a boundary +function IsSpriteInZone(spriteName, zoneName) + local pos = GetPosition(spriteName) + local zone = getMap():getZone(zoneName) + + return (pos:x() >= zone.ul:x()) and (pos:x() <= zone.dr:x()) and (pos:y() >= zone.ul:y()) and (pos:y() <= zone.dr:y()) +end diff --git a/res/scripts/hallucination_mirror.lua b/res/scripts/hallucination_mirror.lua index 6e2ef55..bf1faba 100644 --- a/res/scripts/hallucination_mirror.lua +++ b/res/scripts/hallucination_mirror.lua @@ -1,5 +1,27 @@ hallucination_mirror = {} +function hallucination_mirror.init() + coroutine.yield() + -- This routine makes the player's party face the mirror if they are standing + -- in front of it for a few (5) seconds. The fact that this has to run + -- continuously makes it a bit complicated, and is why we keep checking that + -- we're on the same map. + while getMap():getName() == "hallucination_mirror" do + if IsSpriteInZone("lucas", "mirror_sight") and IsSpriteInZone("kuma", "mirror_sight") and IsSpriteInZone("duster", "mirror_sight") and IsSpriteInZone("boney", "mirror_sight") then + timer = 5000 -- milliseconds + while timer > 0 and getSprite(getPlayerSprite()).characterState == CharacterState.STILL and getMap():getName() == "hallucination_mirror" do + timer = timer - coroutine.yield() + end + + if timer <= 0 and getSprite(getPlayerSprite()).characterState == CharacterState.STILL and getMap():getName() == "hallucination_mirror" then + SetPartyDirection(getPlayerSprite(), Direction.UP) + end + end + + coroutine.yield() + end +end + function hallucination_mirror.mailbox() StartCutscene() DisplayMessage("* The mailbox lid is open...\n* Peek inside?", "", SpeakerType.NONE) -- cgit 1.4.1