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_gun002.wav";
        let se2 = csd~ "bgm\tm2_bom000.wav";
  let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(600);}
            else{SetLife(600);}
            SetDamageRate(100,0);
            LoadGraphic(Enemy);
           
            LoadUserShotData(shotData);
		SetGraphicRect(96,144,144,192);	
          SetInvincibility(120);
          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(600); 
             loop(8){ 
           CreateItem(ITEM_SCORE,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
           }
             }
	}

         task Main{
             yield; 
         Angle;
         Move;
          wait(180);
       if(dif == 1){Shot;}
     else if(dif == 2){Shot2;}
      wait(1800);
      VanishEnemy;
     }

     task Shot{
    let way = 10;
      loop{
     ascent(a in 0..way){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+360/way*a;
          let v = 3;
         let color = 20;
          let delay = 20;
        let accel = -0.25;
        let vmax = 1;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
         PlaySE(se1);
          }
      way += 0.2;
        wait(120);
       }
       }
       
   task Shot2{
    let way = 10;
      loop{
     ascent(a in 0..way){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+360/way*a;
          let v = 3;
         let color = 20;
          let delay = 20;
        let accel = -0.25;
        let vmax = 0.5;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
         PlaySE(se1);
          }
      way += 1;
        wait(100);
       }
       }

    task Angle{
         ascent(a in 0..3600){
          SetGraphicAngle(0,0,a*6);
         wait(1);
           }
       }  

     task Move{
        let radius = 0;
        let angle = GetAngle;
         loop{
           SetX(GetCenterX+offsetX(radius,angle));
           SetY(GetCenterY+offsetY(radius,angle));
           radius += 0.5;
           if(arg == 216){angle -= 2;}
         else if(arg == 108){angle += 2;}
        if(radius >= arg){radius = arg;}
          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;}
       }
}
}