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

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

         task Main{
             yield; 
         Angle;
         Move;
          wait(180);
       Shot;
      wait(1800);
      VanishEnemy;
     }

     task Shot{
    let v = 0;
         let color = 19;
          let delay = 20;
        let accel = 0.005;
        let vmax = 5;
      let way = 0;
      loop{
        let x = GetX;
        let y = GetY;
         let angle = GetAngleToPlayer;
         CreateShot02(x,y,v,angle,accel,vmax,color,delay); 
     loop(way){
         let angle2 = rand(-180,180);
         CreateShot02(x,y,v,angle2,accel,vmax,color,delay); 
        }
         PlaySE(se2); PlaySE(se1);
      v += 0.05;
       way += 0.2;
        wait(60);
       }
       }
       
    task Angle{
         ascent(a in 0..3600){
          SetGraphicAngle(0,0,a*6);
         wait(1);
           }
       }  

     task Move{
        let radius = 0;
        let radius2 = 32;
        let angle = GetAngle;
        let angle2 = 2*angle;
        let x = GetX;
        let y = GetY;
         loop{
           SetX(x+offsetX(radius,angle)+2*offsetX(radius2,angle2));
           SetY(y+offsetY(radius,angle));
           radius += 0.5;
       if(arg == 0){
           angle += 6;
           angle2 += 4;
           }
       else if(arg == 1){
           angle -= 6;
           angle2 += 4;
           }
     else if(arg == 2){
           angle += 6;
           angle2 -= 4;
           }
       else if(arg == 3){
           angle -= 6;
           angle2 -= 4;
           }
        if(radius >= 64){radius = 64;}
          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;}
       }
}
}