script_enemy_main{
      #include_script".\Local.txt"
	let Enemy=csd~"img\dot_yousei.png";
        let shotData = csd ~ "data_usershot.txt";
   let arg = GetArgument;
  let effect = csd ~ "img\circle.png";
	@Initialize
	{

         SetLife(200);
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
           LoadGraphic(effect);
      SetAlpha(0);
            LoadUserShotData(shotData);
      sgr(1,4);	
          SetInvincibility(30);
               Main;
	}
	
	@MainLoop{
		yield;
     SetCollisionA(GetX(),GetY(),12);
     SetCollisionB(GetX(),GetY(),6);
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
         if(!BeVanished){
             AddScore(100); 
   loop(5){
   let radius = rand(0,0);
  let angle = rand(-180,180);
  CreateItem(ITEM_SCORE,GetX+offsetX(radius,angle),GetY+offsetY(radius,angle));
    }
   
             }
	}

         task Main{
             yield; 
       Shot;
   Move;
     }

     task Shot{
   Dan(GetX,GetY,0,90,242,0);
 let w = 40; let v = 4.5;
 if(arg == 2 || arg == 3){w = 30; v = 6;}
  loop{
  ascent(a in 0..5){
  CreateShot01(GetX,GetY,v,GetAngleToPlayer+20*(a-2),40,0);
        }
   wait(w);
      }
    }

   task Dan(x,y,v,angle,color,delay){
        let p = Obj_Create(OBJ_SHOT);
         Obj_SetX(p,x);
         Obj_SetY(p,y);
         Obj_SetSpeed(p,v);
         Obj_SetAngle(p,angle);
         ObjShot_SetGraphic(p,color); 
         ObjShot_SetDelay(p,delay);
         Obj_SetAutoDelete(p,false);
         ObjShot_SetBombResist(p,true);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
   while(!Obj_BeDeleted(p) && GetLife >= 100){
      Obj_SetX(p,GetX);
      Obj_SetY(p,GetY);
     wait(1);
      }
   Obj_Delete(p);
   AddLife(-100);
  }

  task Move{
  SetMovePosition03(GetX,GetY+140,20,1.5);
   wait(180);
  let t = 0; let a = 60;
 let basex = GetX; let basey = GetY;
  loop{
   SetX((-1)^arg*a/80*(t-sin(t))+basex);
   SetY(-a*(1-cos(t))+basey);
  t += 1;
    wait(1);
  if(GetX < minx-20 || GetX > maxx+20){AddLife(99-GetLife);}
      }
   }

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

  function sgr(a,b){SetGraphicRect(a*32,b*32,(a+1)*32,(b+1)*32);}

       function wait(w){
                loop(w){yield;}
       }
}