function GrayStuff_process( inst, key )
	local value = inst
	if value.batch.left == 1 then
		value.score = 500
	end
	inst.speed = 1 + math.sin( (time-inst.creation_time)/1000 )
	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.x, value.targets[value.target][1]-value.x )
			value.vel = { math.cos( angle ), math.sin( angle ) }
		end
	end
	if time - value.last_shot > (1500 * options.enemy_reload) and math.random( 1, 10 ) > 7 then
		value.last_shot = time
		PlaySnd( "shot4.ogg", true, value.x, value.y )
		local plr = math.random( 1, players_num )
		local ang = math.atan2( players[plr].y - value.y, players[plr].x - value.x )
		local vx = math.cos(ang)
		if math.abs( vx ) < 0.3 then
			CreateSimpleBullet( value.x, value.y, { vx, 3 }, {.8, .8, .8, 1 } )
		else
			CreateSimpleBullet( value.x, value.y, { 0, 3 }, { .8, .8, .8, 1 } )
		end
	end
end

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

function CreateGrayStuff( x, y, targets, number )
	local angle = math.atan2( targets[1][2] - y, targets[1][1]-x )
	local batch = { left = number }
	Resume( NewThread( function()
			for i = 1, number do
				local spr = CreateSprite( "sprite", x, y )
				SetObjAnim( spr, 5, false )
				SetObjSpriteColor( spr, RGB(128, 128, 160) )
				SetObjSpriteColor( spr, RGB(128, 200, 128), 0 )
				local vel = { math.cos( angle ), math.sin( angle ) }
				table.insert( enemies,
						{
							sprite = spr,
							x = x,
							y = y,
							size = 16,
							speed = 2,
							targets = deep_copy( targets ),
							target = 1,
							creation_time = time,
							last_shot = 0,
							score = 100,
							vel = vel,
							plr = math.random( 1, players_num ),
							health = math.floor( 1 * options.enemy_health + 0.5 ),
							max_health = math.floor( 1 * options.enemy_health + 0.5 ),
							hit = GrayStuff_hit,
							batch = batch,
							destroy = function( x, y, v ) v.batch.left = v.batch.left - 1 end,
							process = GrayStuff_process
						})
					Wait( 500 )
				 end
			end ))
end