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_gun002.wav";
        let se2 = csd~ "bgm\tm2_coin000.wav";
        let se3 = csd~ "bgm\tm2_alchemist000.wav";
    let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(30);}
            else{SetLife(30);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(70,60,90,100);	
       /*  SetMovePosition03(GetClipMinX,GetY,0); */ 
          SetInvincibility(30);
          LoadSE(se1);LoadSE(se2);LoadSE(se3);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
		SetCollisionB(GetX(),GetY(),12);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

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

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

     task Shot{
          let v = 10;
          let color = 9;
          let delay = 10;
       loop{
          let x = GetX;
          let y = GetY;
      let angle = GetAngleToPlayer;
     if(arg == 2){
        ascent(b in 0..2){
          CreateShot01(x,y,v,angle+20*(b-1/2),color+(arg-1)*5,delay);
           }
        }
     else if(arg == 1){
        ascent(b in 0..1){
          CreateShot01(x,y,v,angle,color+(arg-1)*5,delay);
           }
        }
         PlaySE(se1);
          wait(1);
         }
      }
          
  task Shot2{
          let v = 10;
          let color = 9;
          let delay = 10;
       loop{
          let x = GetX;
          let y = GetY;
      let angle = GetAngleToPlayer;
     if(arg == 2){
        ascent(b in 0..4){
          CreateShot01(x,y,v,angle+20*(b-1)-10,color+(arg-1)*5+24,delay);
           }
        }
     else if(arg == 1){
        ascent(b in 0..3){
          CreateShot01(x,y,v,angle+10*(b-1),color+(arg-1)*5+24,delay);
           }
        }
         PlaySE(se1);
          wait(1);
         }
      }

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

     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;}
       }
}
}