function OrangeRayShooter_process( inst, key )
	local value = inst
	value.speed = 0.5 + 0.5*math.sin( (time-inst.creation_time)/500 )
	if math.abs( inst.targets[inst.target][1] - value.x ) + math.abs( value.targets[value.target][2] - value.y ) < 10 then
		if value.target == #value.targets then
			delete( enemies, key )
		else
			value.target = value.target + 1
			local angle = math.atan2( value.targets[value.target][2] - value.y, value.targets[value.target][1]-value.x )
			value.vel = { math.cos( angle ), math.sin( angle ) }
		end
	end
	if time - value.last_shot > (3000 * options.enemy_reload) then
		value.last_shot = time
		PlaySnd( "shot4.ogg", true, value.x, value.y )
		CreateSimpleRay( value.x-20, value.y, {1, .5, 0, 1} )
		CreateSimpleRay( value.x+20, value.y, {1, .5, 0, 1} )
	end
end

function OrangeRayShooter_hit( inst )
	local col = ( inst.max_health - inst.health ) / inst.max_health
	SetObjSpriteColor( inst.sprite, { 1, 0, 0, col }, 1 )
end

function CreateOrangeRayShooter( x, y, targets )
	local angle = math.atan2( targets[1][2] - y, targets[1][1]-x )
	local spr = CreateSprite( "sprite2", x, y )
	SetObjAnim( spr, 0, false )
	SetObjSpriteColor( spr, { .8, .5, .2, 1} )
	SetObjSpriteColor( spr, { .9, .9, .2, 1 }, 0 )
	local vel = { math.cos( angle ), math.sin( angle ) }
	table.insert( enemies,
		{
			sprite = spr,
			x = x,
			y = y,
			size = 16,
			speed = 3,
			targets = deep_copy( targets ),
			target = 1,
			health = math.floor( 3 * options.enemy_health + 0.5 ),
			max_health = math.floor( 3 * options.enemy_health + 0.5 ),
			last_shot = time-1500,
			score = 500,
			creation_time = time,
			vel = vel,
			hit = OrangeRayShooter_hit,
			process = OrangeRayShooter_process
		})
end
