script_enemy_main {
	let time = 0;
	let phase = 1;
	let rate = 20;
	let kaku = 40;
	let lv = 0;
	let score = 0;
	let angle = -90;
	let rank = GetSpeed();
	let arg = GetArgument();
	let ex = GetCommonData("ex");
	let mapx = GetX();
	let mapy = GetY();
	let bairitu = 1;
	let imgEnemy = GetCurrentScriptDirectory~"img\st4semiboss.png";
	let tama = GetCurrentScriptDirectory~"tama.txt";
	let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
	let se7 = GetCurrentScriptDirectory~"wav\se7.wav";
	let se3 = GetCurrentScriptDirectory~"wav\se3.wav";
	let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
	let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
	let zakoair2 = GetCurrentScriptDirectory~"zakoair2.txt";
	@Initialize(){
		SetLife( 4300 );
		SetInvincibility( 180 );
		LoadGraphic( imgEnemy );
		Tmove;
		SetCommonData("haya",0);
	}
	@MainLoop {
		if(phase==1&&GetLife<=100){
			phase-=1;
			score = 60000;
			if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 500);}
			Tdeath(30,96,2,0);
			Tbaku;Toti;
		}
		if(phase>=1&&time>80){
			SetCollisionA(GetX(), GetY(), 96);
			SetCollisionA(GetX()+cos(angle+120)*96, GetY()+sin(angle+120)*96, 50);
			SetCollisionA(GetX()+cos(angle-120)*96, GetY()+sin(angle-120)*96, 50);
			SetCollisionB(GetX(), GetY(), 75);
			SetCollisionB(GetX()+cos(angle+120)*96, GetY()+sin(angle+120)*96, 30);
			SetCollisionB(GetX()+cos(angle-120)*96, GetY()+sin(angle-120)*96, 30);
		}
		if(GetCommonData("kakusei")>0){lv=1}
		else{lv=0}

		if(time==120){Tshot1a;Tshot1b;}
		if(time==700){Tshot3;}
		if(time==1260){Tshot4;}
		time++;
		yield;
   }
   @Finalize() {
      SetCommonData("haya",1);
   }
   @DrawLoop {
		SetTexture( imgEnemy );
		SetGraphicRect( 1, 1, 320, 256 );
		SetGraphicScale(bairitu,bairitu);
		DrawGraphic( GetX(), GetY()+10 );
   }

   task Tshot1a{
      wait(80);
      let a=0;
   	while(time<630){
         if(phase<=0){return;}
         let p1=atan2( GetPlayerY()-(GetY()+sin(angle+100)*120), GetPlayerX()-(GetX()+cos(angle+100)*120));
         let p2=atan2( GetPlayerY()-(GetY()+sin(angle-100)*120), GetPlayerX()-(GetX()+cos(angle-100)*120));
   		loop(8){
         	CreateShotFromScript( "shot1",GetX()+cos(angle+100)*120+cos(p1+90)*6, GetY()+sin(angle+100)*120+sin(p1+90)*6, 4.5+ex, genteikaku(p1,48), 0, 12);
         	CreateShotFromScript( "shot1",GetX()+cos(angle+100)*120+cos(p1-90)*6, GetY()+sin(angle+100)*120+sin(p1-90)*6, 4.5+ex, genteikaku(p1,48), 0, 12);
   			
         	CreateShotFromScript( "shot1",GetX()+cos(angle-100)*120+cos(p2+90)*6, GetY()+sin(angle-100)*120+sin(p2+90)*6, 4.5+ex, genteikaku(p2,48), 0, 12);
         	CreateShotFromScript( "shot1",GetX()+cos(angle-100)*120+cos(p2-90)*6, GetY()+sin(angle-100)*120+sin(p2-90)*6, 4.5+ex, genteikaku(p2,48), 0, 12);
         	PlaySE(seshot1);
         	wait(3);
   		}
   		wait(30-lv*25);
      }
   }
   task Tshot1b{
   	while(time<630){
         if(phase<=0){return;}
      	let p=GetAngleToPlayer;
   		let a=0.36;
   		loop(3){
   			let b=-1;
   			loop(3+ex){
         		CreateShotFromScript( "shot1",GetX()+cos(angle+20)*40, GetY()+sin(angle+20)*40, 3.5+ex, p-a*24+b*9, 0, 06);
         		CreateShotFromScript( "shot1",GetX()+cos(angle-20)*40, GetY()+sin(angle-20)*40, 3.5+ex, p+a*24+b*9, 0, 06);
   				b++;
   			}
         	PlaySE(seshot2);
         	wait(10-lv*5);
   			a++;
   		}
      }
   }
   task Tshot3{
   	let r=1;
      wait(60);
      let p=GetAngleToPlayer;
   	let n=0;
   	while(time<1200){
   		if(n==0){
         loop(30){
            if(phase<=0){return;}
            let b=-2-ex*2;
            loop(5+ex*4){
               CreateShotFromScript( "shot1",GetX()+33, GetY()-12, 8+ex*2, p+b*(30-ex*13), 0, 11);
               CreateShotFromScript( "shot1",GetX()-33, GetY()-12, 8+ex*2, p+b*(30-ex*13), 0, 11);
               b++;
            }
         	PlaySE(seshot1);
         	wait(2-lv);
         }
   		}
   		if(GetPlayerX>224+r*30){r=1;}
   		else{r=-1}
         loop(30){
            if(phase<=0){return;}
         	p+=r*1.2;
            let b=-2-ex*2;
            loop(5+ex*4){
               CreateShotFromScript( "shot1",GetX()+33, GetY()-12, 8+ex*2, p+b*(30-ex*13), 0, 11);
               CreateShotFromScript( "shot1",GetX()-33, GetY()-12, 8+ex*2, p+b*(30-ex*13), 0, 11);
               b++;
            }
         	PlaySE(seshot1);
         	wait(2-lv);
         }
   		n++;
      }
   }
   task Tshot4{
      wait(60);
   	while(time<1650){
         if(phase<=0){return;}
         let b=-2-ex;
         loop(5+ex*2){
            CreateShotFromScript( "shota",GetX()+33, GetY()-12, 8+ex*2, 90+b*(20-ex*7), 0, 13);
            CreateShotFromScript( "shota",GetX()-33, GetY()-12, 8+ex*2, 90+b*(20-ex*7), 0, 13);
            b++;
         }
         PlaySE(seshot2);
         wait(4-lv*2);
      }
   }
	task Tmove {
		SetMovePositionHermite(224, 160, 200,270,200,90,80);
		wait(100);
		let a=1;
		loop(5){
			if(phase<=0){return;}
			SetMovePosition02(224+rand(10,-10)+a*50, 160+rand(20,-20), 100);
			wait(100);
			a*=-1;
		}
		if(phase<=0){return;}
		SetMovePosition02(224+rand(20,-20), 160+rand(20,-20), 100);
		wait(100);
		
		wait(550);
		let a=0;
		if(phase<=0){return;}
		SetMovePosition02(224, 100, 60);
		wait(60);
		if(phase<=0){return;}
		SetMovePosition02(GetX(), GetY+500, 500);
		wait(500);
		VanishEnemy();
	}
  task Toti{
     SetMovePosition02(224+(GetX-224)/2, GetY+150, 80);
     let a=0;
     loop(80){
       if(a%10==0){PlaySE(se3);}
       bairitu=1-a/80*0.3;
       a++;
       yield;
     }
     Explosion01(GetX,GetY,5,0.4,50);
     PlaySE(se7);
     VanishEnemy();
  }


   #include_function".\efanction.txt"
}
   script_shot shota{
      let out=false;
      let gr=GetArgument;
      let lv=0;
      @Initialize{
         SetDefault(gr+lv*20);
      }
      @MainLoop {
         if(GetX<20||GetX>428||GetY<20){
            out=true;
            End;
         }
      		if(GetY>460){SetAngle(270);}
         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);}
      }
      @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"