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_laser001.wav";
   let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(500);}
            else{SetLife(500);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(60,130,100,160);	
      if(arg == 0){SetInvincibility(120);}
      if(arg == 1){SetInvincibility(120);}
          LoadSE(se1);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
		SetCollisionB(GetX(),GetY(),12);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

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

         task Main{
             yield; 
          wait(60);
       if(dif == 1){Laser;}
    else if(dif == 2){Laser2;}
       Move;
     }

     task Laser{
       if(arg == 0){
           ascent(i in 0..12){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+30*i;
         let length = 600;
         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,720+delay);
        FireShot(0);
          PlaySE(se1); 
            }
         wait(120);
        VanishEnemy;
          }
       else if(arg == 1){
        ascent(b in 0..60){
           ascent(i in 0..6){
        let angle = GetAngleToPlayer+60*i;
        let x = GetX+offsetX(16,angle);
        let y = GetY+offsetY(16,angle);
         let angle2 = angle-90+b*11.1;
         let length = 100;
         let width = 8;
         let color = 191;
          let delay = 20;
         let v = 3;
         CreateLaser01(x,y,v,angle2,length,width,color,delay);
       /*   PlaySE(se1); */
            }
         wait(10);
          }
        }
       }

 task Laser2{
       if(arg == 0){
           ascent(i in 0..12){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+30*i;
         let length = 600;
         let width = 10;
         let color = 192;
         /* let delay = 60; */
    let spin = 0.15*(-1)^i;
   if(GetX >= GetCenterX){spin = 0.15*(-1)^(i+1);}
      ascent(a in 0..7){
       let delay = 60+120*a;
         CreateLaserA(0,x,y,length,width,color,delay); 
         SetLaserDataA(0,0,angle,spin,0,0,0);
         SetShotKillTime(0,30+delay);
        FireShot(0);
        }
          PlaySE(se1); 
            }
         wait(120);
        VanishEnemy;
          }
       else if(arg == 1){
        ascent(b in 0..60){
           ascent(i in 0..12){
        let angle = GetAngleToPlayer+30*i;
        let x = GetX+offsetX(16,angle);
        let y = GetY+offsetY(16,angle);
         let angle2 = angle-90+b*11.1;
         let length = 200;
         let width = 8;
         let color = 191;
          let delay = 20;
         let v = 3;
         CreateLaser01(x,y,v,angle2,length,width,color,delay);
       /*   PlaySE(se1); */
            }
         wait(10);
          }
        }
       }

     task Move{
           SetSpeed(0);
           SetAngle(gangle);
      if(arg == 0){
         wait(60);
         SetSpeed(0);
        wait(120);
         SetSpeed(1.5);
         wait(600);
       VanishEnemy;
         }
    else if(arg == 1){
           wait(60);
         SetSpeed(0);
        wait(660);
         SetSpeed(-3);
         wait(40);
       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;}
       }
}
}