script_enemy_main{
   #include_script".\function_bullet.txt"
        let csd = GetCurrentScriptDirectory;
	let Enemy=csd~"img\dot-kaze-ti.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_swing001.wav";
    let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(10);}
            else{SetLife(10);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);        
            LoadUserShotData(shotData);
		SetMovePosition02(GetX,GetY,0);
          SetInvincibility(20);
          LoadSE(se1);
          let c = rand_int(1,3);
        if(c == 1){red;}
        else if(c == 2){blue;}
        else if(c == 3){green;}
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
		SetCollisionB(GetX(),GetY(),12);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
         if(!BeVanished){
             AddScore(10); 
           loop(2){ 
           CreateItem(ITEM_SCORE,GetX+offsetX(48,rand(-180,180)),GetY+offsetY(48,rand(-180,180)));
           }
             }
      if(dif == 2){
           let radius = 24;
          let color = 40;
          let delay = 0;
         loop(3){
          let angle = rand(-160,-20);
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
          let v = rand(0.5,1.5);
          let accel = rand(0.02,0.05);
           let grvAngle = 90;
          GravityShot(x,y,v,angle,accel,grvAngle,color,delay);
        
           }
          wait(30);
        }
    }

         task Main{
             yield; 
          wait(10);
       Move;
     }

     task Move{
       let r = rand(-128,128);
       let x = GetCenterX+r;
       let y = GetClipMinY+120;
           SetMovePosition03(x,y,20,gspeed);
      loop{
       if(GetSpeed == 0){break;}
       else{wait(1);}
       wait(1);
        }
        wait(60);
       SetSpeed(1);
       SetAngle(GetAngleToPlayer);
      wait(300);
       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 red  { SetGraphicRect(60,130,120,160); }
       sub blue  { SetGraphicRect(60,190,110,220); }
       sub green  { SetGraphicRect(60,260,130,290); }

       function wait(w){
                loop(w){yield;}
       }
}
}