#define max_alpha skill1
#define max_fog 150
var cam_fog = 100; // needs to be a variable so it can get closer and further away to the camera as needed
VECTOR wind;
void set_alpha()
{
var fade_speed = 0.5;
// fade model in
my.alpha=70;
my.max_alpha = integer(random(30));
if(my.max_alpha < 10){ my.max_alpha = 25; }
while(my.alpha < my.max_alpha)
{
my.alpha += fade_speed*time_step;
wait(1);
}
my.alpha = my.max_alpha;
}
void fog_wind()
{
while(1)
{
// new wind direction...
vec_set(wind.x, vector((random(1) - .5)*1.5, (random(1) - .5)*1.5, random(1)*.4));
wait(-5 + random(3));
}
}
void move_fog()
{
var roll_speed;
var fade_distance = cam_fog+(cam_fog/6);
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);
}
}
void autofog()
{
VECTOR cam_pos;
var randint;
vec_scale(my.scale_x, 0.8);
set(my, PASSABLE | TRANSLUCENT); // can add BRIGHT, but slows FPS down
//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);
}
}
void generate_fog()
{
var randint; // random fog sprite
var fogcount;
VECTOR pos_place;
fog_wind(); // sets a random fog position every so often
for(fogcount=0; fogcount<max_fog; fogcount++)
{
// 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/4)) + random(cam_fog/2))));
// vec_set(pos_place.x, nullvector);
// get a random number
randint = integer(random(2));
// create different fog, based on random number
if(randint == 0){ ent_create("Dust_1.tga", pos_place, autofog); }
if(randint == 1){ ent_create("Dust_2.tga", pos_place, autofog); }
}
}