summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-03-09 11:51:34 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-03-09 11:51:34 -0500
commit89fc2da3f08fcd751ca069fde0987d193e59b007 (patch)
tree09d9f8c7fc44a72f3fa7677048a127286ac850a5
parentdd052d68e95f5b2128da272127e165c4a70f3f94 (diff)
downloadtanetane-89fc2da3f08fcd751ca069fde0987d193e59b007.tar.gz
tanetane-89fc2da3f08fcd751ca069fde0987d193e59b007.tar.bz2
tanetane-89fc2da3f08fcd751ca069fde0987d193e59b007.zip
Added "let's switch places!" Claus sprite
He will wander randomly until you get close, and will then run at you. Talking to him or bumping into him does nothing currently. If you move out of his range of interest he will go back to wandering at a walking pace.

#10
-rw-r--r--res/maps/hallucination_interior.tmx33
-rw-r--r--res/scripts/common.lua42
-rw-r--r--res/scripts/hallucination_interior.lua44
-rw-r--r--src/behaviour_system.cpp33
-rw-r--r--src/script_system.cpp4
-rw-r--r--src/sprite.h4
6 files changed, 142 insertions, 18 deletions
diff --git a/res/maps/hallucination_interior.tmx b/res/maps/hallucination_interior.tmx index d42cadc..7e012eb 100644 --- a/res/maps/hallucination_interior.tmx +++ b/res/maps/hallucination_interior.tmx
@@ -1,5 +1,5 @@
1<?xml version="1.0" encoding="UTF-8"?> 1<?xml version="1.0" encoding="UTF-8"?>
2<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="7"> 2<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="14">
3 <properties> 3 <properties>
4 <property name="music" value="red_green_yellow_yellow"/> 4 <property name="music" value="red_green_yellow_yellow"/>
5 </properties> 5 </properties>
@@ -156,6 +156,37 @@
156 <object id="6" name="fromRight" type="warp" x="1007.9" y="445.781"> 156 <object id="6" name="fromRight" type="warp" x="1007.9" y="445.781">
157 <point/> 157 <point/>
158 </object> 158 </object>
159 <object id="7" name="switch_claus" type="sprite" x="864" y="784">
160 <properties>
161 <property name="animation" value="claus"/>
162 <property name="enclosureZone" value="switch_claus_enclosure"/>
163 <property name="interactionScript" value="lets_switch_places"/>
164 <property name="movementSpeed" type="int" value="1"/>
165 <property name="shadow" type="bool" value="true"/>
166 <property name="wander" type="bool" value="true"/>
167 </properties>
168 <point/>
169 </object>
170 <object id="8" name="switch_claus_enclosure" type="zone" x="768" y="656" width="144" height="160"/>
171 <object id="9" name="switch_claus_attention" type="trigger" x="752" y="640" width="176" height="176">
172 <properties>
173 <property name="script" value="switch_claus_attention"/>
174 </properties>
175 </object>
176 <object id="10" name="switch_claus_lose_interest_left" type="trigger" x="720" y="608" width="16" height="112">
177 <properties>
178 <property name="script" value="switch_claus_lose_interest"/>
179 </properties>
180 </object>
181 <object id="11" name="switch_claus_lose_interest_up" type="trigger" x="736" y="608" width="144" height="16">
182 <properties>
183 <property name="script" value="switch_claus_lose_interest"/>
184 </properties>
185 </object>
186 <object id="12" name="switch_claus_hidden" type="zone" x="800" y="704" width="112" height="112"/>
187 <object id="13" name="switch_claus_rsvp" type="warp" x="816" y="688">
188 <point/>
189 </object>
159 </objectgroup> 190 </objectgroup>
160 <layer id="1" name="Upper" width="64" height="64"> 191 <layer id="1" name="Upper" width="64" height="64">
161 <properties> 192 <properties>
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index d0ea6b5..f984667 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua
@@ -34,7 +34,8 @@ SpriteLayer = {
34BehaviourType = { 34BehaviourType = {
35 NONE = 0, 35 NONE = 0,
36 WANDER = 1, 36 WANDER = 1,
37 PATH = 2 37 PATH = 2,
38 FOLLOW = 3
38} 39}
39 40
40CutsceneOptions = { 41CutsceneOptions = {
@@ -440,6 +441,13 @@ function WaitForSpritePath(spriteName)
440 end 441 end
441end 442end
442 443
444--- Sets a sprite to wander.
445function StartWandering(spriteName)
446 local spriteId = getSpriteByAlias(spriteName)
447 local sprite = getSprite(spriteId)
448 sprite.behaviourType = BehaviourType.WANDER
449end
450
443--- Turns off the sprite's behaviour. 451--- Turns off the sprite's behaviour.
444function DisableBehaviour(spriteName) 452function DisableBehaviour(spriteName)
445 local spriteId = getSpriteByAlias(spriteName) 453 local spriteId = getSpriteByAlias(spriteName)
@@ -447,6 +455,23 @@ function DisableBehaviour(spriteName)
447 sprite.behaviourType = BehaviourType.NONE 455 sprite.behaviourType = BehaviourType.NONE
448end 456end
449 457
458--- Directs a sprite to start following a target sprite.
459function FollowSprite(spriteName, targetName)
460 local spriteId = getSpriteByAlias(spriteName)
461 local targetId = getSpriteByAlias(targetName)
462 local sprite = getSprite(spriteId)
463 sprite.followSpriteId = targetId
464 sprite.behaviourType = BehaviourType.FOLLOW
465end
466
467--- Makes a sprite stop following whatever sprite it was following.
468function StopFollowingSprite(spriteName)
469 local spriteId = getSpriteByAlias(spriteName)
470 local sprite = getSprite(spriteId)
471 sprite.followSpriteId = -1
472 sprite.behaviourType = BehaviourType.NONE
473end
474
450--- Fades out the currently playing music. 475--- Fades out the currently playing music.
451-- This does not block. If you want it to block, call Delay for the same amount 476-- This does not block. If you want it to block, call Delay for the same amount
452-- of time. 477-- of time.
@@ -479,6 +504,21 @@ function EnablePlayerControl()
479end 504end
480 505
481--- Makes the specified sprite face toward the †arget sprite. 506--- Makes the specified sprite face toward the †arget sprite.
507-- This version of the function uses any of the eight directions.
508-- @param spriteName the name of the sprite to change the direction of
509-- @param targetName the name of the sprite to face toward
510function FaceTowardSprite(spriteName, targetName)
511 local spriteId = getSpriteByAlias(spriteName)
512 local targetId = getSpriteByAlias(targetName)
513 local sprite = getSprite(spriteId)
514 local target = getSprite(targetId)
515 local diff = vec2i.new(target.loc:x() - sprite.loc:x(), target.loc:y() - sprite.loc:y())
516 local dir = directionFacingPoint(diff)
517
518 SetDirection(spriteName, dir)
519end
520
521--- Makes the specified sprite face toward the †arget sprite.
482-- This version of the function uses the closest cardinal direction. 522-- This version of the function uses the closest cardinal direction.
483-- @param spriteName the name of the sprite to change the direction of 523-- @param spriteName the name of the sprite to change the direction of
484-- @param targetName the name of the sprite to face toward 524-- @param targetName the name of the sprite to face toward
diff --git a/res/scripts/hallucination_interior.lua b/res/scripts/hallucination_interior.lua index f009196..0622453 100644 --- a/res/scripts/hallucination_interior.lua +++ b/res/scripts/hallucination_interior.lua
@@ -226,3 +226,47 @@ function hallucination_interior.mailbox_time_passage()
226 226
227 EnablePlayerControl() 227 EnablePlayerControl()
228end 228end
229
230function hallucination_interior.switch_claus_attention()
231 gamestate.switch_claus_lost_interest = false
232
233 Halt("switch_claus")
234 DisableBehaviour("switch_claus")
235 ShowExpression("switch_claus", "surprise")
236 FaceTowardSprite("switch_claus", "lucas")
237 Delay(1000)
238
239 RemoveExpression("switch_claus")
240
241 if gamestate.switch_claus_lost_interest then
242 SetMovementSpeed("switch_claus", 1)
243 StartWandering("switch_claus")
244 else
245 SetMovementSpeed("switch_claus", 2)
246
247 if IsSpriteInZone("switch_claus", "switch_claus_hidden") then
248 MakeSpriteNotSolid("lucas")
249 DirectSpriteToLocation("switch_claus", "switch_claus_rsvp")
250 MakeSpriteSolid("lucas")
251 WaitForSpritePath("switch_claus")
252 end
253
254 if gamestate.switch_claus_lost_interest then
255 SetMovementSpeed("switch_claus", 1)
256 StartWandering("switch_claus")
257 else
258 FollowSprite("switch_claus", "lucas")
259 end
260 end
261end
262
263function hallucination_interior.switch_claus_lose_interest()
264 gamestate.switch_claus_lost_interest = true
265
266 SetMovementSpeed("switch_claus", 1)
267 StartWandering("switch_claus")
268end
269
270function hallucination_interior.lets_switch_places()
271 -- TODO: let's switch places
272end
diff --git a/src/behaviour_system.cpp b/src/behaviour_system.cpp index b68cd6d..f4f7546 100644 --- a/src/behaviour_system.cpp +++ b/src/behaviour_system.cpp
@@ -19,22 +19,27 @@ void BehaviourSystem::tick(double dt) {
19 while (timer_.step()) { 19 while (timer_.step()) {
20 for (int spriteId : game_.getSprites()) { 20 for (int spriteId : game_.getSprites()) {
21 Sprite& sprite = game_.getSprite(spriteId); 21 Sprite& sprite = game_.getSprite(spriteId);
22 if (!sprite.paused && sprite.behaviourType == BehaviourType::Wander) { 22 if (!sprite.paused) {
23 // 75% chance of changing what's happening 23 if (sprite.behaviourType == BehaviourType::Wander) {
24 if (std::bernoulli_distribution(0.75)(game_.getRng())) { 24 // 75% chance of changing what's happening
25 // 50% chance of choosing a direction or stopping 25 if (std::bernoulli_distribution(0.75)(game_.getRng())) {
26 if (std::bernoulli_distribution(0.5)(game_.getRng())) { 26 // 50% chance of choosing a direction or stopping
27 Direction dir; 27 if (std::bernoulli_distribution(0.5)(game_.getRng())) {
28 switch (std::uniform_int_distribution(0,3)(game_.getRng())) { 28 Direction dir;
29 case 0: dir = Direction::left; break; 29 switch (std::uniform_int_distribution(0,3)(game_.getRng())) {
30 case 1: dir = Direction::up; break; 30 case 0: dir = Direction::left; break;
31 case 2: dir = Direction::right; break; 31 case 1: dir = Direction::up; break;
32 default: dir = Direction::down; break; 32 case 2: dir = Direction::right; break;
33 default: dir = Direction::down; break;
34 }
35 game_.getSystem<CharacterSystem>().moveInDirection(spriteId, dir);
36 } else {
37 game_.getSystem<CharacterSystem>().stopDirecting(spriteId);
33 } 38 }
34 game_.getSystem<CharacterSystem>().moveInDirection(spriteId, dir);
35 } else {
36 game_.getSystem<CharacterSystem>().stopDirecting(spriteId);
37 } 39 }
40 } else if (sprite.behaviourType == BehaviourType::Follow) {
41 Sprite& target = game_.getSprite(sprite.followSpriteId);
42 game_.getSystem<CharacterSystem>().moveInDirection(spriteId, directionFacingPoint(target.loc - sprite.loc));
38 } 43 }
39 } 44 }
40 } 45 }
diff --git a/src/script_system.cpp b/src/script_system.cpp index 50ea60a..a50fa7a 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp
@@ -52,7 +52,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
52 "enclosureZone", &Sprite::enclosureZone, 52 "enclosureZone", &Sprite::enclosureZone,
53 "movementSpeed", &Sprite::movementSpeed, 53 "movementSpeed", &Sprite::movementSpeed,
54 "solid", &Sprite::solid, 54 "solid", &Sprite::solid,
55 "behaviourType", &Sprite::behaviourType); 55 "behaviourType", &Sprite::behaviourType,
56 "followSpriteId", &Sprite::followSpriteId);
56 57
57 engine_.new_usertype<MessageSystem>( 58 engine_.new_usertype<MessageSystem>(
58 "message", 59 "message",
@@ -242,6 +243,7 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
242 loadMapScripts(filename); 243 loadMapScripts(filename);
243 }); 244 });
244 245
246 engine_.set_function("directionFacingPoint", &directionFacingPoint);
245 engine_.set_function("cardinalDirectionFacingPoint", &cardinalDirectionFacingPoint); 247 engine_.set_function("cardinalDirectionFacingPoint", &cardinalDirectionFacingPoint);
246 248
247 engine_.script_file("../res/scripts/common.lua"); 249 engine_.script_file("../res/scripts/common.lua");
diff --git a/src/sprite.h b/src/sprite.h index 2ab306d..10dd3a8 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -45,7 +45,8 @@ enum class CharacterMedium {
45enum class BehaviourType { 45enum class BehaviourType {
46 None, 46 None,
47 Wander, 47 Wander,
48 Path 48 Path,
49 Follow
49}; 50};
50 51
51enum class MirrorType { 52enum class MirrorType {
@@ -128,6 +129,7 @@ public:
128 vec2i pathfindingDestination; 129 vec2i pathfindingDestination;
129 bool cardinalDirectionsOnly = false; 130 bool cardinalDirectionsOnly = false;
130 std::deque<PathfindingInstruction> path; 131 std::deque<PathfindingInstruction> path;
132 int followSpriteId = -1;
131 133
132 // Mirror 134 // Mirror
133 MirrorType mirrorType = MirrorType::None; 135 MirrorType mirrorType = MirrorType::None;