Footsteps sounds (Tehcdemo)

Need help with using DizzyAGE then look here
Post Reply
Verm-V
Your Backpack is Empty
Posts: 27
Joined: Mon Feb 15, 2016 5:53 am

Footsteps sounds (Tehcdemo)

Post by Verm-V » Wed Mar 28, 2018 4:39 pm

Footsteps Tech Demo (V000-001)
https://yadi.sk/d/g67HisAa3TV4Go
Now dizzy knows how to make sounds of steps while walking.
You can make the sounds different depending on the surface (stone, grass, sand, metal, etc.).
--------------------
A little description of what was done.
--------------------
First the sounds. I took the sounds of footsteps from Counter Strike, they are not really suited to the game, but good to show the idea.
Next, the sounds are thrown into the Samples folder and renamed to our task, it turns out something like this:

Code: Select all

10001 pl_step1.wav
10002 pl_step2.wav
10003 pl_step3.wav
10004 pl_step4.wav
10011 pl_wood1.wav
10012 pl_wood2.wav
10013 pl_wood3.wav
10014 pl_wood4.wav
10021 pl_grass1.wav
10022 pl_grass2.wav
10023 pl_grass3.wav
10024 pl_grass4.wav
10031 pl_metal1.wav
10032 pl_metal2.wav
10033 pl_metal3.wav
10034 pl_metal4.wav
10041 pl_sand1.wav
10042 pl_sand2.wav
10043 pl_sand3.wav
10044 pl_sand4.wav
10051 pl_tile1.wav
10052 pl_tile2.wav
10053 pl_tile3.wav
10054 pl_tile4.wav
For each type of surface there are 4 sounds, which will be selected random. Each sound is slightly different from each other, this is done in order to look more natural. First time i tried one sound for all, but i didn't like it.

The sample number is based on the following logic:
The first two digits(counting from left)"10" is to separate step samples from others
The third and fourth digit indicates the material that dizzy is walking
The last digit, the number of the sound in the set for one material.

Further changes in scripts:
sound.gs

Code: Select all

#def   FX_STEP_0_1   10001 //normal step
#def   FX_STEP_0_2   10002
#def   FX_STEP_0_3   10003
#def   FX_STEP_0_4   10004

#def   FX_STEP_1_1   10011 //wood floor step
#def   FX_STEP_1_2   10012
#def   FX_STEP_1_3   10013
#def   FX_STEP_1_4   10014

#def   FX_STEP_2_1   10021 //grass step
#def   FX_STEP_2_2   10022
#def   FX_STEP_2_3   10023
#def   FX_STEP_2_4   10024

#def   FX_STEP_3_1   10031 //metal step
#def   FX_STEP_3_2   10032
#def   FX_STEP_3_3   10033
#def   FX_STEP_3_4   10034

#def   FX_STEP_4_1   10041 //sand step
#def   FX_STEP_4_2   10042
#def   FX_STEP_4_3   10043
#def   FX_STEP_4_4   10044

#def   FX_STEP_5_1   10051 //grass step
#def   FX_STEP_5_2   10052
#def   FX_STEP_5_3   10053
#def   FX_STEP_5_4   10054
Sample names are not important, in code used only their numbers.

def.gs

Code: Select all

#def G_FOOTSTEPS              88   // вкл/выкл звуки шагов

#def MAT_STEP            20   // standart step
#def MAT_STEP_WOOD      21   // wood floor
#def MAT_STEP_GRASS      22   // grass
#def MAT_STEP_METAL      23   // metal plates
#def MAT_STEP_SAND      24   // sand
#def MAT_STEP_STONE      25   // stone
The first variable is the flag whether the sounds of steps are ON ot OFF in the game, the rest is the definition of different materials with different surfaces

in handlers.gs in HandlerGameInit function() add material properties:

Code: Select all

МaterialSetDensity( MAT_STEP,       MATD_HARD );
MaterialSetDensity( MAT_STEP_WOOD,  MATD_HARD );
MaterialSetDensity( MAT_STEP_GRASS, MATD_HARD );
MaterialSetDensity( MAT_STEP_METAL, MATD_HARD );
MaterialSetDensity( MAT_STEP_SAND,  MATD_HARD );
MaterialSetDensity( MAT_STEP_STONE, MATD_HARD );

MaterialSetColor( MAT_STEP,       0xFF006000 );
MaterialSetColor( MAT_STEP_WOOD,  0xFF006000 );
MaterialSetColor( MAT_STEP_GRASS, 0xFF006000 );
MaterialSetColor( MAT_STEP_METAL, 0xFF006000 );
MaterialSetColor( MAT_STEP_SAND,  0xFF006000 );
MaterialSetColor( MAT_STEP_STONE, 0xFF005000 );
All materials are set to BLOCK property, but you can do other things as needed. For example, the CLOUD property is quite suitable for snow

And in the HandlerGameStart () function, enable the flag of steps depending on the option in the ini file:

Code: Select all

// footsteps
mode = 1;                     // Steps sound is ON by default
gs_inigetint("dizzy.ini", "AUDIO", "footsteps", &mode);      // read parameter from ini-file 'footsteps'
GameSet(G_FOOTSTEPS, mode);               // and writhe it to global variable G_FOOTSTEPS
Then in movement.gs in CM_Update function() add the procedure of footsteps sound (I put it in the condition if( PlayerGet(P_STATUS)!=STATUS_SCRIPTED ))

Code: Select all

//steps sound
if(GameGet(G_FOOTSTEPS))
{
   mat_under=0; 
   for(i=20;i<MAT_MAX-1;i++)
   {
      if(IsMaterialUnderPlayer(i)) mat_under = i;
   } //here we determine the material on which is now walking Dizzy
   if( status == STATUS_WALK && mat_under >= 20) 
   // check whether the sound of footsteps is ON, is dizzy in the status of the walk and that the material underneath is have sound
   {
      frame = PlayerGet(P_FRAME);//check the frame number of the animation
      if(frame%8 == 3 || frame%8 == 7 ) //checking if it's a frame where dizzy puts his foot on the ground.
      {
         dfx = ( mat_under - 20 ) * 10; //convert the material number to find the sample
         ddfx = gs_rand(4)+1; //select one of four samples for this material by random
         fx = 10000+dfx+ddfx; //the final number of the sample that will sound
         for (i=SOUND_VOICES-1; i>=0; i--)      
         {
            if (SamplePlaying(i) == fx)      
            SampleStop(i);         
         }//if the selected sample already sounds, then just turn it off, otherwise it will not playing
         SamplePlay(fx);//play sample
      }
   }
}
(here slightly changed that now in the code - cut out debugging information and added comments)

And finally in the map editor assign materials map to those surfaces on which we want hear the steps of those material numbers (20 and more) that we previously defined in def.gs

Now small remarks.
1. The sounds should be as short as possible and not too loud (think 20% or 30% quieter than other sounds), so as not to drown out everything else and not merge into a cacophony.
2. Since the engine produces material under the player in the form of a bitmask, if there are several materials in one place, the sound will be played for the last one in the list
3. Exactly the same principle you can add sounds to dizzy when he is rolling on any surface. Only need the sounds themselves and to experiment on what shots to lose them.
4. All changes were made on a modified engine with a 1-pixel movement Dizzy but the same logic is suitable for a standard engine.
-------------
Sorry for bad english.

Post Reply