#include "././default_system/LoLKshot_Const.txt"
#include "././default_system/Glow_Const.txt"
#include "././default_system/ZUNShot_Const.txt"
#include "./healthbar.dnh"
#include "./se.txt"
#include "./Cutin.txt"



let move = 0;
let i = 0;
let i2 = 0;
let c = 0;
let c2 = 0;

task TFinalize {
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){ 
    	yield; 
    } 
    if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) + ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0) {
    	AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
    	
    }
    move = 0;
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    wait(1);
    Obj_Delete(objBoss); 
    CloseScript(GetOwnScriptID()); 
    return;
}

task LSFinalize{
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){ 
    	yield; 
    } 
    if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) + ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0) {
    	AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
    	
    }
    move = 0;
    StartSlow(GetPlayerID(), 20);
    SE_Play(bossclear,60);
    endrelease;
    Obj_Delete(objBoss);
    wait(50);
    StopSlow(GetPlayerID());
    DeleteShotAll(TYPE_ALL,TYPE_FADE); 
    wait(60);
    CloseScript(GetOwnScriptID()); 
    return;

}
task TDrawLoop {
	//BGM_Play(bgm1,0, 0);
	DeleteShotAll(TYPE_ALL,TYPE_ALL); 
	let imgJunko = GetCurrentScriptDirectory~"./img/Junko.png"; //variable imgExRumia is the location of the image
	ObjPrim_SetTexture(objBoss, imgJunko); //sets the bosses appearance to the image
	ObjSprite2D_SetSourceRect(objBoss, 0, 5, 95, 120); //picks which part of the image the boss uses
	ObjSprite2D_SetDestCenter(objBoss); //sets the image to center of the boss
	MagicCircle;
	AuraGraphics;
	BossLife;
	SpellDamage;
	EnemyMarker;
	damagesfx;
	bossanimation;
	timersound;
}

task bossanimation{
	let l = 0;
	let n = 0;
	while(!Obj_IsDeleted(objBoss)){
		let l = 0;

		while(move == 0 || move == 4){
			let l2 = l + 95;
			ObjSprite2D_SetSourceRect(objBoss, l, 8, l2, 120);
			if(move == 4){ObjSprite2D_SetSourceRect(objBoss, l2, 8, l, 120)};
			loop(2){
				if(move == 0 || move == 4){wait(1);}
			}
			l = l2 + 1;
			if(l > 384-95 && n == 6){n = 0;}
			else if(l > 384-95){l = 0; n +=1;
				loop(4){
					if(move == 0 || move == 4){wait(1);} 
				} 
			}
			else{
				loop(4){
					if(move == 0 || move == 4){wait(1);} 
				}
			}
		}
		l = 0;
		while(move == 1 || move == 2){
			let l2 = l + 95;
			ObjSprite2D_SetSourceRect(objBoss, l, 136, l2, 248);
			if(move == 2){ObjSprite2D_SetSourceRect(objBoss, l2, 136, l, 248)};
			loop(8){
				if(move == 1 || move == 2){wait(1);} 
			} 
			l = l2 + 1;
			if(l > 288){l = 96;}
		}
		l = 0;
		while(move == 5 || move == 6){
			let l2 = l + 95;
			ObjSprite2D_SetSourceRect(objBoss, l, 265, l2, 376);
			if(move == 6){ObjSprite2D_SetSourceRect(objBoss, l2, 265, l, 376)};
			loop(8){
				if(move == 5 || move == 6){wait(1);} 
			}
			l = l2 + 1;
			if(l > 479){l = 96;}
		}
		while(idle == 1){wait(1);}
	}
}

let dsfx = 6;

task damagesfx{
	let life = ObjEnemy_GetInfo(objBoss, INFO_LIFE);
	let llife = ObjEnemy_GetInfo(objBoss, INFO_LIFE)/dsfx;
	let v = 55;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0 && objScene != ID_INVALID){
		let clife = ObjEnemy_GetInfo(objBoss, INFO_LIFE);
		if(clife < life){
			SE_Play(shotdamage1, v);
		}
		if(clife < life && clife < llife){
			SE_Play(shotdamage2, v+5);
		}
		life = ObjEnemy_GetInfo(objBoss, INFO_LIFE);
		wait(5);
	}
}

task changedsfx{
	dsfx = 14;
}

task timersound{
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0 && objScene != ID_INVALID){
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) < 10.1){
			SE_Play(timeout1, 100);
			if(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) < 6){SE_Play(timeout2,50);}
			wait(59);
		}
		wait(1);
	}
}

function spellcutin(name){
	let cutin = GetCurrentScriptDirectory~"img/cutin.png";
	ObjCutin_SetSpellcardS4(name, cutin, KANAKO, 255, 0, 0);
	ObjCutin_LaunchS3(KANAKO, cutin, "Normal");
	ObjEnemyBossScene_StartSpell(objScene); 
	SE_Play(spelldeclare, 80);
	wait(170);
}

task enddelete(obj){
	//while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0 && !Obj_IsDeleted(obj)){wait(3);}
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 0 || objScene == ID_INVALID){
		Obj_Delete(obj);
	}
}

task chargeeffect{
	chargeorb;
	SE_Play(charge2,80);
	wait(55);
	SE_Play(chargefinish,60);
	chargerelease;
}

task chargeeffect2{
	chargeorb;
	SE_Play(charge2,80);
}

task chargeorb{
	let path = GetCurrentScriptDirectory~"./img/ExCircle.png";
	let charge = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(charge, BLEND_ADD_ARGB);
	ObjPrim_SetTexture(charge, path);
	ObjSprite2D_SetSourceRect(charge, 0, 0, 257, 257);
	ObjSprite2D_SetDestCenter(charge);
	Obj_SetRenderPriorityI(charge,24);
	let n = 50;
	let alpha = 200;
	let endalpha = 125;
	let scale = 1.6;
	let am = (alpha-endalpha)/n;
	let sm = scale/n;
	enddelete(charge);
	chargeparticle;
	loop(n){
		ObjRender_SetAlpha(charge,alpha);
		ObjRender_SetScaleXYZ(charge, scale, scale, 1);
		ObjRender_SetPosition(charge, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss),1);
		alpha -= am;
		scale -= sm;
		wait(1);
	}
	Obj_Delete(charge);
}

task chargeparticle{
	let scale = 3.5;
	let angle = rand(0,360);
	let cosin = 150;
	let n = 3;
	let n2 = 7;
	loop(n2){
		loop(n){
			let path = GetCurrentScriptDirectory~"./img/maple.png";
			let leaf = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjRender_SetBlendType(leaf, BLEND_ADD_ARGB);
			ObjPrim_SetTexture(leaf, path);
			ObjSprite2D_SetSourceRect(leaf, 32, 0, 64, 32);
			ObjSprite2D_SetDestCenter(leaf);
			Obj_SetRenderPriorityI(leaf,24);
			ObjRender_SetAlpha(leaf, 125);
			ObjRender_SetScaleXYZ(leaf, scale, scale, 1);
			enddelete(leaf);
			let angle2 = rand(0,360);
			ObjRender_SetAngleXYZ(leaf, angle2,angle2,angle2);
			ObjRender_SetPosition(leaf, ObjMove_GetX(objBoss) + cosin * cos(angle), ObjMove_GetY(objBoss) + cosin * sin(angle),1);
			moveparticle(leaf,cosin,angle,angle2);
			angle += 360/n;
		}
		angle = rand(0,360);
		wait(4);
	}
}

task moveparticle(leaf,cosin,angle,angle2){
	let n = 30;
	let cosinm = cosin/n;
	let sm = 4;
	loop(n){
		ObjRender_SetPosition(leaf, ObjMove_GetX(objBoss) + cosin * cos(angle), ObjMove_GetY(objBoss) + cosin * sin(angle),1);
		ObjRender_SetAngleXYZ(leaf, angle2,angle2,angle2);
		angle2 += sm;
		cosin -= cosinm;
		wait(1)
	}
	Obj_Delete(leaf);
}

task chargerelease{
	let path = GetCurrentScriptDirectory~"./img/ExCircle.png";
	let charge = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(charge, BLEND_ADD_ARGB);
	ObjPrim_SetTexture(charge, path);
	ObjSprite2D_SetSourceRect(charge, 0, 0, 257, 257);
	ObjSprite2D_SetDestCenter(charge);
	Obj_SetRenderPriorityI(charge,24);
	let n = 40;
	let alpha = 200;
	let endalpha = 125;
	let scale = 0;
	let mscale = 3.5;
	let am = (alpha-endalpha)/n;
	let sm = mscale/n;
	releaseparticles;
	enddelete(charge);
	loop(n){
		ObjRender_SetAlpha(charge,alpha);
		ObjRender_SetScaleXYZ(charge, scale, scale, 1);
		ObjRender_SetPosition(charge, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss),1);
		alpha -= am;
		scale += sm;
		wait(1);
	}
	Obj_Delete(charge);
}

task releaseparticles{
	let scale = 3.5;
	let angle = rand(0,360);
	let cosin = 0;
	let n = 8;
	let n2 = 3;
	let alpha = 150;
	loop(n2){
		loop(n){
			let path = GetCurrentScriptDirectory~"./img/maple.png";
			let leaf = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjRender_SetBlendType(leaf, BLEND_ADD_ARGB);
			ObjPrim_SetTexture(leaf, path);
			ObjSprite2D_SetSourceRect(leaf, 32, 0, 64, 32);
			ObjSprite2D_SetDestCenter(leaf);
			Obj_SetRenderPriorityI(leaf,24);
			ObjRender_SetAlpha(leaf, alpha);
			ObjRender_SetScaleXYZ(leaf, scale, scale, 1);
			enddelete(leaf);
			let angle2 = rand(0,360);
			ObjRender_SetAngleXYZ(leaf, angle2,angle2,angle2);
			ObjRender_SetPosition(leaf, ObjMove_GetX(objBoss) + cosin * cos(angle), ObjMove_GetY(objBoss) + cosin * sin(angle),1);
			moveparticle2(leaf,cosin,angle,alpha);
			angle += 360/n;
		}
		angle = rand(0,360);
		wait(7);
	}
}

task moveparticle2(leaf,cosin,angle,alpha){
	let n = 40;
	let cosinmax = 350;
	let cosinm = cosinmax/n;
	let sm = 6;
	let angle2 = rand(0,360);
	loop(n){
		ObjRender_SetPosition(leaf, ObjMove_GetX(objBoss) + cosin * cos(angle), ObjMove_GetY(objBoss) + cosin * sin(angle),1);
		ObjRender_SetAngleXYZ(leaf, angle2,angle2,angle2);
		ObjRender_SetAlpha(leaf, alpha);
		alpha += -3;
		angle2 += sm;
		cosin += cosinm;
		wait(1)
	}
	Obj_Delete(leaf);
}


task EnemyMarker{
	let marker = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriority(marker, 0.1);
	ObjPrim_SetTexture(marker,GetCurrentScriptDirectory() ~ "default_system/img/font1.png");	
	ObjSprite2D_SetSourceRect(marker, 932, 992, 1020, 1024);
	ObjRender_SetAlpha(marker, 255);
	ObjSprite2D_SetDestCenter(marker);
	ObjRender_SetScaleX(marker, 1.4);
	ObjRender_SetScaleY(marker, 0.5);
	//markeralpha(marker);
	while(!Obj_IsDeleted(marker)){
		ObjRender_SetPosition(marker, ObjMove_GetX(objBoss)+32, 472, 1);
		wait(2);
	}
}

task markeralpha(marker){
	let alpha = 255;
	let blink = 1.2;
	let c = 0;
	while(!Obj_IsDeleted(marker)){
		if(c == 0){blink = 1; c+=1;}
		else if(c == 1){blink = 1.04; c = 0;}
		alpha = GetDistance(GetPlayerX(),0,ObjMove_GetX(objBoss),0)*4;
		if(alpha < 255){alpha = 255;}
		if(alpha > 255){alpha = 255;}
		ObjRender_SetAlpha(marker, alpha/blink);
		wait(5);
	}
}

task SpellDamage{
	ObjEnemy_SetDamageRate(objBoss,0,0);
}

task junkoattack{
	if(move == 0 || move == 1){
		move = 5;
	}
	if(move == 2 || move == 4){
		move = 6;
	}
}

let idle = 0;

task junkoidle(t){
	wait(t);
	idle = 1;
	if(move == 5){
		move = 7;
		ObjSprite2D_SetSourceRect(objBoss, 0, 265, 95, 376);
		wait(20);
		move = 0;
	}
	if(move == 1){
		move = 0;
	}
	if(move == 2){
		move = 4;
	}
	if(move == 6){
		move = 7;
		ObjSprite2D_SetSourceRect(objBoss, 95, 265, 0, 376);
		wait(20);
		move = 4;
	}
	idle = 0;
}

task bmovementgraphic(i,f){
	if(i == -1){move = 2}
	else{move = 1;}
	wait(f);
	if(i == -1){move = 4;}
	else{move = 0;}
}

task bmovement(x1, x2, y1, y2, f){
	let x = round(rand(x1,x2));
	let y = round(rand(y1,y2));
	i = round(rand(-1,0));
	i2 = round(rand(-1,0));
	if(i == 0){i = 1;}
	if(c == 2){i = -1;}
	if(c == -2){i = 1;}
	if(i2 == 0){i2 = 1;}
	if(c2 == 1){i2 = -1;}
	if(c2 == -1){i2 = 1;}
	if(ObjMove_GetX(objBoss) + i*x > 294 || ObjMove_GetX(objBoss) + i*x < 90){
		i = i * -1;
	}
	if(ObjMove_GetY(objBoss) + i2*y > 408 || ObjMove_GetY(objBoss) + i2*y < 40){
		i2 = i2 * -1;
	}
	bmovementgraphic(i,f);
	wait(2);
	ObjMove_SetDestAtFrame(objBoss, ObjMove_GetX(objBoss) + i*x, ObjMove_GetY(objBoss) + i2*y, f);
	c += i;
	c2 += i2;
	
}

function GetCenterX(){
     return GetStgFrameWidth() / 2;
}
function GetCenterY(){
     return GetStgFrameHeight() / 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 GetDistance(x1,y1,x2,y2)
{
	return ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5
}

task debugtext(text){
	 let objText = ObjText_Create();
    ObjText_SetText(objText, text);
    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(10);
    Obj_Delete(objText);
}



task MagicCircle{
	//if(ObjEnemyBossScene_GetInfo(objScene, INFO_IS_SPELL)){
		let path = GetCurrentScriptDirectory~"./img/mcircle.png";
		let mc = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(mc, path);
		ObjSprite2D_SetSourceRect(mc, 0, 0, 256, 256);
		ObjSprite2D_SetDestCenter(mc);
		ObjRender_SetAlpha(mc,155);
		Obj_SetRenderPriorityI(mc,24);
		ObjRender_SetScaleXYZ(mc, 0.95, 0.95, 1);
		let n = 0;
		let n2 = 500;
		let s = 0;
		let sc = 0.00045;
		auradelete(mc);
		while(objScene != ID_INVALID && !Obj_IsDeleted(mc)){
			ObjRender_SetPosition(mc, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss)+10, 1);
			ObjRender_SetAngleZ(mc, ObjRender_GetAngleZ(mc)+0.7);
			if(n != n2 && s == 0){
				ObjRender_SetScaleX(mc, ObjRender_GetScaleX(mc)+sc);
				ObjRender_SetScaleY(mc, ObjRender_GetScaleY(mc)-sc);
				n += 1;
				if(n == n2){s = 1; n = 0;}
			}
			if(n != n2 && s == 1){
				ObjRender_SetScaleX(mc, ObjRender_GetScaleX(mc)-sc);
				ObjRender_SetScaleY(mc, ObjRender_GetScaleY(mc)+sc);
				n += 1;
				if(n == n2){s = 0; n = 0;}
			}

			wait(1);
		}
	//}
}

task AuraGraphics{
	let a1 = 35;
	let a2 = 80;
	let x1 = 40;
	let y1 = 30;
	let x2 = 60;
	let y2 =  0;

    let n = 30;
	let c1 = 255 + n;
	let c2 = 80 + n;
	let c3 = 200 + n;
	let c4 = 120 + n;
	let c5 = 30;

    let d1 = 0;
    let d2 = 10;
    let d3 = 20;
	Aura(0,0,45, c1, c2, c1, d1);
	Aura(a1*-1, x1, y1, c3, c2, c1, d2);
	Aura(a1, x1*-1, y1, c1, c2, c3, d2);
	Aura(a2*-1, x2, y2, c4, c2, c1, d3);
	Aura(a2, x2 *-1, y2, c1, c2, c4, d3);
}

let aurashow = 0;

task toggleaura(n){
	aurashow = n;
}

task Aura(angle,x,y, r, g, b, t){
	
		let path = GetCurrentScriptDirectory~"./img/junkoaura.png";
		let aura = ObjPrim_Create(OBJ_SPRITE_2D);
		let aura2 = ObjPrim_Create(OBJ_SPRITE_2D);
		auradetails(aura, path, angle, x, y, r, g, b, t);
		auradetails(aura2, path, angle, x, y, r, g, b, t);
		Obj_SetVisible(aura, false);
		Obj_SetVisible(aura2, false);
		let n = 0;
		let am = 6;
		let n2 = 20;
		let alpha = 200;
		let an = alpha;
		let scale = 1;
		auradelete(aura);
		auradelete(aura2);
		hideaura(aura,aura2);
		wait(t);
		while(objScene != ID_INVALID && !Obj_IsDeleted(aura) && !Obj_IsDeleted(aura2)){
			
			alpha += am;
			if(alpha > an){
				alpha = an;
				ObjRender_SetAlpha(aura, alpha); 
				ObjRender_SetAlpha(aura2, alpha); 
				wait(30); 
				let ln = 10;
				loop(ln){
					if(aurashow == 1){
						scale += 5;
						alpha += -(n2*am)/ln;
						ObjSprite2D_SetDestRect(aura2, -42, -64-scale, 42, 64);
						ObjRender_SetAlpha(aura, alpha);
						ObjRender_SetAlpha(aura2, alpha/1.2);
					}
					wait(1);
				}
				if(aurashow == 1){ObjSprite2D_SetDestRect(aura, -42, -64, 42, 64);}
				if(aurashow == 1){ObjSprite2D_SetDestRect(aura2, -42, -64, 42, 64);}
				alpha = an -n2*am;
			}
			ObjRender_SetAlpha(aura, alpha);
			ObjRender_SetAlpha(aura2, alpha);
			if(alpha == an -n2*am){wait(50);}
			scale = 1;
			
			wait(1);
		}
}

task auradetails(aura, path, angle,x,y, r, g, b, t){
	ObjRender_SetBlendType(aura, BLEND_ADD_ARGB);
	ObjPrim_SetTexture(aura, path);
	ObjSprite2D_SetSourceRect(aura, 0, 1, 84, 128);
	ObjSprite2D_SetDestCenter(aura);
	if(angle == 80 || angle == -80){Obj_SetRenderPriorityI(aura,25);}
	else if(angle == 35 || angle == -35){Obj_SetRenderPriorityI(aura,26);}
	else if(angle == 0){Obj_SetRenderPriorityI(aura,24);}
	ObjRender_SetColor(aura, r, g, b);
	auraposition(aura,x,y);
	ObjRender_SetAngleZ(aura, angle);
}

task hideaura(aura,aura2){
	let ln2 = 15;
	let scale2 = 1;
	while(objScene != ID_INVALID && !Obj_IsDeleted(aura) && !Obj_IsDeleted(aura2)){
		if(aurashow == 0){
			if(scale2 != 0){loop(ln2){
				scale2 += 86/ln2;
				ObjSprite2D_SetDestRect(aura, -42, -64+scale2, 42, 64);
				ObjSprite2D_SetDestRect(aura2, -42, -64+scale2, 42, 64);
				wait(1);
			}}
			Obj_SetVisible(aura, false);
			Obj_SetVisible(aura2, false);
			scale2 = 0;
		}
		else if(aurashow == 1){
			Obj_SetVisible(aura, true);
			Obj_SetVisible(aura2, true);
			if(scale2 != 1){
				scale2 = 1;
				loop(ln2){
					scale2 += 86/ln2;
					ObjSprite2D_SetDestRect(aura, -42, 0-scale2, 42, 64);
					ObjSprite2D_SetDestRect(aura2, -42, 0-scale2, 42, 64);
					wait(1);
				}
				if(aurashow == 1){ObjSprite2D_SetDestRect(aura, -42, -64, 42, 64);}
				if(aurashow == 1){ObjSprite2D_SetDestRect(aura2, -42, -64, 42, 64);}
			}
			scale2 = 1;
		}
		wait(1);
	}
}

task auradelete(aura){
	while(!Obj_IsDeleted(objBoss) && !Obj_IsDeleted(aura)){yield;}
	Obj_Delete(aura);
}

task auraposition(aura,x,y){
	while(objScene != ID_INVALID && !Obj_IsDeleted(aura)){
		ObjRender_SetPosition(aura, ObjMove_GetX(objBoss)-x, ObjMove_GetY(objBoss)-y, 1);
		wait(1);
	}
}

task endrelease{
	let path = GetCurrentScriptDirectory~"./img/ExCircle.png";
	let charge = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(charge, BLEND_ADD_ARGB);
	ObjPrim_SetTexture(charge, path);
	ObjSprite2D_SetSourceRect(charge, 0, 0, 257, 257);
	ObjSprite2D_SetDestCenter(charge);
	Obj_SetRenderPriorityI(charge,24);
	let n = 40;
	let alpha = 200;
	let endalpha = 125;
	let scale = 0;
	let mscale = 3.5;
	let am = (alpha-endalpha)/n;
	let sm = mscale/n;
	let x = ObjMove_GetX(objBoss);
	let y = ObjMove_GetY(objBoss);
	endparticles;
	loop(n){
		ObjRender_SetAlpha(charge,alpha);
		ObjRender_SetScaleXYZ(charge, scale, scale, 1);
		ObjRender_SetPosition(charge, x, y,1);
		alpha -= am;
		scale += sm;
		wait(1);
	}
	Obj_Delete(charge);
}

task endparticles{
	let scale = 3.5;
	let angle = rand(0,360);
	let cosin = 0;
	let n = 8;
	let n2 = 3;
	let alpha = 150;
	let x = ObjMove_GetX(objBoss);
	let y = ObjMove_GetY(objBoss);
	loop(n2){
		loop(n){
			let path = GetCurrentScriptDirectory~"./img/maple.png";
			let leaf = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjRender_SetBlendType(leaf, BLEND_ADD_ARGB);
			ObjPrim_SetTexture(leaf, path);
			ObjSprite2D_SetSourceRect(leaf, 32, 0, 64, 32);
			ObjSprite2D_SetDestCenter(leaf);
			Obj_SetRenderPriorityI(leaf,24);
			ObjRender_SetAlpha(leaf, alpha);
			ObjRender_SetScaleXYZ(leaf, scale, scale, 1);
			let angle2 = rand(0,360);
			ObjRender_SetAngleXYZ(leaf, angle2,angle2,angle2);
			ObjRender_SetPosition(leaf, x + cosin * cos(angle), y + cosin * sin(angle),1);
			endmoveparticle(leaf,cosin,angle,alpha, x, y);
			angle += 360/n;
		}
		angle = rand(0,360);
		wait(7);
	}
}

task endmoveparticle(leaf,cosin,angle,alpha, x, y){
	let n = 40;
	let cosinmax = 350;
	let cosinm = cosinmax/n;
	let sm = 6;
	let angle2 = rand(0,360);
	loop(n){
		ObjRender_SetPosition(leaf, x + cosin * cos(angle), y + cosin * sin(angle),1);
		ObjRender_SetAngleXYZ(leaf, angle2,angle2,angle2);
		ObjRender_SetAlpha(leaf, alpha);
		alpha += -3;
		angle2 += sm;
		cosin += cosinm;
		wait(1)
	}
	Obj_Delete(leaf);
}