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_gun000.wav";
         let se2 = csd~ "bgm\tm2_coin000.wav";
    let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(150);}
            else{SetLife(150);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(60,130,100,160);	
	/*	SetMovePosition03(GetX,GetClipMinY+120,10,3);*/
          SetInvincibility(arg);
          LoadSE(se1); LoadSE(se2);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
		SetCollisionB(GetX(),GetY(),12);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

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

         task Main{
             yield; 
          wait(90);
       Shot;
       Move;
     }

     task Shot{
  /*    Shot1; */
    task Shot1{
        ascent(a in 0..6){
           ascent(i in 0..18){
        let x = GetX;
        let y = GetY;
        let v = 2.2-1/3*a;
         let angle = GetAngleToPlayer+360/18*i;
        let angle2 = atan2(GetPlayerY-GetY-offsetY(60*v,angle),GetPlayerX-GetX-offsetX(60*v,angle));
         let color = 7;
         let color2 = 8;
          let delay = 10;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color2);
         SetShotDataA(0,60,1/v,angle2,0,0,v,color);
         FireShot(0);
          PlaySE(se1);
            }
        wait(10);
          }
       }
     }

      Shot2;
    task Shot2{
   let r = rand(0,60);
    wait(r);
        let v = 2;
    if(dif == 2){v = 4;}
        let angle = rand(-180,180);
        let vmax = v;
        let color = 155+8*2;
         let delay = 20;
       loop{
       ascent(a in 0..3){
        ascent(b in 0..2){
       let x = GetX+offsetX(16+6*a,angle-2*(angle-90)*b); 
       let y = GetY+offsetY(32+6*a,angle-2*(angle-90)*b);
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,0,angle-2*(angle-90)*b,0,0,vmax,color);
         SetShotDataA(0,60,v/2,NULL,0,0.01,vmax,color);
         FireShot(0);
           }
        }
      PlaySE(se1);
   if(dif == 1){
        angle += 15;
         wait(10);
         }
     else if(dif == 2){
          angle += 10;
         wait(3);
         }
          }
     }

     task Move{
   /*   wait(240);
           SetSpeed(1.5);
           SetAngle(rand(60,120));
       wait(360);
       VanishEnemy; */
    SetSpeed(2);
    SetAngle(90);
    wait(360);
    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;}
       }
}
}