#東方弾幕風
#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
	{
		SetLife(1500);
		SetDamageRate(10,0);
		SetGraphicRect(1,1,64,64);
		SetInvincibility(120);
		LoadGraphic(imgExRumia);
		SetTexture(imgExRumia);	
		SetEffectForZeroLife(60,300,2);
		shottask;
	}
	@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;
		let s2=1;
		let angle2=30;
		SetShotAutoDeleteClip(64,512,64,64);
		SetMovePosition02(cx,-120,0);
		wait(2);
		SetMovePosition02(cx,cy-120,60);
		wait(120);
		SetScore(30000);
		SetTimer(99);
		CutIn(YOUMU,"幻想「薄野の亡霊」",0,0,0,0,0);
		wait(120);
		loop
		{
			if(GetEnemyLife>1125)
			{
				wait(20);
				shot(s,s2,rand(30,90),1);
				wait(20);
				shot(s,s2,rand(30,90),0);
			}
			if(GetEnemyLife<=1125&&GetEnemyLife>750)
			{
				wait(20);
				shot(s,s2,rand(30,90),1);
				wait(20);
				shot(s,s2,rand(30,90),0);
			}
			if(GetEnemyLife<=750&&GetEnemyLife>375)
			{
				loop(2)
				{
					wait(3);
					shot(s,s2,rand(30,90),1);
				}
				loop(2)
				{
					wait(3);
					shot(s,s2,rand(30,90),0);
				}
				wait(20);
			}
			if(GetEnemyLife<=375||GetTimer<30)
			{
				loop(5)
				{
					wait(3);
					shot(s,s2,rand(30,90),1);
				}
				loop(5)
				{
					wait(3);
					shot(s,s2,rand(30,90),0);
				}
				wait(35);
			}
			loop(24)
			{
				CreateShotA(s,GetX,GetY,0);
				SetShotDataA(s,0,1,angle2,0,0,3,9);
				FireShot(s);
				angle2-=10;
			}
			angle2=30;
		}
	}
	function shot(let shotid,let shotid2,let shottime,let right)
	{
		let long =48;
		let speed=0;
		let po =0;
		let point=0;
		let r=90;
		let angle=0;
		let carb=0;
		let time=shottime;
		if(right==1)
		{
			point=GetClipMaxX+32;
			angle=rand(220,260);
			carb=rand(-1,0);
		}
		else
		{
			point=GetClipMinX-32;
			angle=rand(320,280);
			carb=rand(1,0);
		}
		CreateLaserC(shotid,point,rand(GetClipMinY,GetClipMaxY),10,long,160,0);
		SetLaserDataC(shotid,0,6,angle,carb,0,2);
		loop(12)
		{
			CreateShotA(shotid2,0,0,0);
			SetShotDataA(shotid2,0,0,90,0,0,3,253);
			SetShotDataA(shotid2,shottime-time,0,rand(260,280),0,0,3,74);
			SetShotDataA(shotid2,shottime-time+10,0,rand(85,95),0,0.1,rand(1.5,2.5)+speed,74);
			AddShot(time,shotid,shotid2,48);	
			time-=4;
			speed-=0.03;
		}
		SetShotKillTime(shotid,shottime);
		FireShot(shotid);
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}