Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, monk12, TipmyPip, Quad, aliswee), 1,029 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Swim Sound, and Time Countdown #453014
07/05/15 11:23
07/05/15 11:23
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
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.
Re: Swim Sound, and Time Countdown [Re: Ruben] #453019
07/05/15 13:36
07/05/15 13:36
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
why not use total_ticks + offset variable and cycle() and maybe also lock the playback by checking if sound is active with snd_playing()?

Re: Swim Sound, and Time Countdown [Re: FBL] #453024
07/05/15 16:00
07/05/15 16:00
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
Code:
#include <acknex.h>
#include <default.c>
#include <level.c>

#define outside_region 0	//0 - box is fully outside the region.
#define intersects_region 1//1 - box is partially inside the region.
#define inside_region 2		//2 - box is fully inside the region.

action test()
{
	
	VECTOR camera_min;
	VECTOR camera_max;
	
	VECTOR region_min;
	VECTOR region_max;
	
	//event
	STRING *my_swim_status=str_create("");
	
	//event sounds
	SOUND* enter_water_snd=snd_create("splash.wav");	
	var enter_snd_handle=0;
	SOUND* exit_water_snd=snd_create("splash.wav");
	var exit_snd_handle=0;
	SOUND* splosh_water_snd=snd_create("whosh.wav");
	var splosh_snd_handle=0;
	
	int player_moved_in_water=0;
	
	while(1)
	{
		vec_set(camera_min,vector(camera.x-10,camera.y-10,camera.z-10));
		vec_set(camera_max,vector(camera.x+10,camera.y+10,camera.z+10));
		
		//find region & get sizes 
		if(region_get("water",1,region_min,region_max))
		{

			if(region_check("water",camera_min,camera_max) == intersects_region)
			{
				//if event wasnt "touching water"
				if(!str_cmpi(my_swim_status,"touching water"))
				{
					my_swim_status="touching water";
					if(!snd_playing (enter_snd_handle))
					{
						enter_snd_handle= snd_play(enter_water_snd,100,50);
					}
				}
			}
			
			if(region_check("water",camera_min,camera_max) == inside_region)
			{
				my_swim_status="inside water";

				if(!snd_playing (splosh_snd_handle) && !snd_playing (enter_snd_handle))
				{
					if(player_moved_in_water==1) splosh_snd_handle= snd_play(splosh_water_snd,100,50);
				}
			}

			if(region_check("water",camera_min,camera_max) == outside_region)
			{
				my_swim_status="outside water";
			}
		
			draw_box3d(region_min,region_max,COLOR_RED,100);
		}
	
		if(key_w || key_s || key_a|| key_d)
		{
			if(str_cmpi(my_swim_status,"inside water"))
			{
				player_moved_in_water=1;
			}
			else player_moved_in_water=0;
		}
		if(!key_w && !key_s && !key_a && !key_d)
		{
			player_moved_in_water=0;
		}
		
		draw_text(my_swim_status,0,100,COLOR_RED);
		DEBUG_VAR(player_moved_in_water,120);
		
		wait(1);
	}
	
}

function main()
{
	warn_level = 4;	
	def_move();

	level_load("1.wmb");
	
}



Compulsive compiler
Re: Swim Sound, and Time Countdown [Re: Wjbender] #453051
07/06/15 08:22
07/06/15 08:22
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you Wjbender. I used parts of your code to make the swimming sound work as it should. It now works, thanks to you.

Now I am trying to figure out the time decrementer issue.

Re: Swim Sound, and Time Countdown [Re: Ruben] #453117
07/08/15 13:18
07/08/15 13:18
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
"timer()" does not at all what you want it to do. Read the manual entry for timer, twice.
You decrease time like every other variable:

var my_timer = 16; // once
...
my_timer -= time_step;

The engine's time logic is in ticks, i.e. 1/16th of a second, which means it takes one second for my_timer to reach 0.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Swim Sound, and Time Countdown [Re: Superku] #453126
07/08/15 21:46
07/08/15 21:46
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
Or, simply said, from the Engine's point of view, our second is 16 ticks game-time...and time_step is the duration of the last frame (but not in milliseconds, in ticks!, so around 0.267 average on 60fps (16 ticks/60 frames)). By decrementing with 0.267 every frame, you're decrementing with 16 points per second!
If you want to decrement with 1 per second, divide time_step / 16, but keep in mind that small numbers can become inaccurate.


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Swim Sound, and Time Countdown [Re: EpsiloN] #453128
07/09/15 05:53
07/09/15 05:53
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you Superku and EpsiloN. I used the information you put forth, and it now works great. It is counting down in seconds.


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1