summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-21 12:31:55 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-21 12:31:55 -0500
commitecbe17b582803aaeaa9ccee88a3d093ff93a6cd3 (patch)
treeb7e14ae55b6c38992598b8571ed217bc8f249887
parentf0eab98e417bf648261a9027bef91fe935af76cb (diff)
downloadtanetane-ecbe17b582803aaeaa9ccee88a3d093ff93a6cd3.tar.gz
tanetane-ecbe17b582803aaeaa9ccee88a3d093ff93a6cd3.tar.bz2
tanetane-ecbe17b582803aaeaa9ccee88a3d093ff93a6cd3.zip
Added sprite pausing
All sprites are now paused when a cutscene starts and unpaused when it ends. Pausing means that the CharacterSystem and BehaviourSystem will not process them in their tick. This allows specific sprites to be unpaused during cutscenes if movement is needed.

The player character is halted and made non-controllable by the script when the cutscene starts and made controllable again when it ends. It is important to remember that if interacting with a sprite that might be moving, you have to manually call Halt() on them in their script to make them stop moving.
-rw-r--r--res/maps/map2.tmx1
-rw-r--r--res/scripts/common.lua15
-rw-r--r--res/scripts/map2.lua11
-rw-r--r--src/behaviour_system.cpp2
-rw-r--r--src/character_system.cpp2
-rw-r--r--src/script_system.cpp9
-rw-r--r--src/sprite.h1
7 files changed, 38 insertions, 3 deletions
diff --git a/res/maps/map2.tmx b/res/maps/map2.tmx index af021bf..77e7725 100644 --- a/res/maps/map2.tmx +++ b/res/maps/map2.tmx
@@ -696,6 +696,7 @@
696 <property name="collisionOffsetY" type="int" value="-8"/> 696 <property name="collisionOffsetY" type="int" value="-8"/>
697 <property name="collisionWidth" type="int" value="12"/> 697 <property name="collisionWidth" type="int" value="12"/>
698 <property name="enclosureZone" value="ionia_enclosure"/> 698 <property name="enclosureZone" value="ionia_enclosure"/>
699 <property name="interactionScript" value="talk_to_ionia"/>
699 <property name="movementSpeed" type="int" value="1"/> 700 <property name="movementSpeed" type="int" value="1"/>
700 <property name="shadow" type="bool" value="true"/> 701 <property name="shadow" type="bool" value="true"/>
701 <property name="wander" type="bool" value="true"/> 702 <property name="wander" type="bool" value="true"/>
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 4dfa1a2..494ace9 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua
@@ -49,6 +49,11 @@ function StartCutscene()
49 playerSprite.controllable = false 49 playerSprite.controllable = false
50 character():halt(playerId) 50 character():halt(playerId)
51 message():displayCutsceneBars() 51 message():displayCutsceneBars()
52
53 local allSprites = getAllSprites()
54 for k,v in pairs(allSprites) do
55 getSprite(v).paused = true
56 end
52end 57end
53 58
54--- Queues a message for display. 59--- Queues a message for display.
@@ -94,6 +99,11 @@ function HideCutsceneBars()
94 local playerId = getPlayerSprite() 99 local playerId = getPlayerSprite()
95 local playerSprite = getSprite(playerId) 100 local playerSprite = getSprite(playerId)
96 playerSprite.controllable = true 101 playerSprite.controllable = true
102
103 local allSprites = getAllSprites()
104 for k,v in pairs(allSprites) do
105 getSprite(v).paused = false
106 end
97end 107end
98 108
99function GetPosition(spriteName) 109function GetPosition(spriteName)
@@ -120,6 +130,11 @@ function WaitForAnimation(spriteName)
120 until sprite.animFinished 130 until sprite.animFinished
121end 131end
122 132
133function Halt(spriteName)
134 local spriteId = getSpriteByAlias(spriteName)
135 character():halt(spriteId)
136end
137
123function PlaySound(filename) 138function PlaySound(filename)
124 mixer():playSound("../res/sfx/" .. filename) 139 mixer():playSound("../res/sfx/" .. filename)
125end 140end
diff --git a/res/scripts/map2.lua b/res/scripts/map2.lua index 3c3a5d9..cb373b4 100644 --- a/res/scripts/map2.lua +++ b/res/scripts/map2.lua
@@ -172,3 +172,14 @@ function map2.approach_doria()
172 172
173 HideCutsceneBars() 173 HideCutsceneBars()
174end 174end
175
176function map2.talk_to_ionia()
177 Halt("ionia")
178 StartCutscene()
179 SetAnimation("ionia", "talk")
180 DisplayMessage("* Kumatora!", "Ionia", SpeakerType.MAN)
181 WaitForEndOfMessage()
182
183 SetAnimation("ionia", "still")
184 HideCutsceneBars()
185end
diff --git a/src/behaviour_system.cpp b/src/behaviour_system.cpp index 8f17329..6cd0b52 100644 --- a/src/behaviour_system.cpp +++ b/src/behaviour_system.cpp
@@ -9,7 +9,7 @@ void BehaviourSystem::tick(double dt) {
9 while (timer_.step()) { 9 while (timer_.step()) {
10 for (int spriteId : game_.getSprites()) { 10 for (int spriteId : game_.getSprites()) {
11 Sprite& sprite = game_.getSprite(spriteId); 11 Sprite& sprite = game_.getSprite(spriteId);
12 if (sprite.wander) { 12 if (sprite.wander && !sprite.paused) {
13 // 75% chance of changing what's happening 13 // 75% chance of changing what's happening
14 if (std::bernoulli_distribution(0.75)(game_.getRng())) { 14 if (std::bernoulli_distribution(0.75)(game_.getRng())) {
15 // 50% chance of choosing a direction or stopping 15 // 50% chance of choosing a direction or stopping
diff --git a/src/character_system.cpp b/src/character_system.cpp index e6dddf6..7b628b0 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp
@@ -96,7 +96,7 @@ void CharacterSystem::tick(double dt) {
96 for (int spriteId : game_.getSprites()) { 96 for (int spriteId : game_.getSprites()) {
97 Sprite& sprite = game_.getSprite(spriteId); 97 Sprite& sprite = game_.getSprite(spriteId);
98 98
99 if (sprite.orientable) { 99 if (sprite.orientable && !sprite.paused) {
100 vec2i pLoc = sprite.loc; 100 vec2i pLoc = sprite.loc;
101 101
102 if (sprite.characterState == CharacterState::Still || 102 if (sprite.characterState == CharacterState::Still ||
diff --git a/src/script_system.cpp b/src/script_system.cpp index d4ee0ce..3293753 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp
@@ -36,7 +36,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
36 "getCurrentFrame", [] (const Sprite& sprite) -> const SpriteFrame& { 36 "getCurrentFrame", [] (const Sprite& sprite) -> const SpriteFrame& {
37 return sprite.frames[sprite.animations[sprite.animationId].frameIndices[sprite.animationFrame]]; 37 return sprite.frames[sprite.animations[sprite.animationId].frameIndices[sprite.animationFrame]];
38 }, 38 },
39 "persistent", &Sprite::persistent); 39 "persistent", &Sprite::persistent,
40 "paused", &Sprite::paused);
40 41
41 engine_.new_usertype<MessageSystem>( 42 engine_.new_usertype<MessageSystem>(
42 "message", 43 "message",
@@ -168,6 +169,12 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
168 }); 169 });
169 170
170 engine_.set_function( 171 engine_.set_function(
172 "getAllSprites",
173 [&] () -> const std::set<int>& {
174 return game_.getSprites();
175 });
176
177 engine_.set_function(
171 "loadMap", 178 "loadMap",
172 [&] (std::string filename) { 179 [&] (std::string filename) {
173 game_.loadMap(filename); 180 game_.loadMap(filename);
diff --git a/src/sprite.h b/src/sprite.h index 4e3e490..35ca7aa 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -43,6 +43,7 @@ public:
43 43
44 std::string alias; 44 std::string alias;
45 bool persistent = false; 45 bool persistent = false;
46 bool paused = false;
46 47
47 // Transform 48 // Transform
48 vec2i loc { 0, 0 }; 49 vec2i loc { 0, 0 };