#include".\LenenBossRender\RenderLenen.txt"
#include".\LenenShot\JINXShot_Const.txt"
#include".\lenselibrary.txt"
#include".\CutinLoad.txt"
#include".\Cutin\Cutin.txt"



let Name1 = GetCurrentScriptDirectory ~"./img/stage_title_0_0.png";
let Name2 = GetCurrentScriptDirectory ~"./img/stage_title_0_1.png";
let Smokeimg = GetCurrentScriptDirectory ~"./img/smoke_00.png";
let Warnimg = GetCurrentScriptDirectory ~"./img/warning.png";
let WhiteC = GetCurrentScriptDirectory ~"./img/whitecircle.png";
let C1 =  GetCurrentScriptDirectory~"./img/spellcard/card1.png";
let C2 =  GetCurrentScriptDirectory~"./img/spellcard/card2.png";
let C3 =  GetCurrentScriptDirectory~"./img/spellcard/card3.png";
let C4 =  GetCurrentScriptDirectory~"./img/spellcard/card4.png";
let C5 =  GetCurrentScriptDirectory~"./img/spellcard/card5.png";
let C6 =  GetCurrentScriptDirectory~"./img/spellcard/card6.png";
let C7 =  GetCurrentScriptDirectory~"./img/spellcard/card7.png";
let C8 =  GetCurrentScriptDirectory~"./img/spellcard/card8.png";
let Chains =  GetCurrentScriptDirectory~"./img/spellcard/spell_009.png";
let CR1 =  GetCurrentScriptDirectory~"./img/spellcard/circle1.png";
let CR2 =  GetCurrentScriptDirectory~"./img/spellcard/circle2.png";
let CR3 =  GetCurrentScriptDirectory~"./img/spellcard/circle3.png";
let CR4 =  GetCurrentScriptDirectory~"./img/spellcard/circle4.png";
let CR5 =  GetCurrentScriptDirectory~"./img/spellcard/circle5.png";
let CR6 =  GetCurrentScriptDirectory~"./img/spellcard/circle6.png";
let Momi = GetCurrentScriptDirectory ~ "img/boss_eff_momiji_001.png";
let Pixel = GetCurrentScriptDirectory ~ "img/pixel.png";

let CardAr = [C1, C2, C3, C4, C5, C6, C7, C8];
let CircleAr = [CR1, CR2, CR3, CR4, CR5, CR6];

	/*
	LoadTexture(BaseImg);
	LoadTexture(TurretImg);
	LoadTexture(CrystalImg);
	LoadTexture(IMG_SUKUNE_BOMB);
	LoadTexture(IMG_SUKUNE_BOMB2);
	LoadTexture(IMG_SUKUNE_BOMB3);
	LoadTexture(IMG_SUKUNE_BOMB4);
	LoadTexture(GravityImg);
	LoadTexture(IMG_YAO_MOW);
	LoadTexture(Name1);
	LoadTexture(Name2);
	LoadTexture(Smokeimg);
	LoadTexture(Warnimg);
	LoadTexture(WhiteC);*/
	LoadTexture(Chains);
	LoadTexture(C1);
	LoadTexture(C2);
	LoadTexture(C3);
	LoadTexture(C4);
	LoadTexture(C5);
	LoadTexture(C6);
	LoadTexture(C7);
	LoadTexture(C8);
	LoadTexture(CR1);
	LoadTexture(CR2);
	LoadTexture(CR3);
	LoadTexture(CR4);
	LoadTexture(CR5);
	LoadTexture(CR6);
	LoadTexture(Momi);
	LoadTexture(Pixel);

function wait(t)
{
	loop(t){yield;}
}
function Distance(x1, y1, x2, y2)
{
	return ((x1-x2)^2 + (y1-y2)^2)^0.5;
}
task ObjMove_SetDestAtFrameWeight(objEnemy, fin_x, fin_y, flame)
{
	let x = ObjMove_GetX(objEnemy);
	let y = ObjMove_GetY(objEnemy);
	let rx = fin_x - x;
	let ry = fin_y - y;
	let t_rate = 90/flame;
	let s = 0.1;
	ObjMove_SetAngle(objEnemy, getDotAngle(fin_x,fin_y,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy)));
	ascent(time in 1 .. flame+1)
	{
		s-=0.1/(flame-1);
		ObjMove_SetSpeed(objEnemy, s);
		ObjMove_SetX(objEnemy, x + rx * sin(t_rate * time));
		ObjMove_SetY(objEnemy, y + ry * sin(t_rate * time));
		yield;
	}
	ObjMove_SetSpeed(objEnemy, 0);
}
function getDotAngle(x1,y1,x2,y2)
{
	let angle=atan2(y1-y2,x1-x2);
	return angle;
}
task Hitbox(obj,scaleX,scaleY)
{
	while(!Obj_IsDeleted(obj))
	{
		let angleG = ObjMove_GetAngle(obj);
		ObjShot_SetIntersectionLine(obj,ObjMove_GetX(obj)+(scaleX)*cos(angleG),ObjMove_GetY(obj)+(scaleX)*sin(angleG),ObjMove_GetX(obj)-(scaleX)*cos(angleG),ObjMove_GetY(obj)-(scaleX)*sin(angleG),scaleY);
		yield;
	}
}
task HitboxSingle(obj,scaleX,scaleY)
{
	if(!Obj_IsDeleted(obj))
	{
		let angleG = ObjMove_GetAngle(obj);
		ObjShot_SetIntersectionLine(obj,ObjMove_GetX(obj)+(scaleX)*cos(angleG),ObjMove_GetY(obj)+(scaleX)*sin(angleG),ObjMove_GetX(obj)-(scaleX)*cos(angleG),ObjMove_GetY(obj)-(scaleX)*sin(angleG),scaleY);
		yield;
	}
}
task ObjMove_SetAngularVelocityA2(obj,deley,turnamount,stoptime)
{
	loop(deley){yield;}
	ObjMove_SetAngularVelocity(obj,turnamount);
	loop(stoptime){yield;}
	ObjMove_SetAngularVelocity(obj,0);
}
task NameShow(text,R,G,B,delay)
{
	loop(delay){yield;}
	let objBackFrame=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(objBackFrame,50);
	ObjPrim_SetTexture(objBackFrame,Name1);
	ObjSprite2D_SetSourceRect(objBackFrame,0,0,181,25);
	ObjSprite2D_SetDestCenter(objBackFrame);
	ObjRender_SetScaleXYZ(objBackFrame,1,1,1);
	ObjRender_SetAngleZ(objBackFrame,-30);
	ObjRender_SetScaleXYZ(objBackFrame,1.5,1.5,1);
	ObjRender_SetColor(objBackFrame,R,G,B);
	
	let objFrontFrame=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(objFrontFrame,50);
	ObjPrim_SetTexture(objFrontFrame,Name2);
	ObjSprite2D_SetSourceRect(objFrontFrame,0,0,230,30);
	ObjSprite2D_SetDestCenter(objFrontFrame);
	ObjRender_SetScaleXYZ(objFrontFrame,1.5,1.5,1);
	ObjRender_SetColor(objFrontFrame,R,G,B);
	
	let objText = ObjText_Create();
    ObjText_SetText(objText, text);
	Obj_SetRenderPriorityI(objText,50);
	ObjText_SetFontSize(objText, 40);
	ObjText_SetFontType(objText, "Times New Roman");
	ObjText_SetFontBold(objText, false);
    ObjText_SetFontColorTop(objText, 255, 255, 255);
    ObjText_SetFontColorBottom(objText, 255, 255, 255);
    ObjText_SetFontBorderType(objText, BORDER_SHADOW);
    ObjText_SetFontBorderColor(objText, 0, 0, 0);
    ObjText_SetFontBorderWidth(objText, 2);
	ObjRender_SetAlpha(objText,0);
	ObjRender_SetScaleXYZ(objFrontFrame,ObjText_GetTotalWidth(objText)/230+0.75,ObjText_GetTotalHeight(objText)/30+0.25,1);
	
	let Alpha = 0;
	let XX = 0-230*2;
	let Distance = 500;
	loop(30)
	{
		ObjRender_SetPosition(objBackFrame,GetStgFrameWidth/2+Distance*cos(150),GetStgFrameHeight/2+Distance*sin(150),0);
		Distance-=430/30;
		ObjRender_SetPosition(objFrontFrame,XX,GetStgFrameHeight/2,0);
		ObjRender_SetPosition(objText,ObjRender_GetX(objFrontFrame)-(ObjText_GetTotalWidth(objText)/2),ObjRender_GetY(objFrontFrame)-(ObjText_GetTotalHeight(objText)/2),0);
		XX+=(GetStgFrameWidth+70)/30;
		
		yield;
	}
	loop(60)
	{
		ObjRender_SetAlpha(objText,Alpha);
		Alpha+=255/10;
		ObjRender_SetPosition(objBackFrame,GetStgFrameWidth/2+Distance*cos(150),GetStgFrameHeight/2+Distance*sin(150),0);
		Distance-=2;
		ObjRender_SetPosition(objFrontFrame,XX,GetStgFrameHeight/2,0);
		ObjRender_SetPosition(objText,ObjRender_GetX(objFrontFrame)-(ObjText_GetTotalWidth(objText)/2),ObjRender_GetY(objFrontFrame)-(ObjText_GetTotalHeight(objText)/2),0);
		XX+=1;
		yield;
	}
	Alpha =255;
	loop(30)
	{
		ObjRender_SetAlpha(objText,Alpha);
		Alpha-=(255)/10;
		ObjRender_SetPosition(objBackFrame,GetStgFrameWidth/2+Distance*cos(150),GetStgFrameHeight/2+Distance*sin(150),0);
		Distance-=485/30;
		ObjRender_SetPosition(objFrontFrame,XX,GetStgFrameHeight/2,0);
		ObjRender_SetPosition(objText,ObjRender_GetX(objFrontFrame)-(ObjText_GetTotalWidth(objText)/2),ObjRender_GetY(objFrontFrame)-(ObjText_GetTotalHeight(objText)/2),0);
		XX+=(GetStgFrameWidth+30)/30;
		yield;
	}
	Obj_Delete(objBackFrame);
	Obj_Delete(objFrontFrame);
	Obj_Delete(objText);
}
task NameShow2(text,R,G,B,delay,XSpeed,XPos,YPos)
{
	loop(delay){yield;}
	let objBackFrame=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(objBackFrame,50);
	ObjPrim_SetTexture(objBackFrame,Name1);
	ObjSprite2D_SetSourceRect(objBackFrame,0,0,181,25);
	ObjSprite2D_SetDestCenter(objBackFrame);
	ObjRender_SetScaleXYZ(objBackFrame,1,1,1);
	ObjRender_SetAngleZ(objBackFrame,-30);
	ObjRender_SetScaleXYZ(objBackFrame,1.5,1.5,1);
	ObjRender_SetColor(objBackFrame,R,G,B);
	
	let objFrontFrame=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(objFrontFrame,50);
	ObjPrim_SetTexture(objFrontFrame,Name2);
	ObjSprite2D_SetSourceRect(objFrontFrame,0,0,230,30);
	ObjSprite2D_SetDestCenter(objFrontFrame);
	ObjRender_SetScaleXYZ(objFrontFrame,1.5,1.5,1);
	ObjRender_SetColor(objFrontFrame,R,G,B);
	
	let objText = ObjText_Create();
    ObjText_SetText(objText, text);
	Obj_SetRenderPriorityI(objText,50);
	ObjText_SetFontSize(objText, 40);
	ObjText_SetFontType(objText, "Times New Roman");
	ObjText_SetFontBold(objText, false);
    ObjText_SetFontColorTop(objText, 255, 255, 255);
    ObjText_SetFontColorBottom(objText, 255, 255, 255);
    ObjText_SetFontBorderType(objText, BORDER_SHADOW);
    ObjText_SetFontBorderColor(objText, 0, 0, 0);
    ObjText_SetFontBorderWidth(objText, 2);
	ObjRender_SetAlpha(objText,0);
	ObjRender_SetScaleXYZ(objFrontFrame,ObjText_GetTotalWidth(objText)/230+0.75,ObjText_GetTotalHeight(objText)/30+0.25,1);
	
	let Alpha = 0;
	let XX = 0-230*2;
	let Distance = 500;
	loop(30)
	{
		ObjRender_SetPosition(objBackFrame,GetStgFrameWidth/2+Distance*cos(150)+(XPos),GetStgFrameHeight/2+Distance*sin(150)+YPos,0);
		Distance-=430/30;
		ObjRender_SetPosition(objFrontFrame,XX,GetStgFrameHeight/2+YPos,0);
		ObjRender_SetPosition(objText,ObjRender_GetX(objFrontFrame)-(ObjText_GetTotalWidth(objText)/2),ObjRender_GetY(objFrontFrame)-(ObjText_GetTotalHeight(objText)/2),0);
		XX+=(GetStgFrameWidth+70)/30*XSpeed;
		
		yield;
	}
	loop(60)
	{
		ObjRender_SetAlpha(objText,Alpha);
		Alpha+=255/10;
		ObjRender_SetPosition(objBackFrame,GetStgFrameWidth/2+Distance*cos(150)+(XPos),GetStgFrameHeight/2+Distance*sin(150)+YPos,0);
		Distance-=2;
		ObjRender_SetPosition(objFrontFrame,XX,GetStgFrameHeight/2+YPos,0);
		ObjRender_SetPosition(objText,ObjRender_GetX(objFrontFrame)-(ObjText_GetTotalWidth(objText)/2),ObjRender_GetY(objFrontFrame)-(ObjText_GetTotalHeight(objText)/2),0);
		XX+=1;
		yield;
	}
	Alpha =255;
	loop(30)
	{
		ObjRender_SetAlpha(objText,Alpha);
		Alpha-=(255)/10;
		ObjRender_SetPosition(objBackFrame,GetStgFrameWidth/2+Distance*cos(150)+(XPos),GetStgFrameHeight/2+Distance*sin(150)+YPos,0);
		Distance-=485/30;
		ObjRender_SetPosition(objFrontFrame,XX,GetStgFrameHeight/2+YPos,0);
		ObjRender_SetPosition(objText,ObjRender_GetX(objFrontFrame)-(ObjText_GetTotalWidth(objText)/2),ObjRender_GetY(objFrontFrame)-(ObjText_GetTotalHeight(objText)/2),0);
		XX+=(GetStgFrameWidth+30)/30;
		yield;
	}
	Obj_Delete(objBackFrame);
	Obj_Delete(objFrontFrame);
	Obj_Delete(objText);
}
task Smoke(x,y,scalex,scaley,startingalpha,duration)
{
	let spin = rand(1,-1);
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,46);
	ObjPrim_SetTexture(obj,Smokeimg);
	ObjSprite2D_SetSourceRect(obj,0,0,301,246);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,scalex,scaley,1);
	//ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	let angleZ = rand(0,360);
	ObjRender_SetPosition(obj,x,y,0);
	let alpha = startingalpha;
	loop(duration)
	{
		ObjRender_SetAngleXYZ(obj,0,0,angleZ);
		angleZ+=spin;
		ObjRender_SetAlpha(obj,alpha);
		alpha-=startingalpha/duration;
		yield;
	}
	Obj_Delete(obj);
}
task Warning(x,y,duration)
{ 
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,Warnimg);
	ObjSprite2D_SetSourceRect(obj,0,0,50,51);
	ObjSprite2D_SetDestRect(obj,0,0,50,51);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,x,y,0);
	let scale = 4;
	loop(6)
	{
		ObjRender_SetAngleZ(obj,rand(0,360));
		ObjRender_SetScaleXYZ(obj,scale,scale,1);
		scale-=3/5;
		yield;
	}
	loop(duration)
	{
		ObjRender_SetAngleZ(obj,rand(0,360));
		yield;
	}
	Obj_Delete(obj);
}
task Warning2(x,y,duration)
{ 
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,46);
	ObjPrim_SetTexture(obj,Warnimg);
	ObjSprite2D_SetSourceRect(obj,0,0,50,51);
	ObjSprite2D_SetDestRect(obj,0,0,50,51);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,x,y,0);
	let scale = 4;
	loop(6)
	{
		ObjRender_SetAngleZ(obj,rand(0,360));
		ObjRender_SetScaleXYZ(obj,scale,scale,1);
		scale-=3/5;
		yield;
	}
	loop(duration)
	{
		ObjRender_SetAngleZ(obj,rand(0,360));
		yield;
	}
	Obj_Delete(obj);
}
task Flash(AlphaMax)
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,WhiteC);
	Obj_SetRenderPriorityI(obj,45);
	ObjRender_SetAngleZ(obj,0);		
	let ALF=0;
	ObjRender_SetAlpha(obj,ALF);
	let scale =10;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	loop(5)
	{
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAlpha(obj,ALF);
		ALF+=AlphaMax/5;
		yield;
	}
	loop(40)
	{
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAlpha(obj,ALF);
		ALF-=AlphaMax/40;
		yield;
	}
	Obj_Delete(obj);
}
task Flash2(AlphaMax)
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,WhiteC);
	Obj_SetRenderPriorityI(obj,45);
	ObjRender_SetAngleZ(obj,0);		
	let ALF=0;
	ObjRender_SetAlpha(obj,ALF);
	let scale =10;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	loop(5)
	{
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAlpha(obj,ALF);
		ALF+=AlphaMax/5;
	}
	loop(40)
	{
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAlpha(obj,ALF);
		ALF-=AlphaMax/40;
		yield;
	}
	Obj_Delete(obj);
}
task Card(R,G,B)
{
	Circles(1);
	Circles(-1);
	SpellChain(GetStgFrameWidth/2+rand(20,-20)+50,GetStgFrameHeight/2,10,180,1.2,1);
	SpellChain(GetStgFrameWidth/2+rand(20,-20)-200,GetStgFrameHeight/2,-30,0,1,0.25);
	SpellChain(GetStgFrameWidth/2+rand(20,-20)+200,GetStgFrameHeight/2,-50,0,1.1,0);
	SpellChain(GetStgFrameWidth/2+rand(20,-20)-200,GetStgFrameHeight/2+80,-80,90,0.75,0.25);
	SpellChain(0+10,		       GetStgFrameHeight/2,0,90,1.5,0);
	SpellChain(GetStgFrameWidth-10,GetStgFrameHeight/2,0,90,1.5,0);
	SE_PlayLen(BossSpell,80+30);
    let a =ObjPrim_Create(OBJ_SPRITE_2D);
    let b =ObjPrim_Create(OBJ_SPRITE_2D);
    let c =ObjPrim_Create(OBJ_SPRITE_2D);
    let d =ObjPrim_Create(OBJ_SPRITE_2D);
    let e =ObjPrim_Create(OBJ_SPRITE_2D);
    let f =ObjPrim_Create(OBJ_SPRITE_2D);
    let g =ObjPrim_Create(OBJ_SPRITE_2D);
    let h =ObjPrim_Create(OBJ_SPRITE_2D);
    let SplitCard = [a, b, c, d, e, f, g, h];
    ascent(i in 0..length(SplitCard))
    {
        ObjPrim_SetTexture(SplitCard[i], CardAr[i]);
        ObjRender_SetBlendType(SplitCard[i], BLEND_ALPHA);
        Obj_SetRenderPriority(SplitCard[i], 0.28);
        ObjSprite2D_SetSourceRect(SplitCard[i], 0, 0, 190, 500);
        ObjSprite2D_SetDestCenter(SplitCard[i]);
        ObjRender_SetColor(SplitCard[i], R, G, B);
        ObjRender_SetAlpha(SplitCard[i], 0);
        ObjRender_SetScaleXYZ(SplitCard[i], 4, 4, 1);
        ObjRender_SetPosition(SplitCard[i], GetStgFrameWidth/2, GetStgFrameHeight/2, 0);
        ScaleDown(SplitCard[i]);
    }
    wait(30);
    let angle = 45;
    CornerMove(SplitCard[0],0, 180, -1);
    CornerMove(SplitCard[1],90, 90, 1);
    CornerMove(SplitCard[2],180, 90, 1);
    CornerMove(SplitCard[3],270, 180, -1);
    BorderSpin(SplitCard[4]);
    let Scaling = 0;
    ScaleUpABit(SplitCard[5], 1);
    ScaleUpABit(SplitCard[6], 200);
    ScalaleUpdown(SplitCard[5], 1.5);
    Spiiiin(SplitCard[5], 1);
    Spiiiin(SplitCard[6], -1);
    Spiiiin(SplitCard[7], 1);
    wait(60);
    AlphaDownAndDelete(SplitCard[5],100);
    AlphaDownAndDelete(SplitCard[6],100);
    wait(30);
    AlphaDownAndDelete(SplitCard[4],100);
    AlphaDownAndDelete(SplitCard[7],100);
    AlphaDownAndDelete(SplitCard[0],100);
    AlphaDownAndDelete(SplitCard[1],100);
    AlphaDownAndDelete(SplitCard[2],100);
    AlphaDownAndDelete(SplitCard[3],100);
    task AlphaDownAndDelete(obj,mult)
    {
        let alpha = 255;
        loop(mult)
        {
            alpha-=255/mult;
            ObjRender_SetAlpha(obj,alpha);
            yield;
        }
        Obj_Delete(obj);
    }
    task ScalaleUpdown(obj, mult)
    {
        wait(35);
        while(!Obj_IsDeleted(obj))
        {
            Scaling+=0.002*mult;
            ObjRender_SetScaleXYZ(obj, 1+Scaling, 1+Scaling, 1);
            yield;
        }
    }
    task Spiiiin(obj, mult)
    {
        wait(30);
        while(!Obj_IsDeleted(obj))
        {
            let angle = ObjRender_GetAngleZ(obj);
            ObjRender_SetAngleZ(obj, angle+(6*mult));
            yield;
        }
    }
    task ScaleUpABit(obj, mult)
    {
        loop(5)
        {
            Scaling+=0.0005*(mult*0.7);
            ObjRender_SetScaleXYZ(obj, 1+Scaling, 1+Scaling, 1);
            yield;
        }
    }
    task BorderSpin(obj)
    {
        let scale = 0;
        while(!Obj_IsDeleted(obj))
        {
            let angle = ObjRender_GetAngleZ(obj);
            ObjRender_SetAngleZ(obj, angle+6);
            scale+=0.002;
            ObjRender_SetScaleXYZ(obj, 0.7+scale, 0.7+scale, 1);
            yield;
        }
    }
    task ScaleDown(obj)
    {
        let alpha = 0;
        let scale = 0;
        loop(15)
        {
            alpha+=4.1*4;
            ObjRender_SetAlpha(obj,alpha);
            scale+=0.055*4;
            ObjRender_SetScaleXYZ(obj, 4-scale, 4-scale, 1);
            yield;
        }
    }
    task CornerMove(obj, i,mult, multi)
    {
        let radius = 0;
        let X = GetStgFrameWidth/2;
        let Y = GetStgFrameHeight/2;
        loop(10)
        {
            ObjRender_SetPosition(obj, X+radius*cos(angle+(i*360/4)+mult), Y+radius*sin(angle+(i*360/4)+mult), 0);
            radius+=6;
            yield;
        }
        wait(40);
        loop(160)
        {
            ObjRender_SetPosition(obj, X+radius*cos(angle+(i*360/4)+mult), Y+radius*sin(angle+(i*360/4)+mult), 0);
            ObjRender_SetAngleZ(obj, ObjRender_GetAngleZ(obj)+(1*multi));
            radius-=0.5;
            yield;
        }
    }
	task Circles(AngleY)
	{
		let count = 270;
		let ArCount = 0;
		let countwait = 0;
		let moveamount = 3;
		let XPlus = 30;
		ascent(i in 0..220)
		{
			
			let objC = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(objC,CircleAr[ArCount]);
			Obj_SetRenderPriority(objC,0.28);
			ObjRender_SetAngleZ(objC,0);		
			let ALF=0;
			ObjRender_SetAlpha(objC,ALF);
			let scale =1;
			ObjRender_SetScaleXYZ(objC,scale,scale,scale);
			ObjSprite2D_SetSourceRect(objC,0,0,80,391);
			ObjSprite2D_SetDestRect(objC,0,0,80,391);
			ObjSprite2D_SetDestCenter(objC);
			ObjRender_SetAngleY(objC,90+90*AngleY);
			
			ObjRender_SetPosition(objC,GetStgFrameWidth/2+XPlus*AngleY,GetStgFrameHeight/2,0);
			ObjRender_SetAlpha(objC,128+(128)*cos(count));
			XPlus+=moveamount;
			if(moveamount>-2)
			{
				moveamount-=6/220;
			}
			count+=260/220;

			if(countwait>4)
			{
				ArCount++;
				countwait = 0;
			}
			countwait++;
			if(ArCount>5){ArCount = 0;}
			yield;
			Obj_Delete(objC);
		}
	}
	task SpellChain(X,Y,angle,moveangle,scale,moveamount)
	{
		let objC = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objC,Chains);
		Obj_SetRenderPriority(objC,0.27);
		ObjRender_SetAngleZ(objC,angle);		
		let ALF=0;
		ObjRender_SetAlpha(objC,ALF);
		
		ObjRender_SetScaleXYZ(objC,scale,scale,scale);
		ObjSprite2D_SetSourceRect(objC,0,0,20,2200);
		ObjSprite2D_SetDestRect(objC,0,0,20,2200);
		ObjSprite2D_SetDestCenter(objC);
		let c = 0;
		ObjRender_SetPosition(objC,X,Y,0);
		loop(30)
		{
			ObjRender_SetAlpha(objC,ALF);
			ObjRender_SetPosition(objC,ObjRender_GetX(objC)+moveamount*cos(moveangle),ObjRender_GetY(objC)+moveamount*sin(moveangle),0);
			ObjSprite2D_SetSourceRect(objC,0,c,20,2200+c);
			c+=5;
			ALF+=255/30;
			yield;
		}
		loop(150)
		{
			ObjRender_SetPosition(objC,ObjRender_GetX(objC)+moveamount*cos(moveangle),ObjRender_GetY(objC)+moveamount*sin(moveangle),0);
			ObjSprite2D_SetSourceRect(objC,0,c,20,2200+c);
			c+=5;
			yield;
		}
		loop(30)
		{
			ObjRender_SetAlpha(objC,ALF);
			ObjRender_SetPosition(objC,ObjRender_GetX(objC)+moveamount*cos(moveangle),ObjRender_GetY(objC)+moveamount*sin(moveangle),0);
			ObjSprite2D_SetSourceRect(objC,0,c,20,2200+c);
			c+=5;
			ALF-=255/30;
			yield;
		}
		Obj_Delete(objC);
	}
}
task ExplodeObject01(type,x,y,speed,dir) 
{
	let objStar = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 130;
	let spinA = rand(0,180);
	let spinB = rand(0,180);
	// let RED = rand(100,255);
	// let GREEN = rand(100,255);
	// let BLUE = rand(100,255);
	let scale = 0;
	
	ObjRender_SetBlendType(objStar, BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(objStar,41);
	ObjPrim_SetTexture(objStar, Momi);
	ObjSprite2D_SetSourceRect(objStar, 42*type, 0, 42*(type+1), 49);
	ObjSprite2D_SetDestCenter(objStar);
	
	while(!Obj_IsDeleted(objStar)) {
		ObjRender_SetPosition(objStar, x, y, 0);
		ObjRender_SetScaleXYZ(objStar, scale*2, scale*2, scale*2);
		ObjRender_SetAngleXYZ(objStar, spinA, spinB, spinA);
		ObjRender_SetAlpha(objStar, alpha);
		if(scale<1 && speed>0) { scale+=0.3; }
		if(speed>1.0) { speed-=0.094; }
		if(speed<=1.0 && alpha>0) { alpha-=16; scale-=0.08; }
		if(alpha<=0) { Obj_Delete(objStar); }
		spinA+=rand(1,2);
		spinB+=rand(-1,-2);
		x+=speed*cos(dir);
		y+=speed*sin(dir);
		yield;
	}
}
task ConcObject01(type,x,y,speed,dir,r) {
	let objStar = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 0;
	let spin = rand(0,180);
	let opacity = 130;
	let rot = 1;
	// let RED = rand(100,255);
	// let GREEN = rand(100,255);
	// let BLUE = rand(100,255);
	let scale = 1*(r/200);
	
	if(r > 200) { scale = 1.00; }
	

	Obj_SetRenderPriorityI(objStar,41);
	ObjPrim_SetTexture(objStar, Momi);
	if(type<5)
	{
		ObjRender_SetBlendType(objStar, BLEND_ADD_ARGB);
		ObjSprite2D_SetSourceRect(objStar, 42*type, 0, 42*(type+1), 49);
	}
	else if(type == 5)
	{
		ObjRender_SetColor(objStar,0,0,0);
		ObjSprite2D_SetSourceRect(objStar, 42*0, 0, 42*(0+1), 49);
	}
	ObjSprite2D_SetDestCenter(objStar);
	
	while(!Obj_IsDeleted(objStar)) {
		ObjRender_SetPosition(objStar, x+r*cos(dir), y+r*sin(dir), 0);
		ObjRender_SetScaleXYZ(objStar, scale*2, scale*2, scale*2);
		ObjRender_SetAngleXYZ(objStar, 0, 0, spin);
		ObjRender_SetAlpha(objStar, alpha);
		if(alpha<opacity && r>=10) { alpha+=opacity/90*speed; }
		if(r<200) { scale-=1/200*speed; }
		if(r<10) { alpha-=opacity/10*speed; }
		if(alpha<=0) { Obj_Delete(objStar); }
		spin+=rand(1,2)*rot;
		r-=speed;
		yield;
	}
}
task ScreenShake(duration,range) 
{
let shake = range;
	loop(duration) {
		Set2DCameraFocusX(Get2DCameraX + rand(-shake, shake));
		Set2DCameraFocusY(Get2DCameraY + rand(-shake, shake));
		shake-=range/duration;
		yield;
		Reset2DCamera;
	}
}
task magiccircle(boss,type)
{ // draw magic circle
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./img/touhoucircle.png";
	let spin = 0;
	let s = 0;
	let size = 0;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetAlpha(obj,130);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(obj,25);
	while(!Obj_IsDeleted(boss) && !Obj_IsDeleted(obj))
	{
		spin += 1/3;
		size = GetCommonData("CircleSize",1);
		ObjRender_SetAngleXYZ(obj,30*sin(spin*1.5)*type,30*cos(spin*1.5-30*sin(spin*3))*type,spin*3*type);
		ObjRender_SetPosition(obj,ObjMove_GetX(boss),ObjMove_GetY(boss),0);
		ObjRender_SetScaleXYZ(obj,size,size,0);
		ObjMove_SetPosition(obj,ObjMove_GetX(boss), ObjMove_GetY(boss));
		yield;
	}
	Obj_Delete(obj);
}

