#東方弾幕風
#Title[さとり通常]
#Text[通常弾幕、再現度は低い]
#ScriptVersion[2]

script_enemy_main
{
	let scroll=0;
	let flag=0;
	let cx=GetCenterX();
	let cy=GetCenterY();
	let boss=GetCurrentScriptDirectory~"img\boss7-2.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetLife(1000);
		SetDamageRate(100,100);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(50);
		SetInvincibility(240);
		LoadGraphic(boss);
		shottask;
		movetask;
		drawtask;
	}
	@MainLoop
	{
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		yield;
	}
	@Finalize
	{
		DeleteGraphic(boss);
	}
	@DrawLoop
	{
		SetTexture(boss);	
		if(flag==1)
		{
			SetGraphicRect(52,0,81,63);
		}
		else if(flag==2)
		{
			SetGraphicRect(24,0,52,63);
		}
		else
		{
			SetGraphicRect(0,0,24,63);
		}
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetX,GetY);
	}
	task shottask
	{
		let r=0;
		let angle=0;
		let a=0;
		wait(120);
		loop
		{
			angle=270;
			r=0;
			a=0;
			loop(10)
			{
				loop(12)
				{
					CreateShot01(GetX+r*cos(a*9),GetY+r*sin(a*9),2,angle+sin(a),51,20);
					CreateShot01(GetX+r*cos(180-a*9),GetY+r*sin(180-a*9),2,180-angle+sin(a),55,20);
					CreateShot01(GetX+r*cos(a*9+120),GetY+r*sin(a*9+120),2,angle+sin(a)+120,51,20);
					CreateShot01(GetX+r*cos(180-a*9+120),GetY+r*sin(180-a*9+120),2,180-angle+sin(a)+120,55,20);
					CreateShot01(GetX+r*cos(a*9+240),GetY+r*sin(a*9+240),2,angle+sin(a)+240,51,20);
					CreateShot01(GetX+r*cos(180-a*9+240),GetY+r*sin(180-a*9+240),2,180-angle+sin(a)+240,55,20);
					angle+=1.8;
					r+=0.8;
					a+=2.4;
					yield;
				}
				CreateShot01(GetX+r*cos(a*9),GetY+r*sin(a*9),2,angle,191,20);
				CreateShot01(GetX+r*cos(180-a*9),GetY+r*sin(180-a*9),2,180-angle,195,20);
				CreateShot01(GetX+r*cos(a*9+120),GetY+r*sin(a*9+120),2,angle+120,191,20);
				CreateShot01(GetX+r*cos(180-a*9+120),GetY+r*sin(180-a*9+120),2,180-angle+120,195,20);
				CreateShot01(GetX+r*cos(a*9+240),GetY+r*sin(a*9+240),2,angle+240,191,20);
				CreateShot01(GetX+r*cos(180-a*9+240),GetY+r*sin(180-a*9+240),2,180-angle+240,195,20);
			}
			wait(120);
			angle=90;
			r=80;
			a=30;
			loop(12)
			{
				loop(10)
				{
					CreateShot01(GetX+r*cos(a*9),GetY+r*sin(a*9),2,angle+cos(a),51,20);
					CreateShot01(GetX+r*cos(180-a*9),GetY+r*sin(180-a*9),2,180-angle+cos(a),55,20);
					CreateShot01(GetX+r*cos(a*9+120),GetY+r*sin(a*9+120),2,angle+cos(a)+120,51,20);
					CreateShot01(GetX+r*cos(180-a*9+120),GetY+r*sin(180-a*9+120),2,180-angle+cos(a)+120,55,20);
					CreateShot01(GetX+r*cos(a*9+240),GetY+r*sin(a*9+240),2,angle+cos(a)+240,51,20);
					CreateShot01(GetX+r*cos(180-a*9+240),GetY+r*sin(180-a*9+240),2,180-angle+cos(a)+240,55,20);
					angle+=1.8;
					r-=0.8;
					a-=2.0;
					yield;
				}
				CreateShot01(GetX+r*cos(a*9),GetY+r*sin(a*9),2,angle,191,20);
				CreateShot01(GetX+r*cos(180-a*9),GetY+r*sin(180-a*9),2,180-angle,195,20);
				CreateShot01(GetX+r*cos(a*9+120),GetY+r*sin(a*9+120),2,angle+120,191,20);
				CreateShot01(GetX+r*cos(180-a*9+120),GetY+r*sin(180-a*9+120),2,180-angle+120,195,20);
				CreateShot01(GetX+r*cos(a*9+240),GetY+r*sin(a*9+240),2,angle+240,191,20);
				CreateShot01(GetX+r*cos(180-a*9+240),GetY+r*sin(180-a*9+240),2,180-angle+240,195,20);
			}
			wait(120);
		}
	}
	task movetask
	{
		wait(120);
		loop
		{
			wait(120);
			move(rand(40, 80), rand(-40, 40), 60,GetClipMinX + 32, GetClipMinY + 80,GetClipMaxX - 32, GetClipMinY + 160);
			wait(120);
		}
	}
	task drawtask
	{
		let x=0;
		loop
		{	
			if(GetX>x+0.5)
			{
				flag=1;
			}
			else if(GetX<x-0.5)
			{
				flag=2;
			}
			else
			{
				flag=0;
			}
			x=GetX;
			scroll++;
			yield;
		}
	}
	function move(xMove, yAdd, frame, left, top, right, bottom)
	{
    		let x;
    		let y;
		if(GetPlayerX < GetX) 
		{
			x = GetX - xMove;
			if(x < left) 
			{
				x = GetX + xMove;
			}
		} 
		else {
			x = GetX + xMove;
			if(right < x)
			{
				x = GetX - xMove;
			}
		}
		y = GetY + yAdd;
		if(y < top)
		{
			y = top;
		}
		else if(bottom < y)
		{
			y = bottom;
		}
  			SetMovePosition02(x, y, frame);
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}