From 312a3738359cc4841cb3ce675583094becd8e830 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 10 Feb 2021 18:12:15 -0500 Subject: Running is preserved across screen transitions --- src/character_system.cpp | 29 +++++++++++++++++------------ src/character_system.h | 2 ++ src/script_system.cpp | 14 +++++++++++++- 3 files changed, 32 insertions(+), 13 deletions(-) (limited to 'src') 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) { Sprite& sprite = game_.getSprite(spriteId); if (sprite.characterState == CharacterState::Crouching) { - setPartyState(spriteId, CharacterState::Running); + startRunning(spriteId); + } +} - for (int followerId : sprite.followers) { - // Halve the movement buffer for the followers. - Sprite& follower = game_.getSprite(followerId); - std::deque newMove; - - while (!follower.trail.empty()) { - newMove.push_back(follower.trail.front()); - follower.trail.pop_front(); - follower.trail.pop_front(); - } +void CharacterSystem::startRunning(int spriteId) { + Sprite& sprite = game_.getSprite(spriteId); + setPartyState(spriteId, CharacterState::Running); + + for (int followerId : sprite.followers) { + // Halve the movement buffer for the followers. + Sprite& follower = game_.getSprite(followerId); + std::deque newMove; - follower.trail = std::move(newMove); + while (!follower.trail.empty()) { + newMove.push_back(follower.trail.front()); + follower.trail.pop_front(); + follower.trail.pop_front(); } + + follower.trail = std::move(newMove); } } 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: void endCrouch(int spriteId); + void startRunning(int spriteId); + void clearSpriteCache() override; 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 @@ #include "game.h" #include "message_system.h" #include "animation_system.h" +#include "character_system.h" ScriptSystem::ScriptSystem(Game& game) : game_(game) { engine_.open_libraries( @@ -13,7 +14,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { engine_.new_usertype( "sprite", "dir", &Sprite::dir, - "followers", &Sprite::followers); + "followers", &Sprite::followers, + "characterState", &Sprite::characterState); engine_.new_usertype( "message", @@ -26,6 +28,10 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { "setSpriteAnimation", &AnimationSystem::setSpriteAnimation, "setSpriteDirection", &AnimationSystem::setSpriteDirection); + engine_.new_usertype( + "character", + "startRunning", &CharacterSystem::startRunning); + engine_.new_usertype( "mixer", "playSound", &Mixer::playSound, @@ -44,6 +50,12 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { return game_.getSystem(); }); + engine_.set_function( + "character", + [&] () -> CharacterSystem& { + return game_.getSystem(); + }); + engine_.set_function( "mixer", [&] () -> Mixer& { -- cgit 1.4.1