#TouhouDanmakufu
#Title[Aya Spellcard 4]
#Text[]
#BackGround[User]
#ScriptVersion[2]



script_enemy_main {
#include_function ".\1Config.txt"
let CSD = GetCurrentScriptDirectory;
let movelol = 0;
#include_function ".\newsfx.txt" // Non ZUN sfx
#include_function ".\Obj_hpb.txt" // TLC Lifebar, no lags :)
#include_function ".\Cutin_Eff.txt"
#include_function ".\function_cutin.txt"
#include_function ".\lib_anime_Aya.txt"
#include_function ".\system\Aura_Effects.dnh"
let SpellBG1 = CSD~"system/1.png";
let SpellBG2 = CSD~"system/Spellbgoverlay.png";
let shot = GetCurrentScriptDirectory() ~ "kshotData.txt" ; // TLC shots
let frame = 0 ;
let cut = CSD ~ "system\Raymoo.png";
let MinX	  = GetClipMinX;
    let MaxX	  = GetClipMaxX;
    let CenX	  = GetCenterX;
    let MinY	  = GetClipMinY;
    let MaxY	  = GetClipMaxY;
    let CenY	  = GetCenterY;
let powerl    = GetCurrentScriptDirectory~".\enm4se\power_logo.wav";
let bgalpha = 0;	//We create a new variable so that the background can fade in smoothly.
let bgangle = 0;	//Angle for the overlayed BG. 
let imgBoss =  GetCurrentScriptDirectory ~ "system\Aya_Main.png" ;

    
    let xIni        = GetCenterX;
    let yIni        = GetClipMinY + 120;

    let startwait = 120;



    @Initialize {
SetShotAutoDeleteClip(100,100,100,100);
LoadUserShotData( shot ) ;
if(Cutin_Activate==2){
cutin("NAZRIN", " "\""Virtue of the Real Wind God"\" ,cut,0,0,384,520);
SetScore(8000000);
}
if(Cutin_Activate==1){
CutinSP("ORIGI1",20,-50,8000000,60,cut,0,0,384,512);
CutinSP2(-275,-10,GetCurrentScriptDirectory~".\spell\1.png",0,0,384,32,255,255,255);
}
if(Cutin_Activate==0){
CutIn(YOUMU,  " "\""Virtue of the Real Wind God"\" ,cut,0,0,384,520);
SetScore(8000000);
}
LoadGraphic(imgBoss);
LoadGraphic(SpellBG1);
LoadGraphic(SpellBG2);
LoadGraphic(cut);
SetMovePosition01(GetCenterX,GetClipMinY+130,3);
//SetX( GetCenterX ) ;
//SetY( GetClipMinY + 130 ) ;
SetLife( 1000 ) ;
InitializeAction;
SetTimer( 65 ) ;
if(Cutin_Activate==1){
Timer(1,0);
}
SetDamageRate( 15, 10 ) ;
let frame = 0 ;
if(lifebar_activate ==1){
hpb(1,0,0);
}
if(Aura_Activate ==1){
Aura5;
}
        Tmain;       
    }

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

    @DrawLoop {
       DrawText("Aya Shameimaru", 40, 35, 12, 255);
if(GetSpeedX()>0){SetAction(ACT_MOVE,0)}
	if(GetSpeedX()<0){SetAction(ACT_MOVE,0)}
SetGraphicScale(1,1);		
	DrawBoss(imgBoss);
    }

    @Finalize {
        
    }

let bgscroll =0;
let bgalpha=0;
 let bgalpha2=0;
@BackGround{

		//if (bgalpha < 255){bgalpha += 5;}


SetAlpha(bgalpha);
	//The background is scaled up so it can fill the whole screen.

 if(bgalpha<200){bgalpha+=2;}
  if(bgalpha2<150){bgalpha2+=2;}
SetTexture(SpellBG1);
SetGraphicScale(1,1);
SetColor(255,255,255);
SetAlpha(bgalpha);
SetGraphicRect(0,0,384,448);
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 Tmain {
                yield;
        SetDamageRate(0, 0);
        wait(120);
        Troutine;
wait(120);
        SetDamageRate(20, -15);
        wait(60);
    }

 task Troutine {

		let ang =0;

		loop {
PlaySE(kira);
			Tleaves(6 ,120 ,-4 ,10 ,0 +ang ,11 ,true);
			wait(70);
PlaySE(kira);
			Tleaves(6 ,90 ,-4 ,10 ,30 +ang ,14 ,true);
			
			wait(90);
			ang +=6;
PlaySE(kira);
			Tleaves(6 ,120 ,4 ,10 ,0 +ang ,17 ,false);
			wait(70);
PlaySE(kira);
			Tleaves(6 ,90 ,4 ,10 ,30 +ang ,11 ,false);

			wait(90);
PlaySE(kira);
			Tleaves(6 ,120 ,4 ,10 ,0 +ang ,17 ,false);
			Tleaves(6 ,90 ,4 ,10 ,30 +ang ,11 ,false);
wait(90);
PlaySE(kira);
			Tleaves(6 ,120 ,4 ,10 ,0 +ang ,17 ,false);
			Tleaves(6 ,120 ,4 ,10 ,0 +ang ,17 ,false);
wait(90);
PlaySE(kira);
Tleaves(3 ,200 ,-4 ,10 ,0 -ang ,14 ,false);
Tleaves(3 ,200 ,4 ,10 ,0 -ang ,16 ,true);
wait(90);
part2;
wait(90*6);
			ang +=6;
		}
	}

	task Tleaves(mul ,r ,ang_v ,a1 ,phi ,grf ,rev) {

		Tleaf(mul ,r ,ang_v ,a1 ,phi +60*0 ,grf ,rev);
		Tleaf(mul ,r ,ang_v ,a1 ,phi +60*1 ,grf ,rev);
		Tleaf(mul ,r ,ang_v ,a1 ,phi +60*2 ,grf ,rev);
		Tleaf(mul ,r ,ang_v ,a1 ,phi +60*3 ,grf ,rev);
		Tleaf(mul ,r ,ang_v ,a1 ,phi +60*4 ,grf ,rev);
		Tleaf(mul ,r ,ang_v ,a1 ,phi +60*5 ,grf ,rev);
	}
task Tleaf(mul ,s ,ang_v ,a1 ,phi ,grf ,rev) {

		let ang_rate = ang_v;
		let ang = 0;
		let id = 0;
		let a= 0;
		let b = 0;
		let c = 0;

		loop(10) {

			loop(360/12/10) {//궞궻loop됷릶궼mul궕6궻궴궖먭뾭

				let r = s*sin(mul *ang);
				let x = r *sin(ang +phi);
				let y = r *cos(ang +phi);

				CreateShotA(id ,GetX() +x ,GetY() +y ,0);
				SetShotDataA(id ,0 ,0 ,atan2(GetY() -(GetY() +y) ,GetX() -(GetX() +x)) ,0 ,0 ,0 ,grf);

				if(rev) {
					SetShotDataA(id ,70 ,0 ,NULL ,ang_rate ,0.04 ,4 ,grf);
					SetShotDataA(id ,250 -b ,NULL ,atan2(GetY() -(GetY() +y) ,GetX() -(GetX() +x)) -a ,-0.5 ,0.02 ,3 ,grf);
					FireShot(id);

					wait(1);
					ang --;
					a -=1;
					b ++;

				}

					else {
						SetShotDataA(id ,70 ,0 ,NULL ,ang_rate ,0.04 ,4 ,grf);
						SetShotDataA(id ,250 -b ,NULL ,atan2(GetY() -(GetY() +y) ,GetX() -(GetX() +x)) +a ,0.5 ,0.02 ,3 ,grf);
						FireShot(id);

						wait(1);
						ang ++;
						a -=1;
						b ++;
							}




			}//loop
			a -=15;
		}
	}//task

   task part2{

PlaySE(kira);
let angle = 1;
let radius = 100;
loop(6){
PlaySE(kira);
			Tleaves(1 ,radius ,4 ,10 ,0 ,rand(11,20) ,true);
Tleaves(1 ,radius ,-4 ,10 ,0 -ang ,rand(11,20) ,false);			
wait(90);
radius += 40;
}
}
function wait(t){loop(t){yield;}}
//걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾



}