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_swing001.wav";
   let dif = GetCommonData("Dif");
	@Initialize
	{
           
         SetLife(20);
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(60,130,120,160);	
		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(200); 
             loop(9){ 
           CreateItem(ITEM_SCORE,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
           }
             }
	}

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

     task Shot{
     let n = rand(0,300);
      wait(n);
     loop{
           ascent(i in 0..3){
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer-1+i;
          let v = 3;
         let color = 76;
          let delay = 10;
         CreateShot01(x,y,v,angle,color,delay); 
          PlaySE(se1);
            }
       wait(60);
        }
     }

 task Shot2{
     loop{
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer+rand(-10,10);
          let v = rand(1,4);
         let color = 76-46;
          let delay = 0;
         CreateShot01(x,y,v,angle,color,delay); 
          PlaySE(se1);
       wait(3);
        }
     }

     task Move{
           SetSpeed(gspeed);
           SetAngle(gangle);
        loop(10){
           SetAngle(GetAngle+arg);
           wait(6);
         }
       wait(120);
       VanishEnemy;
      }
         
  task Move2{
           SetSpeed(gspeed);
           SetAngle(gangle);
        loop(30){
           SetAngle(GetAngleToPlayer);
           wait(3);
         }
       wait(180);
       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;}
       }
}
}