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_gun003.wav";
        let se2 = csd~ "bgm\tm2_coin000.wav";
        let se3 = csd~ "bgm\buble03.wav";
   let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(1000);}
            else{SetLife(1000);}
            SetDamageRate(100,10);
            LoadGraphic(Enemy);
         /* SetTimer(30);*/
            LoadUserShotData(shotData);
		SetGraphicRect(256,120,316,180);	
      if(arg == 0){
         SetMovePosition03(GetX,GetClipMinY+120,10,3);  
         }
     else if(arg == 1){
         SetMovePosition03(GetCenterX-100,GetY,10,3);  
         }
     else if(arg == 2){
         SetMovePosition03(GetCenterX+100,GetY,10,3);  
         }
          SetInvincibility(60);
          LoadSE(se1);LoadSE(se2);LoadSE(se3);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

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

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

     task Shot{
    /*    Shot1; */
     task Shot1{
          let base = GetAngleToPlayer;
          let v = 2.3;
          let color = 14;
          let delay = 0;
        let n = 6;
       loop{
         ascent(a in 0..2){
          let x = GetX;
          let y = GetY;
          let angle = base + 180*a;
          CreateShot01(x,y,v,angle,color,delay);
          }
          base += n;
       n += 0.2;
         PlaySE(se3);
          wait(2);
         }
       }
     Shot2;
    task Shot2{
   wait(60);
     let length = 100; let width = 50;
    let color = 52; let delay = 0;
   let v = 2; let n = 150; let spin = 2;
    loop(20){
    let base = rand(-180,180);
   let x = GetX; let y = GetY;
     ascent(a in 0..4){
      let angle = base + 90*a;
       CreateLaserA(0,x,y,length,width,color,delay); 
       SetLaserDataA(0,0,angle,spin,0,v,GetAngleToPlayer);
        FireShot(0);
          }
        CreateShot01(x,y,v,GetAngleToPlayer,color,delay);
   ascent(f in 0..6){
    ascent(c in 0..19){
    CreateShot01(x,y,1+2*f,GetAngleToPlayer-60+5*(c-9)-30*f,140,delay);
     }
     ascent(b in 0..19){
    CreateShot01(x,y,1+2*f,GetAngleToPlayer+60+5*(b-9)+30*f,140,delay);
     }
    }
      PlaySE(se2);
        wait(n);
   spin = -spin;
    n -= 6;
          }
         wait(30);
      VanishEnemy;
        }
      }
     
    task Shot2{
     Shot2;
    task Shot2{
   wait(60);
     let length = 100; let width = 50;
    let color = 52; let delay = 0;
   let v = 2; let n = 150; let spin = 2;
    loop(20){
    let base = rand(-180,180);
   let x = GetX; let y = GetY;
     ascent(a in 0..4){
      let angle = base + 90*a;
       CreateLaserA(0,x,y,length,width,color,delay); 
       SetLaserDataA(0,0,angle,spin,0,v,GetAngleToPlayer);
        FireShot(0);
          }
        CreateShot01(x,y,v,GetAngleToPlayer,color,delay);
   ascent(f in 0..6){
    ascent(c in 0..19){
    CreateShot01(x,y,1+3*f,GetAngleToPlayer-50+5*(c-9)-20*f,140,delay);
     }
     ascent(b in 0..19){
    CreateShot01(x,y,1+3*f,GetAngleToPlayer+50+5*(b-9)+20*f,140,delay);
     }
    }
      PlaySE(se2);
        wait(n);
   spin = -spin;
    n -= 6;
          }
         wait(30);
      VanishEnemy;
        }
      }
     

     task Move{
           SetSpeed(gspeed);
           SetAngle(gangle);
       wait(140);
       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;}
       }
}
}