define max_alpha, skill1;
define max_fog, 250;
var cam_fog = 500; // needs to be a variable so it can get closer and further away to the camera as needed
var wind[3];
function set_alpha()
{
var fade_speed = 0.5;
// fade model in
my.alpha=0;
my.max_alpha = integer(random(30));
if(my.max_alpha < 10){ my.max_alpha = 15; }
while(my.alpha < my.max_alpha)
{
my.alpha += fade_speed*time_step;
wait(1);
}
my.alpha = my.max_alpha;
}
function fog_wind()
{
while(1)
{
// new wind direction...
vec_set(wind.x, vector((random(0.5) - .25)*1.5, (random(0.5) - .25)*1.5, random(1)*.4));
//wait(-1 + random(3));
wait(1);
}
}
function move_fog()
{
var roll_speed;
var fade_distance;
fade_distance = cam_fog+(cam_fog/7);
var fog_speed = 20;
roll_speed = random(2)-1;
while(me)
{
my.roll += roll_speed*time_step; //roll this sprite
// update position globally
c_move(my, nullvector, vector(random(fog_speed)*wind.x*time_step, random(fog_speed)*wind.y*time_step, 0), IGNORE_PASSABLE);
// fade sprite when close to camera
if(vec_dist(my.x, camera.x) < fade_distance)
{
my.alpha = minv(my.max_alpha, vec_dist(camera.x, my.x) * my.max_alpha / fade_distance);
}
wait(1);
}
}
function autofog()
{
var cam_pos[3];
var randint;
vec_scale(my.scale_x, 0.8);
my.passable = on;
my.transparent = on;
//fade in slowly
set_alpha();
move_fog();
while(me)
{
if(my.alpha < my.max_alpha) { my.alpha += time_step; }
vec_set(cam_pos, camera.x);
cam_pos.z = my.z;
if(vec_dist(my.x, cam_pos) >= cam_fog)
{
// fade the fog out
while(my.alpha > 0) { my.alpha -= time_step; wait(1); }
// set on new position at edge of fog distance
vec_set(my.x, vector(cycle(my.x, camera.x - cam_fog, camera.x + cam_fog), cycle(my.y, camera.y - cam_fog, camera.y + cam_fog), camera.z - random(100) + random (200)));
}
wait(5);
}
}
var fogcount;
function generate_fog()
{
var randint; // random fog sprite
var pos_place[3];
fog_wind(); // sets a random fog position every so often
if(fogcount<250)
{
// set random position around camera
vec_set(pos_place.x, vector(((camera.x - random(cam_fog)) + (camera.x + random(cam_fog))), ((camera.y - random(cam_fog)) + (camera.y + random(cam_fog))), ((camera.z - random(cam_fog/8)) + random(cam_fog/4))));
// vec_set(pos_place.x, nullvector);
// get a random number
randint = integer(random(2));
// create different fog, based on random number
if(randint == 0){you=ent_create("Dust_1.tga", pos_place, autofog);you.passable = on;}
if(randint == 1){you=ent_create("Dust_2.tga", pos_place, autofog);you.passable = on;}
fogcount += 1;
}
else{return;}
}