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(10);
            SetDamageRate(100,100);
            LoadGraphic(Enemy);
            
            LoadUserShotData(shotData);
      sgr(0,1);	
          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{
  loop(5){
    CreateItem(ITEM_SCORE,GetX,GetY);
    }
   }
             }
	}

         task Main{
             yield; 
       Shot;
   Move;
     }

     task Shot{
  let color = 8; let delay = 0;
  let v = 6; 
  loop{
  let x = GetX; let y = GetY;
  let base = rand(-180,180);
    ascent(a in 0..8){
   let angle = base+45*a;
     CreateShot01(x,y,v,angle,color,delay); 
      } 
     wait(10);
     }
   }

  task Move{
  let basex = GetX; let basey = GetY;
   loop{
     if(GetX < basex-40){SetAngle(30); sgr(4,1);}
     if(GetX > basex+40){SetAngle(150);  sgr(8,1);}
     if(GetY > maxy+20){VanishEnemy;}
    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);
     }

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

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