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(30);
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
      sgr(1,2);	
          SetInvincibility(0);
               Main;
	}
	
	@MainLoop{
               SetCollisionA(GetX(),GetY(),12);
		SetCollisionB(GetX(),GetY(),6);
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
         if(!BeVanished){
             AddScore(100); 
   alternative(arg)
   case(31){
    CreateItem(ITEM_1UP,GetX,GetY);
     }
   others{
    CreateItem(ITEM_SCORE,GetX,GetY);
   }
             }
	}

         task Main{
             yield; 
       Shot;
       Move;
     }

     task Shot{
   let w = rand(0,30);
  let v = 6;
   loop{
   let span = 15;
  if(arg >= 20){span = 30;}
    CreateShot01(GetX,GetY,v,GetAngleToPlayer,8,10);
 if(arg >= 10){
    CreateShot01(GetX,GetY,v,GetAngleToPlayer+span,8,10);
    CreateShot01(GetX,GetY,v,GetAngleToPlayer-span,8,10);
    }
    wait(w);
   w = rand(60,90);
      }
       }

     task Move{
    let x = GetX; let y = GetY;
   let a = 1.5; 
       if(arg == 0 || arg == 2 || arg == 4 ||
          arg == 10 || arg == 12 || arg == 14 ||
          arg == 20 || arg == 22 || arg == 24){
    while(GetY<miny+120){
    wait(1);
    }
      loop(60){
      SetAngle(GetAngle-a); 
      wait(1);
     }
 /*     while(GetX<maxx-110+minx+50-x){wait(1);}
      loop(60){
      SetAngle(GetAngle+a); 
      wait(1);
     }    */
     while(GetX<maxx+20){wait(1);}
     }
   else if(arg == 1 || arg == 3 || arg == 5 || 
           arg == 11 || arg == 13 || arg == 15 ||
           arg == 21 || arg == 23 || arg == 25 || 
           arg == 31){
    while(GetY<miny+120){wait(1);}
      loop(60){
      SetAngle(GetAngle+a); 
    sgr(2,3);
      wait(1);
     }
 /*     while(GetX>minx+110+maxx-50-x){wait(1);}
      loop(60){
      SetAngle(GetAngle-a); 
     sgr(5,3);
      wait(1);
     }       */
   sgr(0,2);
     while(GetX>minx-20){wait(1);}
     }
    VanishEnemy;
   }

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