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
	{

         SetLife(50);
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(1,1,64,60);	
          SetInvincibility(60);
          LoadSE(se1);LoadSE(se2);LoadSE(se3);
        SetAlpha(0);
        SetColor(255,128,255);
        SetShotColor(255,255,255);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),18);
		/*SetCollisionB(GetX(),GetY(),24);*/
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

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

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

     task Appear{
        ascent(a in 0..255){
         SetAlpha(a);
         wait(4);
         }
     }

     task Move{
           SetSpeed(gspeed);
        loop(30){
           SetAngle(GetAngleToPlayer);
          wait(60);
           }
       VanishEnemy;   
      }
    
     task Shot{
       loop{
       ascent(b in 0..2){
         ascent(a in 0..2){
             let angle = GetAngleToPlayer-5+10*a;
          let x = GetX+offsetX(0,angle);
          let y = GetY+offsetY(0,angle);
          let v = 1+1*b;
          let color = 135;
          let delay = 0;
           CreateShot01(x,y,v,angle,color,delay);
          PlaySE(se1);
          }
        }
         wait(59);
         }
       }

   task Shot2{
     if(GetPlayerType != REIMU_A){wait(30);}
       loop{
  let base = GetAngleToPlayer;
  let color = 136;
  let r = 255; let g = 196; let b = 196;
  if(arg ==  1){
   base = 90; r = 196; g = 255; b = 196;
        }
   else if(arg ==  2){
   base = GetAngleToPlayer+30; r = 196; g = 196; b = 255;
        }
   SetShotColor(r,g,b);
      ascent(c in 0..6){
       ascent(b in 0..3){
         ascent(a in 0..9){
             let angle = base+60*c;
          let x = GetX+offsetX(0,angle);
          let y = GetY+offsetY(0,angle);
          let v = 2-0.3*b;
          let delay = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,2,angle,0,0,v,color);
         SetShotDataA(0,60,v,angle+15*(a-4),0,0,v,color);
         FireShot(0);
          }
        }
       }
    ascent(c in 0..6){
         ascent(a in 0..9){
             let angle = base+60*c;
          let x = GetX+offsetX(0,angle);
          let y = GetY+offsetY(0,angle);
          let v = 1.5;
          let delay = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,2,angle,0,0,v,color);
         SetShotDataA(0,60,0,angle+25*(a-4)+180,0,0,v,color);
         SetShotDataA(0,90,v,angle+25*(a-4)+180,0,0,v,color);
         FireShot(0);
          }
       }
     PlaySE(se1);
   SetShotColor(255,255,255);
         wait(200);
         }
       }


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