script_enemy_main {
   let time = 0;
   let phase = 1;
   let rate = 20;
   let kaku = 40;
   let lv = 0;
   let score = 0;
   let angle = 180;
   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";
   SetCommonData("haya",0);
   @Initialize(){
       SetLife( 6600 );
       SetInvincibility( 180 );
       LoadGraphic( imgEnemy );
       Tmove;
   }
   @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>360){
         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==360){Tshot1a;Tshot1b;}
   	if(time==900){Tshot2a;}
   	if(time==1440){Tshot3;}
   	if(time==2000){Tshot4;}
   	if(time>360&&time<1440){angle-=0.25;}
      time++;
      yield;
   }
   @Finalize() {
      SetCommonData("haya",1);
   }
   @DrawLoop {
		SetTexture( imgEnemy );
		SetGraphicRect( 1, 1, 320, 256 );
		SetGraphicAngle(0,0,90+angle);
   	SetGraphicScale(bairitu,bairitu);
		DrawGraphic( GetX(), GetY()+10 );
   }

	task Tshot1a{
		let a=0;
		while(time<870){
				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{
		wait(80);
		while(time<870){
		if(phase<=0){return;}
		let p=GetAngleToPlayer;
			let a=0;
			loop(1){
				let b=-1;
				loop(4+ex){
				CreateShotFromScript( "shot1",GetX()+cos(angle+20)*40, GetY()+sin(angle+20)*40, 3.5+ex, p+b*14, 0, 06);
				CreateShotFromScript( "shot1",GetX()+cos(angle-20)*40, GetY()+sin(angle-20)*40, 3.5+ex, p+b*14, 0, 06);
					b++;
				}
				PlaySE(seshot2);
				wait(50-lv*25);
				a++;
			}
		}
	}
   task Tshot2a{
      wait(30);
   	let a=0;
   	while(time<1400){
         if(phase<=0){return;}
   		let b=0;
   		loop(4){
   			let c=0;
   			let r = sin(b*113)*3;
   			loop(4+ex*2){
         		CreateShotFromScript( "shot1",GetX()+cos(angle)*50, GetY()+sin(angle)*50, 4+c*0.7, a*18+b*90+r*c, 0, 02);
         		CreateShotFromScript( "shot1",GetX()+cos(angle)*50, GetY()+sin(angle)*50, 4+c*0.7, a*18+b*90+10+r*c, 0, 02);
   				c++;
   			}
         	PlaySE(seshot2);
   			b++;
   		}
         wait(8-lv*4);
   		a++;
      }
   }
   task Tshot2b{
      wait(60);
   	while(time<1400){
         if(phase<=0){return;}
   		let a=-2-ex*2;
      	let p=GetAngleToPlayer;
   		loop(5+ex*4){
         	CreateShotFromScript( "shot1",GetX()+cos(angle+100)*120, GetY()+sin(angle+100)*120, 3, 90+a*(10-ex*3), 0, 13);
         	CreateShotFromScript( "shot1",GetX()+cos(angle-100)*120, GetY()+sin(angle-100)*120, 3, 90+a*(10-ex*3), 0, 13);
   			a++;
   		}
         PlaySE(seshot1);
         wait(60-lv*30);
      }
   }
   task Tshot3{
   	let r=1;
      wait(60);
      let p=GetAngleToPlayer;
   	let n=0;
   	while(time<1940){
         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.1;
            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<2350){
         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 {
      SetMovePosition02(224, 160, 360);
      wait(360);
      let a=0;
   	loop(18){
         if(phase<=0){return;}
         SetMovePosition02(224+rand(30,-30), 160+rand(20,-20), 60);
         wait(60);
      }
      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"