summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-06 21:15:34 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-06 21:15:34 -0500
commit0e1e97da9e8937d19b0101dcc1f3a16e3db495b6 (patch)
tree64472e8e640bc9884a938106a49b87b43852aa75
parentcb7617344c3b7994cb40d6253a77dbfa3d3ff984 (diff)
downloadtanetane-0e1e97da9e8937d19b0101dcc1f3a16e3db495b6.tar.gz
tanetane-0e1e97da9e8937d19b0101dcc1f3a16e3db495b6.tar.bz2
tanetane-0e1e97da9e8937d19b0101dcc1f3a16e3db495b6.zip
Added sound and animation changes to scripting
-rw-r--r--res/scripts/common.lua17
-rw-r--r--res/scripts/script0001.lua10
-rw-r--r--res/sfx/barking_at_hallucination.wavbin0 -> 1773472 bytes
-rw-r--r--res/sfx/boney_growl.wavbin0 -> 376720 bytes
-rw-r--r--res/sprites/boney_anim.txt10
-rw-r--r--src/game.cpp3
-rw-r--r--src/game.h7
-rw-r--r--src/main.cpp10
-rw-r--r--src/script_system.cpp29
9 files changed, 77 insertions, 9 deletions
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()
21 WaitForEndOfMessage() 21 WaitForEndOfMessage()
22 message():hideCutsceneBars() 22 message():hideCutsceneBars()
23end 23end
24
25function SetAnimation(spriteName, animName)
26 local spriteId = getSpriteByAlias(spriteName)
27 animation():setSpriteAnimation(spriteId, animName)
28end
29
30function PlaySound(filename)
31 mixer():playSound("../res/sfx/" .. filename)
32end
33
34function LoopSound(filename)
35 return mixer():loopSound("../res/sfx/" .. filename)
36end
37
38function StopSound(soundId)
39 mixer():stopChannel(soundId)
40end
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 @@
1function script0001() 1function script0001()
2 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) 2 SetAnimation("boney", "barking")
3 local barkingNoise = LoopSound("barking_at_hallucination.wav")
4
5 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)
6 WaitForEndOfMessage()
7
8 SetAnimation("boney", "crouch")
9 StopSound(barkingNoise)
10 PlaySound("boney_growl.wav")
3 HideCutsceneBars() 11 HideCutsceneBars()
4end 12end
diff --git a/res/sfx/barking_at_hallucination.wav b/res/sfx/barking_at_hallucination.wav new file mode 100644 index 0000000..1cca6a5 --- /dev/null +++ b/res/sfx/barking_at_hallucination.wav
Binary files differ
diff --git a/res/sfx/boney_growl.wav b/res/sfx/boney_growl.wav new file mode 100644 index 0000000..9d70db2 --- /dev/null +++ b/res/sfx/boney_growl.wav
Binary files 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
31run[up]: 52,60,68,76 31run[up]: 52,60,68,76
32run[up_right]: 53,61,69,77 32run[up_right]: 53,61,69,77
33run[right]: 54,62,70,78 33run[right]: 54,62,70,78
34run[down_right]: 55,63,71,79 \ No newline at end of file 34run[down_right]: 55,63,71,79
35barking[down]: 0,32,40,32,40,32,40
36barking[down_left]: 1,33,41,33,41,33,41
37barking[left]: 2,34,42,34,42,34,42
38barking[up_left]: 3,35,43,35,43,35,43
39barking[up]: 4,36,44,36,44,36,44
40barking[up_right]: 5,37,45,37,45,37,45
41barking[right]: 6,38,46,38,46,38,46
42barking[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 @@
1#include "game.h" 1#include "game.h"
2 2
3int Game::emplaceSprite() { 3int Game::emplaceSprite(std::string alias) {
4 int id = sprites_.size(); 4 int id = sprites_.size();
5 sprites_.emplace_back(); 5 sprites_.emplace_back();
6 spriteIds_.push_back(id); 6 spriteIds_.push_back(id);
7 spritesByAlias_[alias] = id;
7 return id; 8 return id;
8} 9}
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:
43 }); 43 });
44 } 44 }
45 45
46 int emplaceSprite(); 46 int emplaceSprite(std::string alias);
47 47
48 const Sprite& getSprite(int id) const { 48 const Sprite& getSprite(int id) const {
49 return sprites_.at(id); 49 return sprites_.at(id);
@@ -57,6 +57,10 @@ public:
57 return spriteIds_; 57 return spriteIds_;
58 } 58 }
59 59
60 int getSpriteByAlias(std::string alias) const {
61 return spritesByAlias_.at(alias);
62 }
63
60 auto spriteView() const { 64 auto spriteView() const {
61 return ranges::views::transform([&] (int id) -> const Sprite& { 65 return ranges::views::transform([&] (int id) -> const Sprite& {
62 return sprites_.at(id); 66 return sprites_.at(id);
@@ -85,6 +89,7 @@ private:
85 89
86 std::vector<int> spriteIds_; 90 std::vector<int> spriteIds_;
87 std::vector<Sprite> sprites_; 91 std::vector<Sprite> sprites_;
92 std::map<std::string, int> spritesByAlias_;
88 std::unique_ptr<Map> map_; 93 std::unique_ptr<Map> map_;
89 Font font_; 94 Font font_;
90}; 95};
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) {
25 auto map = std::make_unique<Map>("../res/maps/map1.tmx", renderer); 25 auto map = std::make_unique<Map>("../res/maps/map1.tmx", renderer);
26 game.setMap(std::move(map)); 26 game.setMap(std::move(map));
27 27
28 int lucasSprite = game.emplaceSprite(); 28 int lucasSprite = game.emplaceSprite("lucas");
29 game.getSystem<TransformSystem>().initSprite(lucasSprite, {32, 32}); 29 game.getSystem<TransformSystem>().initSprite(lucasSprite, {32, 32});
30 game.getSystem<TransformSystem>().setUpCollision(lucasSprite, {-8, -8}, {12, 8}); 30 game.getSystem<TransformSystem>().setUpCollision(lucasSprite, {-8, -8}, {12, 8});
31 game.getSystem<AnimationSystem>().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt", renderer); 31 game.getSystem<AnimationSystem>().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt", renderer);
32 game.getSprite(lucasSprite).controllable = true; 32 game.getSprite(lucasSprite).controllable = true;
33 game.getSystem<CharacterSystem>().initSprite(lucasSprite); 33 game.getSystem<CharacterSystem>().initSprite(lucasSprite);
34 34
35 int kumaSprite = game.emplaceSprite(); 35 int kumaSprite = game.emplaceSprite("kuma");
36 game.getSystem<TransformSystem>().initSprite(kumaSprite, {32, 32}); 36 game.getSystem<TransformSystem>().initSprite(kumaSprite, {32, 32});
37 game.getSystem<AnimationSystem>().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt", renderer); 37 game.getSystem<AnimationSystem>().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt", renderer);
38 game.getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, kumaSprite); 38 game.getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, kumaSprite);
39 39
40 int dusterSprite = game.emplaceSprite(); 40 int dusterSprite = game.emplaceSprite("duster");
41 game.getSystem<TransformSystem>().initSprite(dusterSprite, {32, 32}); 41 game.getSystem<TransformSystem>().initSprite(dusterSprite, {32, 32});
42 game.getSystem<AnimationSystem>().initSprite(dusterSprite, "../res/sprites/duster_anim.txt", renderer); 42 game.getSystem<AnimationSystem>().initSprite(dusterSprite, "../res/sprites/duster_anim.txt", renderer);
43 game.getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, dusterSprite); 43 game.getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, dusterSprite);
44 44
45 int boneySprite = game.emplaceSprite(); 45 int boneySprite = game.emplaceSprite("boney");
46 game.getSystem<TransformSystem>().initSprite(boneySprite, {32, 32}); 46 game.getSystem<TransformSystem>().initSprite(boneySprite, {32, 32});
47 game.getSystem<AnimationSystem>().initSprite(boneySprite, "../res/sprites/boney_anim.txt", renderer); 47 game.getSystem<AnimationSystem>().initSprite(boneySprite, "../res/sprites/boney_anim.txt", renderer);
48 game.getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, boneySprite); 48 game.getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, boneySprite);
49 49
50 int flintSprite = game.emplaceSprite(); 50 int flintSprite = game.emplaceSprite("flint");
51 game.getSystem<TransformSystem>().initSprite(flintSprite, {35*16, 19*16}); 51 game.getSystem<TransformSystem>().initSprite(flintSprite, {35*16, 19*16});
52 game.getSystem<TransformSystem>().setUpCollision(flintSprite, {-8, -8}, {12, 8}); 52 game.getSystem<TransformSystem>().setUpCollision(flintSprite, {-8, -8}, {12, 8});
53 game.getSystem<AnimationSystem>().initSprite(flintSprite, "../res/sprites/flint_anim.txt", renderer); 53 game.getSystem<AnimationSystem>().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 @@
2#include <iostream> 2#include <iostream>
3#include "game.h" 3#include "game.h"
4#include "message_system.h" 4#include "message_system.h"
5#include "animation_system.h"
5 6
6ScriptSystem::ScriptSystem(Game& game) : game_(game) { 7ScriptSystem::ScriptSystem(Game& game) : game_(game) {
7 engine_.open_libraries( 8 engine_.open_libraries(
@@ -15,12 +16,40 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
15 "hideCutsceneBars", &MessageSystem::hideCutsceneBars, 16 "hideCutsceneBars", &MessageSystem::hideCutsceneBars,
16 "isMessageActive", sol::property(&MessageSystem::isMessageActive)); 17 "isMessageActive", sol::property(&MessageSystem::isMessageActive));
17 18
19 engine_.new_usertype<AnimationSystem>(
20 "animation",
21 "setSpriteAnimation", &AnimationSystem::setSpriteAnimation);
22
23 engine_.new_usertype<Mixer>(
24 "mixer",
25 "playSound", &Mixer::playSound,
26 "loopSound", &Mixer::loopSound,
27 "stopChannel", &Mixer::stopChannel);
28
18 engine_.set_function( 29 engine_.set_function(
19 "message", 30 "message",
20 [&] () -> MessageSystem& { 31 [&] () -> MessageSystem& {
21 return game_.getSystem<MessageSystem>(); 32 return game_.getSystem<MessageSystem>();
22 }); 33 });
23 34
35 engine_.set_function(
36 "animation",
37 [&] () -> AnimationSystem& {
38 return game_.getSystem<AnimationSystem>();
39 });
40
41 engine_.set_function(
42 "mixer",
43 [&] () -> Mixer& {
44 return game_.getMixer();
45 });
46
47 engine_.set_function(
48 "getSpriteByAlias",
49 [&] (std::string alias) -> int {
50 return game_.getSpriteByAlias(alias);
51 });
52
24 engine_.script_file("../res/scripts/common.lua"); 53 engine_.script_file("../res/scripts/common.lua");
25} 54}
26 55