From b3720c4a401f345c49eadabdb852968e273e7077 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 17 Feb 2021 15:11:37 -0500 Subject: Added expressions (currently just surprise) --- res/scripts/common.lua | 18 ++++++++++++++++++ res/scripts/map2.lua | 27 +++++++++++++++++++++++++++ res/sprites/expression.png | Bin 0 -> 216 bytes res/sprites/expression_anim.txt | 3 +++ res/sprites/expression_frames.txt | 5 +++++ src/script_system.cpp | 10 +++++++++- 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 res/sprites/expression.png create mode 100644 res/sprites/expression_anim.txt create mode 100644 res/sprites/expression_frames.txt diff --git a/res/scripts/common.lua b/res/scripts/common.lua index f88c4c1..8a9445b 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -207,3 +207,21 @@ function DestroyNamedSprite(alias) local spriteId = getSpriteByAlias(alias) destroySprite(spriteId) end + +function AliasForSpriteExpression(spriteName) + return "expression (" .. spriteName .. ")" +end + +function ShowExpression(spriteName, expression) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + local animFrame = sprite:getCurrentFrame() + local x = sprite.loc:x() + local y = sprite.loc:y() - animFrame.center:y() + + CreateAnimatedSpriteAtPosition(AliasForSpriteExpression(spriteName), "expression", x, y, expression, Direction.DOWN, SpriteLayer.ABOVE) +end + +function RemoveExpression(spriteName) + DestroyNamedSprite(AliasForSpriteExpression(spriteName)) +end diff --git a/res/scripts/map2.lua b/res/scripts/map2.lua index c929e8d..295a0c1 100644 --- a/res/scripts/map2.lua +++ b/res/scripts/map2.lua @@ -74,12 +74,36 @@ function map2.approach_doria() gamestate.approached_doria = true StartCutscene() + SetDirection("boney", Direction.LEFT) + SetAnimation("boney", "barking") + local barkingNoise = LoopSound("barking_at_hallucination.wav") + Delay(200) + + ShowExpression("lucas", "surprise") + SetDirection("lucas", Direction.LEFT) + Delay(100) + + ShowExpression("kuma", "surprise") + ShowExpression("duster", "surprise") + SetDirection("kuma", Direction.LEFT) + SetDirection("duster", Direction.LEFT) + Delay(1000) + PanToSprite("doria", 2000) + Delay(500) + + RemoveExpression("lucas") + RemoveExpression("kuma") + RemoveExpression("duster") WaitForPan() SetDirection("doria", Direction.DOWN_RIGHT) SetAnimation("doria", "talk") + ShowExpression("doria", "surprise") DisplayMessage("* Oh my!\n\f* Is that our little Kumatora I spy? `", "Doria", SpeakerType.MAN) + Delay(1000) + + RemoveExpression("doria") WaitForEndOfMessage() SetAnimation("doria", "still") @@ -89,6 +113,9 @@ function map2.approach_doria() DisplayMessage("* Doria...?\n\f* What the hell... You're still alive?", "Kumatora", SpeakerType.WOMAN) WaitForEndOfMessage() + SetAnimation("boney", "crouch") + StopSound(barkingNoise) + PlaySound("boney_growl.wav") SetAnimation("kuma", "still") Delay(1000) diff --git a/res/sprites/expression.png b/res/sprites/expression.png new file mode 100644 index 0000000..1cc2500 Binary files /dev/null and b/res/sprites/expression.png differ diff --git a/res/sprites/expression_anim.txt b/res/sprites/expression_anim.txt new file mode 100644 index 0000000..299f32c --- /dev/null +++ b/res/sprites/expression_anim.txt @@ -0,0 +1,3 @@ +../res/sprites/expression.png +../res/sprites/expression_frames.txt +surprise[down]: 0 \ No newline at end of file diff --git a/res/sprites/expression_frames.txt b/res/sprites/expression_frames.txt new file mode 100644 index 0000000..692cde2 --- /dev/null +++ b/res/sprites/expression_frames.txt @@ -0,0 +1,5 @@ +16,16 cell size +10 frames per row +1 frames + +16,16,8,16 diff --git a/src/script_system.cpp b/src/script_system.cpp index 3ac04ac..8674f97 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp @@ -20,6 +20,11 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { "x", [] (const vec2i& v) { return v.x(); }, "y", [] (const vec2i& v) { return v.y(); }); + engine_.new_usertype( + "spriteframe", + "center", &SpriteFrame::center, + "size", &SpriteFrame::size); + engine_.new_usertype( "sprite", "loc", &Sprite::loc, @@ -27,7 +32,10 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { "followers", &Sprite::followers, "characterState", &Sprite::characterState, "controllable", &Sprite::controllable, - "animFinished", &Sprite::animFinished); + "animFinished", &Sprite::animFinished, + "getCurrentFrame", [] (const Sprite& sprite) -> const SpriteFrame& { + return sprite.frames[sprite.animations[sprite.animationId].frameIndices[sprite.animationFrame]]; + }); engine_.new_usertype( "message", -- cgit 1.4.1