#TouhouDanmakufu
#Title[Aya SC 3 - E.]
#Text[Aya SC3 - Easy 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 shot1 = CSD~"Shot1.wav";
let shot2 = CSD~"BulletWave.wav";
let death = CSD~"BossDeath.wav";
let time01 = CSD~"timeout01.wav";
let time02 = CSD~"timeout02.wav";
let ayasheet = CSD~"boss_sprites.png";
let ayacutin = CSD~"Cutin.png";
let circle = CSD~"circle.png";
let spellbg1 = CSD~"Spellbg.png";
let spellbg2 = CSD~"Spellbgoverlay.png";
let frame = 0;
#include_function ".\function_cutin.txt"
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"

 @Initialize{
                LoadUserShotData(niceshot);
                LoadGraphic(ayasheet);
                LoadGraphic(circle);
				LoadGraphic(ayacutin);
				LoadGraphic(spellbg1);
				LoadGraphic(spellbg2);
		SetLife(1000);
		SetTimer(60);
		SetInvincibility(100);
		SetScore(100000);
		SetMovePosition03(GetCenterX, GetCenterY-100, 12, 9);
                SetDamageRate(10,5);
                SetEffectForZeroLife(70,200,1);
				cutin("KANAKO","Wind Sign"\""Soujoubo's Fan"\",ayacutin,0,0,256,512);
                mainTask;
				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;
  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 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{
 }
 
 let bgalpha=0;
 let bgalpha2=0;
 let bgscroll=0;

 @BackGround{
  if(bgalpha<200){bgalpha+=2;}
  if(bgalpha2<150){bgalpha2+=2;}
  SetTexture(spellbg1);
  SetGraphicRect(0,0,384,448);
  SetGraphicScale(1,1);
  SetGraphicAngle(0,0,0);
  SetAlpha(bgalpha);
  DrawGraphic(GetCenterX,GetCenterY);
  
  SetTexture(spellbg2);
  SetGraphicRect(0+bgscroll,0+bgscroll,256+bgscroll,256+bgscroll);
  SetGraphicScale(1.8,1.8);
  SetAlpha(bgalpha2);
  DrawGraphic(GetCenterX,GetCenterY);
  
  bgscroll+=1;

 }

     task mainTask{
     wait(100);
	 let addangle = 27.3;
	 
     loop{
	 counter4=0;
	 attacking=true;
	 wait(30);
	 PlaySE(shot1);
	 ascent(j in 0..3){
	 windbullet(addangle+j*360/3,63,addangle,2);
	 }
	 
	 addangle+=17.3;
	 wait(300);
	 
	 counter4=0;
	 attacking=true;
	 wait(30);
	 PlaySE(shot1);
	 ascent(j in 0..3){
	 windbullet(addangle+j*360/3,63,addangle,-2);
	 }
	 
	 addangle+=17.3;
	 wait(300);
     }
     }

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

     task Timer{
     loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time02);}
	wait(60);
	}
        }
		
		
	 task windbullet(angle,slavegraphic,slaveangle,rotation){
	 let ID = Obj_Create(OBJ_SHOT);
	 let frame = 0;
	 let frame2 = 0;
	
	 Obj_SetPosition(ID,GetX,GetY);
	 ObjShot_SetGraphic(ID,6);
	 ObjShot_SetDelay(ID,10);
	 ObjShot_SetBombResist(ID,true);
	 Obj_SetSpeed(ID,3);
	 Obj_SetAngle(ID,angle);
	 
	 
	 while(!Obj_BeDeleted(ID)){
	 frame++;
	 frame2++;
	 
	 if(frame<60){
	 Obj_SetAngle(ID,Obj_GetAngle(ID)+rotation);
	 }
	 
	 if(frame2==5){
	 CreateShotA(1,Obj_GetX(ID),Obj_GetY(ID),20);
	 SetShotDataA(1,0,0,0,0,0,0,6);
	 SetShotKillTime(1,0);
	 FireShot(1);
	 frame2=0;
	 }
	 
	 if(Obj_GetY(ID)<GetClipMinY){

	 CreateLaserA(1,Obj_GetX(ID),Obj_GetY(ID),500,0,6,120);
	 SetLaserDataA(1,0,90,0,0,0,0);
	 
	 ascent(i in 0..15){
	 CreateShotA(2,0,0,30);
	 SetShotDataA(2,0,0,slaveangle*i,10,0,0,slavegraphic);
	 SetShotDataA(2,120,0,NULL,0,0.01,2,NULL);
	 AddShot(0,1,2,i*35);
	 }
	 
	 SetShotKillTime(1,120);
	 PlaySE(shot2);
	 FireShot(1);
	 
	 
	 Obj_Delete(ID);
	 }
	 
	 if(Obj_GetY(ID)>GetClipMaxY){

	 CreateLaserA(1,Obj_GetX(ID),Obj_GetY(ID),500,0,6,120);
	 SetLaserDataA(1,0,270,0,0,0,0);
	 
	 ascent(i in 0..15){
	 CreateShotA(2,0,0,30);
	 SetShotDataA(2,0,0,slaveangle*i,10,0,0,slavegraphic);
	 SetShotDataA(2,120,0,NULL,0,0.01,2,NULL);
	 AddShot(0,1,2,i*35);
	 }
	 
	 SetShotKillTime(1,120);
	 PlaySE(shot2);
	 FireShot(1);
	 
	 
	 Obj_Delete(ID);
	 }
	 
	 if(Obj_GetX(ID)>GetClipMaxX){

	 CreateLaserA(1,Obj_GetX(ID),Obj_GetY(ID),500,0,6,120);
	 SetLaserDataA(1,0,180,0,0,0,0);
	 
	 ascent(i in 0..15){
	 CreateShotA(2,0,0,30);
	 SetShotDataA(2,0,0,slaveangle*i,10,0,0,slavegraphic);
	 SetShotDataA(2,120,0,NULL,0,0.01,2,NULL);
	 AddShot(0,1,2,i*35);
	 }
	 
	 SetShotKillTime(1,120);
	 PlaySE(shot2);
	 FireShot(1);
	 
	 
	 Obj_Delete(ID);
	 }
	 
	 if(Obj_GetX(ID)<GetClipMinX){

	 CreateLaserA(1,Obj_GetX(ID),Obj_GetY(ID),500,0,6,120);
	 SetLaserDataA(1,0,360,0,0,0,0);
	 
	 ascent(i in 0..15){
	 CreateShotA(2,0,0,30);
	 SetShotDataA(2,0,0,slaveangle*i,10,0,0,slavegraphic);
	 SetShotDataA(2,120,0,NULL,0,0.01,2,NULL);
	 AddShot(0,1,2,i*35);
	 }
	 
	 SetShotKillTime(1,120);
	 PlaySE(shot2);
	 FireShot(1);
	 
	 
	 Obj_Delete(ID);
	 }
	 
	 yield;
	 
	 }
	 }	
		
     
}
