script_enemy_main {
	let time = -250;
	let phase = 3;
	let sephase = 3;
	let rate = 0;
	let kaku = 50;
	let score = 0;
	let lv = 0;
	let life = 36500+20;
	let life1 = 22000;
	let life2 = 7000;
	let automove = true;
	let angle = rand(0,360);
	let spin = 0;
	let rank = GetSpeed();
	let arg = GetArgument();
	let ex = GetCommonData("ex");
	let mapy = GetY();
	SetCommonData("bossx",GetX);
	SetCommonData("bossy",GetY);
	SetCommonData("bossphase",3);
	SetCommonData("bossatack",0);
	let imgEnemya = GetCurrentScriptDirectory~"img\st5boss1a.png";
	let imgEnemyb = GetCurrentScriptDirectory~"img\st5boss1b.png";
	let imgEnemyc = GetCurrentScriptDirectory~"img\st5boss1c.png";
	let imgEnemyd = GetCurrentScriptDirectory~"img\st5boss1d.png";
	let tama = GetCurrentScriptDirectory~"tama.txt";
	let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
	let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
	let se6 = GetCurrentScriptDirectory~"wav\se6.wav";
	let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
	let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
	@Initialize(){
		SetLife( 36520 );
		SetInvincibility( 0 );
		SetTimer(300);
		LoadGraphic( imgEnemya );
		LoadGraphic( imgEnemyb );
		LoadGraphic( imgEnemyc );
		LoadGraphic( imgEnemyd );
		LoadUserShotData( tama );
		Tmain1;
	}
	@MainLoop {
		angle+=spin;
		
		if(phase==3){
			SetX(224);
			SetY(GetCommonData("bgy")-mapy);
		}
		
		SetCommonData("bossx",GetX);
		SetCommonData("bossy",GetY);
		if(phase==3&&GetLife<=life1+20){
			phase-=1;
			time=-240;
			score=80000;
			SetCommonData("bossphase",2);
			if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 500);}
			PlaySE(se2);
			Tdeath(15,80,2,0);
			automove=true;
			SetMovePosition02(224+rand(20,-20), 160,120);
			sephase=2;
			Tmain2;
		}
		if(phase==2&&GetLife<=life2+20){
			phase-=1;
			time=-160;
			score=100000;
			SetCommonData("bossphase",1);
			if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 500);}
			PlaySE(se2);
			Tdeath(15,80,2,0);
			automove=true;
			SetMovePosition02(224, 130,100);
			sephase=1;
			Tmain3;
		}
		if(phase==1&&GetLife<=20){
			phase-=1;
			score=120000;
			SetCommonData("bossphase",0);
			if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 500);}
			PlaySE(se2);
			Tdeath(0,80,2,0);
			Tbaku;
			Tbossbaku;
			SetMovePosition02(224+rand(10,-10), 400+rand(10,-10),240);
		}
		
		if(phase==3&&time>=0){
			SetCollisionA(GetX, GetY, 120);
			SetCollisionA(GetX+80, GetY, 90);
			SetCollisionA(GetX-80, GetY, 90);
		}
		if(phase==2&&time>=0){
			SetCollisionA(GetX, GetY, 90);
			let a=0;
			loop(4){
				SetCollisionA(GetX+cos(angle+90*a)*120, GetY+sin(angle+90*a)*120, 30);
				SetCollisionA(GetX+cos(angle+90*a)*180, GetY+sin(angle+90*a)*180, 30);
				a++;
			}
		}
		if(phase==1&&time>=0){
			SetCollisionA(GetX, GetY, 90);
		}
		if(sephase==3&&GetLife<=life1+420){PlaySE(se6);sephase=2;}
		if(sephase==2&&GetLife<=life2+420){PlaySE(se6);sephase=1;}
		if(sephase==1&&GetLife<=420){PlaySE(se6);sephase=0;}
		if(GetCommonData("kakusei")>0){lv=1}
		else{lv=0}
		time++;
		yield;
	}
	@Finalize() {
	}
	@DrawLoop {
		
		if(time%5==0){
			if(life==GetLife){SetColor(255,255,255);}
			else{SetColor(210,210,255);}
			life=GetLife;
			if(phase==0||(time%30<5&&GetLife<920)){SetColor(255,200,200);}
		}
		
		//“y‘ä
		SetTexture( imgEnemyd );
		if(phase==3){
			SetGraphicRect( 0, 0, 288, 288 );
			SetGraphicAngle(0,52,0);
		}
		else if(phase==2){
			if(time<-180){
				SetGraphicRect( 0, 0, 288, 288 );
				SetGraphicAngle(0,52,0);
			}
			else if(time>=-180 && time < -150){
				let a = trunc((time+180)/15);
				SetGraphicRect( 0+a*288, 0, 288+a*288, 288 );
				let b = -time-150;
				SetGraphicAngle(0,52*b/30,0);
			}
			else{
				SetGraphicRect( 288*2, 0, 288*3, 288 );
				SetGraphicAngle(0,0,angle);
			}
		}
		else{
			if(time<-60){
				SetGraphicRect( 288*2, 0, 288*3, 288 );
				SetGraphicAngle(0,0,180);
			}
			else if(time>=-60 && time < -30){
				let a = trunc((-time-30)/15);
				SetGraphicRect( 0+a*288, 0, 288+a*288, 288 );
				let b = time+60;
				SetGraphicAngle(0,-40*b/30,180);
			}
			else{
			SetGraphicRect( 0, 0, 288, 288 );
			SetGraphicAngle(0,-40,180);
			}
		}
		DrawGraphic( GetX(), GetY() );
		
		//”ª–{‘«
		if(phase==3){
			SetTexture( imgEnemya );
			let ang=angle+5.625;
			let dx=trunc(ang/11.25);
			SetGraphicRect( 0+480*dx, 0, 480+480*dx, 480 );
			SetGraphicAngle(0,52,ang%11.25-5.625);
			DrawGraphic( GetX(), GetY() );
		}
		
		
		//‚S–{‘«
		if(phase==2){
			if(time>-120){
				SetTexture( imgEnemyc );
				let r=160;
				if(time<-40){
					r=160+(time+40)*2;
				}
				let a=0;
				loop(4){
					SetGraphicRect( 0, 0, 192, 64 );
					SetGraphicAngle(0,0,angle+90*a);
					DrawGraphic( GetX()+cos(angle+90*a)*r, GetY()+sin(angle+90*a)*r );
					a++;
				}
			}
		}
		
		//–{‘Ì
		SetTexture( imgEnemyb );
		if(phase==3){
			SetGraphicRect( 0, 0, 288, 288 );
			SetGraphicAngle(0,52,0);
		}
		else if(phase==2){
			if(time<-180){
				SetGraphicRect( 0, 0, 288, 288 );
				SetGraphicAngle(0,52,0);
			}
			else if(time>=-180 && time < -150){
				let a = trunc((time+180)/15);
				SetGraphicRect( 0+a*288, 0, 288+a*288, 288 );
				let b = -time-150;
				SetGraphicAngle(0,52*b/30,0);
			}
			else{
				SetGraphicRect( 288*2, 0, 288*3, 288 );
				SetGraphicAngle(0,0,angle);
			}
		}
		else{
			if(time<-60){
				SetGraphicRect( 288*2, 0, 288*3, 288 );
				SetGraphicAngle(0,0,180);
			}
			else if(time>=-60 && time < -30){
				let a = trunc((-time-30)/15);
				SetGraphicRect( 0+a*288, 0, 288+a*288, 288 );
				let b = time+60;
				SetGraphicAngle(0,-40*b/30,180);
			}
			else{
			SetGraphicRect( 0, 0, 288, 288 );
			SetGraphicAngle(0,-40,180);
			}
		}
		DrawGraphic( GetX(), GetY() );
		
	}

	task Tmain1{
		yield;
		wait(200);
		let s = 1;
		loop{
			Fspin(1.2*s);
			if(phase<=2){return;}
			SetCommonData("bossatack",1);
			Tshot11a;
			Tshot11b;
			Tshot11c;
			wait(600);
			if(phase<=2){return;}
			SetCommonData("bossatack",0);
			
			wait(60);
			if(phase<=2){return;}
			let a=0;
			loop(4){
				let ang = 45 + a*90;
				CreateShotFromScript( "shota",GetX()+cos(ang)*80, GetY()+sin(ang)*60, 1.5, 270, 0, 00);
				a++;
			}
			PlaySE(seshot2);
			
			Fspin(-1.0*s);
			if(phase<=2){return;}
			SetCommonData("bossatack",2);
			Tshot12a;
			Tshot12b;
			wait(500);
			if(phase<=2){return;}
			SetCommonData("bossatack",0);
			
			wait(60);
			if(phase<=2){return;}
			let a=0;
			loop(4){
				let ang = 45 + a*90;
				CreateShotFromScript( "shota",GetX()+cos(ang)*80, GetY()+sin(ang)*60, 1.5, 270, 0, 00);
				a++;
			}
			PlaySE(seshot2);
			
			Fspin(0.9*s);
			if(phase<=2){return;}
			SetCommonData("bossatack",3);
			Tshot13a;
			Tshot13b;
			wait(700);
			if(phase<=2){return;}
			SetCommonData("bossatack",0);
			
			Fspin(2.35*s);
			if(phase<=2){return;}
			SetCommonData("bossatack",4);
			Tshot14a;
			Tshot14b;
			wait(300);
			Fspin(0.5*s);
			if(phase<=2){return;}
			SetCommonData("bossatack",0);
			
			s*=-1;
		}

	}
	
	task Tmain2{
		loop(160){
			spin=0;
			angle=0;
			yield;
		}
		Tmove2;
		Tmain2a;
		let r=(rand_int(0,1)-0.5);
		let a=rand_int(0,2);
		loop{
			if(phase<=1){return;}
			Fspin2(-0.5*r);
			Tshot20(r, 4+2*(a%3));
			r*=-1;
			a+=rand_int(1,2);
		}
	}
	task Tmain2a{
		let a=rand_int(0,6);
		wait(160);
		loop{
			
			let b=a%7;
			if(phase<=1){return;}
			if(b==0){
				Tshot21();
			}
			else if(b==1){
				Tshot22();
			}
			else if(b==2){
				Tshot23();
			}
			else if(b==3){
				Tshot24();
			}
			else if(b==4){
				Tshot25();
			}
			else if(b==5){
				Tshot26();
			}
			else if(b==6){
				Tshot27();
			}
			a+=rand_int(1,2);
			
			wait(140);
		}
	}
	task Tmove2 {
		let dx=rand(0.2,0.3);
		let dy=0.3;
		loop{
			if(phase<=1){return;}
			
			let x=GetX();
			let y=GetY();
			if(x>224+50){dx=-rand(0.2,0.3);}
			if(x<224-50){dx=rand(0.2,0.3);}
			if(y>240+80){dy=-0.3;}
			if(y<240-80){dy=0.3;}
			
			SetX(x+dx);
			SetY(y+dy);
			yield;
		}
	}

	task Tmain3{
		wait(160);
		Tmove3;
		wait(60);
		Tshot31();
	}
	
	task Tmove3{
		loop{
			if(phase<=0){
				return;
			}
			SetMovePosition02(224+rand(10,-10), 130+rand(10,-10),120);
			wait(120);
		}
	}
	
	function Fspin(let s) {
		if(s>spin){
			while(spin<s){
				if(phase<=2){spin=0;return;}
				spin+=0.008;
				yield;
			}
		}
		else{
			while(spin>s){
				if(phase<=2){spin=0;return;}
				spin-=0.008;
				yield;
			}
		}
	}
	
	function Fspin2(let s) {
		if(s>spin){
			while(spin<s){
				if(phase<=1){spin=0;return;}
				spin+=0.005;
				yield;
			}
		}
		else{
			while(spin>s){
				if(phase<=1){spin=0;return;}
				spin-=0.005;
				yield;
			}
		}
	}
	
	#include_function".\efanction.txt"
	#include_function".\st5boss1a.txt"
}

script_shot shota{//—U“±
	let out=false;
	let gr=01;
	let arg=GetArgument;
	let pl=GetAngleToPlayer;
	let ex = GetCommonData("ex");
	let lv=0;
	let time=arg;
	@Initialize{
	   SetDefault(gr+lv*20);
	}
	@MainLoop {
		if(GetX<20||GetX>428||GetY<20||GetY>460){
		   out=true;
		   End;
		}
		if(GetCommonData("kakusei")>0){
		   lv=1;
		   if(GetPoint==0){lv=2;SetSpeed(GetSpeed+0.04);}
		}
		else{lv=0}
		SetDefault(gr+lv*20);
		if((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2<=4){SetCommonData("gekitui",1);}
		
		if(time==60){
			SetAngle(90);
			SetSpeed(3.5+ex);
		}
		if(time>60){
			if(sin(GetAngleToPlayer() - GetAngle())>0){
				SetAngle(GetAngle()+0.7+ex*0.4);
			}
			else{
				SetAngle(GetAngle()-0.7-ex*0.4);
			}
			
			if(time%8==0){
				CreateShotFromScript( "shot3",GetX(), GetY(), 0.04+ex*0.02, GetAngle()+(time-60)*1.5+180, 0, 13);
				CreateShotFromScript( "shot3",GetX(), GetY(), 0.04+ex*0.02, GetAngle()-(time-60)*1.5+180, 0, 13);
			}
			if(ex==1&&time%8==0){
				CreateShotFromScript( "shot3",GetX(), GetY(), 0.02, GetAngle()+(time-60)*2.2, 0, 13);
				CreateShotFromScript( "shot3",GetX(), GetY(), 0.02, GetAngle()-(time-60)*2.2, 0, 13);
			}
		}
		time++;
	}
	@DrawLoop {
	   DrawGraphicDefault();
	}
	@Finalize{
	   if(out==false&&OnBomb==false){
	      if(GetCommonData("kakusei")>0){
	         CreateShotFromScript( "kinka",GetX(), GetY(), 0, 270, 0, 0);
	      }
	      if(OnBomb==false&&GetCommonData("kakusei")==0){
	         CreateShotFromScript( "isi",GetX(), GetY(), 0, 270, 0, 0);
	      }
	   }
	}
}

script_shot shotb{//Šp‘¬“x+‰Á‘¬
	let out=false;
	let gr=02;
	let arg=GetArgument;
	let lv=0;
	let kasoku=GetSpeed;
	let time=0;
	let ex = GetCommonData("ex");
	@Initialize{
		SetDefault(gr+lv*20);
	}
	@MainLoop {
		if(GetX<20||GetX>428||GetY<20||GetY>460){
			out=true;
			End;
		}
		if(GetCommonData("kakusei")>0){
			lv=1;
			if(GetPoint==0){lv=2;SetSpeed(GetSpeed+0.03)}
		}
		else{lv=0}
		if(time<120){
			SetAngle(GetAngle+0.9*arg);
		}
		SetSpeed(GetSpeed+0.017);
		SetDefault(gr+lv*20);
		if((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2<=4){SetCommonData("gekitui",1);}
		time++;
	}
	@DrawLoop {
		DrawGraphicDefault();
	}
	@Finalize{
	   if(out==false&&OnBomb==false){
	      if(GetCommonData("kakusei")>0){
	         CreateShotFromScript( "kinka",GetX(), GetY(), 0, 270, 0, 0);
	      }
	      if(OnBomb==false&&GetCommonData("kakusei")==0){
	         CreateShotFromScript( "isi",GetX(), GetY(), 0, 270, 0, 0);
	      }
	   }
	}
}

script_shot shotc{//•Ç”½ŽË
	let out=false;
	let gr=01;
	let arg=GetArgument;
	let pl=GetAngleToPlayer;
	let ex = GetCommonData("ex");
	let lv=0;
	let time=0;
	@Initialize{
		SetDefault(gr+lv*20);
	}
	@MainLoop {
		if(GetX<20||GetX>428||GetY<20||GetY>460){
			let a=0;
			loop(4+ex*4){
				let ang=a*(90-ex*45);
				CreateShotFromScript( "shot1",GetX()+cos(ang)*10, GetY()+sin(ang)*10, 2.3+ex*0.5, ang, 0, 2);
				CreateShotFromScript( "shot1",GetX()+cos(ang)*10, GetY()+sin(ang)*10, 1.8+ex*0.5, ang, 0, 2);
				a++;
			}
			out=true;
			End;
		}
		if(GetCommonData("kakusei")>0){
		   lv=1;
		   if(GetPoint==0){lv=2;SetSpeed(GetSpeed+0.04);}
		}
		else{lv=0}
		SetDefault(gr+lv*20);
		
		time++;
	}
	@DrawLoop {
		DrawGraphicDefault();
	}
	@Finalize{
		if(out==false&&OnBomb==false){
			if(GetCommonData("kakusei")>0){
			CreateShotFromScript( "kinka",GetX(), GetY(), 0, 270, 0, 0);
			}
			if(OnBomb==false&&GetCommonData("kakusei")==0){
				CreateShotFromScript( "isi",GetX(), GetY(), 0, 270, 0, 0);
			}
		}
	}
}    
script_shot shotd{//—U“±
	let out=false;
	let gr=01;
	let arg=GetArgument;
	let ex = GetCommonData("ex");
	let lv=0;
	let time=arg;
	@Initialize{
	   SetDefault(gr+lv*20);
	}
	@MainLoop {
		if(GetX<20||GetX>428||GetY<20||GetY>460){
		   out=true;
		   End;
		}
		if(GetCommonData("kakusei")>0){
		   lv=1;
		   if(GetPoint==0){lv=2;SetSpeed(GetSpeed+0.04);}
		}
		else{lv=0}
		SetDefault(gr+lv*20);
		if((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2<=4){SetCommonData("gekitui",1);}
		
			let r = 1.3;
			if(sin(GetAngleToPlayer() - GetAngle())>0){
				SetAngle(GetAngle()+r);
			}
			else{
				SetAngle(GetAngle()-r);
			}
		
		if(time<180){
			if(cos(GetAngleToPlayer() - GetAngle())>0.5){
				if(GetSpeed<5.0){SetSpeed(GetSpeed+0.03);}
			}
			else{
				if(GetSpeed>1.0){SetSpeed(GetSpeed-0.03);}
			}
		}
		else{
			SetSpeed(GetSpeed+0.03);
		}
		
		
		if(time%8==0){
			if(ex==0){
				CreateShotFromScript( "shot3",GetX(), GetY(), 0.04, GetAngle()+180, 0, 06);
			}
			else{
				CreateShotFromScript( "shot3",GetX(), GetY(), 0.04, GetAngle()+90, 0, 06);
				CreateShotFromScript( "shot3",GetX(), GetY(), 0.04, GetAngle()-90, 0, 06);
			}
		}
		time++;
	}
	@DrawLoop {
	   DrawGraphicDefault();
	}
	@Finalize{
	   if(out==false&&OnBomb==false){
	      if(GetCommonData("kakusei")>0){
	         CreateShotFromScript( "kinka",GetX(), GetY(), 0, 270, 0, 0);
	      }
	      if(OnBomb==false&&GetCommonData("kakusei")==0){
	         CreateShotFromScript( "isi",GetX(), GetY(), 0, 270, 0, 0);
	      }
	   }
	}
}
script_shot shote{//”­‹¶
	let out=false;
	let gr=01;
	let arg=GetArgument;
	let ex = GetCommonData("ex");
	let lv=0;
	let time=0;
	let r=1;
	let ang=GetAngle;
	@Initialize{
		SetDefault(gr+lv*20);
		if(arg<0){
			r=-1;
		}
	}
	@MainLoop {
		
		if(time%8==0){//‚Tƒ{ƒX31
			CreateShotFromScript( "shot3",GetX(), GetY(), 0.012+ex*0.006, GetAngle+arg+(time*2.5)*r, 0, 13);
			//CreateShotFromScript( "shot1",GetX(), GetY(), 1.5+ex*1.0, GetAngle+arg+(time*2.5)*r, 0, 13);
		}
		
		
		if(GetX<20||GetX>428||GetY<20||GetY>460){
			out=true;
			End;
		}
		if(GetCommonData("kakusei")>0){
		   lv=1;
		   if(GetPoint==0){lv=2;SetSpeed(GetSpeed+0.04);}
		}
		else{lv=0}
		SetDefault(gr+lv*20);
		if((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2<=4){SetCommonData("gekitui",1);}
		
		time++;
	}
	@DrawLoop {
		DrawGraphicDefault();
	}
	@Finalize{
		if(out==false&&OnBomb==false){
			if(GetCommonData("kakusei")>0){
			CreateShotFromScript( "kinka",GetX(), GetY(), 0, 270, 0, 0);
			}
			if(OnBomb==false&&GetCommonData("kakusei")==0){
				CreateShotFromScript( "isi",GetX(), GetY(), 0, 270, 0, 0);
			}
		}
	}
}
#include_script".\escript.txt"