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_gun003.wav";
        let se2 = csd~ "bgm\tm2_coin000.wav";
        let se3 = csd~ "bgm\freeze07.wav";
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(1000);}
            else{SetLife(1000);}
            SetDamageRateEx(0,0,0,0);
            LoadGraphic(Enemy);
         /* SetTimer(30); */ 
            LoadUserShotData(shotData);
		SetGraphicRect(70,60,90,100);	
          SetInvincibility(0);
          LoadSE(se1);LoadSE(se2);LoadSE(se3);
               Main;
	}
	
	@MainLoop{
              SetCollisionA(GetX(),GetY(),24);
        /*	SetCollisionB(GetX(),GetY(),24);*/
		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;
        SetAlpha(255);
       SetColor(32,32,32);
         scale;  
       Move;  
        Shot;
     }

     function scale{
          ascent(a in 1..180){
            SetGraphicScale(a/8,a/8);
            wait(1);
          }
       }

     task Shot{
        let way = 8;
        let length = 1200; let width = 10;
          let color = 247;
          let delay = 60;
         let w = 3*delay;
     loop{
       let angle = rand(-165,-105);
         loop(2){
        let x = GetPlayerX + offsetX(-600,angle);
        let y = GetPlayerY + offsetY(-600,angle);
        L(x,y,angle,length,width,color,delay,w);
         angle = -180-angle;
         }
       wait(w);
       Move;
      delay -= 3;
    /*  if(delay <= 5){delay = 5;}
      if(w <= 15){w = 15;}  */
  if(delay <= 1){delay = 1;}
      if(w <= 3){w = 3;}  
        }
      }
          

     task Move{
             SetMovePosition03(GetPlayerX,GetPlayerY,20,5);
      } 

      task L(x,y,angle,length,width,color,delay,w){
              let l = Obj_Create(OBJ_LASER);
              Obj_SetX(l,x);
              Obj_SetY(l,y);
              Obj_SetAngle(l,angle);
              Obj_SetAutoDelete(l,false);
              ObjShot_SetGraphic(l,color);
              ObjShot_SetDelay(l,delay);
              Obj_SetCollisionToObject(l,true);
              Obj_SetCollisionToPlayer(l,true);
              ObjLaser_SetLength(l,length);
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,true);
           wait(delay);
           PlaySE(se3);
           wait(w-delay);
           Obj_Delete(l);
     }

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