script_enemy_main{
   #include_script".\function_bullet.txt"
        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(150);}
            else{SetLife(150);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(48,144,96,192);	
		SetMovePosition02(GetX,GetY,0);
          SetInvincibility(20);
          SetAlpha(0);
          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(120);
       if(dif == 1){Shot;}
     else if(dif == 2){Shot2;}
     }

     task Shot{
     ascent(a in 0..arg){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+360/arg*a;
          let v = 1.5;
         let color = 17;
          let delay = 20;
        let accel = 0;
        let vmax = v;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
         PlaySE(se1);
          }
        wait(1);
      VanishEnemy;
       }
       
  task Shot2{
     ascent(a in 0..arg){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+360/arg*a;
          let v = 1.5;
         let color = 17;
          let delay = 20;
        let accel = 0;
        let vmax = v;
          ReflectShot(x,y,v,angle,1,true,true,true,false,color,delay);
         PlaySE(se1);
          }
        wait(1);
      VanishEnemy;
       }

    task Angle{
         ascent(a in 0..255){
          SetGraphicAngle(0,0,a);
          SetAlpha(a*2);
         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;}
       }
}
}