#TouhouDanmakufu
#Title[Remilia NON-SC 4. Easy Mode]
#Text[NON SC4.]
#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 shot2 = CSD~"Shot3.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";
let hitbox = true;
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"

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

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

     task mainTask{
     wait(100);
     let wave = 50;
     let addangle = 0;
     loop{
     hitbox=false;
     ascent(l in 0..14){
     wait(16);
     PlaySE(laserSE);
     SetMovePosition02(rand(GetClipMinX+50,GetClipMaxX-50),GetCenterY-120,20);
     ascent(i in -7..8){
     SetShotDirectionType(PLAYER);
     CreateLaser01(GetX+cos(wave)*20,GetY+sin(wave)*20,7,i*7,200,10,2,10);
     SetShotDirectionType(ABSOLUTE);
     wave+=5;
     }
     }     
     hitbox=true;
     wait(300);
     hitbox=false;
     loop(35){
     wait(8);
     PlaySE(shot);
     SetMovePosition02(rand(GetClipMinX+50,GetClipMaxX-50),GetCenterY-120,20);
     ascent(i in 0..2){
     ascent(l in 0..3){
     CreateShotA(1,GetX,GetY,5);
     CreateShotA(2,GetX,GetY,5);
     SetShotDataA(1,0,4,i*360/2+addangle,5,0,0,216);
     SetShotDataA(2,0,4,i*360/2-addangle,-5,0,0,218);
     SetShotDataA(1,60,4-l/2,NULL,0,0,0,216);
     SetShotDataA(2,60,4-l/2,NULL,0,0,0,218);
     FireShot(1);
     FireShot(2);
     }
     addangle+=3.5;
     }
     }
     hitbox=true;
     wait(300);

     hitbox=false;
     SetMovePosition03(GetCenterX, GetCenterY-120, 10, 3);
     ascent(i in 0..17){
     wait(16);
     PlaySE(shot2);
     addangle+=13.5;
     ascent(l in -7..8){
     SetShotDirectionType(PLAYER);
     CreateShot01(GetX,GetY+50,5.4,l*20,229,20);
     CreateShot01(GetX,GetY-50,4.4,addangle+l*20,204,20);
     SetShotDirectionType(ABSOLUTE);
     }}
     hitbox=true;
     wait(300);
     }
     }
 
     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 Timer{
     loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time02);}
	wait(60);
	}
        }
     
}



