function LongThingy_process( v, key )
	if dist( v.x, v.y, v.target[1], v.target[2] ) < 16 then
		delete( enemies, key )
	end
	if v.num > 0 and v.batch.dead > v.num - 500 then
		if v.batch.dead > v.num then
			v.immortal = false
			EnemyHit( key, players[1] )
		end
		v.batch.dead = v.batch.dead + 50
	end
end

function LongThingy_destroy( x, y, v )
	v.batch.dead = v.batch.dead + 1
end

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

function CreateLongThingy( x, y, target, n )
	local angle = math.atan2( target[2] - y, target[1]-x )
	local batch = { dead = 0 }
	local sh_x, sh_y = -math.cos( angle ), -math.sin( angle )
	local spr = CreateSprite( "long_thingy", x, y )
	SetObjAnim( spr, "head", false )
	SetObjSpriteAngle( spr, angle - math.pi/2 )
	table.insert( enemies,
				{
					sprite = spr,
					x = x,
					y = y,
					size = 16,
					speed = 1,
					target = target,
					score = 500,
					head = true,
					num = 0,
					vel = { -sh_x, -sh_y },
					batch = batch,
					health = math.floor( 3 * options.enemy_health + 0.5 ),
					max_health = math.floor( 3 * options.enemy_health + 0.5 ),
					destroy = LongThingy_destroy,
					hit = LongThingy_hit,
					process = LongThingy_process
				})
	local x, y = x + 32*sh_x, y + 32*sh_y
	spr = CreateSprite( "long_thingy", x, y )
	SetObjAnim( spr, "neck", false )
	SetObjSpriteAngle( spr, angle - math.pi/2 )
	table.insert( enemies,
				{
					sprite = spr,
					x = x,
					y = y,
					size = 16,
					speed = 1,
					target = target,
					score = 100,
					immortal = true,
					num = 500,
					vel = { -sh_x, -sh_y },
					batch = batch,
					process = LongThingy_process
				})
	for i = 1, n do
		x, y = x + 32*sh_x, y + 32*sh_y
		spr = CreateSprite( "long_thingy", x, y )
		SetObjAnim( spr, "body", false )
		SetObjSpriteAngle( spr, angle - math.pi/2 )
		table.insert( enemies,
				{
					sprite = spr,
					x = x,
					y = y,
					size = 16,
					speed = 1,
					target = target,
					score = 100,
					num = 500+i*500,
					immortal = true,
					vel = { -sh_x, -sh_y },
					batch = batch,
					process = LongThingy_process
				})	
	end
	x, y = x + 32*sh_x, y + 32*sh_y
	spr = CreateSprite( "long_thingy", x, y )
	SetObjAnim( spr, "tail", false )
	SetObjSpriteAngle( spr, angle - math.pi/2 )
	table.insert( enemies,
				{
					sprite = spr,
					x = x,
					y = y,
					size = 16,
					speed = 1,
					target = target,
					score = 100,
					immortal = true,
					num = 1000+500*n,
					vel = { -sh_x, -sh_y },
					batch = batch,
					process = LongThingy_process
				})
end