
#Title[uւȂVYv]
#Text[EXy4]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   let name        = " uւȂVYv";
   let imgBOSS = csd~"img\dot_gengetu.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png"; 
  let vanish = true;

   @Initialize{
 SetCommonDataEx("","bg",10);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(3333333);
           SetLife(1);
      SetDamageRate(0,0);
    SetDurableSpellCard;
           SetTimer(99);
           SetInvincibility(120);
         sgr(0,0);
      /*   SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);*/
        SetAlpha(255);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
   Circle3(60);
           TMain;
    }

   @MainLoop{
    if(OnEvent){break;}
     if(!OnBomb && !vanish){
      SetCollisionA(GetX, GetY, 24);
      SetCollisionB(GetX, GetY, 18);
     }
         yield;
       }

   @DrawLoop{
         SetTexture(imgBOSS);  
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
 SetCommonDataEx("","bg",8);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
  loop(100){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       }   
  CreateItem(ITEM_1UP,GetX,GetY); 
     }
 
     task TMain{
    yield;
 vanish = false;
   SetX(cx);
   SetY(miny+100);
  /*   SetGraphicScale(0,0);
    SetX(cx);
   SetY(miny+100);
     ascent(a in 0..21){
     SetGraphicScale(a*0.05,a*0.05);
   if(a >= 15){vanish = false;}
      wait(1);
        }    */
          wait(120);  
    vanish = true;
        Shot;
        Count;
    loop{
   if(OnPlayerMissed){
   DeleteEnemyShot(ALL);}
    wait(1);
      }   
    }

   task Shot{
  SetAlpha(128);
  let way = 30;
   ascent(b in 0..3){
  ascent(a in 0..way){
  let angle = 360/way*a+90;
  CreateShot01(GetX,GetY,3+0.5*b,angle,49,0);
          }
        }
   PlaySE(seshot2);
     ascent(a in 0..21){
     SetGraphicScale(1-a*0.05,1-a*0.05);
      wait(1);
        }
   SetX(cx);
   SetY(cy);
     ascent(a in 0..61){
     SetGraphicScale(a*0.05/3,a*0.05/3);
      wait(1);
        }
   wait(120);

  let w = 240;
  loop(10){
  let x = GetX; let y = GetY;
  let v = 1;  let angle = 0;
  ascent(a in 0..4){
  let vector = 90*a;
  let d = -(-1)^a*1.25;
 LaserA(x,y,angle,d,v,vector);
         }
   SetX(GetPlayerX);
   wait(w);
  w -= 8;
 let x = GetX; let y = GetY;
  let v = 0.75;  let angle = rand(-180,180);
  let vector = GetAngleToPlayer;
  let d = 3;
 LaserD(x,y,angle,d,v,vector);
  if(w <= 30){w = 30;}
 x = GetX;  y = GetY;
    ascent(a in 0..2){
  let vector = 90*a-45;
  let d = -1.25;
 LaserA(x,y,angle,d,v,vector);
        }
       ascent(a in 0..2){
  let vector = 90*a+135;
  let d = 1.25;
 LaserA(x,y,angle,d,v,vector);
        }
  SetX(GetPlayerX);
       wait(w);
    w -= 8;
  if(w <= 30){w = 30;}
     let x = GetX; let y = GetY;
  let v = 0.75;  let angle = rand(-180,180);
  let vector = GetAngleToPlayer;
  let d = 3;
 LaserD(x,y,angle,d,v,vector);
        }   
  DeleteEnemyShotToItem(ALL);

 let w = 240;
 loop(10){
   let x = [minx,minx,maxx,maxx]; 
   let y = [miny,maxy,miny,maxy];
  let v = 1;  let angle = 0;
   ascent(a in 0..2){
  let vector = 180+atan2(y[a]-GetPlayerY,x[a]-GetPlayerX);
  let d = -1.25;
 LaserA(x[a],y[a],angle,d,v,vector);
        }
       ascent(a in 2..4){
  let vector = 180+atan2(y[a]-GetPlayerY,x[a]-GetPlayerX);
  let d = 1.25;
 LaserA(x[a],y[a],angle,d,v,vector);
        }
 SetX(GetPlayerX);
  SetY(GetPlayerY);
   wait(w);
  w -= 9;
  if(w <= 30){w = 30;}
    ascent(a in 0..2){
  let vector = 180+atan2(y[a]-GetPlayerY,cx-GetPlayerX);
  let d = -1.25;
 LaserA(cx,y[a],angle,d,v,vector);
        }
       ascent(a in 1..3){
  let vector = 180+atan2(cy-GetPlayerY,x[a]-GetPlayerX);
  let d = 1.25;
 LaserA(x[a],cy,angle,d,v,vector);
        }
 let v = 0.75;  let angle = rand(-180,180);
  let vector = GetAngleToPlayer;
  let d = 3;
 LaserD(GetX,GetY,angle,d,v,vector);
   SetX(GetPlayerX);
  SetY(GetPlayerY);
   wait(w);
    w -= 9;
  if(w <= 30){w = 30;}
  let v = 0.75;  let angle = rand(-180,180);
  let vector = GetAngleToPlayer;
  let d = 3;
 LaserD(GetX,GetY,angle,d,v,vector);
      }
    }

   task LaserA(x,y,angle,d,v,vector){
  let length = 100;
  let width = 20;
  let color = RED01; //185
 loop(4){
   CreateLaserA(1,x,y,length,width,color,0);
  SetLaserDataA(1,0,angle,d,0,v,vector);
   FireShot(1);
    angle += 90;
    }
  PlaySE(seray);
  CreateShot01(x,y,v,vector,49,0);
      }

  task LaserD(x,y,angle,d,v,vector){
    let length = 110;
  let width = 20;
  let color = RED01; //185
   let color2 = BLUE01; 
 loop(4){
   CreateLaserA(1,x,y,length,width,color,0);
  SetLaserDataA(1,0,angle,d,0,v,vector);
   FireShot(1);
    CreateLaserA(0,x,y,length,width,color2,0);
  SetLaserDataA(0,0,angle,d,0,v,vector);
   FireShot(0);
    angle += 90;
    }
   loop(4){
    CreateLaserA(1,x,y,length,width,color,0);
  SetLaserDataA(1,0,angle,-d,0,v,vector);
   FireShot(1);
   CreateLaserA(0,x,y,length,width,color2,0);
  SetLaserDataA(0,0,angle,-d,0,v,vector);
   FireShot(0);
    angle += 90;
    }
   CreateShot01(x,y,v,vector,49,0);
    CreateShot01(x,y,v,vector,54,0);
   PlaySE(seray);
      }

   function Move{
    ascent(a in 0..21){
     SetGraphicScale(1-a*0.05,1-a*0.05);
   if(a >= 15){vanish = true;}
      wait(1);
        }
   SetX(rand(minx+64,maxx-64));
   SetY(GetY);
     ascent(a in 0..21){
     SetGraphicScale(a*0.05,a*0.05);
   if(a >= 15){vanish = false;}
      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*128,b*128,(a+1)*128,(b+1)*128);}

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