script_enemy_main{
        let csd = GetCurrentScriptDirectory;
	let Enemy=csd~"img\familiar.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_gun002.wav";
        let se2 = csd~ "bgm\buble03.wav";
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(150);}
            else{SetLife(150);}
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
           
            LoadUserShotData(shotData);
		SetGraphicRect(96,144,144,192);	
          SetInvincibility(120);
          LoadSE(se1); LoadSE(se2);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
	   /*    SetCollisionB(GetX(),GetY(),12);  */
		yield;
	}
	
       	@DrawLoop{
             /*  SetTexture(Enemy);*/
		DrawGraphic(GetX,GetY);
	}

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

         task Main{
             yield; 
      /*   Angle;  */
         Move; 
       Shot;
     }

     task Shot{
   let d = 0;
      loop{
     ascent(a in 0..2){
        let x = GetX;
        let y = GetY;
         let angle = GetAngle-90+180*a+d*(-1)^a;
          let v = 1;
         let color = 32;
          let delay = 10;
        let accel = 0;
        let vmax = 10;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
       /*  PlaySE(se1); */
          }
       d += 6;
        wait(6);
       }
       }
       
    task Angle{
         ascent(a in 0..3600){
          SetGraphicAngle(0,0,a*6);
         wait(1);
           }
       }  

     task Move{
      let px = GetPlayerX;
    if(px >= GetX){SetAngle(0);}
    else if(px <= GetX){SetAngle(180);}
        SetMovePosition02(px,GetY,60);
        wait(60);
       ascent(a in 0..60){
         SetAngle(GetAngle+(90-GetAngle)/60*a);
         wait(1);
        }
       SetSpeed(3);
     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;}
       }
}
}