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_swing001.wav";
  let dif = GetCommonData("Dif");
	@Initialize
	{

         SetLife(40);
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(60,130,120,160);	
		SetMovePosition02(GetX,GetY,0);
          SetInvincibility(0);
          LoadSE(se1);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
		SetCollisionB(GetX(),GetY(),12);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
         if(!BeVanished){
             AddScore(100); 
         loop(4){ 
           CreateItem(ITEM_SCORE,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
           }
             }
	}

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

     task Shot{
    if(arg == 0){
    let w = rand_int(0,90);
      wait(w);
     loop{
           ascent(i in 0..3){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-30+i*30;
          let v = 6; let accel = -0.1; let vmin = 2;
         let color = 25;
          let delay = 10;
         CreateShot02(x,y,v,angle,accel,vmin,color,delay); 
          PlaySE(se1);
            }
       wait(60);
        }
        }

       else if(arg == 1){
    let w = rand_int(0,90);
      wait(w);
     loop{
           ascent(i in 0..6){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-10+(i-2)*20;
          let v = 3; let accel = -0.01; let vmin = -10;
         let color = 31;
          let delay = 10;
         CreateShot02(x,y,v,angle,accel,vmin,color,delay); 
          PlaySE(se1);
            }
       wait(30);
        }
        }
       else if(arg == 2){
     loop{
           loop(7){
        let x = GetX;
        let y = GetY;
         let angle = rand(-20,200);
          let v = rand(0.2,2);
         let color = 72;
          let delay = 10;
         CreateShot01(x,y,v,angle,color,delay); 
          PlaySE(se1);
            }
       wait(60);
        }
        }
       else if(arg == 3){
     loop{
           ascent(i in 0..5){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-30+i*15;
         let length = 450;
         let width = 10;
         let color = 192;
          let delay = 60;
         CreateLaserA(0,x,y,length,width,color,delay); 
         SetLaserDataA(0,0,angle,0,0,0,0);
         SetShotKillTime(0,360+delay);
        FireShot(0);
        /*  PlaySE(se1); */
          wait(20);
            }
       wait(30);
        }
        }
       }

   task Shot2{
      if(arg == 0){
    let w = rand_int(0,20);
      wait(w);
     loop{
           ascent(i in 0..9){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+3*(i-4)+1.5;
          let v = 5; let accel = -0.05; let vmin = 3;
         let color = 25+8;
          let delay = 10;
         CreateShot02(x,y,v,angle,accel,vmin,color,delay); 
          PlaySE(se1);
            }
       wait(60);
        }
        }

       else if(arg == 1){
    let w = rand_int(0,20);
      wait(w);
     loop{
      ascent(a in 0..5){
        let x = GetX;
        let y = GetY;
         let angle = 90;
          let v = 3; let accel = 0; let vmin = 0.5;
         let color = 31;
          let delay = 10+5*a;
         CreateShot02(x,y,v,angle,accel,vmin,color,delay); 
       }
   PlaySE(se1);
       wait(30);
        }
        }
       else if(arg == 2){
     loop{
           loop(14){
        let x = GetX;
        let y = GetY;
         let angle = rand(-20,200);
          let v = rand(1,4);
         let color = 72+8;
          let delay = 10;
         CreateShot01(x,y,v,angle,color,delay); 
            }
     PlaySE(se1);
       wait(60);
        }
        }
       else if(arg == 3){
     loop{
           ascent(i in 0..5){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-30+i*15;
         let length = 450;
         let width = 10;
         let color = 192;
          let delay = 60;
         CreateLaserA(0,x,y,length,width,color,delay); 
         SetLaserDataA(0,0,angle,0,0,0,0);
         SetShotKillTime(0,360+delay);
        FireShot(0);
        /*  PlaySE(se1); */
          wait(20);
            }
       wait(30);
        }
        }
       }

     task Move{
           SetSpeed(gspeed);
           SetAngle(gangle);
         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 setGraphicStop  { SetGraphicRect( 40,  20, 80, 100); }

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