#TouhouDanmakufu
#Title[Aya NON-SC 1 - N.]
#Text[NON SC1 - Normal Mode.]
#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 ayasheet = CSD~"boss_sprites.png";
let circle = CSD~"circle.png";
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"

 @Initialize{
                LoadUserShotData(niceshot);
                SetX(0);
                SetY(0);
                LoadGraphic(ayasheet);
                LoadGraphic(circle);
		SetLife(500);
		SetTimer(40);
		SetInvincibility(100);
		SetMovePosition03(GetCenterX, GetCenterY-120, 12, 9);
                SetDamageRate(20,20);
                SetEffectForZeroLife(70,200,1);
                mainTask;
				mainTask2;
                MOVE;
                Timer;

    CreateAnimation("aya", "idle", 4);
    SetAnimationFrame("aya", "idle", 0, ayasheet, 12, 0, 0, 64, 64);
    SetAnimationFrame("aya", "idle", 1, ayasheet, 12, 64, 0, 128, 64);
    SetAnimationFrame("aya", "idle", 2, ayasheet, 12, 128, 0, 192, 64);
    SetAnimationFrame("aya", "idle", 3, ayasheet, 12, 192, 0, 256, 64);

    CreateAnimation("aya", "move", 4);
    SetAnimationFrame("aya", "move", 0, ayasheet, 12, 0, 64, 64, 128);
    SetAnimationFrame("aya", "move", 1, ayasheet, 12, 64, 64, 128, 128);
    SetAnimationFrame("aya", "move", 2, ayasheet, 12, 128, 64, 192, 128);
    SetAnimationFrame("aya", "move", 3, ayasheet, 12, 192, 64, 256, 128);

    CreateAnimation("aya", "shoot", 4);
    SetAnimationFrame("aya", "shoot", 0, ayasheet, 12, 0, 128, 64, 192);
    SetAnimationFrame("aya", "shoot", 1, ayasheet, 12, 64, 128, 128, 192);
    SetAnimationFrame("aya", "shoot", 2, ayasheet, 12, 128, 128, 192, 192);
    SetAnimationFrame("aya", "shoot", 3, ayasheet, 12, 192, 128, 256, 192);

  }


  @MainLoop{
  yield;
  SetCollisionA(GetX,GetY,30);
  SetCollisionB(GetX,GetY,25);
 }

 let counter1=0;
 let counter2=0;
 let counter3=0;
 let counter4=0;
 let graphicangle=0;
 let circlespin=0;
 let wave=0;
 let float=0;
 let attacking=false;

 @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(ayasheet);
  SetGraphicScale(1,1);
  SetAlpha(255);
  
  if(attacking==true && counter4==0){
  Animate("aya","shoot",false);
  counter4++;}

  //reset counter4 in the maintask!


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

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

  if(GetSpeedX==0 && counter3==0){
  Animate("aya","idle",true);
  
  if(counter2>0){
  graphicangle=0;}
  
  if(counter1>0){
  graphicangle=180;}
  
  counter3++;
  counter1=0;
  counter2=0;}

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

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

 @Finalize{
 }
 

     task mainTask{
     wait(100);
     let addangle=0;
     loop{
	 PlaySE(shot);
	 ascent(j in 0..4){
     ascent(i in 0..12){
	 CreateShot01(GetX+cos(i*360/12)*20,GetY+sin(i*360/12)*20,4,addangle+j*360/4,26,15);
	 }
	 }
	 addangle+=18.3;
	 wait(10);
     }
     }

	 task mainTask2{
     wait(100);
     loop{
	 ascent(j in 0..8){
     ascent(i in 0..12){
	 CreateShot01(GetX+cos(i*360/12)*20,GetY+sin(i*360/12)*20,3,GetAngleToPlayer+j*360/8,30,15);
	 }
	 }
	 wait(60);
     }
     }
	 
     task MOVE{
     wait(100);
     loop{
     wait(280);
     SetMovePosition03(rand(GetCenterX,GetClipMaxX-50), GetCenterY-120, 12, 4);
     wait(280);
     SetMovePosition03(rand(GetCenterX,GetClipMinX+50), GetCenterY-120, 12, 4);
     }
     }

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