Community

SCI Programming => SCI Community How To's & Tutorials => Topic started by: gumby on September 16, 2012, 05:27:49 PM

Title: Give the ego footstep sounds
Post by: gumby on September 16, 2012, 05:27:49 PM
Here's how to do it, using the SNDBLAST or MTBLAST drivers.  I created 4 separate WAV footstep sounds & appended them to 4 empty sound resources.  Then in the room script, I added a doit() method which basically checks the current loop of the ego.  On two of the cells, we trigger a random sound playback of one of the footsteps.

Code: [Select]
(local
     currentCel
     previousCel
     loop
)

...

(method (doit)
(var randomSound)
        = currentCel (send gEgo:cel)

        (if (<> currentCel previousCel)
            = loop (send gEgo:loop)
            = randomSound Random(0 3)
 
            // ego is walking horizonally
   (if(== loop 0 or == loop 1)
      (if(== currentCel 0 or == currentCel 4)    
   (send gTheSoundFX:
           prevSignal(0)
   stop()
   number(randomSound)
   play()
   )
)
    )

   // ego is walking vertically
   (if(== loop 2 or == loop 3)
      (if(== currentCel 3 or == currentCel 0)    
   (send gTheSoundFX:
  prevSignal(0)
  stop()
          number(randomSound)
  play()
    )
       )
   )
)
= previousCel currentCel
)
I did have to make a modification to the ego view in the template game.  The 'vertical' animations (the ones where the ego is walking toward/away from you) only had 5 cells, which made the ego sound like he was hobbling.  I added an additional cell to each loop which worked, but the result is that the ego appears to be dancing.  Quite humorous.

I've uploaded the demo (with source code) to the fan games section. (http://sciprogramming.com/esd_scigames/game.php?action=download&id=173)
Title: Re: Give the ego footstep sounds
Post by: Collector on September 16, 2012, 09:50:41 PM
It doesn't seem to be showing up, yet. Are you going to add this to the Wiki, too?
Title: Re: Give the ego footstep sounds
Post by: gumby on September 16, 2012, 11:58:27 PM
Yes, it's now added to the wiki.
Title: Re: Give the ego footstep sounds
Post by: Cloudee1 on September 17, 2012, 05:42:59 PM
Amusing... the game can be downloaded now. I've gone ahead and added a link in your original post to the game. Almost sounds like he's running when the player moves north and south. But neat either way.
Title: Re: Give the ego footstep sounds
Post by: gumby on September 17, 2012, 09:16:07 PM
Yeah, the problem is the different number of cells, 8 vs 6.  Probably the correct way to do this is to have 8 cells for the north/sound animations too.  But then I'm guessing that the ego would appear to walk too slowly based on the amount of distance traveled on the screen.