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\arrow01.wav";
        let se2 = csd~ "bgm\buble03.wav";
   let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(3000);}
            else{SetLife(3000);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
       SetTexture(Enemy);
     /*  SetTimer(60); */
          SetMovePosition02(GetCenterX,GetClipMinY+30,60); 
            LoadUserShotData(shotData);
		SetGraphicRect(48,144,96,192);	
          SetInvincibility(120);
          LoadSE(se1); LoadSE(se2);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),24);
	     /*  SetCollisionB(GetX(),GetY(),12);  */
		yield;
	}
	
       	@DrawLoop{
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
         if(!BeVanished){
             AddScore(600); 
        PlaySE(se2);
             loop(100){ 
           CreateItem(ITEM_SCORE,GetX+2*offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
           }
          CreateItem(ITEM_1UP,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
             }
	}

         task Main{
             yield; 
     Angle;
         wait(60); 
       /*  Move; */
       Shot;  
     wait(3600);
     VanishEnemy;
     }

     task Shot{
   let way = 1;
      loop{
    let base = GetAngleToPlayer;
        let x = GetX;
        let y = GetY;
         let angle = base+rand(-60,60);
          let v = rand(6,10);
         let color = 25;
          let delay = 0;
        let accel = -0.3;
        let vmin = 0;
         let vmax = 10;
   let v2 = rand(0.5,2);
   let angle2 = rand(-60,60);
   let angle3 = rand(-120,120);
  if(dif == 2){ v2 = v2*3;}
     ascent(a in 0..way){
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,vmin,color+2);
         SetShotDataA(0,90,v,angle+angle2,0,accel,vmin,color+6);
         SetShotDataA(0,180+10*a,v2,angle+angle3,0,0,v,color);
         FireShot(0);
     }
       /*  PlaySE(se1); */
       wait(1);
       }
       }
       
    task Angle{
     let a = 0;
         loop{
          SetGraphicAngle(0,0,a);
         a += 7;
         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);  */    
      }

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