summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--res/scripts/common.lua28
-rw-r--r--src/script_system.cpp26
2 files changed, 53 insertions, 1 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index f43b2e0..0c0205b 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua
@@ -7,6 +7,17 @@ SpeakerType = {
7 NONHUMAN = 5 7 NONHUMAN = 5
8} 8}
9 9
10Direction = {
11 UP = 0,
12 UP_RIGHT = 1,
13 RIGHT = 2,
14 DOWN_RIGHT = 3,
15 DOWN = 4,
16 DOWN_LEFT = 5,
17 LEFT = 6,
18 UP_LEFT = 7
19}
20
10function DisplayMessage(msg, name, type) 21function DisplayMessage(msg, name, type)
11 message():displayMessage(msg, name, type) 22 message():displayMessage(msg, name, type)
12end 23end
@@ -57,9 +68,26 @@ function RemoveFadeout(length)
57 setFadeoutProgress(0.0) 68 setFadeoutProgress(0.0)
58end 69end
59 70
71function SetPartyDirection(spriteId, direction)
72 animation():setSpriteDirection(spriteId, direction)
73
74 local sprite = getSprite(spriteId)
75
76 for i=1,#sprite.followers do
77 animation():setSpriteDirection(sprite.followers[i], direction)
78 end
79end
80
60function ChangeMap(map, warp) 81function ChangeMap(map, warp)
82 local playerId = getControllableSprite()
83 local playerSprite = getSprite(playerId)
84 local direction = playerSprite.dir
85
61 FadeToBlack(150) 86 FadeToBlack(150)
62 loadMap("../res/maps/" .. map .. ".tmx", warp) 87 loadMap("../res/maps/" .. map .. ".tmx", warp)
88
89 local newPlayerId = getControllableSprite()
90 SetPartyDirection(newPlayerId, direction)
63 coroutine.yield() 91 coroutine.yield()
64 RemoveFadeout(150) 92 RemoveFadeout(150)
65end 93end
diff --git a/src/script_system.cpp b/src/script_system.cpp index a5e9403..6b35b73 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp
@@ -10,6 +10,11 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
10 sol::lib::coroutine, 10 sol::lib::coroutine,
11 sol::lib::math); 11 sol::lib::math);
12 12
13 engine_.new_usertype<Sprite>(
14 "sprite",
15 "dir", &Sprite::dir,
16 "followers", &Sprite::followers);
17
13 engine_.new_usertype<MessageSystem>( 18 engine_.new_usertype<MessageSystem>(
14 "message", 19 "message",
15 "displayMessage", &MessageSystem::displayMessage, 20 "displayMessage", &MessageSystem::displayMessage,
@@ -18,7 +23,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
18 23
19 engine_.new_usertype<AnimationSystem>( 24 engine_.new_usertype<AnimationSystem>(
20 "animation", 25 "animation",
21 "setSpriteAnimation", &AnimationSystem::setSpriteAnimation); 26 "setSpriteAnimation", &AnimationSystem::setSpriteAnimation,
27 "setSpriteDirection", &AnimationSystem::setSpriteDirection);
22 28
23 engine_.new_usertype<Mixer>( 29 engine_.new_usertype<Mixer>(
24 "mixer", 30 "mixer",
@@ -51,6 +57,24 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
51 }); 57 });
52 58
53 engine_.set_function( 59 engine_.set_function(
60 "getControllableSprite",
61 [&] () -> int {
62 for (int id : game_.getSprites()) {
63 Sprite& sprite = game_.getSprite(id);
64 if (sprite.controllable) {
65 return id;
66 }
67 }
68 return -1;
69 });
70
71 engine_.set_function(
72 "getSprite",
73 [&] (int id) -> Sprite& {
74 return game_.getSprite(id);
75 });
76
77 engine_.set_function(
54 "loadMap", 78 "loadMap",
55 [&] (std::string filename, std::string warpPoint) { 79 [&] (std::string filename, std::string warpPoint) {
56 game_.loadMap(filename, warpPoint); 80 game_.loadMap(filename, warpPoint);