function BossSI_process( inst, key )
	local v = inst
	if v.dead then
		return
	end
	if not boss_SI then
		CreateParticleSystem( "pexplosion", v.x, v.y )
		delete( enemies, key )
		return
	end
	if not boss_SI.active then
		if v.y >= -150 then
			boss_SI.active = true
		else
			return
		end
	end
	if v.immortal then
		v.immortal = false
		v.speed = 0
	end
	if ( time % 1000 > 500 ) then
		SetObjAnim( v.sprite, 19-v.class*2, false )
	else
		SetObjAnim( v.sprite, (19-v.class*2)+1, false )
	end
	boss_SI.parts = boss_SI.parts - 1
	boss_SI.did_turn[inst] = true
	if time > boss_SI.last_step + 500 then
		if boss_SI.step < boss_SI.last_step_n then
			v.x = v.x + 10 * boss_SI.step_dir
		else
			v.y = v.y + 10
		end
	end
	if time - v.last_shot > (1500 * options.enemy_reload) then
		v.last_shot = time
		if math.random( 1, 10 ) > 7 then
			PlaySnd( "shot1.wav", true, v.x, v.y )
			CreateSimpleBullet( v.x, v.y, { 0, 3 }, { 1, .3, .3, 1 } )
			if v.class > 1 then
				CreateSimpleBullet( v.x, v.y, { -0.5, 2.7 }, { .3, .3, 1, 1 } )
				CreateSimpleBullet( v.x, v.y, {  0.5, 2.7 }, { .3, .3, 1, 1 } )
			end
			if v.class > 2 then
				CreateSimpleBullet( v.x-10, v.y-10, { 0, 3 }, { 1, .3, .3, 1 } )
				CreateSimpleBullet( v.x+10, v.y-10, { 0, 3 }, { 1, .3, .3, 1 } )
			end
		end
	end
	if v.y > 400 then v.y = v.y-400 end
	if boss_SI.parts == 0 then
		if time > boss_SI.last_step + 500 then
			boss_SI.last_step = time
		end
		boss_SI.step = boss_SI.step + 1
		if boss_SI.step > boss_SI.last_step_n + 1 then
			boss_SI.last_step_n = 11
			boss_SI.step_dir = -boss_SI.step_dir
			boss_SI.step = 0
		end
		boss_SI.parts = boss_SI.parts_left
		boss_SI.did_turn = {}
	end
end

function BossSI_hit( v )
	SetObjSpriteColor( v.sprite, {1,1,1,1} )
end

function BossSI_destroy( x, y, v, k )
	if v.dead then
		return
	end
	boss_SI.parts_left = boss_SI.parts_left - 1
	if not boss_SI.did_turn[ v] then
		boss_SI.parts = boss_SI.parts - 1
	end
	if boss_SI.parts_left == 0 then
		boss_SI = nil
		if BossDefeated then BossDefeated() end
	end
end

function CreateBossSI()
	local x
	local y
	if not boss_SI then boss_SI = { step = 0, step_dir = 1, last_step = time, parts = 66, parts_left = 66, active = false, last_step_n = 5, did_turn = {} } end
	for i = 1, 11 do
		for j = 1, 3 do
			x = -250 + ( 550 / 11 ) * (i - 1)
			y = -400 - 32 * (j-1)
			local spr = CreateSprite( "sprite", x , y )
			SetObjAnim( spr, 17, false )
			table.insert( enemies,
					{
							sprite = spr,
							x = x,
							y = y,
							size = 16,
							speed = 1,
							last_shot = 0,
							score = 300,
							vel = { 0, 3 },
							health = 1,
							immortal = true,
							class = 1,
							unbombable = true,
							destroy = BossSI_destroy,
							process = BossSI_process
						})
			CreateLightSource( enemies[#enemies], {1,1,1,-.25}, 45 )
		end
		for j = 4, 5 do
			x = -250 + ( 550 / 11 ) * (i - 1)
			y = -400 - 32 * (j-1)
			local spr = CreateSprite( "sprite", x , y )
			SetObjAnim( spr, 15, false )
			table.insert( enemies,
					{
							sprite = spr,
							x = x,
							y = y,
							size = 16,
							speed = 1,
							last_shot = 0,
							score = 300,
							vel = { 0, 3 },
							health = 1,
							class = 2,
							immortal = true,
							unbombable = true,
							destroy = BossSI_destroy,
							process = BossSI_process
						})
			CreateLightSource( enemies[#enemies], {1,1,1,-.25}, 45 )
		end
		for j = 6, 6 do
			x = -250 + ( 550 / 11 ) * (i - 1)
			y = -400 - 32 * (j-1)
			local spr = CreateSprite( "sprite", x , y )
			SetObjAnim( spr, 13, false )
			table.insert( enemies,
					{
							sprite = spr,
							x = x,
							y = y,
							size = 16,
							speed = 1,
							last_shot = 0,
							score = 300,
							vel = { 0, 3 },
							health = 1,
							class = 3,
							immortal = true,
							unbombable = true,
							destroy = BossSI_destroy,
							process = BossSI_process
						})
			CreateLightSource( enemies[#enemies], {1,1,1,-.25}, 45 )
		end
	end
end

function CreateBossSIFinal()
	local x
	local y
	if not boss_SI then boss_SI = { step = 0, step_dir = 1, last_step = time, parts = 66, parts_left = 66, active = false, last_step_n = 5, did_turn = {} } end
	for i = 1, 11 do
		for j = 1, 1 do
			x = -250 + ( 550 / 11 ) * (i - 1)
			y = -400 - 32 * (j-1)
			local spr = CreateSprite( "sprite", x , y )
			SetObjAnim( spr, 17, false )
			SetObjSpriteColor( spr, { 1, 0, 1, 1 } )
			table.insert( enemies,
					{
							sprite = spr,
							x = x,
							y = y,
							size = 16,
							speed = 1,
							last_shot = 0,
							score = 300,
							vel = { 0, 3 },
							health = 3,
							immortal = true,
							class = 1,
							unbombable = true,
							hit = BossSI_hit,
							destroy = BossSI_destroy,
							process = BossSI_process
						})
			CreateLightSource( enemies[#enemies], {1,0,1,-.25}, 45 )
		end
		for j = 2, 2 do
			x = -250 + ( 550 / 11 ) * (i - 1)
			y = -400 - 32 * (j-1)
			local spr = CreateSprite( "sprite", x , y )
			SetObjAnim( spr, 17, false )
			SetObjSpriteColor( spr, { 0, 1, 1, 1 } )
			table.insert( enemies,
					{
							sprite = spr,
							x = x,
							y = y,
							size = 16,
							speed = 1,
							last_shot = 0,
							score = 300,
							vel = { 0, 3 },
							health = 3,
							immortal = true,
							class = 1,
							unbombable = true,
							hit = BossSI_hit,
							destroy = BossSI_destroy,
							process = BossSI_process
						})
			CreateLightSource( enemies[#enemies], {0,1,1,-.25}, 45 )
		end
		for j = 3, 4 do
			x = -250 + ( 550 / 11 ) * (i - 1)
			y = -400 - 32 * (j-1)
			local spr = CreateSprite( "sprite", x , y )
			SetObjSpriteColor( spr, { 0, 1, 1, 1 } )
			SetObjAnim( spr, 15, false )
			table.insert( enemies,
					{
							sprite = spr,
							x = x,
							y = y,
							size = 16,
							speed = 1,
							last_shot = 0,
							score = 300,
							vel = { 0, 3 },
							health = 1,
							class = 2,
							immortal = true,
							unbombable = true,
							hit = BossSI_hit,
							destroy = BossSI_destroy,
							process = BossSI_process
						})
			CreateLightSource( enemies[#enemies], {0,1,1,-.25}, 45 )
		end
		for j = 5, 5 do
			x = -250 + ( 550 / 11 ) * (i - 1)
			y = -400 - 32 * (j-1)
			local spr = CreateSprite( "sprite", x , y )
			SetObjSpriteColor( spr, { 0, 1, 0, 1 } )
			SetObjAnim( spr, 15, false )
			table.insert( enemies,
					{
							sprite = spr,
							x = x,
							y = y,
							size = 16,
							speed = 1,
							last_shot = 0,
							score = 300,
							vel = { 0, 3 },
							health = 1,
							class = 2,
							immortal = true,
							unbombable = true,
							hit = BossSI_hit,
							destroy = BossSI_destroy,
							process = BossSI_process
						})
			CreateLightSource( enemies[#enemies], {0,1,0,-.25}, 45 )
		end
		for j = 5, 5 do
			x = -250 + ( 550 / 11 ) * (i - 1)
			y = -400 - 32 * (j-1)
			local spr = CreateSprite( "sprite", x , y )
			SetObjSpriteColor( spr, { 0, 1, 0, 1 } )
			SetObjAnim( spr, 13, false )
			table.insert( enemies,
					{
							sprite = spr,
							x = x,
							y = y,
							size = 16,
							speed = 1,
							last_shot = 0,
							score = 300,
							vel = { 0, 3 },
							health = 1,
							class = 3,
							immortal = true,
							hit = BossSI_hit,
							unbombable = true,
							destroy = BossSI_destroy,
							process = BossSI_process
						})
			CreateLightSource( enemies[#enemies], {0,1,0,-.25}, 45 )
		end
	end
end