From 89fc2da3f08fcd751ca069fde0987d193e59b007 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 9 Mar 2021 11:51:34 -0500 Subject: Added "let's switch places!" Claus sprite He will wander randomly until you get close, and will then run at you. Talking to him or bumping into him does nothing currently. If you move out of his range of interest he will go back to wandering at a walking pace. #10 --- res/maps/hallucination_interior.tmx | 33 ++++++++++++++++++++++++- res/scripts/common.lua | 42 +++++++++++++++++++++++++++++++- res/scripts/hallucination_interior.lua | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) (limited to 'res') diff --git a/res/maps/hallucination_interior.tmx b/res/maps/hallucination_interior.tmx index d42cadc..7e012eb 100644 --- a/res/maps/hallucination_interior.tmx +++ b/res/maps/hallucination_interior.tmx @@ -1,5 +1,5 @@ - + @@ -156,6 +156,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/scripts/common.lua b/res/scripts/common.lua index d0ea6b5..f984667 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -34,7 +34,8 @@ SpriteLayer = { BehaviourType = { NONE = 0, WANDER = 1, - PATH = 2 + PATH = 2, + FOLLOW = 3 } CutsceneOptions = { @@ -440,6 +441,13 @@ function WaitForSpritePath(spriteName) end end +--- Sets a sprite to wander. +function StartWandering(spriteName) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.behaviourType = BehaviourType.WANDER +end + --- Turns off the sprite's behaviour. function DisableBehaviour(spriteName) local spriteId = getSpriteByAlias(spriteName) @@ -447,6 +455,23 @@ function DisableBehaviour(spriteName) sprite.behaviourType = BehaviourType.NONE end +--- Directs a sprite to start following a target sprite. +function FollowSprite(spriteName, targetName) + local spriteId = getSpriteByAlias(spriteName) + local targetId = getSpriteByAlias(targetName) + local sprite = getSprite(spriteId) + sprite.followSpriteId = targetId + sprite.behaviourType = BehaviourType.FOLLOW +end + +--- Makes a sprite stop following whatever sprite it was following. +function StopFollowingSprite(spriteName) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.followSpriteId = -1 + 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. @@ -478,6 +503,21 @@ function EnablePlayerControl() playerSprite.controllable = true end +--- Makes the specified sprite face toward the †arget sprite. +-- This version of the function uses any of the eight directions. +-- @param spriteName the name of the sprite to change the direction of +-- @param targetName the name of the sprite to face toward +function FaceTowardSprite(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 = directionFacingPoint(diff) + + SetDirection(spriteName, dir) +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 diff --git a/res/scripts/hallucination_interior.lua b/res/scripts/hallucination_interior.lua index f009196..0622453 100644 --- a/res/scripts/hallucination_interior.lua +++ b/res/scripts/hallucination_interior.lua @@ -226,3 +226,47 @@ function hallucination_interior.mailbox_time_passage() EnablePlayerControl() end + +function hallucination_interior.switch_claus_attention() + gamestate.switch_claus_lost_interest = false + + Halt("switch_claus") + DisableBehaviour("switch_claus") + ShowExpression("switch_claus", "surprise") + FaceTowardSprite("switch_claus", "lucas") + Delay(1000) + + RemoveExpression("switch_claus") + + if gamestate.switch_claus_lost_interest then + SetMovementSpeed("switch_claus", 1) + StartWandering("switch_claus") + else + SetMovementSpeed("switch_claus", 2) + + if IsSpriteInZone("switch_claus", "switch_claus_hidden") then + MakeSpriteNotSolid("lucas") + DirectSpriteToLocation("switch_claus", "switch_claus_rsvp") + MakeSpriteSolid("lucas") + WaitForSpritePath("switch_claus") + end + + if gamestate.switch_claus_lost_interest then + SetMovementSpeed("switch_claus", 1) + StartWandering("switch_claus") + else + FollowSprite("switch_claus", "lucas") + end + end +end + +function hallucination_interior.switch_claus_lose_interest() + gamestate.switch_claus_lost_interest = true + + SetMovementSpeed("switch_claus", 1) + StartWandering("switch_claus") +end + +function hallucination_interior.lets_switch_places() + -- TODO: let's switch places +end -- cgit 1.4.1