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_gun001.wav";
  let dif = GetCommonData("Dif");
	@Initialize
	{
           
     SetLife(50);
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(60,190,100,220);	
		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(200); 
             loop(8){ 
           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{
      wait(120);
     ascent(t in 0..6){
           ascent(i in 0..12){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-15+i*30;
          let v = t*2+10;
         let color = arg;
          let delay = 10;
          let accel = -1;
          let vmin = 1;
         CreateShot02(x,y,v,angle,accel,vmin,color,delay); 
         PlaySE(se1);
            }
          }
       }

   task Shot2{
      wait(60);
   ascent(b in 0..4){
     ascent(t in 0..6){
           ascent(i in 0..12){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+i*30+15*b;
          let v = t*2+10;
         let color = arg;
          let delay = 10;
          let accel = -1;
          let vmin = 0.5*(t+1);
         CreateShot02(x,y,v,angle,accel,vmin,color,delay); 
         PlaySE(se1);
            }
          }
      wait(60-15*b);
        }
       }

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