! ********** THIS INFORM EXAMPLE GAME WAS WRITTEN BY ! ********** Donnie Russell, October 2002 Constant Story "InfAud Example"; Constant Headline "^A demonstration of an external sound system.^"; Include "InfAudPre"; Include "Parser"; Include "VerbLib"; Include "InfAudPost"; ! ********** GLOBAL VARIABLES Global last_real_location; Global last_monster; ! ********** CLASSES Class NowhereArea with AreaNumber 0, StartMusic [ ; ], StopMusic [ ; ], has ; Class OutsideArea with AreaNumber 1, StartMusic [ ; SOUND("loop loops/forest.ogg +10 64 * ambienton ambient/rustle.wav +0 255 7");], StopMusic [ ; SOUND("playing loops/forest.ogg -10 close * ambientoff ambient/rustle.wav");], has ; Class InsideArea with AreaNumber 2, StartMusic [ ; SOUND("loop loops/house.ogg +10 64");], StopMusic [ ; SOUND("playing loops/house.ogg -10 close");], has ; Class Monster has ; ! ********** ROOMS NowhereArea Nowhere "nowhere" has ; InsideArea Foyer "In the Foyer" with description "The door leading out is north. Another room can be entered to the east.", n_to OutsideForest, e_to LivingRoom, has light; InsideArea -> Clock "an old grandfather clock" with StartSound [ ; SOUND("loop loops/clock.wav +10 32");], StopSound [ ; SOUND("playing loops/clock.wav -10 close");], name 'clock', describe [; "An old grandfather clock is ticking nearby.";], description "The clock looks to be about a hundred years old, at least.", has static; InsideArea LivingRoom "In the Living Room" with description "The door leading out is west.", w_to Foyer, has light; OutsideArea OutsideForest "Outside the Forest" with description "An overgrown path lined with high weeds leads west into the forest. A small house can be entered to the south.", w_to NearOak, s_to Foyer, has light; OutsideArea NearOak "Near the Oak Tree" with description "The path is less overgrown here. It continues into the forest.", e_to OutsideForest, w_to Clearing, has light; OutsideArea -> OakTree "an old oak tree" with name 'tree', describe [; "Just inside this dense forest stands an old oak tree.";], description "The tree looks to be about a hundred years old, at least.", before [; Touch: "The bark is very rough."; Attack: SOUND("pan 32 * play hit.wav +0 255 3 * pan off"); "You punch the trunk three times for no apparent reason."; ], has static; OutsideArea Clearing "A Small Clearing" with description "The path ends here, at a small clearing. The clearing extends to the north and south.", e_to NearOak, n_to NorthClearing, s_to SouthClearing, has light; OutsideArea NorthClearing "North Clearing" with description "This is the north end of the clearing.", s_to Clearing, has light; OutsideArea SouthClearing "South Clearing" with description "This is the south end of the clearing.", n_to Clearing, has light; OutsideArea -> Waterfall "a waterfall" with StartSound [ ; SOUND("loop loops/waterfall.wav +10 32");], StopSound [ ; SOUND("playing loops/waterfall.wav -10 close");], name 'waterfall', describe [; "A waterfall cascades down the side of a small hill.";], description "The water is flowing very fast.", has static; ! ********** MONSTERS Monster Wolf "a menacing wolf" with StartMusic [ ; SOUND("loop loops/wolf.ogg +10 64");], StopMusic [ ; SOUND("playing loops/wolf.ogg -10 close");], name 'wolf', describe [; "A terrifying wolf is standing some distance away.";], description "It stares at you, its teeth flashing menacingly.", before [; Attack: StopDaemon(self); move self to Nowhere; SOUND("repeatat 1500 * pan 192 * play wolf.aif +0 255 2 * pan off * repeatat 0"); "You start to attack the wolf, but it runs away."; ], daemon [ start end; start = parent(self); end = MoveRandom(self, OutsideArea); if (start==end) return; if (start==real_location) print "^A menacing wolf stalks away."; if (end==real_location) print "^A menacing wolf comes into view."; move self to end; ], has static; Monster Snake "a snake" with StartMusic [ ; SOUND("loop loops/snake.ogg +10 64");], StopMusic [ ; SOUND("playing loops/snake.ogg -10 close");], name 'snake', describe [; "A huge snake is curled up nearby.";], description "It hisses at you, its fangs flashing menacingly.", before [; Attack: move self to Nowhere; "You start to attack the snake, but it slithers away."; ], has static; ! ********** ROUTINES [ UpdateSound x m; m = nothing; objectloop (x ofclass Monster) if (x in real_location) {m = x; break;} if (m~=nothing) { if (m~=last_monster) { if (last_monster==nothing) last_real_location.StopMusic(); else last_monster.StopMusic(); m.StartMusic(); } } else { if (last_monster~=nothing) {last_monster.StopMusic(); real_location.StartMusic();} else if (real_location.AreaNumber~=last_real_location.AreaNumber) {last_real_location.StopMusic(); real_location.StartMusic();} } if (real_location~=last_real_location) { objectloop (x provides StopSound) if (x in last_real_location) x.StopSound(); objectloop (x provides StartSound) if (x in real_location) x.StartSound(); } last_real_location = real_location; last_monster = m; ]; [ MoveRandom o x start end d n i; start = parent(o); n = 0; objectloop (d in compass) {end = start.(d.door_dir); if (end ofclass x) n++;} if (n==0) return start; i = random(n); n = 0; objectloop (d in compass) {end = start.(d.door_dir); if (end ofclass x) n++; if (i==n) return end;} return start; ]; ! ********** LIBRARY ENTRY POINT ROUTINES [ AfterPrompt; UpdateSound(); ]; [ Initialise; SOUND("ambientoff all * playing all -0 close"); move Wolf to OutsideForest; move Snake to NearOak; last_real_location = Nowhere; last_monster = nothing; PlayerTo(LivingRoom, 1); StartDaemon(Wolf); ]; Include "Grammar";