diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-10 18:12:15 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-10 18:12:15 -0500 |
commit | 312a3738359cc4841cb3ce675583094becd8e830 (patch) | |
tree | 7028d5fa8fdc0f98653e4638452daeaa4120ce41 | |
parent | ee7077c7ff0c22a4909c15ab34aed777b45b977e (diff) | |
download | tanetane-312a3738359cc4841cb3ce675583094becd8e830.tar.gz tanetane-312a3738359cc4841cb3ce675583094becd8e830.tar.bz2 tanetane-312a3738359cc4841cb3ce675583094becd8e830.zip |
Running is preserved across screen transitions
-rw-r--r-- | res/scripts/common.lua | 13 | ||||
-rw-r--r-- | src/character_system.cpp | 29 | ||||
-rw-r--r-- | src/character_system.h | 2 | ||||
-rw-r--r-- | src/script_system.cpp | 14 |
4 files changed, 45 insertions, 13 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 0c0205b..9674b2c 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua | |||
@@ -18,6 +18,13 @@ Direction = { | |||
18 | UP_LEFT = 7 | 18 | UP_LEFT = 7 |
19 | } | 19 | } |
20 | 20 | ||
21 | CharacterState = { | ||
22 | STILL = 0, | ||
23 | WALKING = 1, | ||
24 | CROUCHING = 2, | ||
25 | RUNNING = 3 | ||
26 | } | ||
27 | |||
21 | function DisplayMessage(msg, name, type) | 28 | function DisplayMessage(msg, name, type) |
22 | message():displayMessage(msg, name, type) | 29 | message():displayMessage(msg, name, type) |
23 | end | 30 | end |
@@ -82,12 +89,18 @@ function ChangeMap(map, warp) | |||
82 | local playerId = getControllableSprite() | 89 | local playerId = getControllableSprite() |
83 | local playerSprite = getSprite(playerId) | 90 | local playerSprite = getSprite(playerId) |
84 | local direction = playerSprite.dir | 91 | local direction = playerSprite.dir |
92 | local oldState = playerSprite.characterState | ||
85 | 93 | ||
86 | FadeToBlack(150) | 94 | FadeToBlack(150) |
87 | loadMap("../res/maps/" .. map .. ".tmx", warp) | 95 | loadMap("../res/maps/" .. map .. ".tmx", warp) |
88 | 96 | ||
89 | local newPlayerId = getControllableSprite() | 97 | local newPlayerId = getControllableSprite() |
90 | SetPartyDirection(newPlayerId, direction) | 98 | SetPartyDirection(newPlayerId, direction) |
99 | |||
100 | if oldState == CharacterState.RUNNING then | ||
101 | character():startRunning(newPlayerId) | ||
102 | end | ||
103 | |||
91 | coroutine.yield() | 104 | coroutine.yield() |
92 | RemoveFadeout(150) | 105 | RemoveFadeout(150) |
93 | end | 106 | end |
diff --git a/src/character_system.cpp b/src/character_system.cpp index 888914f..94833a8 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp | |||
@@ -156,21 +156,26 @@ void CharacterSystem::endCrouch(int spriteId) { | |||
156 | Sprite& sprite = game_.getSprite(spriteId); | 156 | Sprite& sprite = game_.getSprite(spriteId); |
157 | 157 | ||
158 | if (sprite.characterState == CharacterState::Crouching) { | 158 | if (sprite.characterState == CharacterState::Crouching) { |
159 | setPartyState(spriteId, CharacterState::Running); | 159 | startRunning(spriteId); |
160 | } | ||
161 | } | ||
160 | 162 | ||
161 | for (int followerId : sprite.followers) { | 163 | void CharacterSystem::startRunning(int spriteId) { |
162 | // Halve the movement buffer for the followers. | 164 | Sprite& sprite = game_.getSprite(spriteId); |
163 | Sprite& follower = game_.getSprite(followerId); | 165 | setPartyState(spriteId, CharacterState::Running); |
164 | std::deque<Movement> newMove; | 166 | |
165 | 167 | for (int followerId : sprite.followers) { | |
166 | while (!follower.trail.empty()) { | 168 | // Halve the movement buffer for the followers. |
167 | newMove.push_back(follower.trail.front()); | 169 | Sprite& follower = game_.getSprite(followerId); |
168 | follower.trail.pop_front(); | 170 | std::deque<Movement> newMove; |
169 | follower.trail.pop_front(); | ||
170 | } | ||
171 | 171 | ||
172 | follower.trail = std::move(newMove); | 172 | while (!follower.trail.empty()) { |
173 | newMove.push_back(follower.trail.front()); | ||
174 | follower.trail.pop_front(); | ||
175 | follower.trail.pop_front(); | ||
173 | } | 176 | } |
177 | |||
178 | follower.trail = std::move(newMove); | ||
174 | } | 179 | } |
175 | } | 180 | } |
176 | 181 | ||
diff --git a/src/character_system.h b/src/character_system.h index 39b3958..3933e1b 100644 --- a/src/character_system.h +++ b/src/character_system.h | |||
@@ -31,6 +31,8 @@ public: | |||
31 | 31 | ||
32 | void endCrouch(int spriteId); | 32 | void endCrouch(int spriteId); |
33 | 33 | ||
34 | void startRunning(int spriteId); | ||
35 | |||
34 | void clearSpriteCache() override; | 36 | void clearSpriteCache() override; |
35 | 37 | ||
36 | private: | 38 | private: |
diff --git a/src/script_system.cpp b/src/script_system.cpp index 6b35b73..d8d93e3 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "game.h" | 3 | #include "game.h" |
4 | #include "message_system.h" | 4 | #include "message_system.h" |
5 | #include "animation_system.h" | 5 | #include "animation_system.h" |
6 | #include "character_system.h" | ||
6 | 7 | ||
7 | ScriptSystem::ScriptSystem(Game& game) : game_(game) { | 8 | ScriptSystem::ScriptSystem(Game& game) : game_(game) { |
8 | engine_.open_libraries( | 9 | engine_.open_libraries( |
@@ -13,7 +14,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
13 | engine_.new_usertype<Sprite>( | 14 | engine_.new_usertype<Sprite>( |
14 | "sprite", | 15 | "sprite", |
15 | "dir", &Sprite::dir, | 16 | "dir", &Sprite::dir, |
16 | "followers", &Sprite::followers); | 17 | "followers", &Sprite::followers, |
18 | "characterState", &Sprite::characterState); | ||
17 | 19 | ||
18 | engine_.new_usertype<MessageSystem>( | 20 | engine_.new_usertype<MessageSystem>( |
19 | "message", | 21 | "message", |
@@ -26,6 +28,10 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
26 | "setSpriteAnimation", &AnimationSystem::setSpriteAnimation, | 28 | "setSpriteAnimation", &AnimationSystem::setSpriteAnimation, |
27 | "setSpriteDirection", &AnimationSystem::setSpriteDirection); | 29 | "setSpriteDirection", &AnimationSystem::setSpriteDirection); |
28 | 30 | ||
31 | engine_.new_usertype<CharacterSystem>( | ||
32 | "character", | ||
33 | "startRunning", &CharacterSystem::startRunning); | ||
34 | |||
29 | engine_.new_usertype<Mixer>( | 35 | engine_.new_usertype<Mixer>( |
30 | "mixer", | 36 | "mixer", |
31 | "playSound", &Mixer::playSound, | 37 | "playSound", &Mixer::playSound, |
@@ -45,6 +51,12 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
45 | }); | 51 | }); |
46 | 52 | ||
47 | engine_.set_function( | 53 | engine_.set_function( |
54 | "character", | ||
55 | [&] () -> CharacterSystem& { | ||
56 | return game_.getSystem<CharacterSystem>(); | ||
57 | }); | ||
58 | |||
59 | engine_.set_function( | ||
48 | "mixer", | 60 | "mixer", |
49 | [&] () -> Mixer& { | 61 | [&] () -> Mixer& { |
50 | return game_.getMixer(); | 62 | return game_.getMixer(); |