#東方弾幕風
#Title[虹剣「エレメンタリーソード」]
#Text[派生スペル]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]


script_enemy_main
{
	let count=0;
	let cx=GetCenterX();//STGシーンの中心x座標を取得;
	let step=1;
	let imgExRumia="script\ExRumia\img\ExRumia.png";
	let imgExRumiaBack="script\ExRumia\img\ExRumiaBack.png";
	let Timer=[GetCurrentScriptDirectory~"se\cursor15_b.wav",GetCurrentScriptDirectory~"se\cursor15_a.wav"];
	let timestart=0;
	let seNumber=2;
	let SE=[GetCurrentScriptDirectory~"se\arrow01.wav",
	        GetCurrentScriptDirectory~"se\eco02_b.wav",
	        GetCurrentScriptDirectory~"se\eco00.wav"];
	@Initialize
	{
		SetScore(100000);//スペルカードボーナスを50000に設定
		SetLife(216);//ライフを280に設定
		SetDamageRate(1,0);//披ダメージを10%に設定
		SetTimer(1000);//時間制限を60秒に設定
		SetRateScoreSystemEnable(false);

		SetGraphicRect(1,1,64,64);//描画元矩形を設定
		SetInvincibility(30);//敵を30フレーム無敵にする
		LoadGraphic(imgExRumia);//画像「img\ExRumia.png」を読みこむ		
		LoadGraphic(imgExRumiaBack);
		ascent(i in 0..seNumber){LoadSE(SE[i]);}
		LoadSE(Timer[0]);
		LoadSE(Timer[1]);
		SetColor(255,64,255);
		SetMovePosition02(cx-60*step,120,60);//座標(cx-60*step,120)へ60フレームかけて移動する
		Concentration01(120);
		CutIn(KOUMA,"虹剣「エレメンタリーソード」",0,0,0,0,0);//スペルカード名表示
	}
	
	@MainLoop
	{
		if(GetTimer==9 && timestart==0){Timecounter;timestart++;}
		SetColor(255,64,255);
		yield;
		if(count==90)
		{
			SetMovePosition02(cx-60*step,120,60);
			Concentration01(120);
		}
		if(count==150)
		{//レーザーを出現させる
			let laser=0;
			CreateLaserB(laser,0,30,PURPLE02,0);
			SetShotKillTime(laser,180);
			if(step==1){SetLaserDataB(laser,0,10,0,0,0,0,0,0);}
			else if(step==-1){SetLaserDataB(laser,0,10,0,0,180,0,180,0)};		
			SetLaserDataB(laser,60,0,NULL,0,NULL,0,NULL,0);
			SetLaserDataB(laser,90,0,NULL,0,NULL,-3.0*step,NULL,-3.0*step);
				
			let i=60;
			while(i<90)
			{
				let j=0;
				while(j<400)
				{//レーザーに弾を登録する
					let shot=1;
					CreateShotA(shot,0,0,30);
					if(step==1){SetShotDataA(shot,0,1.5,90,0,0,1.5,RED02);}
					else if(step==-1){SetShotDataA(shot,0,1.5,270,0,0,1.5,BLUE02);}
					AddShot(i,laser,shot,j);
					j+=40;
				}
				i+=5;
			}
			SetLaserDataB(laser,180,0,NULL,0,NULL,0,NULL,0);
			
			i=90;
			while(i<180)
			{
				let j=0;
				while(j<400)
				{
					let shot=1;
					CreateShotA(shot,0,0,30);
					if(step==1){SetShotDataA(shot,0,1.5,270,0,0,1.5,YELLOW02);}
					else if(step==-1){SetShotDataA(shot,0,1.5,90,0,0,1.5,GREEN02);}
					AddShot(i,laser,shot,j);
					j+=40;
				}
				i+=4;
			}		
			FireShot(laser);
		}
		if(count==210)
		{
			SetMovePosition03(cx,240,15,10);
		}	
		if(count==300)
		{
			SetMovePosition03(cx+60*step,120,15,10);
			Concentration01(120);
		}
		if(count==360)
		{
			let laser=0;
			CreateLaserB(laser,0,30,PURPLE02,0);
			SetShotKillTime(laser,180);
			if(step==1){SetLaserDataB(laser,0,10,0,0,180,0,180,0);}
			else if(step==-1){SetLaserDataB(laser,0,10,0,0,0,0,0,0)};		
			SetLaserDataB(laser,60,0,NULL,0,NULL,0,NULL,0);
			SetLaserDataB(laser,90,0,NULL,0,NULL,3.0*step,NULL,3.0*step);
				
			let i=60;
			while(i<90)
			{
				let j=0;
				while(j<400)
				{
					let shot=1;
					CreateShotA(shot,0,0,30);
					if(step==1){SetShotDataA(shot,0,1.5,270,0,0,1.5,ORANGE02);}
					else if(step==-1){SetShotDataA(shot,0,1.5,90,0,0,1.5,AQUA02);}
					AddShot(i,laser,shot,j);
					j+=40;
				}
				i+=5;
			}
			SetLaserDataB(laser,180,0,NULL,0,NULL,0,NULL,0);
			
			i=90;
			while(i<180)
			{
				let j=0;
				while(j<400)
				{
					let shot=1;
					CreateShotA(shot,0,0,30);
					if(step==1){SetShotDataA(shot,0,1.5,90,0,0,1.5,PURPLE02);}
					else if(step==-1){SetShotDataA(shot,0,1.5,270,0,0,1.5,WHITE02);}
					AddShot(i,laser,shot,j);
					j+=40;
				}
				i+=4;
			}		
			FireShot(laser);
		}
		if(count==420)
		{
			SetMovePosition03(cx,240,15,10);
		}	
		if(count==540)
		{
			SetMovePosition03(cx-180*step,16,15,10);
			Concentration01(120);
		}
		if(count==600)
		{
			let laser=0;
			CreateLaserB(laser,0,30,PURPLE02,0);
			SetShotKillTime(laser,90);
			if(step==1){SetLaserDataB(laser,0,10,0,0,0,0,0,0);}
			else if(step==-1){SetLaserDataB(laser,0,10,0,0,180,0,180,0);}	
			SetLaserDataB(laser,60,0,NULL,0,NULL,0,NULL,0);			
			let i=60;
			while(i<90)
			{
				let j=0;
				while(j<400)
				{
					let shot=1;
					CreateShotA(shot,0,0,30);
					if(step==1){SetShotDataA(shot,0,1.5,90,0,0,1.5,RED02);}
					else if(step==-1){SetShotDataA(shot,0,1.5,270,0,0,1.5,GREEN02);}
					AddShot(i,laser,shot,j);
					j+=40;
				}
				i+=4;
			}
			FireShot(laser);
		}
		if(count==660)
		{
			SetMovePosition03(cx-180*step,400,15,10);
		}
		if(count==660)
		{
			let laser=0;
			CreateLaserB(laser,0,30,PURPLE02,0);
			SetShotKillTime(laser,170);
			if(step==1){SetLaserDataB(laser,0,3,0,0,45,0,45,0);}
			else if(step==-1){SetLaserDataB(laser,0,3,0,0,135,0,135,0);}		
			SetLaserDataB(laser,60,2.5,NULL,0,NULL,-3*step,NULL,-3*step);			
			let i=120;
			while(i<170)
			{
				let j=0;
				while(j<400)
				{
					let shot=1;
					CreateShotA(shot,0,0,30);
					if(step==1){SetShotDataA(shot,0,1.5,270,0,0,1.5,BLUE02);}
					else if(step==-1){SetShotDataA(shot,0,1.5,90,0,0,1.5,YELLOW02);}
					AddShot(i,laser,shot,j);
					j+=40;
				}
				i+=5;
			}
			FireShot(laser);
		}
		if(count==720)
		{
			SetMovePosition02(cx+180*step,18,60);
		}
		if(count==810)
		{
			step*=-1;
			count=89;
		}
		SetCollisionA(GetX(),GetY(),32);//当たり判定(自弾)登録
		SetCollisionB(GetX(),GetY(),24);//当たり判定(体当たり)登録
		count++;			
	}
	
	@Finalize
	{//読みこんだファイルを削除
		DeleteGraphic(imgExRumia);	
		DeleteGraphic(imgExRumiaBack);
		loop(8)
		{
			CreateItem(ITEM_SCORE,cx+rand(-100,100),rand(20,100));
		}
	}
	
	@DrawLoop
	{
		//Exルーミア描画
		DrawText("E.Frandle",50,40,18,255);
		SetFontColor(255,100,150,50,80,46);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetAlpha(255);
		SetTexture(imgExRumia);
		if(int(GetSpeedX())==0){SetGraphicRect(64,1,127,64);}
		else if(GetSpeedX()>0){SetGraphicRect(192,1,255,64);}
		else if(GetSpeedX()<0){SetGraphicRect(128,1,191,64);}
		DrawGraphic(GetX(),GetY());
	}

	task Timecounter{
		function Wait(let frame){loop(frame){yield};}
		
		loop(7){
			PlaySE(Timer[0]);
			Wait(60);
			}
		loop(3){
			PlaySE(Timer[0]);
			PlaySE(Timer[1]);
			Wait(60);
			}
		}
}