summary refs log tree commit diff stats
path: root/res
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
parent4be70b7d55493cdc2d5e909d5101e70a16bee6f1 (diff)
downloadtanetane-e03683852cac9b31ca846fcf13ff53abf99232c7.tar.gz
tanetane-e03683852cac9b31ca846fcf13ff53abf99232c7.tar.bz2
tanetane-e03683852cac9b31ca846fcf13ff53abf99232c7.zip
Added A* pathfinding
Diffstat (limited to 'res')
-rw-r--r--res/maps/underwater_start.tmx5
-rw-r--r--res/scripts/common.lua54
-rw-r--r--res/scripts/underwater_start.lua21
3 files changed, 79 insertions, 1 deletions
diff --git a/res/maps/underwater_start.tmx b/res/maps/underwater_start.tmx index 7f9cb8c..0ced9c4 100644 --- a/res/maps/underwater_start.tmx +++ b/res/maps/underwater_start.tmx
@@ -1,5 +1,5 @@
1<?xml version="1.0" encoding="UTF-8"?> 1<?xml version="1.0" encoding="UTF-8"?>
2<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="32" height="32" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="4"> 2<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="32" height="32" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="5">
3 <properties> 3 <properties>
4 <property name="music" value="barren_factory"/> 4 <property name="music" value="barren_factory"/>
5 </properties> 5 </properties>
@@ -96,6 +96,9 @@
96 <point/> 96 <point/>
97 </object> 97 </object>
98 <object id="3" name="fish1_enclosure" type="zone" x="176" y="144" width="80" height="96"/> 98 <object id="3" name="fish1_enclosure" type="zone" x="176" y="144" width="80" height="96"/>
99 <object id="4" name="fish_destination" type="warp" x="184" y="122">
100 <point/>
101 </object>
99 </objectgroup> 102 </objectgroup>
100 <layer id="1" name="Upper" width="32" height="32"> 103 <layer id="1" name="Upper" width="32" height="32">
101 <properties> 104 <properties>
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
diff --git a/res/scripts/underwater_start.lua b/res/scripts/underwater_start.lua index 56b0b5e..7259d05 100644 --- a/res/scripts/underwater_start.lua +++ b/res/scripts/underwater_start.lua
@@ -9,5 +9,26 @@ function underwater_start.talk_to_fish1()
9 StartCutscene() 9 StartCutscene()
10 DisplayMessage("* You deserved what she did to you.", "Fish", SpeakerType.BOY) 10 DisplayMessage("* You deserved what she did to you.", "Fish", SpeakerType.BOY)
11 WaitForEndOfMessage() 11 WaitForEndOfMessage()
12
13 Delay(500)
14
15 PanToSprite("fish1", 1000)
16 WaitForPan()
17
18 Delay(500)
19
20 UnpauseSprite("fish1")
21 RemoveEnclosureZone("fish1")
22 DirectSpriteToLocation("fish1", "fish_destination", PathfindingOptions.CARDINAL_DIRECTIONS_ONLY)
23 CameraFollowSprite("fish1")
24 WaitForSpritePath("fish1")
25
26 Delay(1000)
27 DestroyNamedSprite("fish1")
28
29 Delay(500)
30
31 ReturnCamera(1000)
32
12 HideCutsceneBars() 33 HideCutsceneBars()
13end \ No newline at end of file 34end \ No newline at end of file