#TouhouDanmakufu
#Title[Aya Spellcard 3 easy]
#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 ".\lib_anime_Aya.txt"
#include_function ".\function_cutin.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 Protection of the Youkai Mountain"\" ,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 Protection of the Youkai Mountain"\" ,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( 65 ) ;
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(30);
        TshotR;
        TshotW;
        TshotA;
        //SetDamageRate(10, 15);
        wait(60);
    }

  task TshotR {
        let x;
        let y;

        let interval = 4;

        y = GetClipMinY - 5 + 200;
        loop(50) {
            x = rand(GetClipMinX - 105, GetClipMaxX + 105);
            CreateShot01(x, y, rand(2, 4), 90, 37, 4);
            y -= 4;
PlaySE(shot6);
            wait(interval);
        }

        y = GetClipMinY - 5;
        loop {
            x = rand(GetClipMinX - 55, GetClipMaxX + 55);
            CreateShot01(x, y, rand(3, 5), 90, 37, 0);
PlaySE(shot6);
            wait(interval);
        }
    }

//걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾

   
    task TshotW {
        let speed;
        let angle;
        let color = [20, 12, 20, 12, 20, 12];

        let speedA = [3, 3, 4, 4, 5, 5];
        let angleA = [-30, 210, -10, 190, 10, 170];
        let angleB = [50, 130, 70, 110, 90, 90];
        let interval = 5;

        wait(60);

        loop {
            ascent(i in 0..6) {
                speed = speedA[i] * rand(0.98, 1.02);
                angle = angleA[i] + rand(-2, 2);
                CreateShotA(0, GetX, GetY, 6);
                SetShotDataA(0, 0, speed, angle, 0, -speed / 60, 0, color[i]);

                loop(10) {
                    speed = rand(4, 6);
                    angle = angleB[i];
                    CreateShotA(1, 0, 0, 0);
                    SetShotDataA(1, 0, speed, angle, rand(-0.6, 0.6), 0, 0, color[i]);
                    AddShot(60, 0, 1, 0);
                }

                SetShotKillTime(0, 61);
                FireShot(0);
            }
            wait(interval);
        }
    }

//걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾

  
    task TshotA {
        let interval = 60;

        wait(180);

        loop {
PlaySE(lazor);
            shotL;
            wait(interval);
        }
    }

  
    task shotL {
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, 175);
        ObjShot_SetDelay(obj, 7);

        let obj2 = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj2, 175);
        ObjShot_SetDelay(obj2, 0);
        Obj_SetCollisionToPlayer(obj2, false);

        loop(7) {
            Obj_SetPosition(obj, GetX, GetY);
            Obj_SetPosition(obj2, GetX, GetY);
            yield;
        }

        let speed = 1.6;
        let angle = atan2(GetPlayerY - GetY, GetPlayerX - GetX) + rand(-45, 45);
        Obj_SetAngle(obj, angle);
        Obj_SetSpeed(obj, speed);
        Obj_SetPosition(obj, GetX, GetY);
        Obj_SetAngle(obj2, angle);
        Obj_SetSpeed(obj2, speed);
        Obj_SetPosition(obj2, GetX, GetY);

        let objE = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(objE,175);
        Obj_SetAngle(objE, angle);
        Obj_SetSpeed(objE, speed);
        Obj_SetPosition(objE, GetX, GetY);

        let frame = 0;
        while(Obj_BeDeleted(obj) == false) {
          if(frame % 5 == 0) {
              // ObjShot_SetDelay(objE, 17);
            }
            if(frame == 70) {
                speed = 0.8;
                angle = atan2(GetPlayerY - Obj_GetY(obj),
                              GetPlayerX - Obj_GetX(obj)) + rand(-15, 15);
                Obj_SetAngle(obj, angle);
                Obj_SetSpeed(obj, speed);
                Obj_SetAngle(obj2, angle);
                Obj_SetSpeed(obj2, speed);
                ObjShot_SetGraphic(objE, 175);
                ObjShot_SetDelay(objE, 17);
                Obj_SetAngle(objE, angle);
                Obj_SetSpeed(objE, speed);
            }
            if(frame == 130) {
                speed = 2.5;
                angle = atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj));
                Obj_SetAngle(obj, angle);
                Obj_SetSpeed(obj, speed);
                Obj_SetAngle(obj2, angle);
                Obj_SetSpeed(obj2, speed);
                ObjShot_SetGraphic(objE, 175);
                ObjShot_SetDelay(objE, 17);
                Obj_SetAngle(objE, angle);
                Obj_SetSpeed(objE, speed);
            }
            Obj_SetPosition(objE, Obj_GetX(obj) + speed * cos(angle),
                                  Obj_GetY(obj) + speed * sin(angle));
            frame ++;
            yield;
        }

        ObjShot_SetDelay(objE, 0);
        Obj_Delete(obj2);
        Obj_Delete(objE);
    }


   
function wait(t){loop(t){yield;}}
//걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾걾



}