script_enemy_main{
        let csd = GetCurrentScriptDirectory;
	let Enemy=csd~"img\familiar.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_shoot002.wav";
        let se2 = csd~ "bgm\tm2_bom000.wav";
   let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(1500);}
            else{SetLife(1500);}
            SetDamageRate(50,10);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(48,144,96,192);	
		SetMovePosition02(GetX,GetY,0);
          SetInvincibility(20);
          SetAlpha(255);
          LoadSE(se1); LoadSE(se2);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),12);  
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

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

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

     task Shot{
    let way = 18;
   loop(30){
   let r = rand(-180,180);
   ascent(b in 0..2){
     ascent(a in 0..way){
        let x = GetX+0;
        let y = GetY;
         let angle = r+360/way*a;
          let v = 1.5-b/2;
         let color = 12;
          let delay = 20;
        let accel = 0;
        let vmax = v;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
        CreateShot02(x,y,v,angle+10,accel,vmax,color-8,delay); 
         PlaySE(se1);
          }
   /*   ascent(a in 0..way){
        let x = GetX-30;
        let y = GetY;
         let angle = r+360/way*a;
          let v = 1.5-b/2;
         let color = 12;
          let delay = 20;
        let accel = 0;
        let vmax = v;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
        CreateShot02(x,y,v,angle+10,accel,vmax,color-8,delay); 
         PlaySE(se1);
          }  */
       }
        wait(120);
         }
       }
     
  task Shot2{
   wait(300);
    let way = 18;
   loop(30){
   let r = rand(-180,180);
   ascent(b in 0..2){
     ascent(a in 0..way){
        let x = GetX+30;
        let y = GetY;
         let angle = r+360/way*a;
          let v = 3-b;
         let color = 12;
          let delay = 20;
        let accel = 0;
        let vmax = v;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
        CreateShot02(x,y,v,angle+10,accel,vmax,color-8,delay); 
          }
      ascent(a in 0..way){
        let x = GetX-30;
        let y = GetY;
         let angle = r+360/way*a;
          let v = 3-b;
         let color = 12;
          let delay = 20;
        let accel = 0;
        let vmax = v;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
        CreateShot02(x,y,v,angle+10,accel,vmax,color-8,delay); 
          }  
       }
   PlaySE(se1);
        wait(120);
         }
       }
  
    task Angle{
         ascent(a in 0..3600){
          SetGraphicAngle(0,0,a);
         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;}
       }
}
}