From 470b1d43fb6f8e17624ee90f87270de5bd6ff77e Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 13 Feb 2021 20:50:21 -0500 Subject: Added lightning sprite to mailbox event Sprites can be destroyed now, which really just means that their index is removed from the list of active sprites. The actual memory is not freed until all sprites are deleted on map change. Sprite layers are introduced. All sprites by default are on layer 0 (Normal) which renders them in between the lower and upper map layers. There is also a layer 1 (Above) that renders above the upper map layer, and the sprite for the lightning strike uses this layer in order to not be hidden by the trees. Fixed a bug where waiting for the end of a non-looping animation would trip the flag immediately upon the final frame activating, instead of waiting the length of the last frame. --- res/maps/map2.tmx | 5 ++++- res/scripts/common.lua | 24 ++++++++++++++++++++++++ res/scripts/map2.lua | 9 ++++++++- res/sprites/lightning.png | Bin 0 -> 11405 bytes res/sprites/lightning_anim.txt | 3 +++ res/sprites/lightning_frames.txt | 14 ++++++++++++++ res/sprites/lucas_anim.txt | 3 ++- 7 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 res/sprites/lightning.png create mode 100644 res/sprites/lightning_anim.txt create mode 100644 res/sprites/lightning_frames.txt (limited to 'res') diff --git a/res/maps/map2.tmx b/res/maps/map2.tmx index 6316ef5..f6d6dd2 100644 --- a/res/maps/map2.tmx +++ b/res/maps/map2.tmx @@ -1,5 +1,5 @@ - + @@ -657,6 +657,9 @@ + + + diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 3db1b26..04f6c5a 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -25,6 +25,11 @@ CharacterState = { RUNNING = 3 } +SpriteLayer = { + NORMAL = 0, + ABOVE = 1 +} + function StartCutscene() local playerId = getPlayerSprite() local playerSprite = getSprite(playerId) @@ -59,6 +64,12 @@ function HideCutsceneBars() playerSprite.controllable = true end +function GetPosition(spriteName) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + return sprite.loc +end + function SetDirection(spriteName, dir) local spriteId = getSpriteByAlias(spriteName) animation():setSpriteDirection(spriteId, dir) @@ -137,3 +148,16 @@ function ChangeMap(map, warp) RemoveFadeout(150) newPlayerSprite.controllable = true end + +function CreateAnimatedSpriteAtPosition(alias, character, x, y, animName, direction, layer) + local spriteId = emplaceSprite(alias) + transform():initSprite(spriteId, x, y, layer) + animation():initSprite(spriteId, "../res/sprites/" .. character .. "_anim.txt") + animation():setSpriteDirection(spriteId, direction) + animation():setSpriteAnimation(spriteId, animName) +end + +function DestroyNamedSprite(alias) + local spriteId = getSpriteByAlias(alias) + destroySprite(spriteId) +end diff --git a/res/scripts/map2.lua b/res/scripts/map2.lua index 3bc9eff..1ef1235 100644 --- a/res/scripts/map2.lua +++ b/res/scripts/map2.lua @@ -29,8 +29,15 @@ function map2.mailbox_lightning() DisplayMessage("* ...?", "", SpeakerType.NONE) WaitForEndOfMessage() + local lucasPos = GetPosition("lucas") + CreateAnimatedSpriteAtPosition("lightning_from_mailbox", "lightning", lucasPos:x() + 56, lucasPos:y() - 72, "strike", Direction.DOWN_LEFT, SpriteLayer.ABOVE) + SetDirection("lucas", Direction.DOWN) - SetAnimation("lucas", "electrocute!") + SetAnimation("lucas", "lightning_electrocute!") + WaitForAnimation("lucas") + + DestroyNamedSprite("lightning_from_mailbox") + SetAnimation("lucas", "lightning_collapse!") WaitForAnimation("lucas") DisplayMessage("* It was lightning.\n\fAh.", "", SpeakerType.NONE) diff --git a/res/sprites/lightning.png b/res/sprites/lightning.png new file mode 100644 index 0000000..c456338 Binary files /dev/null and b/res/sprites/lightning.png differ diff --git a/res/sprites/lightning_anim.txt b/res/sprites/lightning_anim.txt new file mode 100644 index 0000000..bafb68d --- /dev/null +++ b/res/sprites/lightning_anim.txt @@ -0,0 +1,3 @@ +../res/sprites/lightning.png +../res/sprites/lightning_frames.txt +strike[down_left]: 0,1,3,2 \ No newline at end of file diff --git a/res/sprites/lightning_frames.txt b/res/sprites/lightning_frames.txt new file mode 100644 index 0000000..4a8fee5 --- /dev/null +++ b/res/sprites/lightning_frames.txt @@ -0,0 +1,14 @@ +160,128 cell size +10 frames per row +10 frames + +112,128,60,56 +128,128,72,64 +116,128,64,64 +116,128,64,64 +88,96,40,96 +88,96,40,96 +80,96,40,96 +160,32,123,83 +160,32,123,91 +160,32,123,91 diff --git a/res/sprites/lucas_anim.txt b/res/sprites/lucas_anim.txt index 12a373e..d03e213 100644 --- a/res/sprites/lucas_anim.txt +++ b/res/sprites/lucas_anim.txt @@ -32,4 +32,5 @@ run[up]: 71,79,87,95 run[up_right]: 72,80,88,96 run[right]: 73,81,89,97 run[down_right]: 74,82,90,98 -electrocute![down]: 116,117,118,116,117,118,116,117,118,119,120,121,122 \ No newline at end of file +lightning_electrocute![down]: 116,117,118,116,117,118,116,117,118,116 +lightning_collapse![down]: 119,120,121,122 \ No newline at end of file -- cgit 1.4.1