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 se2 = csd~ "bgm\tm2_coin000.wav";
        let se3 = csd~ "bgm\tm2_alchemist000.wav";
  let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(10);}
            else{SetLife(10);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
		SetGraphicRect(70,60,90,100);	
	/*	SetMovePosition02(GetX,GetY,0);  */
          SetInvincibility(10);
          LoadSE(se1);LoadSE(se2);LoadSE(se3);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
		SetCollisionB(GetX(),GetY(),12);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
         if(!BeVanished){
             AddScore(100);
         loop(6){ 
             CreateItem(ITEM_SCORE,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
             }
       let angle = GetAngleToPlayer;
      let v = 3;
        let color = 70;
        let delay = 0;
          let x = GetX+offsetX(8,angle);
          let y = GetY+offsetY(8,angle);
      if(dif == 1){
          CreateShot01(x,y,v,angle,color,delay);
               }
      else if(dif == 2){
         ascent(a in 0..3){
          CreateShot02(x,y,0,angle+30*(a-1),0.05,6,55,0);
              }
            }
          PlaySE(se1);
          }
	}

         task Main{
             yield; 
       Move;
     }

     task Move{
           SetSpeed(gspeed);
           SetAngle(gangle);
        wait(50);
          SetSpeed(0.5);
        wait(30);
          let x = GetX;
          let y = GetY;
          let angle = GetAngle;
          let v = 0;
          let color = 77;
          let delay = 0;
          Bullet(x,y,v,angle,color,delay);
        wait(1);
           SetSpeed(gspeed);
           SetAngle(arg);
       wait(120);
       VanishEnemy;   
      }

     task Bullet(x,y,v,angle,color,delay){
            let b = Obj_Create(OBJ_SHOT);
            Obj_SetX(b,x);
            Obj_SetY(b,y);
            Obj_SetSpeed(b,v);
            Obj_SetAngle(b,angle);
            ObjShot_SetGraphic(b,color);
            ObjShot_SetDelay(b,delay);

   wait(60);
       Obj_Delete(b);
        ascent(i in 0..19){
             let angle = Obj_GetAngle(b)+180+(-1)^(arg/2)*i*7;
             let x = Obj_GetX(b);
             let y = Obj_GetY(b);
             let v = 9+i;
             let color = 77;
             let delay = 0;
             let accel = -0.5;
             let vmin = 0.8;
     if(dif == 2){vmin = 3;}
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color);
         SetShotDataA(0,10,vmin,NULL,0,0,vmin,color);
         FireShot(0);
         PlaySE(se2);
          }
     }  

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