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

	@Finalize{ 
   let rank = GetCommonDataDefaultEx("","PlayRank",0);
         if(!BeVanished){
             AddScore(100); 
   loop(12){
   let radius = rand(0,0);
  let angle = rand(-180,180);
  CreateItem(ITEM_SCORE,GetX+offsetX(radius,angle),GetY+offsetY(radius,angle));
    }
       rank += 1;
             }
   SetCommonDataEx("","PlayRank",rank);
	}

         task Main{
             yield; 
  Circle(20);
   ascent(a in 0..30){
       SetAlpha(255/30*a);
      wait(1);
    }
       Shot;
     }

     task Shot{
  alternative(arg)
  case(0){
  loop(8){
  let base = GetAngleToPlayer+rand(-10,10);
   ascent(a in 0..16){
   let angle = base + 360/16*a;
  CreateShot02(GetX,GetY,4,angle,-0.1,1.2,1,20);
  }
  wait(15);
  PlaySE(seshot1);
     }
    }
  case(1){
  loop(8){
  let base = GetAngleToPlayer;
   ascent(a in 0..9){
   let angle = base + 360/16*(a-4);
  CreateShot02(GetX,GetY,4,angle,-0.1,1.5,6,20);
  }
  wait(15);
  PlaySE(seshot1);
     }
    }
 case(2){
  loop(8){
  let base = GetAngleToPlayer;
   ascent(a in 0..3){
   let v = 0.5*a;
  CreateShot02(GetX,GetY,4,base,-0.1,3.5-v,6,20);
  }
  wait(15);
  PlaySE(seshot1);
     }
  }
 case(3){
  loop(8){
  let base = GetAngleToPlayer+rand(-10,10);
  ascent(b in 0..12){
     let angle = base + 30*b;
   ascent(a in 0..3){
   let v = 1*a;
  CreateShot02(GetX,GetY,4,angle,-0.1,3-v,1,20);
  }
  }
  wait(15);
  PlaySE(seshot1);
     }
    }
   SetInvincibility(30);
   ascent(a in 0..30){
       SetAlpha(255-255/30*a);
      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;}
       }
}