#include "././default_system/LoLKshot_Const.txt"
#include "././default_system/Glow_Const.txt"
#include "././default_system/ZUNShot_Const.txt"
#include "././default_system/CancelShotConst.txt"
#include "./se.txt"

function GetCenterX(){
     return 384 / 2;
}
function GetCenterY(){
     return 448 / 2;
}
function wait(n){
     loop(n){yield;}
}

function GetAngleBetween(p1, p2){
	return atan2(ObjMove_GetY(p1)-ObjMove_GetY(p2),ObjMove_GetX(p1)-ObjMove_GetX(p2));
}

function GetAngleBetween2(x1, y1, x2, y2){
	return atan2(y1-y2,x1-x2);
}

function GetDistance(x1,y1,x2,y2)
{
	return ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5;
}

function PlayerX(){
	return GetPlayerX();
}

function PlayerY(){
	return GetPlayerY();
}

function Rotate2D_X(x, y, xo, yo, angle) {
    x -= xo;
    y -= yo;
    return xo + x * cos(angle) - y * sin(angle);
}

function Rotate2D_Y(x, y, xo, yo, angle) {
    x -= xo;
    y -= yo;
    return yo + y * cos(angle) + x * sin(angle);
}

task debugtext(text, t){
	 let objText = ObjText_Create();
    ObjText_SetText(objText, text);
    Obj_SetRenderPriority(objText, 60);
    ObjText_SetFontSize(objText, 24);
    ObjText_SetFontType(objText, "Russell Square Regular");
    ObjText_SetFontBold(objText, true);
    ObjText_SetFontColorTop(objText, 255, 255, 255);
    ObjText_SetFontColorBottom(objText, 255, 255, 255);
    ObjText_SetFontBorderType(objText, BORDER_FULL);
    ObjText_SetFontBorderColor(objText, 224, 64, 192);
    ObjText_SetFontBorderWidth(objText, 1);
    wait(t);
    Obj_Delete(objText);
}

let lowq = 0;

task spawnsimple(bullet, tog){
    /*if(tog == 1 && lowq == 1){
        ObjRender_SetScaleXYZ(bullet, 1, 1, 1);
        ObjRender_SetAlpha(bullet, 255);
        return;
    }*/
    // spawncustom(bullet, 1, 2.5, 0.7, 70, 255, 8, t8)
    let scale = 2;
    let n = 8;
    let sp = (scale-1)/n;
    let alpha = 70;
    let alphap = (255-alpha)/n;
    
    loop(n){
        ObjRender_SetScaleXYZ(bullet, scale, scale, 1);
        ObjRender_SetAlpha(bullet, alpha);
        scale -= sp;
        alpha += alphap;
        wait(1);
    }
    sp = (1-scale)/n;
    loop(n){
        ObjRender_SetScaleXYZ(bullet, scale, scale, 1);
        ObjRender_SetAlpha(bullet, alpha);
        scale += sp;
        //alpha += alphap/2;
        wait(1);

    }
    ObjRender_SetScaleXYZ(bullet, 1, 1, 1);
    ObjRender_SetAlpha(bullet, 255);
}

task spawncustom(bullet, nscale, bscale, sscale, salpha, alpha, t1, t2, tog){
    /*if(tog == 1 && lowq == 1){
        ObjRender_SetScaleXYZ(bullet, nscale, nscale, 1);
        ObjRender_SetAlpha(bullet, alpha);
        return;
    }*/
    let sp = (bscale-sscale)/t1;
    let alphap = (alpha-salpha)/t1;
    
    alpha = salpha;
    let scale = bscale;
    loop(t1){
        ObjRender_SetScaleXYZ(bullet, scale, scale, 1);
        ObjRender_SetAlpha(bullet, alpha);
        scale -= sp;
        alpha += alphap;
        wait(1);
    }
    sp = (nscale-scale)/t2;
    loop(t2){
        ObjRender_SetScaleXYZ(bullet, scale, scale, 1);
        ObjRender_SetAlpha(bullet, alpha);
        scale += sp;
        wait(1);

    }
    ObjRender_SetScaleXYZ(bullet, nscale, nscale, 1);
    ObjRender_SetAlpha(bullet, alpha);
}

task spawncustom2(bullet, nscale, bscale, salpha, alpha, t1, tog){
    /*if(tog == 1 && lowq == 1){
        ObjRender_SetScaleXYZ(bullet, nscale, nscale, 1);
        ObjRender_SetAlpha(bullet, alpha);
        return;
    }*/
    let sp = (bscale-nscale)/t1;
    let alphap = (alpha-salpha)/t1;
    
    alpha = salpha;
    let scale = bscale;
    loop(t1){
        ObjRender_SetScaleXYZ(bullet, scale, scale, 1);
        ObjRender_SetAlpha(bullet, alpha);
        scale -= sp;
        alpha += alphap;
        wait(1);
    }
    ObjRender_SetScaleXYZ(bullet, nscale, nscale, 1);
    ObjRender_SetAlpha(bullet, alpha);
}


task spawncustomarray(bulletarray, nscale, bscale, sscale, salpha, alpha, t1, t2, tog){
    /*if(tog == 1 && lowq == 1){
        let n = length(bulletarray);
        ascent(i in 0..n){
            ObjRender_SetScaleXYZ(bulletarray[i], nscale, nscale, 1);
            ObjRender_SetAlpha(bulletarray[i], alpha);
        }
        return;
    }*/
    let sp = (bscale-sscale)/t1;
    let alphap = (alpha-salpha)/t1;
    
    alpha = salpha;
    let scale = bscale;
    let n = length(bulletarray);
    loop(t1){
        ascent(i in 0..n){
            if(!Obj_IsDeleted(bulletarray[i])){
                ObjRender_SetScaleXYZ(bulletarray[i], scale, scale, 1);
                ObjRender_SetAlpha(bulletarray[i], alpha);
            }
        }
        scale -= sp;
        alpha += alphap;
        wait(1);
    }
    sp = (nscale-scale)/t2;
    loop(t2){
        ascent(i in 0..n){
            if(!Obj_IsDeleted(bulletarray[i])){
                ObjRender_SetScaleXYZ(bulletarray[i], scale, scale, 1);
                ObjRender_SetAlpha(bulletarray[i], alpha);
            }
        }
        scale += sp;
        wait(1);
    }
    ascent(i in 0..n){
        if(!Obj_IsDeleted(bulletarray[i])){
            ObjRender_SetScaleXYZ(bulletarray[i], nscale, nscale, 1);
            ObjRender_SetAlpha(bulletarray[i], alpha);
        }
    }
}

task spawncustomarray2(bulletarray, nscale, bscale, salpha, alpha, t1, tog){
    let n = length(bulletarray);
    /*if(tog == 1 && lowq == 1){
        ascent(i in 0..n){
            ObjRender_SetScaleXYZ(bulletarray[i], nscale, nscale, 1);
            ObjRender_SetAlpha(bulletarray[i], alpha);
        }
        return;
    }*/
    let sp = (bscale-nscale)/t1;
    let alphap = (alpha-salpha)/t1;
    

    let scale = bscale;
    loop(t1){
        ascent(i in 0..n){
            ObjRender_SetScaleXYZ(bulletarray[i], scale, scale, 1);
            ObjRender_SetAlpha(bulletarray[i], salpha);
        }
        scale -= sp;
        salpha += alphap;
        wait(1);
    }
    ascent(i in 0..n){
        ObjRender_SetScaleXYZ(bulletarray[i], nscale, nscale, 1);
        ObjRender_SetAlpha(bulletarray[i], salpha);
    }
}