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_clock000.wav";
        let se2 = csd~ "bgm\tm2_bom000.wav";
   let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(450);}
            else{SetLife(450);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            SetTimer(arg);
            LoadUserShotData(shotData);
		SetGraphicRect(0,144,48,192);	
		SetMovePosition02(GetX,GetY,0);
          SetInvincibility(60*arg);
          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(30){ 
           CreateItem(ITEM_SCORE,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
           }
             }
	}

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

     task Shot{
     loop{
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer;
         let angle2 = atan2(GetCenterY-GetY,GetCenterX-GetX);
          let v = 0;
         let color = 21;
         let color2 = 23;
          let delay = 20;
        let accel = 0.001;
        let vmax = 100;
        CreateShot02(x,y,v,angle,accel*2,vmax,color,delay); 
        CreateShot02(x,y,0,angle2,accel,vmax,color2,delay); 
         PlaySE(se1);
        wait(1);
       v += 0.02;
          }
       }
       
  task Shot2{
     loop{
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer;
         let angle2 = atan2(GetCenterY-GetY,GetCenterX-GetX);
          let v = 0;
         let color = 21;
         let color2 = 23;
          let delay = 20;
        let accel = 0.001;
        let vmax = 100;
        CreateShot02(x,y,v,angle,accel*2,vmax,color,delay); 
        CreateShot02(x,y,0,angle2,accel,vmax,color2,delay); 
        CreateShot02(x,y,0,angle,accel/2,vmax,color2-1,delay); 
        CreateShot02(x,y,0,angle2,accel/1.7,vmax,color2-4,delay);  
         PlaySE(se1);
        wait(1);
       v += 0.02;
          }
       }

    task Angle{
      loop{
        SetMovePosition02(GetClipMaxX,GetY,120);
         ascent(a in 0..120){
          SetGraphicAngle(0,0,-a*3/4);
         wait(1);
           }
       SetMovePosition02(GetX,GetClipMaxY,120);
       ascent(a in 0..120){
          SetGraphicAngle(0,0,-90-a*3/4);
         wait(1);
           }
       SetMovePosition02(GetClipMinX,GetY,120);
         ascent(a in 0..120){
          SetGraphicAngle(0,0,-180-a*3/4);
         wait(1);
           }
        SetMovePosition02(GetX,GetClipMinY,120);
       ascent(a in 0..120){
          SetGraphicAngle(0,0,-270-a*3/4);
         wait(1);
           }
        }
      /* 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;}
       }
}
}