#TouhouDanmakufu
#Title[Aya Spellcard 2]
#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 {
        

LoadUserShotData( shot ) ;
if(Cutin_Activate==2){
cutin("NAZRIN", "Air Current "\""Tengu Wings"\" ,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, "Air Current "\""Tengu Wings"\" ,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( 600 ) ;
InitializeAction;
SetTimer( 45 ) ;
if(Cutin_Activate==1){
Timer(1,0);
}
SetDamageRate( 25, 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;
        wait(120);
        TshotP;
        wait(90);
        TshotA;
    }




    task TshotA {
        let x;
        let y;
        let speed;
        let angle;

        let quantity = 18;
        let radius = 10;
        let radiusspeed = 0.25;
        let speedBase = 1.4;
        let interval = 135;

        let dir;
        let angleBase;
        let xspeed;
        let yspeed;

        loop {
            angleBase = atan2(GetPlayerY - GetY, GetPlayerX - GetX);
            dir = rand(0, 360);
PlaySE(shot4);
            loop(quantity) {
                x = GetX + radius * cos(dir);
                y = GetY + radius * sin(dir);
                xspeed = speedBase * cos(angleBase) + radiusspeed * cos(dir);
                yspeed = speedBase * sin(angleBase) + radiusspeed * sin(dir);
                angle = atan2(yspeed, xspeed);
                speed = (xspeed^2 + yspeed^2) ^ 0.5;
                shotL(x, y, speed, angle);
                dir += 360 / quantity;
            }
            wait(interval);
        }
    }

 
    task shotL(x, y, speed, angle) {
        SetShotColor(255, 255, 255);
        CreateShot01(x, y, speed, angle, 2, 0);

        
    }




    task TshotP {
        let x;
        let y;
        let angle = 270;

        let width = 20;
        let turnspeed = 2.51;
        let interval = 2;

        let frame = 2;

        loop {
            angle = 270 + (360 - width) / 2 * sin(frame);
            shotP(angle);
            shotP(180 - angle);
            frame += turnspeed * interval;
PlaySE(shot6);
            wait(interval);
        }
    }

  
    task shotP(angle) {
        let x;
        let y;
        let speed = 1;
        let delay = 13;

        let radius = 42;
        let interval = 1;

        x = GetX + radius * cos(angle);
        y = GetY + radius * sin(angle);

        loop(10) {
            CreateShot01(x, y, speed, angle, 17, delay);
            speed += 0.8;
            delay += -1;
            wait(interval);
        }
    }
function wait(t){loop(t){yield;}}
//걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾



}