Sunday, February 8, 2015

Scene Managing

Lately, I was looking at the code for a game that used constants and a global variable to keep track of scene changes, something I've done in at least one of my WIPs, too. It got me thinking that it'd be nice to have some code available for spitting scene stuff out so authors don't have to reinvent the wheel each time.

A room might check scene settings like this:

enumerate start = 1 step * 2
{
START, JOURNEY, EXPLODED_DYNAMITE, END
}
room start_room "Start Room"
{
long_desc
{
if Seen(EXPLODED_DYNAMITE)
"This place is in shambles now that you exploded all that dynamite!"
else
"Wow, this place is pristine."
}
}


And here is the actual scene routines and code:

! example linear game scenes
!enumerate start = 1
!{
! FIRST_SCENE, SECOND_SCENE, THIRD_SCENE, FINALE
!}
! example unordered scene game (must also #set UNORDERED_SCENES)
!enumerate start = 1 step * 2
!{
! START, PATH1, PATH2, PATH3, PATH4, END
!}
#set SCENE_MANAGER
#set UNORDERED_SCENES
#ifset SCENE_MANAGER
#ifset UNORDERED_SCENES
global current_scene
#endif
global scene
routine Seen(obj) ! returns true if the given scene has been "seen" yet
{
#ifset UNORDERED_SCENES
if (scene & obj)
return true
#else
if scene => obj
return true
#endif
}
routine CurrentScene ! returns the value of current_scene or the scene variables
{
#ifset UNORDERED_SCENES
return current_scene
#else
return scene
#endif
}
routine SetScene(obj) ! changes the scene (or current_scene if using UNORDERED_SCENES) variable to obj
{
#ifset UNORDERED_SCENES
current_scene = obj
scene = scene | obj
#else
scene = obj
#endif
}
#endif ! ifset SCENE_MANAGER


Anyhow, not sure how useful this will be to most people so I probably won't add it to Roodylib, but there it is!

No comments:

Post a Comment