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\buble03.wav";
   let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(150);}
            else{SetLife(150);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
           
            LoadUserShotData(shotData);
		SetGraphicRect(144,144,192,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); 
        PlaySE(se2);
             loop(16){ 
           CreateItem(ITEM_SCORE,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
           }
             }
	}

         task Main{
             yield; 
      /*   Angle;  */
         Move; 
       Shot;
     }

     task Shot{
    if(dif == 1){Shot1;   Shot2;}
  else if(dif == 2){Shot3; Shot2; AddLife(-50);}
    task Shot1{
      loop{
     ascent(a in 0..2){
        let x = GetX;
        let y = GetY;
         let angle = GetAngle-45+90*a;
          let v = GetSpeed*2^(1/2);
         let color = 27;
          let delay = 0;
        let accel = 0;
        let vmax = 10;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
       /*  PlaySE(se1); */
          }
        wait(10);
       }
       }
    task Shot2{
   let r = rand(10,90);
    wait(r);
  let color = 39;
  let w = 90;
   let v = 3;
  let span = 30;
  let way = 4;
   if(dif == 2){color += 16;  span = 20; way = 8;}
         loop{
     ascent(a in 0..way){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+span*(a-(way-2)/2)-span/2;
          let delay = 10;
        let accel = 0;
        let vmax = 10;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
       /*  PlaySE(se1); */
          }
        wait(w);
       }
       }
 task Shot3{
      loop{
     ascent(a in 0..6){
        let x = GetX;
        let y = GetY;
         let angle = 60*a;
          let v = GetSpeed*2^(1/2);
         let color = 27;
          let delay = 0;
        let accel = 0;
        let vmax = 10;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
       /*  PlaySE(se1); */
          }
        wait(10);
       }
       }
     }
       
    task Angle{
         ascent(a in 0..3600){
          SetGraphicAngle(0,0,a*6);
         wait(1);
           }
       }  

     task Move{
  /*    let px = GetPlayerX;
    if(px >= GetX){SetAngle(0);}
    else if(px <= GetX){SetAngle(180);}
        SetMovePosition02(px,GetY,60);
        wait(60);
       ascent(a in 0..60){
         SetAngle(GetAngle+(90-GetAngle)/60*a);
         wait(1);
        }
       SetSpeed(3);  */
     loop{
          if(GetY >= GetClipMaxY+20){VanishEnemy;}
           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;}
       }
}
}