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(500);}
            else{SetLife(500);}
            SetDamageRate(100,10);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(256,1,316,60);	
		SetMovePosition02(GetX,GetY,0);
          SetInvincibility(180);
          LoadSE(se1);LoadSE(se2);LoadSE(se3);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),12);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
         if(!BeVanished){
             AddScore(1000);
         loop(20){ 
             CreateItem(ITEM_SCORE,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
             }
          DeleteEnemyShotToItem(ALL);
          }
	}

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

     task Shot{
      wait(10);
     loop{
      let r = GetAngleToPlayer;
        loop(6){
           ascent(i in 0..36){
        let x = GetX;
        let y = GetY;
         let angle = r+i*10;
          let v = 5;
         let color = 69;
          let delay = 10;
          let accel = -0.1;
          let vmin = 2;
        CreateShotA(0,x,y,delay); 
        SetShotDataA(0,0,v,angle,0,accel,vmin,color);
        FireShot(0);
          PlaySE(se1);
            }
        wait(5);
        }
       wait(arg);
        }
     }

  task Shot2{
      wait(10);
    ShotA;
    ShotB;
   task ShotA{
     loop{
  let r = GetAngleToPlayer;
           ascent(i in 0..15){
    ascent(a in 0..15){
        let x = GetX;
        let y = GetY;
         let angle = r+i+30*a-7.5;
          let v = 5;
         let color = 69;
          let delay = 10;
          let accel = -0.1;
          let vmin = 3+0.1*i;
        CreateShotA(0,x,y,delay); 
        SetShotDataA(0,0,v,angle,0,accel,vmin,color);
        FireShot(0);
          }
          PlaySE(se1);
   wait(1);
            }
    if(GetEnemyNum <= 1){arg = 5;}
      wait(arg);
        }
        }

  task ShotB{
     loop{
  let r = GetAngleToPlayer;
           ascent(i in 0..15){
    ascent(a in 0..15){
        let x = GetX;
        let y = GetY;
         let angle = r-i-30*a+7.5;
          let v = 5;
         let color = 69;
          let delay = 10;
          let accel = -0.1;
          let vmin = 3+0.1*i;
        CreateShotA(0,x,y,delay); 
        SetShotDataA(0,0,v,angle,0,accel,vmin,color);
        FireShot(0);
          }
          PlaySE(se1);
   wait(1);
            }
  if(GetEnemyNum <= 1){arg = 5;}
      wait(arg);
        }
        }
     }

     task Move{
           SetSpeed(gspeed);
           SetAngle(gangle);
     wait(180);
       SetSpeed(0); 
     wait(600);
        SetSpeed(1);
      wait(180);
      VanishEnemy;  
      }

     task Bullet(x,y,v,angle,color,delay){
            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));
           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;}
       }
}
}