I have two tasks that I am trying to perform:

(1) When the player jumps into water, or moves underwater, I would like a "swimming" sound to initiate one at a time.

When I try to initiate the swimming sound, it initiates many many swimming sounds at once, making an ugly noise of many swimming sounds firing off at once. I only want the swimming sound to initiate one at a time.

Here is my code to try and make this happen:

Code:
...

player_code()
{
   ...

   while(1)
   {
      ...

      if(region_check("water",vMin,vMax))
      {
         snd_play ( sndSwim, 100, 0 );
         
         ...
      }

      ...

      wait(1);
   }
}



When the player makes contact with the region titled "water", the "swim" sound fires off one after another in rapid succession, making a loud and irritating noise. Does anyone know of a way to make the "swim" sound initiate only once at a time?

(2) When the player is swimming underwater, I would like a "Breath Control:" countdown to appear on the screen, counting down in seconds from a certain number like 15, and when the number decrements down to 0, the player suffocates and dies.

Here is my code to try and make this happen:

Code:
...

var time_elapsed;

...

TEXT* breathControlText =
{
   layer = 10;
   pos_x = 350;
   pos_y = 490;
   string ("BREATH CONTROL: ");
}

PANEL* breathControlAmount =
{
   ...

   digits (590, 490, 5, *, 1, time_elapsed);
}

...

player_code()
{
   ...

   while(1)
   {
      ...

      if(region_check("water",vMin,vMax))
      {
         snd_play ( sndSwim, 100, 0 );
         
         ...

         set(breathControlText, SHOW);
   	 set(breathControlAmount, SHOW);
   		
	 time_elapsed = timer();
      }

      ...

      wait(1);
   }
}

...



When the player makes contact with the region titled "water", the message comes up on the screen saying, "BREATH CONTROL:", and the time_elapsed value shows next to it, however the time_elapsed value displays approximately 16000, and jitters into the 15000 range, and jitters quickly back and forth between these two ranges without going anywhere else. Does anyone know how to make the time_elapsed value show the elapsed time in seconds that the player is in contact with the region titled "water"? Better yet, does anyone know how to make the time_elapsed value count down in seconds from 15 to 0?

Last edited by Ruben; 07/05/15 11:29.