#TouhouDanmakufu
#Title[Remilia NON-SC 3. Normal Mode.]
#Text[NON 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 circle = CSD~"circle.png";
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"

 @Initialize{
                LoadUserShotData(niceshot);
                LoadGraphic(remiliasheet);
                LoadGraphic(circle);
		SetLife(500);
		SetTimer(40);
		SetInvincibility(100);
		SetMovePosition03(GetCenterX, GetCenterY-120, 12, 9);
                SetDamageRate(20,20);
                SetEffectForZeroLife(70,200,1);
                mainTask;
                Support;
                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;
  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{
 }
 

     task mainTask{
     wait(100);
     let addangle=0;
     loop{
     CreateEnemyFromScript("chain_gang",GetX,GetY,3,addangle,1);
     wait(120);
     addangle+=137.5;
     }
     }

     task Support{
     wait(100);
     let addangle=0;
     loop{
     wait(120);
     ascent(l in 0..16){
     wait(6);
     PlaySE(shot);
     ascent(i in 0..10){
     CreateShot01(GetX,GetY,1+l/5,i*30+addangle,216,10);
     }
     addangle+=37.3;
     }
     addangle+=56.5;
     }
     }

     task MOVE{
     wait(100);
     loop{
     wait(400);
     SetMovePosition03(rand(GetCenterX,GetClipMaxX-30), GetCenterY-120, 10, 4);
     wait(400);
     SetMovePosition03(rand(GetCenterX,GetClipMinX+30), 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 chain_gang {
 let CSD = GetCurrentScriptDirectory;
 let niceshot = CSD~"\supershot\supershot.txt";
 let fampoint = GetArgument;
 let shot = CSD~"Shot4.wav";
 let charge = CSD~"se_ch02.wav";
 let frame = 0;
#include_function ".\FunctionLib.dnh"
@Initialize{
    LoadUserShotData(niceshot);
    SetLife(10);
    MOVE;
    Shoot;
    Delete;
 }

@MainLoop{
  yield;
 }

@DrawLoop{
 }

@Finalize{
 }

    task MOVE{
    SetSpeed(3);
    wait(30);
    loop(10){
    SetAngle(atan2(GetPlayerY-GetY,GetPlayerX-GetX));
    wait(6);
    }
    }
  
    task Shoot{
    ascent(i in 0..60){
    PlaySE(shot);
    CreateShotA(1,GetX,GetY,5);
    SetShotDataA(1,0,0,GetAngle,0,0,0,72);
    SetShotDataA(1,180-i*3,0,NULL,0,0.02,3,NULL);
    FireShot(1);
    wait(5);
    }
    }
 
    task Delete{
    loop{
    if(GetX>GetClipMaxX+100 || GetX<GetClipMinY-100 || GetY>GetClipMaxY+100 || GetY<GetClipMinY-100){
    VanishEnemy;}
    yield;
    }
    }



}


