script_enemy_main{
        let csd = GetCurrentScriptDirectory;
	let Enemy=csd~"img\dot-kaze-ti.png";
        let shotData = csd ~ "data_usershot.txt";
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;
        let arg = GetArgument;
        let se1 = csd~ "bgm\tm2_swing001.wav";
        let se2 = csd~ "bgm\tm2_bom000.wav";
        let se3 = csd~ "bgm\tm2_alchemist000.wav";
  let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(2000);}
            else{SetLife(2000);}
            SetDamageRate(100,10);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(256,1,316,60);	
		SetMovePosition02(GetX,GetY,0);
          SetInvincibility(90);
          LoadSE(se1);LoadSE(se2);LoadSE(se3);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
     DeleteEnemyShotToItem(ALL);
      wait(10);
   let n = 150; let vmax = 3;
  if(dif == 2){n = 600; vmax = 6;}
       loop(n){
             let angle = rand(-180,180);
          let x = GetX+offsetX(32,angle);
          let y = GetY+offsetY(32,angle);
          let v = rand(0.2,vmax);
          let color = 242;
          let delay = 30;
           Bullet(x,y,v,angle,color,delay,0);
          PlaySE(se2);
          }
         if(!BeVanished){
             AddScore(1000);
         loop(48){ 
             CreateItem(ITEM_SCORE,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
             }
          }
	}

         task Main{
             yield; 
          wait(10);
      if(dif == 1){ Shot;Shot2;}
    else if(dif == 2){Shot3;Shot4;}
      Move;
     }

     task Shot{
      wait(90);
     loop{
      let r = rand(70,110);
           ascent(i in 0..340){
        let x = GetX;
        let y = GetY;
         let angle = r+i+10;
          let v = 0;
         let color = 28;
          let delay = 10;
          let accel = 0.1;
          let vmax = 3;
        CreateShotA(0,x,y,delay); 
        SetShotDataA(0,0,v,angle,0,accel,vmax,color);
       /* SetShotDataA(0,180,NULL,angle,0,accel,vmax,color);*/
        FireShot(0);
          PlaySE(se1);
            }
       wait(180);
        }
     }

 task Shot3{
      wait(90);
     loop{
      let r = rand(80,100);
           ascent(i in 0..350){
        let x = GetX;
        let y = GetY;
         let angle = r+i+5;
          let v = 0;
         let color = 28;
          let delay = 10;
          let accel = 0.1;
          let vmax = 3;
        CreateShotA(0,x,y,delay); 
        SetShotDataA(0,0,v,angle,0,accel,vmax,color);
       /* SetShotDataA(0,10,NULL,angle,0,accel,vmax,color);*/
        FireShot(0);
          PlaySE(se1);
            }
       wait(30);
        }
     }

     task Move{
           SetSpeed(gspeed*2);
           SetAngle(gangle);
     wait(90);
       SetSpeed(0);
       wait(1800);
       VanishEnemy;   
      }
    
     task Shot2{
          wait(240);
       loop{
         loop(30){
             let angle = rand(-180,180);
          let x = GetX+offsetX(32,angle);
          let y = GetY+offsetY(32,angle);
          let v = rand(0.5,3);
          let color = 241;
          let delay = 30;
           Bullet(x,y,v,angle,color,delay,0);
          PlaySE(se2);
          }
         wait(360);
         }
       }

   task Shot4{
          wait(90);
       loop{
         loop(180){
             let angle = rand(-180,180);
          let x = GetX+offsetX(32,angle);
          let y = GetY+offsetY(32,angle);
          let v = rand(0.2,4);
          let color = 241;
          let delay = 30;
           CreateShot01(x,y,v,angle,color,delay);
          PlaySE(se2);
          }
         wait(90);
         }
       }

     task Bullet(x,y,v,angle,color,delay,ss){
            let b = Obj_Create(OBJ_SHOT);
            Obj_SetX(b,x);
            Obj_SetY(b,y);
            Obj_SetSpeed(b,v);
            Obj_SetAngle(b,angle);
            ObjShot_SetGraphic(b,color);
            ObjShot_SetDelay(b,delay);
        loop{
           if(Obj_GetX(b)<=GetClipMinX||Obj_GetX(b)>=GetClipMaxX||Obj_GetY(b)<=GetClipMinY){
           Obj_SetAngle(b,180+atan2(Obj_GetY(b)-GetPlayerY, Obj_GetX(b)-GetPlayerX)+ss);
           break;
           }
           wait(1);
          }
     }  

     function offsetX(radius,angle){
           return radius * cos(angle);
     }

        function offsetY(radius,angle){
            return radius * sin(angle);
     }           

       function move(f){
          SetMovePosition02(rand(GetClipMinX+60,GetClipMaxX-60),GetY+rand(-20,20),f);
     }
            
        function sc(r,g,b){
             SetShotColor(r,g,b);
     }

       sub setGraphicStop  { SetGraphicRect( 40,  20, 80, 100); }

       function wait(w){
                loop(w){yield;}
       }
}
}