event_inherited()

hp = 4
spr_idle = spr_enemy_green
spr_aggro = spr_enemy_green_aggro
spr_hurt = spr_enemy_green_hurt
aggro_dist = 400
spd = 1

state.add("hurt", {
	enter: function(){
		hp = approach(hp, 0, 1)
		sprite_index = spr_hurt
	},
	step: function(){
		if (animation_end()){
			state_switch(get_previous_state(id))
		}
		
		if (hp == 0){
			repeat (5) instance_create_layer(x, y, "Instances", obj_dust)
			instance_destroy()
		}
		
		move_and_collide()
		
		if (hsp != 0) image_xscale = sign(hsp)
	}
})
state.add("chase", {
    enter: function(){
        sprite_index = spr_aggro
		alarm[0] = 60
    },
    step: function(){
		var _list = ds_list_create()
		collision_line_list(x, y, obj_player.x, obj_player.y, obj_wall, false, true, _list, false)
		if (ds_list_empty(_list) && alarm[0] == -1){
			alarm[0] = 60
			audio_play_sound(sfx_shoot, 2, false)
			with (instance_create_layer(x, y, "Instances", obj_bullet)) direction = point_direction(x, y, obj_player.x, obj_player.y)
		}
		
		ds_list_destroy(_list)
		
		
        //image_angle = point_direction(x, y, obj_player.x, obj_player.y)
		if (hsp != 0) image_xscale = sign(hsp)
        mp_potential_step_object(obj_player.x, obj_player.y, spd, par_enemy_avoid)
		
		if (point_distance(x, y, obj_player.x, obj_player.y) > aggro_dist){
			state_switch(get_previous_state(id))
		}
    },
})
