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_shoot003.wav";
        let se2 = csd~ "bgm\buble03.wav";
	@Initialize
	{
            if(GetPlayerType == REIMU_A){SetLife(150);}
            else{SetLife(150);}
            SetDamageRate(0,0);
            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); 
             loop(1){ 
           CreateItem(ITEM_SCORE,GetX+offsetX(32,rand(-180,180)),GetY+offsetY(32,rand(-180,180)));
           }
             }
	}

         task Main{
             yield; 
        Move; 
       Shot;
     }

     task Shot{
     let way = 24;
     ascent(a in 0..way){
         let angle = GetAngleToPlayer+360/way*a;
         let color = 129;
      if(arg < 0){color = 136;}
          let delay = 10;
        let spin = arg;
        P(angle,color,delay,spin);
         PlaySE(se1); 
          }
       } 

     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);   */
     wait(901);
     loop{
          if(GetY >= GetClipMaxY+20){VanishEnemy;}
           wait(1);   
            }     
      }

      task P(angle,color,delay,spin){
        let p = Obj_Create(OBJ_SHOT);
         Obj_SetX(p,GetX);
         Obj_SetY(p,GetY);
         Obj_SetSpeed(p,0);
         Obj_SetAngle(p,angle);
         ObjShot_SetGraphic(p,color);
         ObjShot_SetDelay(p,delay);
         ObjShot_SetBombResist(p,false);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
         Obj_SetAutoDelete(p,false);
        Set;
       wait(900);
        Obj_Delete(p);
         task Set{
          let radius = 0;
          while(!Obj_BeDeleted(p)){
         descent(a in 0..192){
            Obj_SetAngle(p,Obj_GetAngle(p)+spin);
            Obj_SetX(p,GetX+offsetX(radius,Obj_GetAngle(p)+90));
            Obj_SetY(p,GetY+offsetY(radius,Obj_GetAngle(p)+90));
            radius += a/100;
            wait(1);
               }
           ascent(a in 0..192){
            Obj_SetAngle(p,Obj_GetAngle(p)+spin);
            Obj_SetX(p,GetX+offsetX(radius,Obj_GetAngle(p)+90));
            Obj_SetY(p,GetY+offsetY(radius,Obj_GetAngle(p)+90));
            radius -= a/100;
            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;}
       }
}
}