if(my.state==2) //chasing player
{
if(c_trace(my.x, content_right, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES)+c_trace(my.x, content_left, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES)==0)
{
vec_set(temp_vec, player.x); //turn smoothly to player
vec_sub(temp_vec,my.x);
vec_to_angle(temp_angle, temp_vec);
if(ang(temp_angle.pan - my.pan)<-2|ang(temp_angle.pan - my.pan)>2) my.pan += sign(ang(temp_angle.pan - my.pan))*time_step*5;
}
vec_set(content_right, vector(50, -20, -15));
vec_rotate(content_right, my.pan);
vec_add(content_right, my.x);
if(c_trace(my.x, content_right, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES)!=0)
{
my.pan += 10 * time_step; // then rotate the enemy, allowing it to avoid the obstacle
}
vec_set(content_left, vector(50, 20, -15));
vec_rotate(content_left, my.pan);
vec_add(content_left, my.x);
if(c_trace(my.x, content_left, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES)!=0)
{
my.pan -= 10 * time_step; // then rotate the enemy, allowing it to avoid the obstacle
}
c_move (my, vector(10 * time_step, 0, 0), nullvector, GLIDE|IGNORE_PASSABLE);
ent_animate(my, "run", my.animation_frame, ANM_CYCLE); // play the "run" animation
my.animation_frame += 9 * time_step; // "9" controls the animation speed
if(vec_dist(my.x, player.x)<500) //attack
{
my.state=3;
my.animation_frame=0;
}
if(vec_dist(my.x, player.x)>2500) //stand
{
my.state=1;
my.animation_frame=0;
}
}