MCS' Coding Tips
                 "Success!"



  
Adding ambient sounds to particular levels

   Written by MCS
   Tested by Quinnsey


   
Main Page

News

Wolfenstein 3D
Texture Library


MCS' Coding
Tips - "Success"!


Utilities

Spear
Resurrection


Wolfendoom

Wolf
Collection


Original Wolf 3D

Doom/Duke
maps


Other Stuff

Links

Questions?
Email us!
This tutorial describes how to add ambient sounds to your game. If you ever played project Totengraeber, you would have noticed that those sounds, if used properly, can contribute to the athmosphere of your addon.

There are several ways to implement this feature. So I'll give you an example that can be modified to your likings. It's all a matter of taste.


Open WL_PLAY.C and do a search for the following:

long funnyticount;

below this line, add this one:

long ambientcount;

Now do a search for this block:

//
  // MAKE FUNNY FACE IF BJ DOESN'T MOVE FOR AWHILE
  //

  #ifdef SPEAR
  funnyticount += tics;
  if (funnyticount > 30l*70)
  {
   funnyticount = 0;
   StatusDrawPic (17,4,BJWAITING1PIC+(US_RndT()&1));
   facecount = 0;
  }
  #endif

and add the following block below it:

//
  // PLAY AMBIENT SOUNDS DURING PARTICULAR LEVELS
  //
  switch (gamestate.mapon)
   {
   case 0:  // level 1
    ambientcount += tics;
    if (ambientcount > 30l*70) //30l means every 30 seconds
     {
     ambientcount = 0;
     if (!DigiPlaying)
      SD_PlaySound(SPIONSND);
     }
    break;

   case 6:  // level 7
    ambientcount += tics;
    if (ambientcount > 15l*70) //15l means every 15 seconds
     {
     ambientcount = 0;
     {
     int sounds[8]=
     {
     DEATHSCREAM1SND,
     DEATHSCREAM2SND,
     DEATHSCREAM3SND,
     DEATHSCREAM4SND,
     DEATHSCREAM5SND,
     DEATHSCREAM7SND,
     DEATHSCREAM8SND,
     };

     if (!DigiPlaying)
      SD_PlaySound (sounds[US_RndT()%7]);
     }
     }
    break;

   default: // levels without ambient sounds
    break;
    }


In this example, ambient sounds are played in both levels 1 and 7.
In level 1, the same sound is played every 30 seconds. In level 7, the engine plays one of the guard's "death scream" sounds at random every 15 seconds. (In Wolf, time is measured in "tics" which are 1/70 of a second each, hence the "30l * 70" formula).
The example should be pretty self-explanatory, so it shouldn't be a problem to extend it to suit your needs.


Success!
MCS.