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_gun003.wav";
        let se2 = csd~ "bgm\tm2_coin000.wav";
        let se3 = csd~ "bgm\buble03.wav";
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(1000);}
            else{SetLife(1000);}
            SetDamageRateEx(100,100,100,100);
            LoadGraphic(Enemy);
          SetTimer(30);  
            LoadUserShotData(shotData);
		SetGraphicRect(0,48,48,96);	
          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; 
       Move;  
        Shot;
     }

     task Shot{
        loop{
          if(GetKeyState(VK_SLOWMOVE) == KEY_HOLD){
         let x = GetX; let y = GetY;
         let v = 0; let angle = 0;
         let color = 246; let delay = 0;
         CreateShotA(0,x,y,delay);
           SetShotDataA(0,0,v,angle,0,0,v,color);
           SetShotKillTime(0,1);
           FireShot(0);
            }
         wait(1);
         }
      }
          

     task Move{
          loop{
         let angle = GetAngle;
            if(GetX <= GetClipMinX || GetX >= GetClipMaxX){
             SetAngle(180-angle);
             }
           else if(GetY <= GetClipMinY){
            SetAngle(-angle);
             }
        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;}
       }
}
}