From c25ab2537cb201dc46b7c1d375dd1c12411fe85c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 10 Feb 2021 20:09:42 -0500 Subject: Player movement/input is halted during cutscenes --- res/scripts/common.lua | 11 +++++++++++ res/scripts/default.lua | 2 +- res/scripts/script0001.lua | 1 + res/scripts/test_trigger.lua | 1 + src/character_system.cpp | 12 ++++++++++++ src/character_system.h | 2 ++ src/script_system.cpp | 3 ++- 7 files changed, 30 insertions(+), 2 deletions(-) diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 1841662..b540548 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -25,6 +25,13 @@ CharacterState = { RUNNING = 3 } +function StartCutscene() + local playerId = getPlayerSprite() + local playerSprite = getSprite(playerId) + playerSprite.controllable = false + character():halt(playerId) +end + function DisplayMessage(msg, name, type) message():displayMessage(msg, name, type) end @@ -38,6 +45,10 @@ end function HideCutsceneBars() WaitForEndOfMessage() message():hideCutsceneBars() + + local playerId = getPlayerSprite() + local playerSprite = getSprite(playerId) + playerSprite.controllable = true end function SetAnimation(spriteName, animName) diff --git a/res/scripts/default.lua b/res/scripts/default.lua index 6188c36..936a543 100644 --- a/res/scripts/default.lua +++ b/res/scripts/default.lua @@ -1,5 +1,5 @@ function default() + StartCutscene() DisplayMessage("No problem here.", "", SpeakerType.NONE) - WaitForEndOfMessage() HideCutsceneBars() end diff --git a/res/scripts/script0001.lua b/res/scripts/script0001.lua index fcf7029..e5078f2 100644 --- a/res/scripts/script0001.lua +++ b/res/scripts/script0001.lua @@ -1,4 +1,5 @@ function script0001() + StartCutscene() SetAnimation("boney", "barking") local barkingNoise = LoopSound("barking_at_hallucination.wav") diff --git a/res/scripts/test_trigger.lua b/res/scripts/test_trigger.lua index cd64fb8..58325e5 100644 --- a/res/scripts/test_trigger.lua +++ b/res/scripts/test_trigger.lua @@ -1,4 +1,5 @@ function test_trigger() + StartCutscene() PlaySound("boney_growl.wav") DisplayMessage("Hi! Welcome to the funky zone.", "", SpeakerType.NONE) WaitForEndOfMessage() diff --git a/src/character_system.cpp b/src/character_system.cpp index 781b50d..aad8c1b 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp @@ -248,6 +248,18 @@ void CharacterSystem::stopRunningSound(Sprite& sprite) { } } +void CharacterSystem::halt(int spriteId) { + // Because special stuff happens when we stop running, we have to handle the + // running case here. + Sprite& sprite = game_.getSprite(spriteId); + if (sprite.characterState == CharacterState::Running) { + stopRunning(spriteId); + } else { + // Other than that, it is simple to go to Still from Walking or Crouching. + setPartyState(spriteId, CharacterState::Still); + } +} + void CharacterSystem::clearSpriteCache() { for (Sprite& sprite : game_.getSprites() | game_.spriteView()) { if (sprite.runningSfxChannel != -1) { diff --git a/src/character_system.h b/src/character_system.h index 3933e1b..c6d4e6d 100644 --- a/src/character_system.h +++ b/src/character_system.h @@ -33,6 +33,8 @@ public: void startRunning(int spriteId); + void halt(int spriteId); + void clearSpriteCache() override; private: diff --git a/src/script_system.cpp b/src/script_system.cpp index 8fd5028..0fa0c1b 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp @@ -31,7 +31,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { engine_.new_usertype( "character", - "startRunning", &CharacterSystem::startRunning); + "startRunning", &CharacterSystem::startRunning, + "halt", &CharacterSystem::halt); engine_.new_usertype( "mixer", -- cgit 1.4.1