
#Title[「Who the Devil is she ?」]
#Text[夢月・スペル9]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   let name        = "「 Who the Devil is she ?」";
   let imgBOSS = csd~"img\dot_mugetu.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png"; 
  let vanish = false;
   let start = false;

   @Initialize{
  SetCommonDataEx("","bg",4);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(1000000);
  SetDurableSpellCard;
           SetLife(1);
      SetDamageRate(0,0);
           SetTimer(90);
           SetInvincibility(90*60);
         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(!vanish){
      SetCollisionA(GetX, GetY, 24);
      SetCollisionB(GetX, GetY, 18);
     }
         yield;
       }

   @DrawLoop{
   if(vanish){SetAlpha(0);}
         SetTexture(imgBOSS);  
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
  SetCommonDataEx("","bg",3);
  SetShotAutoDeleteClip(64,64,64,64);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
  loop(64){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       }   
     }
 
     task TMain{
     wait(120);
  SetShotAutoDeleteClip(5,5,5,5);
    vanish = true;
   PlaySE(sevanish1);
   PlaySE(sevanish2);
  SetX(cx); SetY(miny-600);
   loop(3){Explosion01(GetX,GetY,0,10,10);}
     Enemy;
        Shot; 
        Count;
    loop{
   if(OnBomb){
   SetAlpha(0);
   SetDamageRate(0,0);}
     else{
    SetAlpha(255);
   SetDamageRate(20,0);}
    wait(1);
      }
    }

   task Shot{
  while(!start){wait(1);}
  SetShotAutoDeleteClip(64,64,64,64);
 let w = 300;
 loop(3){
  Shot1; Shot2;  Shot100(RED01);
   wait(w);
  Shot3; Shot4;   Shot100(BLUE01);
     wait(w);
  Shot5; Shot6;   Shot100(GREEN01);
   wait(w);
    Shot7;  Shot8;   Shot100(ORANGE01);
   w -= 60;
  if(w < 60){w = 60;}
    wait(w);
   Shot9;  Shot10;   Shot100(YELLOW01);
    wait(w);
  }

    task Shot1{
    let way = 21;
  let base = rand(-20,20);
  let base2 = rand(-20,20);
   ascent(a in 0..way){
      let y1 = miny+(miny+maxy)/(way)*a+base;
      let y2 = maxy-(miny+maxy)/(way)*a+base2;
    CreateShot01(minx,y1,1.5,atan2(cy-y1,cx-minx),RED01,20);
    CreateShot01(maxx,y2,1.5,atan2(cy-y2,cx-maxx),RED01,20);
          }
    PlaySE(seshot1);
       }
     task Shot2{
    let way = 18;
  let base = rand(-20,20);
  let base2 = rand(-20,20);
   ascent(a in 0..way){
      let x1 = minx+(minx+maxx)/(way)*a+base;
      let x2 = maxx-(minx+maxx)/(way)*a+base2;
    CreateShot01(x1,miny,1.5,atan2(cy-miny,cx-x1),RED01,20);
    CreateShot01(x2,maxy,1.5,atan2(cy-maxy,cx-x2),RED01,20);
          }
    PlaySE(seshot1);
       }

     task Shot3{
    let way = 14;
  let base = rand(-20,20);
  let base2 = rand(-20,20);
    ascent(b in 0..2){
   ascent(a in 0..way){
      let y1 = miny+(miny+maxy)/(way)*a+base;
      let y2 = maxy-(miny+maxy)/(way)*a+base2;
    CreateShot01(minx,y1,2-b,0,BLUE01,20);
    CreateShot01(maxx,y2,2-b,180,BLUE01,20);
          }
      }
    PlaySE(seshot1);
       }
     task Shot4{
    let way = 12;
  let base = rand(-20,20);
  let base2 = rand(-20,20);
     ascent(b in 0..2){
   ascent(a in 0..way){
      let x1 = minx+(minx+maxx)/(way)*a+base;
      let x2 = maxx-(minx+maxx)/(way)*a+base2;
    CreateShot01(x1,miny,2-b,90,BLUE01,20);
    CreateShot01(x2,maxy,2-b,-90,BLUE01,20);
          }
        }
    PlaySE(seshot1);
       }

     task Shot5{
    let way = 14;
  let base = rand(-20,20);
  let base2 = rand(-20,20);
    ascent(b in 0..2){
   ascent(a in 0..way){
      let y1 = miny+(miny+maxy)/(way)*a+base;
      let y2 = maxy-(miny+maxy)/(way)*a+base2;
    CreateShot01(minx,y1,1,-30+60*b,GREEN01,20);
    CreateShot01(maxx,y2,1,150+60*b,GREEN01,20);
          }
      }
    PlaySE(seshot1);
       }
     task Shot6{
    let way = 12;
  let base = rand(-20,20);
  let base2 = rand(-20,20);
     ascent(b in 0..2){
   ascent(a in 0..way){
      let x1 = minx+(minx+maxx)/(way)*a+base;
      let x2 = maxx-(minx+maxx)/(way)*a+base2;
    CreateShot01(x1,miny,1,60+60*b,GREEN01,20);
    CreateShot01(x2,maxy,1,-60-60*b,GREEN01,20);
          }
        }
    PlaySE(seshot1);
       }

  task Shot7{
    let way = 18;
   ascent(a in 0..way){
      let y1 = miny+(miny+maxy)/(way)*a;
      let y2 = maxy-(miny+maxy)/(way)*a;
    CreateShot01(minx,y1,1.25,atan2(GetPlayerY-y1,GetPlayerX-minx),ORANGE01,20);
    CreateShot01(maxx,y2,1.25,atan2(GetPlayerY-y2,GetPlayerX-maxx),ORANGE01,20);
          }
    PlaySE(seshot1);
       }
     task Shot8{
    let way = 15;
   ascent(a in 0..way){
      let x1 = minx+(minx+maxx)/(way)*a;
      let x2 = maxx-(minx+maxx)/(way)*a;
   CreateShot01(x1,miny,1.25,atan2(GetPlayerY-miny,GetPlayerX-x1),ORANGE01,20);
    CreateShot01(x2,maxy,1.25,atan2(GetPlayerY-maxy,GetPlayerX-x2),ORANGE01,20);
          }
    PlaySE(seshot1);
       }

  task Shot9{
    let way = 14;
   ascent(a in 0..way){
      let y1 = miny+(miny+maxy)/(way)*a;
      let y2 = maxy-(miny+maxy)/(way)*a;
    CreateShot01(minx,y1,2,atan2(GetPlayerY-y1,GetPlayerX-minx),YELLOW01,20);
    CreateShot01(maxx,y2,2,atan2(GetPlayerY-y2,GetPlayerX-maxx),YELLOW01,20);
          }
    PlaySE(seshot1);
       }
     task Shot10{
    let way = 12;
   ascent(a in 0..way){
      let x1 = minx+(minx+maxx)/(way)*a;
      let x2 = maxx-(minx+maxx)/(way)*a;
   CreateShot01(x1,miny,2,atan2(GetPlayerY-miny,GetPlayerX-x1),YELLOW01,20);
    CreateShot01(x2,maxy,2,atan2(GetPlayerY-maxy,GetPlayerX-x2),YELLOW01,20);
          }
    PlaySE(seshot1);
       }

   task Shot100(color){
    let delay = 20;
   ascent(a in 0..5){
   let v = 1+0.5*a;
   CreateShot01(minx,miny,v,90,color,delay);
   CreateShot01(minx,maxy,v,0,color,delay);
   CreateShot01(maxx,maxx,v,-90,color,delay);
   CreateShot01(maxx,miny,v,180,color,delay);
          }
    PlaySE(seshot1);
       }
    }

   task Enemy{
  CreateEnemyFromScript("S",cx,miny+100,0,0,0);
   wait(180*4+60);
   CreateEnemyFromScript("S",cx,miny+100,0,0,0);
   wait(60);
   CreateEnemyFromScript("S",minx,miny,0,0,0);
    wait(30);
   CreateEnemyFromScript("S",minx,maxy,0,0,0);
    wait(30);
   CreateEnemyFromScript("S",maxx,maxy,0,0,0);
    wait(30);
   CreateEnemyFromScript("S",maxx,miny,0,0,0);
   wait(60+180*4+360);
   start = true;
   while(GetTimer > 13){wait(1);}
   CreateEnemyFromScript("S",cx,miny+100,0,0,0);
  }

    task Move{
    }

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

script_enemy S{
      #include_script".\Local.txt"
  let csd = GetCurrentScriptDirectory;
	let Enemy=csd~"img\dot_yousei.png";
        let shotData = csd ~ "data_usershot.txt";
   let arg = GetArgument;
  let effect = csd ~ "img\circle.png";
	@Initialize
	{
         SetLife(9999);
            SetDamageRateEx(0,0,0,0);
            LoadGraphic(Enemy);
           LoadGraphic(effect);
      SetAlpha(0);
            LoadUserShotData(shotData);
      sgr(1,4);	
          SetInvincibility(0);
               Main;
	}
	
	@MainLoop{
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
	}

         task Main{
       Shot;
     Move;
     }

    task Shot{
  let v = 0.3;
  let color = BLUE02;
  let delay = 10;
  loop{
   let x = GetX;
   let y = GetY;
   ascent(a in 0..3){
  let base = GetAngleToPlayer+60*(a-1);
  if(GetEnemyShotCount <= 640){
    CreateShot01(x,y,v,base,color,delay);
    }
         }
     wait(5);
  if(GetX == x && GetY == y){wait(25);}
       }
     }

  task Circle(size){
           let c= Obj_Create(OBJ_EFFECT);
             Obj_SetX(c,GetX);
             Obj_SetY(c,GetY);
             Obj_SetAngle(c,0);
             ObjEffect_SetAngle(c,0,0,0);
             ObjEffect_SetTexture(c,effect);
             ObjEffect_SetRenderState(c,ADD);
             ObjEffect_SetPrimitiveType(c,PRIMITIVE_TRIANGLEFAN);
             ObjEffect_SetLayer(c,0);
             ObjEffect_CreateVertex(c,62);
             ObjEffect_SetVertexXY(c,0,0,0);
             ObjEffect_SetVertexUV(c,0,128,128);
             ObjEffect_SetVertexColor(c,0,255,255,255,255);
             ObjEffect_SetScale(c,size/10,size/10);

            ascent(let i in 0..61){
                ObjEffect_SetVertexXY(c,i+1,cos(i*6)*20,sin(i*6)*20);
                ObjEffect_SetVertexUV(c,i+1,cos(i*6)*128+128,sin(i*6)*128+128);
                ObjEffect_SetVertexColor(c,i+1,255,255,255,255);
            }
      Set; 
     task Set{
         while(!Obj_BeDeleted(c)){
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            wait(1);
           }
         }
    }

   task Move{
   wait(60);
     loop(4){
      SetMovePosition02(GetPlayerX,GetPlayerY,90);
        wait(180);
          }
        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;}
       }
}