script_enemy_main{
        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_gun002.wav";
        let se2 = csd~ "bgm\tm2_bom000.wav";
    let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(40);}
            else{SetLife(40);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(60,190,90,220);
          SetInvincibility(20);
          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(1){ 
           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;}
       Move;
     }

     task Shot{
    loop{
       let n = rand(60,240);
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer;
          let v = 4;
         let color = 8;
          let delay = 0;
        let accel = 0;
        let vmax = v;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
      if(arg == 2||arg == 3){
           CreateShot02(x,y,v,angle+30,accel,vmax,color,delay); 
           CreateShot02(x,y,v,angle-30,accel,vmax,color,delay); 
         }
        wait(n);
          }
       }
       
  task Shot2{
    loop{
       let n = 60;
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer;
          let v = 4;
         let color = 8;
          let delay = 0;
        let accel = 0;
        let vmax = v;
     ascent(a in 0..9){
         CreateShot02(x,y,v,angle+20*(a-4),accel,vmax,color,delay); 
      }
     wait(n/2);
    ascent(a in 0..8){
         CreateShot02(x,y,v,angle+20*(a-4)+10,accel,vmax,color,delay); 
      }
        wait(n/2);
          }
       }

    task Angle{
      let a = 0;
        loop{
          SetGraphicAngle(0,0,a);
       a += 2;
         wait(1);
           }
       }  

     task Move{
           wait(90);
          ascent(a in 0..60){
             SetAngle(a*2*(-1)^arg+90);
            wait(1);
        }
          ascent(a in 0..15){
             SetAngle(-a*2*(-1)^arg+90+110*(-1)^arg);
            wait(1);
        }
      wait(90);
       ascent(a in 0..45){
             SetAngle(-a*2*(-1)^arg+90+90*(-1)^arg);
            wait(1);
        }
      wait(240);
     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;}
       }
}
}