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,50);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
      sgr(0,1);	
          SetInvincibility(30);
               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{
  loop(8){
    CreateItem(ITEM_SCORE,GetX,GetY);
    }
   }
             }
	}

         task Main{
             yield; 
       Shot;
   Move;
     }

     task Shot{
  let color = 8; let delay = 0;
  let v = 6; 
  loop(30){
  let x = GetX; let y = GetY;
    ascent(a in 0..5){
   let angle = atan2(GetY-cy,GetX-cx)+20*(a-2);
     CreateShot01(x,y,v,angle,color,delay); 
      } 
     wait(20);
     }
    loop(30){
  let x = GetX; let y = GetY;
    ascent(a in 0..5){
   let angle = atan2(cy-GetY,cx-GetX)+180+20*(a-2);
     CreateShot01(x,y,v,angle,color,delay); 
      } 
     wait(20);
     }
   }

  task Move{
   loop(600){
     if(GetX < minx+20 && GetY > maxy-20){SetAngle(-90); sgr(0,0);}
     if(GetX > maxx-20 && GetY < miny+20){SetAngle(90);  sgr(0,0);}
     if(GetY < miny+20 && GetX < minx+20){SetAngle(0);  sgr(4,1);}
     if(GetY > maxy-20 && GetX > maxx-20){SetAngle(180);  sgr(8,1);}
    wait(1);
       }
     SetSpeed(0);
     wait(90);
     SetAngle(atan2(GetPlayerY-GetY,GetPlayerX-GetX));
     SetSpeed(3);
     wait(240);
     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;}
       }
}