From 0e1e97da9e8937d19b0101dcc1f3a16e3db495b6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 6 Feb 2021 21:15:34 -0500 Subject: Added sound and animation changes to scripting --- res/scripts/common.lua | 17 +++++++++++++++++ res/scripts/script0001.lua | 10 +++++++++- res/sfx/barking_at_hallucination.wav | Bin 0 -> 1773472 bytes res/sfx/boney_growl.wav | Bin 0 -> 376720 bytes res/sprites/boney_anim.txt | 10 +++++++++- src/game.cpp | 3 ++- src/game.h | 7 ++++++- src/main.cpp | 10 +++++----- src/script_system.cpp | 29 +++++++++++++++++++++++++++++ 9 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 res/sfx/barking_at_hallucination.wav create mode 100644 res/sfx/boney_growl.wav diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 7e8276f..e7af1cf 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -21,3 +21,20 @@ function HideCutsceneBars() WaitForEndOfMessage() message():hideCutsceneBars() end + +function SetAnimation(spriteName, animName) + local spriteId = getSpriteByAlias(spriteName) + animation():setSpriteAnimation(spriteId, animName) +end + +function PlaySound(filename) + mixer():playSound("../res/sfx/" .. filename) +end + +function LoopSound(filename) + return mixer():loopSound("../res/sfx/" .. filename) +end + +function StopSound(soundId) + mixer():stopChannel(soundId) +end diff --git a/res/scripts/script0001.lua b/res/scripts/script0001.lua index 3a09705..326b37c 100644 --- a/res/scripts/script0001.lua +++ b/res/scripts/script0001.lua @@ -1,4 +1,12 @@ function script0001() - DisplayMessage("It's almost suppertime.\nHinawa should be back soon.\nWhat? She's not coming back? Why, did you do something to her?\nHuh? I did it to her? Hinawa isn't coming back?\nWho are you? What did you do?\nIt's time for supper. It's time for supper.", "Flint", SpeakerType.MAN) + SetAnimation("boney", "barking") + local barkingNoise = LoopSound("barking_at_hallucination.wav") + + DisplayMessage("Lucas. It's me, Flint. Your father.\nI found Claus. He's here. After three years I've finally found your brother.\nLook at me when I'm talking to you, Lucas.\nWhen Claus gets home, we won't need you anymore. You're nothing compared to him.", "Flint", SpeakerType.MAN) + WaitForEndOfMessage() + + SetAnimation("boney", "crouch") + StopSound(barkingNoise) + PlaySound("boney_growl.wav") HideCutsceneBars() end diff --git a/res/sfx/barking_at_hallucination.wav b/res/sfx/barking_at_hallucination.wav new file mode 100644 index 0000000..1cca6a5 Binary files /dev/null and b/res/sfx/barking_at_hallucination.wav differ diff --git a/res/sfx/boney_growl.wav b/res/sfx/boney_growl.wav new file mode 100644 index 0000000..9d70db2 Binary files /dev/null and b/res/sfx/boney_growl.wav differ diff --git a/res/sprites/boney_anim.txt b/res/sprites/boney_anim.txt index a384105..324860e 100644 --- a/res/sprites/boney_anim.txt +++ b/res/sprites/boney_anim.txt @@ -31,4 +31,12 @@ run[up_left]: 51,59,67,75 run[up]: 52,60,68,76 run[up_right]: 53,61,69,77 run[right]: 54,62,70,78 -run[down_right]: 55,63,71,79 \ No newline at end of file +run[down_right]: 55,63,71,79 +barking[down]: 0,32,40,32,40,32,40 +barking[down_left]: 1,33,41,33,41,33,41 +barking[left]: 2,34,42,34,42,34,42 +barking[up_left]: 3,35,43,35,43,35,43 +barking[up]: 4,36,44,36,44,36,44 +barking[up_right]: 5,37,45,37,45,37,45 +barking[right]: 6,38,46,38,46,38,46 +barking[down_right]: 7,39,47,39,47,39,47 \ No newline at end of file diff --git a/src/game.cpp b/src/game.cpp index 4ea7fd2..447b62a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,8 +1,9 @@ #include "game.h" -int Game::emplaceSprite() { +int Game::emplaceSprite(std::string alias) { int id = sprites_.size(); sprites_.emplace_back(); spriteIds_.push_back(id); + spritesByAlias_[alias] = id; return id; } diff --git a/src/game.h b/src/game.h index 2f1149d..87e23d3 100644 --- a/src/game.h +++ b/src/game.h @@ -43,7 +43,7 @@ public: }); } - int emplaceSprite(); + int emplaceSprite(std::string alias); const Sprite& getSprite(int id) const { return sprites_.at(id); @@ -57,6 +57,10 @@ public: return spriteIds_; } + int getSpriteByAlias(std::string alias) const { + return spritesByAlias_.at(alias); + } + auto spriteView() const { return ranges::views::transform([&] (int id) -> const Sprite& { return sprites_.at(id); @@ -85,6 +89,7 @@ private: std::vector spriteIds_; std::vector sprites_; + std::map spritesByAlias_; std::unique_ptr map_; Font font_; }; diff --git a/src/main.cpp b/src/main.cpp index 3ea92ae..c23897b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,29 +25,29 @@ void loop(Renderer& renderer) { auto map = std::make_unique("../res/maps/map1.tmx", renderer); game.setMap(std::move(map)); - int lucasSprite = game.emplaceSprite(); + int lucasSprite = game.emplaceSprite("lucas"); game.getSystem().initSprite(lucasSprite, {32, 32}); game.getSystem().setUpCollision(lucasSprite, {-8, -8}, {12, 8}); game.getSystem().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt", renderer); game.getSprite(lucasSprite).controllable = true; game.getSystem().initSprite(lucasSprite); - int kumaSprite = game.emplaceSprite(); + int kumaSprite = game.emplaceSprite("kuma"); game.getSystem().initSprite(kumaSprite, {32, 32}); game.getSystem().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt", renderer); game.getSystem().addSpriteToParty(lucasSprite, kumaSprite); - int dusterSprite = game.emplaceSprite(); + int dusterSprite = game.emplaceSprite("duster"); game.getSystem().initSprite(dusterSprite, {32, 32}); game.getSystem().initSprite(dusterSprite, "../res/sprites/duster_anim.txt", renderer); game.getSystem().addSpriteToParty(lucasSprite, dusterSprite); - int boneySprite = game.emplaceSprite(); + int boneySprite = game.emplaceSprite("boney"); game.getSystem().initSprite(boneySprite, {32, 32}); game.getSystem().initSprite(boneySprite, "../res/sprites/boney_anim.txt", renderer); game.getSystem().addSpriteToParty(lucasSprite, boneySprite); - int flintSprite = game.emplaceSprite(); + int flintSprite = game.emplaceSprite("flint"); game.getSystem().initSprite(flintSprite, {35*16, 19*16}); game.getSystem().setUpCollision(flintSprite, {-8, -8}, {12, 8}); game.getSystem().initSprite(flintSprite, "../res/sprites/flint_anim.txt", renderer); diff --git a/src/script_system.cpp b/src/script_system.cpp index 7f4729b..e2b117a 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp @@ -2,6 +2,7 @@ #include #include "game.h" #include "message_system.h" +#include "animation_system.h" ScriptSystem::ScriptSystem(Game& game) : game_(game) { engine_.open_libraries( @@ -15,12 +16,40 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { "hideCutsceneBars", &MessageSystem::hideCutsceneBars, "isMessageActive", sol::property(&MessageSystem::isMessageActive)); + engine_.new_usertype( + "animation", + "setSpriteAnimation", &AnimationSystem::setSpriteAnimation); + + engine_.new_usertype( + "mixer", + "playSound", &Mixer::playSound, + "loopSound", &Mixer::loopSound, + "stopChannel", &Mixer::stopChannel); + engine_.set_function( "message", [&] () -> MessageSystem& { return game_.getSystem(); }); + engine_.set_function( + "animation", + [&] () -> AnimationSystem& { + return game_.getSystem(); + }); + + engine_.set_function( + "mixer", + [&] () -> Mixer& { + return game_.getMixer(); + }); + + engine_.set_function( + "getSpriteByAlias", + [&] (std::string alias) -> int { + return game_.getSpriteByAlias(alias); + }); + engine_.script_file("../res/scripts/common.lua"); } -- cgit 1.4.1