script_enemy_main {
   let time = 0;
   let rate = 1;
   let phase = 1;
   let score =3000;
   let angle = 90;
   let rank = GetSpeed;
   let ex = 0;
   let arg = GetArgument();
   let imgEnemy = GetCurrentScriptDirectory~"img\dot__yousei_r.png";
   let imgmahou = GetCurrentScriptDirectory~"img\kdm_seal001.png";
   let tama = GetCurrentScriptDirectory~"tama.txt";
   let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
   let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
   let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
   let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
   @Initialize(){
      SetLife( 1800 );
      SetInvincibility(180);
      LoadUserShotData( tama );
      SetSpeed(5);
      Tshot1;
      Tmove;
   	if(GetCommonData("ex")==1){ex=1;}
   }
   @MainLoop {
      if(phase==1&&GetLife<=100){
         phase-=1;
         PlaySE(se2);
         Tdeath(10,64,3,20);
      	if(ex==1){
            let p=GetAngleToPlayer;
            SetShotDirectionType(ABSOLUTE);
      		let a=-2;
      		loop(5){
            	CreateShot02( GetX(), GetY(), 0, p+a*8, 0.2, 10, ORANGE02, 0);
      			a++;
      		}
      	}
      }
      if(phase>=1){
      SetCollisionA(GetX, GetY, 20);
      SetCollisionA(GetX+80, GetY-30, 20);
      SetCollisionA(GetX+40, GetY-20, 20);
      SetCollisionA(GetX-40, GetY-20, 20);
      SetCollisionA(GetX-80, GetY-30, 20);
      }
      yield;
      time++;
   }
   @Finalize() {
   }
   @DrawLoop {
		SetTexture( imgEnemy );
      SetGraphicRect( 0, 0, 32, 32 );
      SetGraphicAngle(0,0,angle-90);
		DrawGraphic( GetX(), GetY() );
		SetTexture( imgmahou );
      SetGraphicRect( 0, 0, 32,32 );
      SetGraphicAngle(0,0,angle-90);
		DrawGraphic( GetX()+40, GetY()-30 );
		DrawGraphic( GetX()-40, GetY()-30 );
		DrawGraphic( GetX()+80, GetY()-20 );
		DrawGraphic( GetX()-80, GetY()-20 );
   }

   task Tshot1{
      yield;
      wait(180);
      loop{
			loop(2){
         	if(phase<1){return;}
				let a=-2.5-ex;
				let p=genteikaku(GetAngleToPlayer,32);
            SetShotDirectionType(ABSOLUTE);
				loop(6){
         		SetShotDirectionType(ABSOLUTE);
         		CreateShot01( GetX(), GetY(), 4.5+ex*2, p+a*16, ORANGE04, 0);
					a++;
				}
				wait(15);
         	if(phase<1){return;}
				let a=-3-ex;
            SetShotDirectionType(ABSOLUTE);
				loop(7){
         		SetShotDirectionType(ABSOLUTE);
         		CreateShot01( GetX(), GetY(), 4.5+ex*2, p+a*16, ORANGE04, 0);
					a++;
				}
				wait(15);
				if(ex==1){
         	if(phase<1){return;}
				let a=-3.5-ex;
            SetShotDirectionType(ABSOLUTE);
				loop(8){
         		SetShotDirectionType(ABSOLUTE);
         		CreateShot01( GetX(), GetY(), 4.5+ex*2, p+a*16, ORANGE04, 0);
					a++;
				}
				}
				wait(25);
      	}
      	wait(40-ex*20);
      	
         if(phase<1){return;}
         SetShotDirectionType(ABSOLUTE);
         let p=atan2( GetPlayerY()-(GetY()-30), GetPlayerX()-(GetX()+80));
         CreateShot01( GetX()+80, GetY()-30, 8.5+ex*5, p, WHITE02, 0);
         PlaySE(seshot1);
      	wait(10);
         if(phase<1){return;}
         SetShotDirectionType(ABSOLUTE);
         let p=atan2( GetPlayerY()-(GetY()-20), GetPlayerX()-(GetX()+40));
         CreateShot01( GetX()+40, GetY()-20, 8.5+ex*5, p, WHITE02, 0);
         PlaySE(seshot1);
      	wait(10);
         if(phase<1){return;}
         SetShotDirectionType(ABSOLUTE);
         let p=atan2( GetPlayerY()-(GetY()-20), GetPlayerX()-(GetX()-40));
         CreateShot01( GetX()-40, GetY()-20, 8.5+ex*5, p, WHITE02, 0);
         PlaySE(seshot1);
      	wait(10);
         if(phase<1){return;}
         SetShotDirectionType(ABSOLUTE);
         let p=atan2( GetPlayerY()-(GetY()-30), GetPlayerX()-(GetX()-80));
         CreateShot01( GetX()-80, GetY()-30, 8.5+ex*5, p, WHITE02, 0);
         PlaySE(seshot1);
      	wait(50);
		}
	}

  task Tmove {
     SetMovePosition02(224,GetY+200,180);
     wait(180);
     SetMovePosition02(224+30,GetY,100);
     wait(120);
     SetMovePosition02(224-30,GetY,120);
     wait(120);
     SetMovePosition02(224+30,GetY,120);
     wait(120);
     SetMovePosition02(224-30,GetY,120);
     wait(120);
     SetMovePosition02(224+30,GetY,120);
     wait(120);
     SetMovePosition02(224-30,GetY,120);
     wait(120);
     SetMovePosition02(224-300,GetY-30,180);
     wait(180);
     VanishEnemy();
  }


   #include_function".\efanc.txt"
}
