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
	{
          
         SetLife(50);
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(60,260,110,290);	
		SetMovePosition02(GetX,GetY,0);
          SetInvincibility(20);
          LoadSE(se1); LoadSE(se2);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
		SetCollisionB(GetX(),GetY(),12);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

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

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

     task Shot{
      wait(60);
    loop(3){
     ascent(t in 0..9){
        ascent(s in 0..arg){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-7.5*(arg-1)+15*s;
          let v = 8;
         let color = 111;
          let delay = 20;
        let accel = -1;
        let vmax = 1.3+0.25*t;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
         PlaySE(se1);
          }
         wait(1);
            }
        }
       }

     task Shot2{
  let v = 1.3;
         loop(3){
        let angle = GetAngleToPlayer+15;
            loop(12){
             CreateShot01(GetX,GetY,v,angle,28,10);
             angle += 30;
            PlaySE(se2);
              }
      v -= 0;
           wait(20);
             }
         }

  task Shot3{
      wait(60);
    loop(3){
     ascent(t in 0..20){
        ascent(s in 0..arg*2+1){
        let x = GetX;
        let y = GetY;
         let angle = 90-20*(arg)+20*s;
          let v = 1+t*0.5;
         let color = 111;
          let delay = 20;
        let accel = -1;
        let vmax = v;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
         PlaySE(se1);
          }
         wait(1);
            }
        }
       }

     task Shot4{
         loop(6){
        let angle = GetAngleToPlayer+10;
   ascent(a in 0..3){
    let v = 1+0.6*a;
            loop(18){
             CreateShot01(GetX,GetY,v,angle,28,10);
             angle += 20;
            PlaySE(se2);
              }
           }
           wait(10);
             }
         }

     task Move{
           SetSpeed(gspeed);
           SetAngle(gangle);
         wait(60);
         SetSpeed(0);
         wait(120);
         SetSpeed(-2*gspeed);
       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;}
       }
}
}