
#Title[幽香・スペル1]
#Text[陽符 「ソーラースパーク」]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
 #include_function".\function_effect.txt"
   let imgBOSS = csd~"img\dot_yuka.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png";
  let vanish = false;
  let mirage = false;
  let name        = "陽符 「ソーラースパーク」";

   @Initialize{
 SetCommonDataEx("","bg",6);
           SetLife(700);
      SetDamageRate(20,0);
     /*      SetTimer(30);  */
           SetInvincibility(10);
         sgr(0,0);
 /*SetMovePosition03(GetCenterX,GetClipMinY+60,20,10);*/
        SetAlpha(0);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
           TMain;
    }

   @MainLoop{
    if(OnEvent){break;}
   if(!vanish && !OnBomb){
           SetCollisionA(GetX, GetY, 36);
           SetCollisionB(GetX, GetY, 18);
        }
   if(!vanish && mirage && !OnBomb){
       SetCollisionA(2*cx-GetX, GetY, 36);
        SetCollisionB(2*cx-GetX, GetY, 18);
        }
         yield;
       }

   @DrawLoop{
         SetTexture(imgBOSS);  
        DrawGraphic(GetX,GetY);
   if(mirage == true){DrawGraphic(2*cx-GetX,GetY);}
     }

    @Finalize{
  loop(64){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       } 
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
     }
 
     task TMain{
  yield;
  SpinMotion(48);
 SetX(cx);
   SetY(miny+60);
      ascent(a in 0..18){
      SetAlpha(15*a);
   if(a >= 15){vanish = false;}
   wait(2);
      }

  Circle2(60);
  CutIn(KOUMA, name, "", 0, 0, 0, 0);
  SetScore(1500000);
  SetTimer(65);
   SetInvincibility(150);
          wait(90);
        Shot;
    loop{
   if(OnBomb){
   SetAlpha(0);
   SetDamageRate(0,0);}
     else {
   SetDamageRate(20,0);}
    wait(1);
      }
    }

   task Shot{
   loop{
  Spark(180,255,255,255,true);
  PlaySE(secon);
 CreateLaserB(0,600,10,BLUE01,180);
   SetLaserDataB(0,0,0,20,0,90,0,90,0);
  SetShotKillTime(0,180);
   FireShot(0);
  wait(180);
  sgr(5,2);
  CreateLaserB(0,600,550,BLUE01,0);
   SetLaserDataB(0,0,0,20,0,90,0,90,0);
  SetShotKillTime(0,360);
   FireShot(0);
  PlaySE(MS);
  MotionBlurEx(ALL,360,122,ADD);
 A;  B;
  ascent(a in 0..6){
 if(a == 2 || a == 4){ PlaySE(MS);}
  Explosion01(GetX,GetY,0.01,1,60);
     wait(60);
       }
   SpinMotion(35);
  mirage = true;
   Move;
    Spark(120,255,255,255,true);
  PlaySE(secon);
 CreateLaserB(0,600,10,BLUE01,120);
   SetLaserDataB(0,0,0,20,0,90,0,90,0);
  SetShotKillTime(0,120);
   FireShot(0);
 CreateLaserA(1,2*cx-GetX,GetY+20,600,10,BLUE01,120);
  SetLaserDataA(1,0,90,0,0,0,0);
   SetShotKillTime(1,120);
   FireShot(1);
  wait(120);
  sgr(5,2);
  CreateLaserB(0,600,200,BLUE01,0);
   SetLaserDataB(0,0,0,20,0,90,0,90,0);
  SetShotKillTime(0,240);
   FireShot(0);
  CreateLaserA(1,2*cx-GetX,GetY+20,600,200,BLUE01,0);
  SetLaserDataA(1,0,90,0,0,0,0);
   SetShotKillTime(1,240);
   FireShot(1);
  PlaySE(MS);
  MotionBlurEx(ALL,240,122,ADD);
  C;
  wait(300);
 SpinMotion(35);
 mirage = false;
    ascent(a in 0..18){
      SetAlpha(255-15*a);
   if(a < 15){vanish = true;}
   wait(2);
      }
   SetX(cx);
   SetY(maxy+600);
  SetAlpha(255);
   SetInvincibility(90);
    E;
  wait(90);
   SetX(cx);
   SetY(miny+60);
      ascent(a in 0..18){
      SetAlpha(15*a);
   if(a >= 15){vanish = false;}
     wait(2);
       }
   E;
   wait(180); 
    }
  
   task E{
      loop(30){
    CreateEnemyFromScript("S",cx,cy,0,0,0);
    wait(6);
     } 
  }  

  task A{
  wait(60);
  loop(10){
  ascent(a in 0..18){
    ascent(c in 0..2){
 let angle =  GetAngleToPlayer+20*a;
 let x = GetX+offsetX(5,angle-90+180*c);
      let y = GetY+offsetY(5,angle-90+180*c);
    CreateShot01(x,y,8,angle,174,0);
         }
        }
      wait(30);
        }
      }
  task B{
  wait(60);
  loop(300){
 let angle =  rand(150,390);
 let x = GetX;
  let y = GetY;
    CreateShot01(x,y,rand(0.5,5),angle,48,0);
      wait(1);
        }
      }
  task C{
   let color = 174;
   let delay = 0;
     ascent(a in 0..20){
   let v = 0.2+0.5*a;
    ascent(d in 0..2){
     ascent(b in 0..6){
   ascent(c in 0..2){
 let angle =  90+(-80+15*b)*(-1)^d;
 let x = GetX+offsetX(5,angle-90+180*c);
 let y = GetY+offsetY(5,angle-90+180*c);
 let x2 = 2*cx-GetX+offsetX(5,angle-90+180*c);
  CreateShot01(x,y,v,angle,color,delay);
 CreateShot01(x2,y,v,angle,color,delay);
           }
         } 
      }
  PlaySE(seshot1);
   wait(3);
  if(a <= 3){wait(7);}
          }
        }
    }

    function Move{
   ascent(a in 0..18){
      SetAlpha(255-15*a);
   if(a < 15){vanish = true;}
   wait(2);
      }
   SetX(rand(minx+64,maxx-64));
   SetY(miny+rand(32,140));
      ascent(a in 0..18){
      SetAlpha(15*a);
   if(a >= 15){vanish = false;}
   wait(2);
      }

 }

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

  task SpinMotion(f){
      ascent(a in 0..4){
         sgr(7,a);
       wait(f/4);
            }
          sgr(0,0);
      }

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

 script_enemy S{
      #include_script".\Local.txt"
  let csd = GetCurrentScriptDirectory;
	let Enemy=csd~"img\dot_yuka.png";
        let shotData = csd ~ "data_usershot.txt";
   let arg = GetArgument;
  let effect = csd ~ "img\circle.png";
 let dlaser = csd~ "se\laserdelay.wav"; 
  let seray = csd~ "se\Laser.wav"; 
 let vanish = false;
  let minx = GetClipMinX;
   let maxx = GetClipMaxX;
   let miny = GetClipMinY;
   let maxy = GetClipMaxY;
  
	@Initialize
	{
         SetLife(9999);
            SetDamageRateEx(20,0,20,0);
            LoadGraphic(Enemy);
           LoadGraphic(effect);
  LoadSE(dlaser); LoadSE(seray);
      SetAlpha(255);
            LoadUserShotData(shotData);
      sgr(0,0);	
          SetInvincibility(0);
               Main;
	}
	
	@MainLoop{
		yield;
	}
	
       	@DrawLoop{
               SetTexture(Enemy);
		DrawGraphic(GetX,GetY);
	}

	@Finalize{ 
	}

         task Main{
             yield;
    SpinMotion(48);
   SetX(rand(minx+20,maxx-20));
   SetY(miny+rand(32,180));
     /* ascent(a in 0..18){
      SetAlpha(15*a);
   if(a >= 15){vanish = false;}
   wait(2);
      }   */
   ascent(a in 0..8){
  let angle = 45*a;
    CreateLaser01(GetX,GetY,3,angle,150,10,BLUE01,10);
        }
  PlaySE(seray);
  wait(20);
   SpinMotion(48);
  ascent(a in 0..18){
      SetAlpha(255-15*a);
   if(a < 15){vanish = true;}
   wait(2);
      }
  VanishEnemy;
     }

    task Shot{
    }

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

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

   task SpinMotion(f){
      ascent(a in 0..4){
         sgr(7,a);
       wait(f/4);
            }
          sgr(0,0);
      }

    function Move{
   ascent(a in 0..18){
      SetAlpha(255-15*a);
   if(a < 15){vanish = true;}
   wait(2);
      }
   SetX(rand(minx+64,maxx-64));
   SetY(miny+rand(32,140));
      ascent(a in 0..18){
      SetAlpha(15*a);
   if(a >= 15){vanish = false;}
   wait(2);
      }
    }
}    