#TouhouDanmakufu
#Title[Vampire Sign "Bat Festival". Lunatic Mode.]
#Text[Remilia SC5.]
#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 summonSE = CSD~"fam.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;
let hitbox = true;
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"

 @Initialize{
                LoadUserShotData(niceshot);
                LoadGraphic(remiliasheet);
                LoadGraphic(spellbg);
                LoadGraphic(circle);
		SetLife(1000);
		SetTimer(80);
                SetScore(100000);
		SetInvincibility(100);
		SetMovePosition03(GetCenterX, GetCenterY-120, 12, 9);
                SetDamageRate(10,5);
                SetEffectForZeroLife(70,200,1);
                CutIn(YOUMU,"Vampire Sign"\""Bat Festival"\",remiliacutin,0,0,256,512);
                mainTask;
                HITBOX; 
                Support;
                Antibomb;
                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);

    CreateAnimation("remilia", "bat", 4);
    SetAnimationFrame("remilia", "bat", 0, remiliasheet, 8, 0, 204, 64, 256);
    SetAnimationFrame("remilia", "bat", 1, remiliasheet, 8, 64, 204, 128, 256);
    SetAnimationFrame("remilia", "bat", 2, remiliasheet, 8, 128, 204, 192, 256);
    SetAnimationFrame("remilia", "bat", 3, remiliasheet, 8, 192, 204, 256, 256);

  }


  @MainLoop{
  yield;
  if(frame<1300){frame++;}
  if(frame==1200){SetDamageRate(50,50);}
 }

 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 && hitbox==true){
  graphicangle=0;
  Animate("remilia","move",false);
  counter1++;
  counter2=0;
  counter3=0;}

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

  if(GetSpeedX==0 && counter3==0 && hitbox==true){
  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{
 PlaySE(death);
 }
 
 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;
     let wave=0;
     let wave2=0;
     loop{
     PlaySE(summonSE);
     ascent(i in 0..6){
     CreateEnemyFromScript("batfamiliar",GetX,GetY,1,i*360/6+addangle,1);}
     addangle+=17.5;
     wait(400);
     }
     }


     task Support{
     wait(100);
     let wave=0;
     loop{
     wait(200);
     PlaySE(summonSE);
     CreateEnemyFromScript("batfamiliar",GetCenterX+cos(wave)*60,GetClipMinY,2,90+sin(wave)*30,2);
     wave+=139.5;
     wait(200);
     PlaySE(summonSE);
     CreateEnemyFromScript("batfamiliar",GetClipMaxX,GetCenterY+sin(wave)*120,2,180+sin(wave)*30,2);
     wave+=139.5;
     wait(200);
     PlaySE(summonSE);
     CreateEnemyFromScript("batfamiliar",GetClipMinX,GetCenterY+sin(wave)*120,2,360+sin(wave)*30,2);
     wave+=139.5;
     wait(200);
     PlaySE(summonSE);
     CreateEnemyFromScript("batfamiliar",GetCenterX+cos(wave)*60,GetClipMaxY,2,270+sin(wave)*30,2);
     wave+=139.5;
     }
     }

     task HITBOX{
     let batcounter=0;
     loop{
     if(hitbox==true){
     SetCollisionA(GetX,GetY,30);
     SetCollisionB(GetX,GetY,25);
     batcounter=0;
     }
     if(hitbox==false && batcounter==0){
     Animate("remilia","bat",true);
     counter1=0;
     counter2=0;
     counter3=0;
     batcounter++;
     }
     yield;
     }
     }

     task Antibomb{
     loop{
     if(OnBomb){
     hitbox=false;}
     if(!OnBomb){
     hitbox=true;}
     yield;
     }
     }

     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 batfamiliar {
 let CSD = GetCurrentScriptDirectory;
 let niceshot = CSD~"\supershot\supershot.txt";
 let fampoint = GetArgument;
 let shot = CSD~"Shot1.wav";
 let shot2 = CSD~"BulletWave.wav";
 let charge = CSD~"se_ch02.wav";
 let frame = 0;
 let batangle = 0;
let remiliasheet = CSD~"boss15.png";
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"

@Initialize{
    LoadUserShotData(niceshot);
    SetLife(150);
    Bounce;
    Shoot;
    Delete;

    CreateAnimation("bat", "fly", 4);
    SetAnimationFrame("bat", "fly", 0, remiliasheet, 8, 0, 204, 64, 256);
    SetAnimationFrame("bat", "fly", 1, remiliasheet, 8, 64, 204, 128, 256);
    SetAnimationFrame("bat", "fly", 2, remiliasheet, 8, 128, 204, 192, 256);
    SetAnimationFrame("bat", "fly", 3, remiliasheet, 8, 192, 204, 256, 256);

    Animate("bat","fly",true);
 }

@MainLoop{
  SetCollisionA(GetX,GetY,20);
  SetCollisionB(GetX,GetY,15);
  yield;
 }

@DrawLoop{
  SetTexture(remiliasheet);
  SetGraphicScale(1,1);
  if(GetSpeedX>0){
  batangle=0;}
  if(GetSpeedX<0){
  batangle=180;}
  SetGraphicAngle(batangle,0,0);
  DrawAnimatedSprite("bat", GetX, GetY);
 }

@Finalize{
 }

    task Bounce{
    loop{
    if(fampoint==1){
 
    if(GetX<GetClipMinX || GetX>GetClipMaxX){
    SetAngle(180-GetAngle);}

    if(GetY<GetClipMinY || GetY>GetClipMaxY){
    SetAngle(360-GetAngle);}}

    yield;
    }
    }
  
    task Shoot{
    let wave=0;
    let addangle=0; 
    loop{

    if(fampoint==1){
    wait(200);
    PlaySE(shot2);
    ascent(i in 0..20){
     CreateShotA(i,GetX+cos(wave)*10,GetY+sin(wave)*10,5);
     SetShotDataA(i,0,0,i*18+addangle,6,0,0,55);
     SetShotDataA(i,60,0,NULL,0,0.05,2,NULL);
     FireShot(i);
    wave+=18;
    }
    addangle+=57.5;}

    if(fampoint==2){
    ascent(l in 0..20){
    PlaySE(shot);
    ascent(i in 0..4){
     CreateShotA(i,GetX+cos(wave)*5,GetY+sin(wave)*5,10);
     SetShotDataA(i,0,0,GetAngle+i*90,0,0,0,216);
     SetShotDataA(i,300-l*15,0,NULL,0,0.05,2,NULL);
     FireShot(i);
    wave+=1;}
    wait(15);}}

    yield;
    }
    }
 
    task Delete{
    loop{
    if(GetX>GetClipMaxX+100 || GetX<GetClipMinY-100 || GetY>GetClipMaxY+100 || GetY<GetClipMinY-100){
    VanishEnemy;}
    yield;
    }
    }



}


