#東方弾幕風
#Title[紋章「多重図形結界」]
#Text[試作]
#ScriptVersion[2]
script_enemy_main
{
	let cx=GetCenterX();//STGシーンの中心x座標を取得
	let cy=GetCenterY();//STGシーンの中心y座標を取得
	let imgExRumia=GetCurrentScriptDirectory~"img\ExRumia.png";
	let imgExRumiaBack=GetCurrentScriptDirectory~"img\ExRumiaBack.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetScore(30000);
		SetLife(600);
		SetDamageRate(10,8);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(60);
		SetGraphicRect(1,1,64,64);
		SetInvincibility(60);
		LoadGraphic(imgExRumia);
		SetTexture(imgExRumia);	
		shottask;
		CutIn(YOUMU,"紋章「多重図形結界」",0,0,0,0,0);//スペルカード名表示
	}
	@MainLoop
	{
		yield;
		SetCollisionA(GetX(),GetY(),24);//当たり判定(自弾)登録
		SetCollisionB(GetX(),GetY(),24);//当たり判定(体当たり)登録
	}
	@Finalize
	{
		loop(8)
		{
			CreateItem(ITEM_SCORE,cx+rand(-100,100),rand(20,100));
		}
	}
	@DrawLoop
	{
		SetGraphicRect(1,1,64,64);
		SetAlpha(255);
		DrawGraphic(GetX(),GetY());
	}
	task shottask
	{
		let s=0;
		wait(120);
		loop
		{
			let angle=rand(0,360);
			angle=rand(0,360);
			shot(s,GetX+80*cos(angle),GetY+80*sin(angle),angle+150);
			shot(s,GetX+80*cos(angle+120),GetY+80*sin(angle+120),angle+270);
			shot(s,GetX+80*cos(angle+240),GetY+80*sin(angle+240),angle+30);
			shot2(s,GetX+80*cos(angle+45),GetY+80*sin(angle+45),angle+270);
			shot2(s,GetX+80*cos(angle+135),GetY+80*sin(angle+135),angle);
			shot2(s,GetX+80*cos(angle+225),GetY+80*sin(angle+225),angle+90);
			shot2(s,GetX+80*cos(angle+315),GetY+80*sin(angle+315),angle+180);
			shot3(s,angle);
			wait(60);
		}
	}
	function shot(let shotid,let x,let y,let angle)
	{
		let speed=0;
		let angle2=0;
		loop(28)
		{
			speed=((x - GetX) ^ 2 + (y - GetY) ^ 2) ^ 0.5/40;
			angle2=atan2(GetY-y,GetX-x)+90;
			CreateShotA(shotid,x,y,10);
			SetShotDataA(shotid,0,0,angle2,0,speed/100,speed,9);
			FireShot(shotid);
			x=x+5*cos(angle);
			y=y+5*sin(angle)
		}
	}
	function shot2(let shotid,let x,let y,let angle)
	{
		let speed=0;
		let angle2=0;
		loop(23)
		{
			speed=((x - GetX) ^ 2 + (y - GetY) ^ 2) ^ 0.5/40;
			angle2=atan2(y-GetY,x-GetX)+90;
			CreateShotA(shotid,x,y,10);
			SetShotDataA(shotid,0,0,angle2,0,speed/100,speed,11);
			FireShot(shotid);
			x=x+5*cos(angle);
			y=y+5*sin(angle);
		}
	}
	function shot3(let shotid,let angle)
	{
		let x=0;
		let y=0;
		let speed=0;
		loop(72)
		{
			x=GetX+60*cos(angle);
			y=GetY+60*sin(angle);
			speed=((x - GetX) ^ 2 + (y - GetY) ^ 2) ^ 0.5/40;
			CreateShotA(shotid,x,y,10);
			SetShotDataA(shotid,0,1,angle-180,0,speed/100,speed,13);
			FireShot(shotid);
			angle+=5;
		}
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}