#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");
}