script_enemy_main{
    #include_script".\th4_1595\@Df\f\lib_Houtou.txt"
        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_laser000.wav";
        let se2 = csd~ "bgm\bomb1.wav";
        let se3 = csd~ "bgm\byoro07.wav";
    let imgBeam = csd ~ "th4_1595\@Df\f\img\\houtou.png";
    let imgFire = csd ~ "th4_1595\@Df\f\img\\Fire.png";
  let dif = GetCommonData("Dif");
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(40);}
            else{SetLife(40);}
            SetDamageRate(100,10);
            LoadGraphic(Enemy);
   /*       SetTimer(30);   */
            LoadUserShotData(shotData);
		SetGraphicRect(60,260,100,290);	
          SetInvincibility(0);
          LoadSE(se1);LoadSE(se2);LoadSE(se3);
               Main;
        LoadGraphic(imgBeam); LoadGraphic(imgFire);
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
               SetCollisionB(GetX(),GetY(),12);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

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

         task Main{
             yield; 
     SetColor(255,255,64);
       Move;  
        Shot;
     }

  /* Houtou(x,y,angle,color,delay,kill); */

     task Shot{
     let a = rand(-180,180);
        loop{
        SetGraphicAngle(0,0,a);
        a += 14;
       wait(1);
         }
      }
          

     task Move{
        loop{
          if(GetX <= GetClipMinX || 
             GetX >= GetClipMaxX ||
             GetY <= GetClipMinY ||
             GetY >= GetClipMaxY
             )
          {break;}
           wait(1);
              }
   SetDamageRate(0,0);
      let x = GetX; let y = GetY;
     let angle = atan2(GetPlayerY-GetY,GetPlayerX-GetX)+rand(-10,10);
  if(dif == 1){angle = atan2(GetPlayerY-GetY,GetPlayerX-GetX);}
      let color = arg; let delay = 60;
      let kill = 240;
       Houtou(x,y,angle,color,delay,kill); 
     wait(delay);
     PlaySE(se2);
     wait(kill+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;}
       }
}
}