#TouhouDanmakufu
#Title[Destiny "Shattering of Bonds". Normal Mode.]
#Text[Remilia SC3.]
#Player[FREE]
#BGM[.\BGM1.wav]
#ScriptVersion[2]

script_enemy_main{
let CSD = GetCurrentScriptDirectory;
let niceshot = CSD~"\supershot\supershot.txt";
let laserSE = CSD~"Laser3.wav";
let shot = CSD~"Shot1.wav";
let death = CSD~"BossDeath.wav";
let time01 = CSD~"timeout01.wav";
let time02 = CSD~"timeout02.wav";
let remiliasheet = CSD~"boss15.png";
let remiliacutin = CSD~"remilia.png";
let circle = CSD~"circle.png";
let spellbg = CSD~"cdbg15.png";
let frame = 0;
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"

 @Initialize{
                LoadUserShotData(niceshot);
                LoadGraphic(remiliasheet);
                LoadGraphic(spellbg);
                LoadGraphic(circle);
		SetLife(1000);
		SetTimer(60);
                SetScore(100000);
		SetInvincibility(100);
		SetMovePosition03(GetCenterX, GetCenterY-120, 12, 9);
                SetDamageRate(10,5);
                SetEffectForZeroLife(70,200,1);
                CutIn(YOUMU,"Destiny"\""Shattering of Bonds"\",remiliacutin,0,0,256,512);
                mainTask;
                MOVE;
                Timer;


    CreateAnimation("remilia", "idle", 1);
    SetAnimationFrame("remilia", "idle", 0, remiliasheet, 12, 0, 0, 64, 82);

    CreateAnimation("remilia", "move", 3);
    SetAnimationFrame("remilia", "move", 0, remiliasheet, 12, 0, 0, 64, 82);
    SetAnimationFrame("remilia", "move", 1, remiliasheet, 12, 64, 0, 128, 82);
    SetAnimationFrame("remilia", "move", 2, remiliasheet, 12, 128, 0, 192, 82);

  }


  @MainLoop{
  yield;
  if(frame<900){frame++;}
  if(frame==800){SetDamageRate(50,50);}
  SetCollisionA(GetX,GetY,30);
  SetCollisionB(GetX,GetY,25);
 }

 let counter1=0;
 let counter2=0;
 let counter3=0;
 let graphicangle=0;
 let circlespin=0;
 let wave=0;
 let float=0;

 @DrawLoop{

  SetTexture(circle);
  SetGraphicRect(64,64,192,192);
  SetGraphicScale(1+sin(wave)*0.2,1+sin(wave)*0.2);
  SetGraphicAngle(0,0,circlespin);
  SetAlpha(100);
  DrawGraphic(GetX,GetY);
  circlespin+=4;
  wave+=2;

  SetTexture(remiliasheet);
  SetGraphicScale(1,1);
  SetAlpha(255);


  if(GetSpeedX>0 && counter1==0){
  graphicangle=0;
  Animate("remilia","move",false);
  counter1++;
  counter2=0;
  counter3=0;}

  if(GetSpeedX<0 && counter2==0){
  graphicangle=180;
  Animate("remilia","move",false);
  counter2++;
  counter1=0;
  counter3=0;}

  if(GetSpeedX==0 && counter3==0){
  Animate("remilia","idle",true);
  counter3++;
  counter1=0;
  counter2=0;}

  //true makes it loop, false makes it continue on the last sprite.

  SetGraphicAngle(graphicangle,0,0);
  DrawAnimatedSprite("remilia", GetX, GetY+sin(float)*4);
  float += (1/((|GetSpeedX|)+1))*3;
 }

 @Finalize{
 }
 
 let bgalpha=0;
 let bgspin=0;

 @BackGround{
  if(bgalpha<150){bgalpha+=2;}
  SetTexture(spellbg);
  SetGraphicRect(0,0,256,256);
  SetGraphicScale(2.2,2.2);
  SetGraphicAngle(0,0,bgspin);
  SetAlpha(bgalpha);
  DrawGraphic(GetCenterX,GetCenterY);
  bgspin+=1;

 }

     task mainTask{
     wait(100);
     let addangle=0;
     loop{
     ascent(i in 0..10){
     CreateEnemyFromScript("chains",GetX,GetY,3,GetAngleToPlayer+addangle+i*360/10,2);}
     wait(250);
     addangle+=67.5;
     ascent(i in 0..10){
     CreateEnemyFromScript("chains",GetX,GetY,3,GetAngleToPlayer-addangle+i*360/10,1);}
     wait(250);
     addangle+=81.5;
     ascent(i in 0..5){
     CreateEnemyFromScript("chains",GetX,GetY,2,GetAngleToPlayer+addangle+i*360/5,2);
     CreateEnemyFromScript("chains",GetX,GetY,2,GetAngleToPlayer-addangle+i*360/5,1);}
     addangle+=67.5;
     wait(250);
     }
     }


     task MOVE{ 
     wait(100);
     loop{
     wait(400);
     SetMovePosition03(rand(GetCenterX,GetClipMaxX-50), GetCenterY-120, 10, 4);
     wait(400);
     SetMovePosition03(rand(GetClipMinX+50,GetCenterX), GetCenterY-120, 10, 4);
     }
     }

     task Timer{
     loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time02);}
	wait(60);
	}
        }

     
}



//Familiar Scripting Starts Here!!!

script_enemy chains {
 let CSD = GetCurrentScriptDirectory;
 let niceshot = CSD~"\supershot\supershot.txt";
 let fampoint = GetArgument;
 let shot = CSD~"Shot1.wav";
 let charge = CSD~"se_ch02.wav";
 let frame = 0;
 let frame2 = 0;
#include_function ".\FunctionLib.dnh"
@Initialize{
    LoadUserShotData(niceshot);
    SetLife(10);
    MOVE;
    Shoot;
    Activate;
 }

@MainLoop{
  yield;
 }

@DrawLoop{
 }

@Finalize{
 }

    task MOVE{

    if(fampoint==1){
    loop(30){
    SetAngle(GetAngle+10);
    wait(2);}
}

    if(fampoint==2){
    loop(30){
    SetAngle(GetAngle-10);
    wait(2);}
}

    }

  
    task Shoot{
    loop{
    if(GetY<GetClipMaxY && GetY>GetClipMinY && GetX>GetClipMinX && GetX>GetClipMinX && fampoint==1){
    PlaySE(shot);
    chainpart(1,1,5.5);
    wait(5);
    PlaySE(shot);
    chainpart(-1,-1,-5.5);
    wait(5);
    PlaySE(shot);
    chainpart(1,-1,-5.5);
    wait(5);
    PlaySE(shot);
    chainpart(-1,1,5.5);
    wait(5);}

    if(GetY<GetClipMaxY && GetY>GetClipMinY && GetX>GetClipMinX && GetX>GetClipMinX && fampoint==2){
    PlaySE(shot);
    chainpart(-1,0,-5.5);
    wait(5);
    PlaySE(shot);
    chainpart(1,1,5.5);
    wait(5);
    PlaySE(shot);
    chainpart(-1,1,5.5);
    wait(5);
    PlaySE(shot);
    chainpart(1,-1,-5.5);
    wait(5);}
    yield;
    }
    }
 
    task Activate{
    loop{
    frame2++;
    if(frame2==251){
    VanishEnemy;}
    yield;
    }
    }

    task chainpart(xchange,ychange,anglechange){
    let id = Obj_Create(OBJ_SHOT);

    Obj_SetPosition(id,GetX,GetY);
    Obj_SetSpeed(id,0);
    Obj_SetAngle(id,GetAngle+180);
    Obj_SetAlpha(id,200);
    ObjShot_SetGraphic(id,70);
    ObjShot_SetDelay(id,5);

    while(!Obj_BeDeleted(id)){
 
    if(frame2>200 && frame2<250){
    Obj_SetPosition(id,Obj_GetX(id)+xchange,Obj_GetY(id)+ychange);
    Obj_SetAngle(id,Obj_GetAngle(id)+anglechange);}
    
    if(frame2==250){
    Obj_SetSpeed(id,1.5);}

    yield;
    }
    }

}
