|
Swim Sound, and Time Countdown
#453014
07/05/15 11:23
07/05/15 11:23
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
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:
...
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:
...
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: FBL]
#453024
07/05/15 16:00
07/05/15 16:00
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
#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
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|