summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-10 18:12:15 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-10 18:12:15 -0500
commit312a3738359cc4841cb3ce675583094becd8e830 (patch)
tree7028d5fa8fdc0f98653e4638452daeaa4120ce41 /src
parentee7077c7ff0c22a4909c15ab34aed777b45b977e (diff)
downloadtanetane-312a3738359cc4841cb3ce675583094becd8e830.tar.gz
tanetane-312a3738359cc4841cb3ce675583094becd8e830.tar.bz2
tanetane-312a3738359cc4841cb3ce675583094becd8e830.zip
Running is preserved across screen transitions
Diffstat (limited to 'src')
-rw-r--r--src/character_system.cpp29
-rw-r--r--src/character_system.h2
-rw-r--r--src/script_system.cpp14
3 files changed, 32 insertions, 13 deletions
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) { 163void 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
36private: 38private:
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
7ScriptSystem::ScriptSystem(Game& game) : game_(game) { 8ScriptSystem::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();