<?xml version="1.0" ?>
<!DOCTYPE bulletml SYSTEM "../barrage.dtd">

<barrage>

<barrageInfo>
  <filename>Ketsui_4boss_bit1</filename>
  <group>user</group>
  <title>アンバーばらまきビット</title>
  <description>だんだん広くなる2wayを撃ちながら移動するビット。人気有る攻撃なのに収録されてないようなのでちょっとひねって作ってみました</description>
  <capture>適当に。</capture>
  <author>Pentan</author>
</barrageInfo>

<barrageStyle>
  <bulletLanguage name="lua"/>
</barrageStyle>

<lua>
<![CDATA[
plybitx=150
topx, topy=0,0

function top()
	local turn=getTurn()
	
	topx, topy=getX(), getY()
	plybitx=150-getRank()*80
	fire( 0, 0, "kizunaBit", 0 )
	fire( 0, 0, "kizunaBit", 2 )
	
	local interval=math.floor( 60-getRank()*30)
	
	if turn>1200 then
		if turn>1300 then quit() end
	elseif math.mod( turn, 30 )==0 then
		if math.random()<0.5 then
			fire( 12, 3-10*getRank(), "bitShooter" )
		else
			fire( -12, 3-10*getRank(), "bitShooter" )
		end
	end
end

border=10
function kizunaBit(id)
	local cx, cy=getPlayerX()-( (id-1)*plybitx), getPlayerY()
	if cx<border then
		cy=topy+(cy-topy)*(topx-border)/(topx-cx)
		cx=border
	elseif cx>getMaxX()-border then
		cy=topy+(cy-topy)*(topx-getMaxX()+border)/(topx-cx)
		cx=getMaxX()-border
	end
	
	setPos( cx, cy )
	if getTurn()>0 then
		local vx, vy=topx-cx, topy-cy
		local spd=10/math.sqrt( vx*vx+vy*vy)
		fire( vx*spd, vy*spd, "kizunaShot" )
		vanish()
	end
end

function kizunaShot()
	catoff=30
	if math.abs(topx-getX())<catoff and math.abs(topy-getY())<catoff then vanish() end
end

bitspd=3.0
function bitShooter()
	if getTurn()>5 then
		local aim=getPlayerAngle()+0.2-math.random()*0.4
		if math.random()<0.5 then
			fire( math.sin(aim)*bitspd, -math.cos(aim)*bitspd, "shooter1" )
		else
			fire( math.sin(aim)*bitspd, -math.cos(aim)*bitspd, "shooter2" )
		end
		vanish()
	end
end

function twoway( width )
	local spd=1.5
	local bvx, bvy=getSpeedX()/bitspd, getSpeedY()/bitspd
	local sn, cs=math.sin(width*0.5), math.cos(width*0.5)
	fire( (bvx*cs-bvy*sn)*spd, (bvx*sn+bvy*cs)*spd )
	fire( (bvx*cs+bvy*sn)*spd, (-bvx*sn+bvy*cs)*spd )
end

function vanishCheck()
	local px, py=getPlayerX(), getPlayerY()
	local cx, cy=getX(), getY()
	local v1x, v1y=topx-cx, topy-cy
	local v2x, v2y=px-plybitx-cx, py-cy
	local v3x, v3y=px+plybitx-cx, py-cy
	
	if v1x*v2y-v1y*v2x<0 and v2x*v3y-v2y*v3x<0 and v3x*v1y-v3y*v1x<0 then
		vanish()
	end
	
end

function shooter1()
	-- wide
	local turn=getTurn()
	if math.mod( turn, 4 )==0 then
		local w=0.15+turn*0.1
		twoway( w )
	end
	vanishCheck()
end

function shooter2()
	-- narrow
	fire( getSpeedX(), getSpeedY(), "shooter22" )
	vanish()
end

function shooter22()
	local turn=getTurn()
	if math.mod( turn, 4 )==0 then
		local w=0.1+turn*0.02
		twoway( w )
	end
	vanishCheck()
end

]]>
</lua>

</barrage>