#define status skill1
#define STATUS_IDLE 0
#define STATUS_WALK 1
#define STATUS_ATTACK 2
action enemy()
{
my.status = STATUS_IDLE;
while(me)
{
switch(my.status)
{
case STATUS_IDLE: //wait until i see player
if(c_trace(me.x,player.x,IGNORE_PASSABLE))
my.status = STATUS_WALK;
break;
case STATUS_WALK: //walk to player
if(vec_dist(my.x,player.x) < 128) we are close enough to attack him
my.status = STATUS_ATTACK;
VECTOR temp;
vec_set(temp,player.x);
vec_sub(temp,my.x);
vec_to_angle(temp,temp);
my.pan = temp.x; //Turn to player
c_move(me,vector(5 * time_step,0,0),nullvector,GLIDE | IGNORE_PASSABLE); //walk to player
break;
case STATUS_ATTACK: //Ok, now attack player
ent_animate(me,"attack,anim_status,ANM_CYCLE);
player.health -= 5; //5 DMG per hit
if(vec_dist(me.x,player.x) > 192) //Enemy lost player
my.status = STATUS_IDLE;
break;
}
wait(1);
}
}