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\bell01.wav";
   let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(40);}
            else{SetLife(15);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(60,130,100,160);	
		SetMovePosition02(GetX,GetClipMinY+60,60);
          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(60);
       if(dif == 1){Shot;}
    else if(dif == 2){Shot2;}
       Move;  
     }

     task Shot{
    if(arg == 0){
           ascent(i in 0..8){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-45+i*45;
          let v = 5;
         let color = 49;
          let delay = 10;
         CreateShot01(x,y,v,angle,color,delay); 
         CreateShot01(x,y,v/2,angle+22.5,color,delay); 
          PlaySE(se1);
       SetDamageRate(25,100);
            }
       wait(60);
        }

       else if(arg == 1){
     loop{
           ascent(i in 0..5){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-30+i*15;
          let v = 1.5;
         let color = 25;
          let delay = 10;
         CreateShot01(x,y,v,angle,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){
           ascent(i in 0..12){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-30+i*30;
          let v = 6;
         let color = 49;
          let delay = 10;
         CreateShot01(x,y,v,angle,color,delay); 
         CreateShot01(x,y,v/2,angle+15,color,delay); 
            }
       ascent(i in 0..12){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+i*30;
          let v = 3;
         let color = 9;
          let delay = 0;
       let length = 100; let width = 10;
       CreateLaser01(x,y,v,angle+7.5,length,width,color,delay);
       CreateLaser01(x,y,v,angle-7.5,length,width,color,delay);
            }
      PlaySE(se1);
       SetDamageRate(25,10);
       wait(60);
        }

       else if(arg == 1){
     loop{
           ascent(i in 0..5){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-30+i*15;
          let v = 1.5;
         let color = 25;
          let delay = 10;
         CreateShot01(x,y,v,angle,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 Move{
         wait(120);
      SetMovePosition02(GetX,GetClipMinY-100,60);
       wait(60);
       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;}
       }
}
}