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

	@Finalize{ 
         if(!BeVanished){
             AddScore(300); 
             loop(4){ 
           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(arg);
     ascent(t in 0..6){
           ascent(i in 0..8){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-90+i*30;
          let v = t*2+10;
         let color = 96;
          let delay = 10;
          let accel = -1;
          let vmin = 0;
          let vmax = 5;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,vmin,color);
         SetShotDataA(0,60,NULL,angle,0,-accel/20,vmax,color);
         FireShot(0);
         PlaySE(se1);
            }
          }
       }

   task Shot2{
      wait(arg);
   loop(1){
     ascent(t in 0..6){
           ascent(i in 0..32){
        let x = GetX;
        let y = GetY;
         let angle = i*11.25;
          let v = t*2+13;
         let color = 96+8;
          let delay = 10;
          let accel = -1;
          let vmin = 0;
          let vmax = 5;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,accel,vmin,color);
         SetShotDataA(0,60,NULL,angle,0,-accel/20,vmax,color);
         FireShot(0);
         PlaySE(se1);
            }
          }
        wait(90);
        }
       }

     task Move{
           SetSpeed(gspeed);
           SetAngle(gangle);
      loop{
         if(GetY > GetClipMaxY+20){VanishEnemy;}
        wait(1);
         }
      }
         

     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;}
       }
}
}