diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2021-07-05 11:58:29 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2021-07-05 11:58:29 -0400 |
commit | 324346a87c114f0991a092ac8653afecada364b5 (patch) | |
tree | f88ac730897056918b366e7fabaad2b136383d59 /res | |
parent | d983ef6b8d66d916ed7502cf6d35b573c5366257 (diff) | |
download | tanetane-324346a87c114f0991a092ac8653afecada364b5.tar.gz tanetane-324346a87c114f0991a092ac8653afecada364b5.tar.bz2 tanetane-324346a87c114f0991a092ac8653afecada364b5.zip |
Added background scripts
Background scripts are scripts that are launched when a map is loaded. They differ in use from a map's init script in that they are expected to contain an infinite loop. These scripts are linked to a sprite and will be killed when that sprite is destroyed (usually when the map is unloaded, but if the sprite is made persistent then it may last longer). The thread running the script is given no warning that it is being killed; the coroutine is simply never called again, and the thread is disposed of. Because of this, background scripts MUST ensure the game is in a consistent state before coroutine yielding, because it is not guaranteed that the coroutine will ever be called again.
Diffstat (limited to 'res')
-rw-r--r-- | res/scripts/common.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 2e95f26..35eec22 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua | |||
@@ -579,6 +579,20 @@ function FaceTowardSpriteCardinally(spriteName, targetName) | |||
579 | SetDirection(spriteName, dir) | 579 | SetDirection(spriteName, dir) |
580 | end | 580 | end |
581 | 581 | ||
582 | --- Checks whether the given sprite is facing another sprite. | ||
583 | -- @param spriteName the name of the sprite whose facing direction is relevant | ||
584 | -- @param targetName the name of the sprite that is or isn't being looked at | ||
585 | function IsFacingTowardSprite(spriteName, targetName) | ||
586 | local spriteId = getSpriteByAlias(spriteName) | ||
587 | local targetId = getSpriteByAlias(targetName) | ||
588 | local sprite = getSprite(spriteId) | ||
589 | local target = getSprite(targetId) | ||
590 | local diff = vec2i.new(target.loc:x() - sprite.loc:x(), target.loc:y() - sprite.loc:y()) | ||
591 | local dir = directionFacingPoint(diff) | ||
592 | |||
593 | return sprite.dir == dir | ||
594 | end | ||
595 | |||
582 | --- Detaches the sprite's followers and erases their following trails. | 596 | --- Detaches the sprite's followers and erases their following trails. |
583 | function BreakUpParty(spriteName) | 597 | function BreakUpParty(spriteName) |
584 | local spriteId = getSpriteByAlias(spriteName) | 598 | local spriteId = getSpriteByAlias(spriteName) |