
let MainSTG = GetMainStgScriptDirectory;

let img_effect = MainSTG~"ds_system/img/effect.png"; // Effect Sheet
let img_effect2 = MainSTG~"ds_system/img/effect2.png"; // Effect 2 Sheet
let img_effect3 = MainSTG~"ds_system/img/effect3.png"; // Effect 3 Sheet
let img_break = MainSTG~"ds_system/img/efbreak.png"; // Bullet Break Sheet
let img_fairy = MainSTG~"ds_system/img/enemy.png"; // Fairy Sheet
let img_SpellAttack = MainSTG~"ds_system/img/effect3/effect37.png"; // Spell Declare
let img_lifebar = MainSTG~"ds_system/img/lifebar.png"; // Lifebar

let DIFFICULTY_EASY = 12;
let DIFFICULTY_NORMAL = 36;
let DIFFICULTY_HARD = 48;
let DIFFICULTY_LUNATIC = 72;
let DIFFICULTY_OVERDRIVE = 96;

let GetCenterX = GetStgFrameWidth/2;
let GetCenterY = GetStgFrameHeight/2;
let LastTimeStop = 0;
let IsTimeStopped = false;
let bosstime = 99;
let TimeSpeed = 1;

let Anim_Attack = 0;
let IsAttackAnimPlaying = false;
let Enemy_Move = 0;

let EnemyX = GetCommonData("StarX1", 0);
let EnemyY = GetCommonData("StarY1", 0);

let EnemyDead = false;
let quality = GetCommonData("quality", 2);

let TotalEffectMax = 24*quality;
let TotalEffect = 0;

function CreateBossObject(SBIimage, rec1, rec2, rec3, rec4){
	let CBOboss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(CBOboss);
	ObjPrim_SetTexture(CBOboss, SBIimage); 
	ObjSprite2D_SetSourceRect(CBOboss, rec1, rec2, rec3, rec4); 
	return CBOboss;
}

function CreateEnemyObject(CEOlife, SBIimage, rec1, rec2, rec3, rec4){
	let CEOboss = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(CEOboss);
	ObjPrim_SetTexture(CEOboss, SBIimage); 
	ObjSprite2D_SetSourceRect(CEOboss, rec1, rec2, rec3, rec4); 
	ObjSprite2D_SetDestCenter(CEOboss);
	ObjEnemy_SetLife(CEOboss, CEOlife);
	return CEOboss;
}

function CreateFairyObject(CEOlife){
	let cfofairy = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(cfofairy);
	ObjPrim_SetTexture(cfofairy, img_fairy); 
	ObjEnemy_SetLife(cfofairy, CEOlife);
	return cfofairy;
}

task BossLifeSingle(EnemyObj){
	let path = img_lifebar;
	let countVertex = 48;
	
	let objOutline = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objOutline, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objOutline, countVertex);
	ObjRender_SetBlendType(objOutline, BLEND_ALPHA);
	Obj_SetRenderPriority(objOutline, 0.69);
	ObjPrim_SetTexture(objOutline, path);
	
	let objLife = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objLife, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objLife, countVertex);
	ObjRender_SetBlendType(objLife, BLEND_ALPHA);
	Obj_SetRenderPriority(objLife, 0.68);
	ObjPrim_SetTexture(objLife, path);
	
	let objLife2 = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objLife2, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objLife2, countVertex);
	ObjRender_SetBlendType(objLife2, BLEND_ALPHA);
	Obj_SetRenderPriority(objLife2, 0.68);
	ObjPrim_SetTexture(objLife2, path);
	
	ascent (iVert in 0..countVertex/2){
		let vertex = iVert * 2;
		ObjPrim_SetVertexUVT(objOutline, vertex+0, 0, 0);
		ObjPrim_SetVertexUVT(objOutline, vertex+1, 4, 16);	
		ObjPrim_SetVertexUVT(objLife, vertex+0, 6, 0);
		ObjPrim_SetVertexUVT(objLife, vertex+1, 10, 16);	
		ObjPrim_SetVertexUVT(objLife2, vertex+0, 6, 0);
		ObjPrim_SetVertexUVT(objLife2, vertex+1, 10, 16);		
	}
	
	
	let mx = 0;
	let my = 0;
	let maxRadius = 56;
	
	let lifeRateRender = 0;
	
	let lifeTotalMax = ObjEnemy_GetInfo(EnemyObj, INFO_LIFE);
	let lifeTotal = ObjEnemy_GetInfo(EnemyObj, INFO_LIFE);
	let lifeRate = min(lifeTotal / lifeTotalMax, lifeRateRender);
	
	
	
	ObjRender_SetScaleXYZ(objOutline, -1, 1, 1);
	ObjRender_SetScaleXYZ(objLife, -1, 1, 1);
	ObjRender_SetScaleXYZ(objLife2, -1, 1, 1);
	
	while(lifeTotal / lifeTotalMax>0){
		mx = ObjRender_GetX(EnemyObj);
		my = ObjRender_GetY(EnemyObj);
		RefreshVertex(objOutline);
		
		if(GetCommonData("ForceLifebar", 0) != 0){
			lifeRateRender = 0;
		}
		
		
		yield;
	}
	
	Obj_Delete(objOutline);
	Obj_Delete(objLife);
	Obj_Delete(objLife2);
	

	task RefreshVertex(objid){
	
		lifeTotal = ObjEnemy_GetInfo(EnemyObj, INFO_LIFE);
		lifeRate = min(lifeTotal / lifeTotalMax, lifeRateRender);
		
		ascent(iVert in 0..countVertex/2){
			let indexVert = iVert * 2;
			let angle = (360 / (countVertex/2 - 1) * iVert);
			angle = min(360*(lifeRateRender), angle);
			let x = maxRadius*cos(angle-90);
			let y = maxRadius*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife, indexVert + 0 , x, y, 0);
			x = (maxRadius*1.025)*cos(angle-90);
			y = (maxRadius*1.025)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife, indexVert + 1 , x, y, 0);
			
			x = (maxRadius*1.065)*cos(angle-90);
			y = (maxRadius*1.065)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife2, indexVert + 0 , x, y, 0);
			x = (maxRadius*1.09)*cos(angle-90);
			y = (maxRadius*1.09)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife2, indexVert + 1 , x, y, 0);
			
			angle = min(360*(lifeRate), angle);
			x = (maxRadius)*cos(angle-90);
			y = (maxRadius)*sin(angle-90);
			ObjPrim_SetVertexPosition(objOutline, indexVert + 0 , x, y, 0);			
			x = (maxRadius*1.075)*cos(angle-90);
			y = (maxRadius*1.075)*sin(angle-90);
			ObjPrim_SetVertexPosition(objOutline, indexVert + 1 , x, y, 0);
		}
		ObjRender_SetPosition(objOutline, mx, my, 0);
		ObjRender_SetPosition(objLife, mx, my, 0);
		ObjRender_SetPosition(objLife2, mx, my, 0);
		
		lifeRateRender = min(1, lifeRateRender+0.02);
		
	}
}


function DrawText(txtStr, txtX, txtY, txtSize, txtWidth, presetTxtColor, txtPriority){
	let SnowDrawText = ObjText_Create;
	//DrawText("", GetPlayerX-24, GetPlayerY, 11, 300, "black", 0.80);
	ObjText_SetText(SnowDrawText,txtStr);
	SetTextColor;
	ObjText_SetFontSize(SnowDrawText,txtSize);
	ObjText_SetHorizontalAlignment(SnowDrawText, ALIGNMENT_LEFT);
	ObjText_SetFontBorderWidth(SnowDrawText,1);
	ObjText_SetFontBorderType(SnowDrawText,BORDER_FULL);
	ObjText_SetMaxWidth(SnowDrawText, txtWidth);
	Obj_SetRenderPriority(SnowDrawText, txtPriority);
	ObjRender_SetPosition(SnowDrawText, txtX, txtY, 0);
	
	task SetTextColor{
		if(presetTxtColor=="black"){
			ObjText_SetFontColorTop(SnowDrawText,0,0,0);
			ObjText_SetFontColorBottom(SnowDrawText,0,0,0);
			ObjText_SetFontBorderColor(SnowDrawText,161,161,255);
		}
		if(presetTxtColor=="red"){
			ObjText_SetFontColorTop(SnowDrawText,175,20,111);
			ObjText_SetFontColorBottom(SnowDrawText,190,10,123);
			ObjText_SetFontBorderColor(SnowDrawText,0,0,64);
		}
		if(presetTxtColor=="blue"){
			ObjText_SetFontColorTop(SnowDrawText,20,80,175);
			ObjText_SetFontColorBottom(SnowDrawText,80,50,175);
			ObjText_SetFontBorderColor(SnowDrawText,0,0,64);
		}
	}
	
	return SnowDrawText;
}

function DrawQuickText(txtStr, txtX, txtY){
	let SnowDrawText = ObjText_Create;
	let presetTxtColor = "black";
	//DrawText("", GetPlayerX-24, GetPlayerY, 11, 300, "black", 0.80);
	ObjText_SetText(SnowDrawText,txtStr);
	SetTextColor;
	ObjText_SetFontSize(SnowDrawText,16);
	ObjText_SetHorizontalAlignment(SnowDrawText, ALIGNMENT_LEFT);
	ObjText_SetFontBorderWidth(SnowDrawText,1);
	ObjText_SetFontBorderType(SnowDrawText,BORDER_FULL);
	ObjText_SetMaxWidth(SnowDrawText, 300);
	Obj_SetRenderPriority(SnowDrawText, 0.6);
	ObjRender_SetPosition(SnowDrawText, txtX, txtY, 0);
	
	task SetTextColor{
		if(presetTxtColor=="black"){
			ObjText_SetFontColorTop(SnowDrawText,0,0,0);
			ObjText_SetFontColorBottom(SnowDrawText,0,0,0);
			ObjText_SetFontBorderColor(SnowDrawText,161,161,255);
		}
		if(presetTxtColor=="red"){
			ObjText_SetFontColorTop(SnowDrawText,175,20,111);
			ObjText_SetFontColorBottom(SnowDrawText,190,10,123);
			ObjText_SetFontBorderColor(SnowDrawText,0,0,64);
		}
		if(presetTxtColor=="blue"){
			ObjText_SetFontColorTop(SnowDrawText,20,80,175);
			ObjText_SetFontColorBottom(SnowDrawText,80,50,175);
			ObjText_SetFontBorderColor(SnowDrawText,0,0,64);
		}
	}
	
	return SnowDrawText;
}


task ConcentrationA1{

}

task ConcentrationF1(objid, r, g, b, delay){
	let locframe = 0;
	let cx = ObjRender_GetX(objid);
	let cy = ObjRender_GetY(objid);
	CreateCircleA1(objid, 136, -80/delay*2, 12, r, g, b);
	while(delay>0){
		if(Obj_IsDeleted(objid)){return;}
		cx = ObjRender_GetX(objid);
		cy = ObjRender_GetY(objid);
		if(locframe>2){
			ExplosionA3(cx, cy, cx+rand(64, 128)*cos(rand(0,360)), cy+rand(64, 128)*sin(rand(0,360)), rand(1, 3)); 
			locframe = 0;
		}
		locframe++;
		delay--;
		yield;
	}
	PlaySound("labullet");
	CreateCircleA1(objid, 0, 10, 1, r, g, b);
	loop((quality+3)*6){ExplosionA3(cx+rand(215, 160)*cos(rand(0,360)), cy+rand(215, 160)*sin(rand(0,360)), cx, cy, rand(2, 3.75));}
	
	task ExplosionA3(dx, dy, deX, deY, scale){
		// sloppier than sloppy
		let angX = rand(180, -180);
		let angY = rand(180, -180);
		let angZ = rand(180, -180);
		let spd = scale*1.5;
		let ang = atan2(dy - deY, dx - deX);
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.60);
		ObjPrim_SetTexture(obj, img_effect);
		ObjSprite2D_SetSourceRect(obj, 32, 228, 64, 252);
		ObjSprite2D_SetDestRect(obj, -16, -12, 16, 12);
		ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
		ObjRender_SetPosition(obj, deX, deY, 0);
		let alpha = 195;
		let randX = rand(-500, 500);
		let randY = rand(-500, 500);
		let odist = GetDistance(deX,deY,dx,dy);
		while(!Obj_IsDeleted(obj)){
			let dist = GetDistance(deX,deY,dx,dy);
			scale = scale-0.05;
			alpha += -0.1;
			deX += spd*cos(ang);
			deY += spd*sin(ang);
			angX += randX/85;
			angY += randY/85;
			angZ += randX/135+randY/135;
			ObjRender_SetPosition(obj, deX, deY, 0);
			ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
			ObjRender_SetAlpha(obj, alpha*(dist/odist));
			ObjRender_SetScaleXYZ(obj, scale, scale, scale);
			if(scale<0||dist<spd){Obj_Delete(obj)}
			yield;
		}
		Obj_Delete(obj);
	}
}

task ConcentrationF2(objid){
	let locframe = 0;
	while(!EnemyDead){
		let x = ObjRender_GetX(objid);
		let y = ObjRender_GetY(objid);
		if(locframe>7-quality){loop(3){ExplosionA3(EnemyX, EnemyY, rand(1, 2.35));} locframe = 0;}
		locframe++;
		yield;
	}
	task ExplosionA3(dx, dy, deScale){
		// sloppier than sloppy
		let angX = rand(180, -180);
		let angY = rand(180, -180);
		let angZ = rand(180, -180);
		let spd = rand(1, 4);
		let deX = dx+rand(64, 160)*cos(angZ);
		let deY = dy+rand(64, 160)*sin(angZ);
		let ang = atan2(dy - deY, dx - deX);
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.60);
		ObjPrim_SetTexture(obj, img_effect);
		ObjSprite2D_SetSourceRect(obj, 32, 228, 64, 252);
		ObjSprite2D_SetDestRect(obj, -16, -12, 16, 12);
		ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
		ObjRender_SetPosition(obj, deX, deY, 0);
		ObjRender_SetColor(obj, 128, 128, 255);
		let alpha = 195;
		let scale = deScale;
		let randX = rand(-500, 500);
		let randY = rand(-500, 500);
		while(!Obj_IsDeleted(obj)){
			let dist = GetDistance(deX,deY,dx,dy);
			scale = scale-0.05;
			alpha += -0.1;
			deX += spd*cos(ang);
			deY += spd*sin(ang);
			angX += randX/85;
			angY += randY/85;
			angZ += randX/135+randY/135;
			
			ObjRender_SetPosition(obj, deX, deY, 0);
			ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
			ObjRender_SetAlpha(obj, alpha);
			ObjRender_SetScaleXYZ(obj, scale, scale, scale);
			
			if(scale<0||dist<spd){Obj_Delete(obj)}
			yield;
		}
		Obj_Delete(obj);
	}
}

task ConcentrationF3(objid, r, g, b, delay){
	let locframe = 0;
	let cx = ObjRender_GetX(objid);
	let cy = ObjRender_GetY(objid);
	CreateCircleA1(objid, 136, -80/delay*2, 12, r, g, b);
	while(delay>0){
		if(Obj_IsDeleted(objid)){return;}
		cx = ObjRender_GetX(objid);
		cy = ObjRender_GetY(objid);
		if(locframe>2){
			ExplosionA3(cx, cy, cx+rand(64, 128)*cos(rand(0,360)), cy+rand(64, 128)*sin(rand(0,360)), rand(1, 3)); 
			locframe = 0;
		}
		locframe++;
		delay--;
		yield;
	}
	
	task ExplosionA3(dx, dy, deX, deY, scale){
		// sloppier than sloppy
		let angX = rand(180, -180);
		let angY = rand(180, -180);
		let angZ = rand(180, -180);
		let spd = scale*1.5;
		let ang = atan2(dy - deY, dx - deX);
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.60);
		ObjPrim_SetTexture(obj, img_effect);
		ObjSprite2D_SetSourceRect(obj, 32, 228, 64, 252);
		ObjSprite2D_SetDestRect(obj, -16, -12, 16, 12);
		ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
		ObjRender_SetPosition(obj, deX, deY, 0);
		let alpha = 195;
		let randX = rand(-500, 500);
		let randY = rand(-500, 500);
		let odist = GetDistance(deX,deY,dx,dy);
		while(!Obj_IsDeleted(obj)){
			let dist = GetDistance(deX,deY,dx,dy);
			scale = scale-0.05;
			alpha += -0.1;
			deX += spd*cos(ang);
			deY += spd*sin(ang);
			angX += randX/85;
			angY += randY/85;
			angZ += randX/135+randY/135;
			ObjRender_SetPosition(obj, deX, deY, 0);
			ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
			ObjRender_SetAlpha(obj, alpha*(dist/odist));
			ObjRender_SetScaleXYZ(obj, scale, scale, scale);
			if(scale<0||dist<spd){Obj_Delete(obj)}
			yield;
		}
		Obj_Delete(obj);
	}
}


task LoadSoundEffects{
	LoadSound(MainSTG~"source/Sounds/alarm.wav");
	LoadSound(MainSTG~"source/Sounds/timeout.wav");
	LoadSound(MainSTG~"source/Sounds/timeout2.wav");
	LoadSound(MainSTG~"source/Sounds/timestop.wav");
	LoadSound(MainSTG~"source/Sounds/spell.wav");
	LoadSound(MainSTG~"source/Sounds/spellfinal.wav");
	LoadSound(MainSTG~"source/Sounds/laser1.wav");
	LoadSound(MainSTG~"source/Sounds/laser2.wav");
	LoadSound(MainSTG~"source/Sounds/master.wav");
	LoadSound(MainSTG~"source/Sounds/final.wav");
	LoadSound(MainSTG~"source/Sounds/barrage.wav");
	LoadSound(MainSTG~"source/Sounds/barrage2.wav");
	LoadSound(MainSTG~"source/Sounds/charge.wav");
	LoadSound(MainSTG~"source/Sounds/chargedown.wav");
	LoadSound(MainSTG~"source/Sounds/chargelong.wav");
	LoadSound(MainSTG~"source/Sounds/chargepower.wav");
	LoadSound(MainSTG~"source/Sounds/spirit.wav");
	LoadSound(MainSTG~"source/Sounds/smbullet.wav");
	LoadSound(MainSTG~"source/Sounds/option.wav");
	LoadSound(MainSTG~"source/Sounds/opshow.wav");
	LoadSound(MainSTG~"source/Sounds/ophide.wav");
	LoadSound(MainSTG~"source/Sounds/sword1.wav");
	LoadSound(MainSTG~"source/Sounds/labullet.wav");
	LoadSound(MainSTG~"source/Sounds/death.wav");
	LoadSound(MainSTG~"source/Sounds/death2.wav");
	LoadSound(MainSTG~"source/Sounds/damage1.wav");
	LoadSound(MainSTG~"source/Sounds/damage2.wav");
	LoadSound(MainSTG~"source/Sounds/damage3.wav");
}

task PlaySound(str){
	PlaySE(MainSTG~"source/Sounds/"~str~".wav")
}

task PlayEnemyHitSound(SoundHitEffectObjectID, hitsoundtype){
	let bosshp = ObjEnemy_GetInfo(SoundHitEffectObjectID, INFO_LIFE);
	let origbosshp = ObjEnemy_GetInfo(SoundHitEffectObjectID, INFO_LIFE);
	
	while(EnemyDead == false && Obj_IsDeleted(SoundHitEffectObjectID) == false){
		if(bosshp != ObjEnemy_GetInfo(SoundHitEffectObjectID, INFO_LIFE) && hitsoundtype == 1){
			if(ObjEnemy_GetInfo(SoundHitEffectObjectID, INFO_LIFE) > origbosshp/12){PlaySound("damage1");}
			if(ObjEnemy_GetInfo(SoundHitEffectObjectID, INFO_LIFE) < origbosshp/12){PlaySound("damage2");}
			SetAreaCommonData("CirnoPlayer", "IncreaseIce", 0.6);
		}
		if(bosshp != ObjEnemy_GetInfo(SoundHitEffectObjectID, INFO_LIFE) && hitsoundtype == 2){PlaySound("damage1");}
		if(bosshp != ObjEnemy_GetInfo(SoundHitEffectObjectID, INFO_LIFE) && hitsoundtype == 3){PlaySound("damage3");}
		
		bosshp = ObjEnemy_GetInfo(SoundHitEffectObjectID, INFO_LIFE);
		yield;
	}
}

task SetInvincibility(SnowEnemyObject, TFRAMES, SIshot, SIbomb){
	ObjEnemy_SetDamageRate(SnowEnemyObject, 0, 0);	
	loop(TFRAMES){yield;}
	ObjEnemy_SetDamageRate(SnowEnemyObject, SIshot, SIbomb);	
}

task StarOnBossSingle(SnowEnemyObject){ 
	//This is a relic from 0.12m and I'll optimize it later
	let objStar = ObjPrim_Create(OBJ_SPRITE_2D);
	let objxpos=ObjMove_GetX(SnowEnemyObject);
	let objypos=ObjMove_GetY(SnowEnemyObject);
	let object_time = 30;
	let obj_angle = 330;
	let osize = 0;
	let obj_sizeset = 0;
	let sizeinc = 5;
	let angleinc = 5;
	let fullsize = 0;
	let sizeframe = 0;
	let ax2 = 0.04;
	let bx2 = 1.35;

	ObjRender_SetBlendType(objStar, BLEND_ALPHA);
	Obj_SetRenderPriority(objStar, 0.30);
	ObjPrim_SetTexture(objStar, img_effect);
	ObjSprite2D_SetSourceRect(objStar, 128, 80, 256, 208);
	ObjSprite2D_SetDestRect(objStar, -64, -64, 64, 64);
	
	
	ObjRender_SetAlpha(objStar, 145);
	ObjRender_SetColor(objStar, 200,200,200);
	
	while(!Obj_IsDeleted(SnowEnemyObject)){
		if(IsTimeStopped == false){
			objxpos = ObjMove_GetX(SnowEnemyObject);
			objypos = ObjMove_GetY(SnowEnemyObject);
	
			
			StarSize;
			ObjRender_SetX(objStar, objxpos);
			ObjRender_SetY(objStar, objypos);
			ObjRender_SetScaleXYZ(objStar, osize/95, osize/95, 1);
			ObjRender_SetAngleZ(objStar, obj_angle);
		}
		yield;
	}
	Obj_Delete(objStar);
	
	task StarSize{
		sizeframe++;
		if(sizeframe>=TimeSpeed-1){
			if(fullsize==2){
				if(obj_sizeset==0){sizeinc+=ax2}
				if(obj_sizeset==1){sizeinc-=ax2}
				
				if(sizeinc<-bx2){obj_sizeset=0}
				if(sizeinc>bx2){obj_sizeset=1}
				
				obj_angle-=angleinc;
				angleinc = min(angleinc+0.5, 5);
				
				osize+=sizeinc;
			}
			if(fullsize!=2){obj_angle-=angleinc;angleinc-=0.06;}
			if(osize<145&&fullsize==0){osize+=5;}
			if(osize>144&&fullsize==0){
				fullsize=1;
				loop(55){yield;}
				sizeinc=0;
				angleinc=0;
				fullsize=2;
			}
			sizeframe = 1;
		}
	}	
}

task AuraOnBossSingle(objid, r, g, b){	
	loop(4){yield;}
	if(quality==0){return;}
	let fe = 0;
	while(!Obj_IsDeleted(objid)){
		if(fe>=6){
			EffectAu1(ObjRender_GetX(objid), ObjRender_GetY(objid), 0);
			EffectAu1(ObjRender_GetX(objid), ObjRender_GetY(objid), 1);
			fe = 0;
		}
		fe+=1;
		yield;
	}	
	task EffectAu1(x, y, type){
		let oy = y;
		let alpha = rand(155, 205);
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.31);
		ObjPrim_SetTexture(obj, img_effect);
		ObjSprite2D_SetSourceRect(obj, (type)*48, 144, (type+1)*48, 192);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetScaleXYZ(obj, rand(1, 1.65), rand(1, 1.95), 1);
		ObjRender_SetAngleZ(obj, rand(0, 360));
		let rang = 90;
		if(type==0){
			ObjRender_SetAngleZ(obj, rand(-20, 20));
		}else{rang = rand(0,360);}
		ObjRender_SetColor(obj, r, g, b);
		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetAlpha(obj, alpha);
		while(alpha>0){
			x = x-((1-type)*2.5+0.65)*cos(rang);
			y = y-((1-type)*2.5+0.65)*sin(rang);
			alpha = max(alpha-8, 0);
			ObjRender_SetPosition(obj, x, y, 0);
			ObjRender_SetAlpha(obj, alpha);
			yield;
		}
		Obj_Delete(obj);
	}
}

task NameOnBossSingle(objid, text){
	if(quality==0){return}
	let objText = ObjText_Create;
	ObjText_SetFontSize(objText, 11);
	ObjText_SetFontColorTop(objText, 120, 220, 154);
	ObjText_SetFontColorBottom(objText, 120, 220, 154);
	
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_LEFT);
	ObjText_SetMaxWidth(objText, 999);
	Obj_SetRenderPriority(objText, 0.79);
	ObjRender_SetX(objText, 0);
	ObjRender_SetY(objText, 1);
	ObjText_SetText(objText, text);
	if(quality==1){
		ObjRender_SetY(objText, 14);
	}
	
	
	while(!Obj_IsDeleted(objid)){
		yield;
	}
	Obj_Delete(objText);
}

task ExplosionA1(deX, deY, angX, angY, angZ){
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ALPHA );
	Obj_SetRenderPriority(obj, 0.50);
	ObjPrim_SetTexture(obj, img_effect);
	ObjSprite2D_SetSourceRect(obj, 129, 17, 191, 79);
	ObjSprite2D_SetDestRect(obj, -32, -32, 32, 32);
	ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
	ObjRender_SetPosition(obj, deX, deY, 0);
	
	let alpha = 255;
	let scale = 0;
	let expo = 0.4;
	let RandZ = rand(-170,170);
	while(Obj_IsDeleted(obj)==false){
	
		if(alpha>100){scale += expo;}else{scale -= expo;}
		alpha -= 5;
		if(expo>0){expo = expo^1.07;}
		
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetScaleXYZ(obj, scale*1.1, scale*1.1, 1);
		
		if(alpha<0){Obj_Delete(obj)}
		yield;
	}
	Obj_Delete(obj);
}

task ExplosionA2(deX, deY, angX, angY, angZ, deScale){
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.60);
	ObjPrim_SetTexture(obj, img_effect);
	ObjSprite2D_SetSourceRect(obj, 32, 228, 64, 252);
	ObjSprite2D_SetDestRect(obj, -16, -12, 16, 12);
	ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
	ObjRender_SetPosition(obj, deX, deY, 0);
	
	let alpha = 125;
	let scale = deScale;
	let randX = rand(-500, 500);
	let randY = rand(-500, 500);
	let RandZ = rand(-170,170);
	//atan2(randY - deX, randX - deY);
	while(Obj_IsDeleted(obj)==false){
		scale += -0.05;
		alpha += -0.1;
		deX += randX/100;
		deY += randY/100;
		angX += randX/85;
		angY += randY/85;
		angZ += randX/135+randY/135;
		
		ObjRender_SetPosition(obj, deX, deY, 0);
		ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		
		if(scale<0.01){Obj_Delete(obj)}
		yield;
	}
	Obj_Delete(obj);
}

task ExplosionB1(deX, deY, presetColor, angX, angY, angZ){
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ALPHA );
	Obj_SetRenderPriority(obj, 0.50);
	ObjPrim_SetTexture(obj, img_effect);
	if(presetColor=="red"){ObjSprite2D_SetSourceRect(obj, 129, 17, 191, 79);}
	if(presetColor=="blue"){ObjSprite2D_SetSourceRect(obj, 192, 17, 259, 79);}
	if(presetColor=="yellow"){ObjSprite2D_SetSourceRect(obj, 0, 81, 65, 145);}
	if(presetColor=="green"){ObjSprite2D_SetSourceRect(obj, 64, 81, 129, 145);}
	ObjSprite2D_SetDestRect(obj, -32, -32, 32, 32);
	ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
	ObjRender_SetPosition(obj, deX, deY, 0);
	
	let alpha = 155;
	let scale = 0;
	let expo = 0.4;
	let RandZ = rand(-170,170);
	while(Obj_IsDeleted(obj)==false){
	
		scale += expo/2;
		alpha -= 6.2;
		if(expo>0){expo = expo^1.07;}
		
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetScaleXYZ(obj, scale*1.1, scale*1.1, 1);
		
		if(alpha<0){Obj_Delete(obj)}
		yield;
	}
	Obj_Delete(obj);
}

task ExplosionB2(deX, deY, colorR, colorG, colorB, deScale){
	if(TotalEffect>TotalEffectMax){return;}
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let angX = rand(-360, 360);
	let angY = rand(-360, 360);
	let angZ = rand(-360, 360);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.60);
	ObjPrim_SetTexture(obj, img_effect);
	ObjSprite2D_SetSourceRect(obj, 0, 228, 33, 251);
	ObjSprite2D_SetDestRect(obj, -16, -12, 16, 12);
	ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
	ObjRender_SetPosition(obj, deX, deY, 0);
	ObjRender_SetColor(obj, colorR, colorG, colorB);
	
	let alpha = 105;
	let scale = deScale;
	let randX = rand(-500, 500);
	let randY = rand(-500, 500);
	let RandZ = rand(-170,170);
	//atan2(randY - deX, randX - deY);
	TotalEffect++;
	while(Obj_IsDeleted(obj)==false){
		scale += -0.05;
		alpha += -0.1;
		deX += randX/100;
		deY += randY/100;
		angX += randX/85;
		angY += randY/85;
		angZ += randX/135+randY/135;
		
		ObjRender_SetPosition(obj, deX, deY, 0);
		ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		
		if(scale<0.01){Obj_Delete(obj)}
		yield;
	}
	TotalEffect--;
	Obj_Delete(obj);
}

task CreateCircleA1(objid, siz, sinc, destsiz, r, g, b){
	let alpha = 255;
	let countVertex = 50;
	
	let circ = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetPrimitiveType(circ, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetTexture(circ, NULL);
	Obj_SetRenderPriority(circ, 0.60);
	ObjPrim_SetVertexCount(circ, countVertex);
	ObjRender_SetBlendType(circ, BLEND_ALPHA);
	
	
	ObjPrim_SetVertexUVT(circ, 0, 0, 0);	
	ObjPrim_SetVertexPosition(circ, 0, 0, 0, 0);
	ObjPrim_SetVertexColor(circ, 0, 255, 255, 255);
	ObjPrim_SetVertexAlpha(circ, 0, 0);
	let x = ObjRender_GetX(objid);
	let y = ObjRender_GetY(objid);
	ObjRender_SetPosition(circ, x, y, 0);
	
	ascent(iVert in 1..countVertex){
		let angle = (360 / (countVertex - 2) * iVert);
		ObjPrim_SetVertexUVT(circ, iVert, 0, 0);	
		let x = siz*cos(angle);
		let y = siz*sin(angle);
		ObjPrim_SetVertexPosition(circ, iVert , x, y, 0);
		ObjPrim_SetVertexColor(circ, iVert, r, g, b);
		ObjPrim_SetVertexAlpha(circ, iVert, alpha);
	}
	while(alpha>0){
		if(!Obj_IsDeleted(objid)){
			x = ObjRender_GetX(objid);
			y = ObjRender_GetY(objid);
		}
		ObjRender_SetPosition(circ, x, y, 0);
		siz += sinc/TimeSpeed;
		alpha -= 8;
		ascent(iVert in 1..countVertex){
			let angle = (360 / (countVertex - 2) * iVert);
			ObjPrim_SetVertexPosition(circ, iVert , (siz+8)*cos(angle), (siz+8)*sin(angle), 0);
			ObjPrim_SetVertexAlpha(circ, iVert, alpha);
		}
		yield;
	}
	Obj_Delete(circ);
}


task ClearBullets(x, y, type, Tsize, Tspd, Tmaxrad, delay){
	let stopclear = true;
	loop(delay){yield;}
	while(stopclear==true){
		DeleteShotInCircle(TYPE_ALL,type,x,y,Tsize);
		Tsize += Tspd;
		if(Tsize>=Tmaxrad){
			stopclear = false;
		}
		yield;
	}
}

task CutInS1(SnowEnemyObject, CutType, CutSpellName, CutSpellImage, CutX1, CutY1, CutX2, CutY2){
	yield;
	let objSpellCutIn = SetSpellCutInProperties;
	let objSpellBG = ObjPrim_Create(OBJ_SPRITE_2D);
	let objTxt = ObjText_Create;
	
	let SpellDataAttempt = CutSpellName~IntToString(GetCommonData("StageDiffic", 36))~GetPlayerID~"Attempt";
	let SpellDataGet = CutSpellName~IntToString(GetCommonData("StageDiffic", 36))~GetPlayerID~"Get";
	let SpellValueAttempt = GetAreaCommonData("SpellFunctions", SpellDataAttempt, 0);
	let SpellValueGet = GetAreaCommonData("SpellFunctions", SpellDataGet, 0);
	
	let SpellTextX = 0;
	let SpellTextX2 = 0;
	let SpellTextY = 0;
	let SpellTextSet = 0;
	
	let SpellTextSize = 0;
	let SpellTextSizeInc = 0;
	
	let SpellBGAlpha = 0;
	
	let CutInAlpha = 0;
	let CutInX = 0;
	let CutInY = 0;
	let CutInPosInc = 0;
	
	let CutInTime = 0;
	let CutInitialize = false;
	
	
	SetTextProperties;
	SetSpellBGProperties;
	
	// Checker List
	if(CutType!="YOUMU" && CutType!="DAIYOUSEI" && CutType!="KYOUKO" && CutType!="KANAKO" 
	&& CutType!="NAZRIN" && CutType!="BYAKUREN" && CutType!="AYA" && CutType!="TEXT"){
		RaiseError("Invalid Cutin Type");
	}
	
	if(CutType!="AYA"){
		if(IsReplay == false){
			SpellValueAttempt++;
			SetAreaCommonData("SpellFunctions", SpellDataAttempt, SpellValueAttempt);
			SaveCommonDataAreaA1("SpellFunctions");
		}
	}
	
	
	
	//mu
	
	if(CutType=="YOUMU"){TextYoumu;}
	if(CutType=="DAIYOUSEI"){TextDaiyousei;}
	if(CutType=="KYOUKO"){TextKyouko;}
	if(CutType=="NAZRIN"){TextNazrin;}
	if(CutType=="KANAKO"){TextKanako;}
	if(CutType=="BYAKUREN"){TextByakuren;}
	if(CutType=="AYA"){TextAya;}
	if(CutType=="TEXT"){TextText;}
	BonusPoint;
	
	while(CutInTime<206){
		CutInTime++;					
		yield;
	}
	Obj_Delete(objSpellCutIn);
	
	
	SpellBGAlpha = 255;
	while(!Obj_IsDeleted(SnowEnemyObject)){
		if(GetPlayerY < 96){
			SpellBGAlpha = max(SpellBGAlpha-10, 85);
		}else{SpellBGAlpha = min(SpellBGAlpha+10, 255);}
		ObjRender_SetAlpha(objTxt, SpellBGAlpha);
		ObjRender_SetAlpha(objSpellBG, SpellBGAlpha);
		
		SpellTextX = GetStgFrameWidth-384;
		SpellTextX2 = GetStgFrameWidth-384;
		ObjRender_SetPosition(objSpellBG, 384+SpellTextX, SpellTextY, 0);
		ObjRender_SetPosition(objTxt, -24+SpellTextX2, SpellTextY+15, 0);
		
		yield;
	}
	Obj_Delete(objTxt);
	Obj_Delete(objSpellBG);
	
	task TextYoumu{
		CutInY = -60;
		SpellTextY = GetStgFrameHeight/4*3;
		SpellTextX = 310;
		SpellTextX2 = 310;
		BorderOfSpiritEffect;
		while(SpellTextSet!=4){			
			if(CutInTime<120&&CutInAlpha<255){CutInAlpha+=3;}
			if(CutInTime>119&&CutInAlpha>0){CutInAlpha-=3;}
			
			ObjRender_SetPosition(objSpellCutIn, 384, CutInY, 0);
			
			ObjRender_SetPosition(objSpellBG, 384+SpellTextX, SpellTextY, 0);
			ObjRender_SetPosition(objTxt, 70+SpellTextX2, SpellTextY+15, 0);
			
			ObjRender_SetAlpha(objSpellCutIn, CutInAlpha);
			
			if(SpellTextSet==0){
				SpellTextX-=10;
				if(SpellTextX==0){SpellTextSet=1;}
			}
			if(SpellTextSet==0 || SpellTextSet==1){
				SpellTextX2-=5;
				if(SpellTextX2==0){SpellTextSet=2;}
			}
			if(CutInTime==100){SpellTextSet=3;}
			if(SpellTextSet==3){
				SpellTextY-=10;
				if(SpellTextY<25){SpellTextSet=4;}
			}			
			CutInY+=0.9;
			yield;
		}
	}
	
	task TextDaiyousei{
		CutInY = 120;
		SpellTextY = GetStgFrameHeight/6*4;
		SpellTextX = 0;
		SpellTextX2 = 0;
		SpellTextSize = 164;
		BorderOfSpiritEffect;
		ObjSprite2D_SetDestRect(objSpellCutIn, -CutX2/2, 0, CutX2/2, CutY2);
		while(CutInTime<119||CutInAlpha>0){
			if(CutInTime<120&&CutInAlpha<255){CutInAlpha+=3;CutInPosInc+=0.03;}
			if(CutInTime>119&&CutInAlpha>0){CutInAlpha-=3;CutInPosInc-=0.028;}
			
			ObjRender_SetPosition(objSpellCutIn, GetCenterX, CutInY, 0);
			ObjRender_SetAlpha(objSpellCutIn, CutInAlpha);
			
			ObjRender_SetPosition(objSpellBG, 384+SpellTextX, SpellTextY, 0);
			ObjRender_SetPosition(objTxt, 70+SpellTextX2, SpellTextY+15, 0);
			
			
			if(SpellTextSize>0){
				SpellTextSize-=4.45;
				ObjSprite2D_SetDestRect(objSpellBG, -256-SpellTextSize, -SpellTextSize, 0, 36);
			}
			else{
				ObjSprite2D_SetDestRect(objSpellBG, -256, 0, 0, 36);
				if(SpellTextY>20 && CutInTime > 85){SpellTextY-=10;}
			}
			
			if(SpellBGAlpha<255){SpellBGAlpha+=4.5}
			ObjRender_SetAlpha(objTxt, SpellBGAlpha);
			ObjRender_SetAlpha(objSpellBG, SpellBGAlpha);
			
			CutInY-=CutInPosInc;
			yield;
		}
	}
	
	task TextKanako{
		ObjSprite2D_SetDestCenter(objSpellCutIn);
		CutInX = GetCenterX*2+180;
		CutInY = GetCenterY-190;
		SpellTextY = GetStgFrameHeight/6*4;
		SpellTextX = 0;
		SpellTextX2 = 0;
		SpellTextSize = 164;
		SpellAttackEffect(180, 1.5);
		CutInPosInc = 18;
		CutInAlpha = 20;
		while(CutInTime<=206){
		
			if(CutInTime<31){CutInX-=CutInPosInc; CutInY+=CutInPosInc; CutInAlpha+=2;if(CutInTime>8){CutInPosInc-=0.85;}}
			if(CutInTime==30){CutInPosInc = 0.35;}
			if(CutInTime>=31 && CutInTime<130){CutInY-=CutInPosInc;CutInPosInc+=0.0225;if(CutInAlpha<235){CutInAlpha+=5;}}
			if(CutInTime>=130){CutInY-=CutInPosInc;CutInPosInc-=0.035;CutInAlpha-=3;}
			
			ObjRender_SetPosition(objSpellCutIn, CutInX, CutInY, 0);
			ObjRender_SetAlpha(objSpellCutIn, CutInAlpha);
			
			ObjRender_SetPosition(objSpellBG, 384+SpellTextX, SpellTextY, 0);
			ObjRender_SetPosition(objTxt, 70+SpellTextX2, SpellTextY+15, 0);
			
			
			if(SpellTextSize>0){
				SpellTextSize-=4.45;
				ObjSprite2D_SetDestRect(objSpellBG, -256-SpellTextSize, -SpellTextSize, 0, 36);
			}
			else{
				ObjSprite2D_SetDestRect(objSpellBG, -256, 0, 0, 36);
				if(SpellTextY>20 && CutInTime > 85){SpellTextY-=10;}
			}
			
			if(SpellBGAlpha<255){SpellBGAlpha+=4.5}
			ObjRender_SetAlpha(objTxt, SpellBGAlpha);
			ObjRender_SetAlpha(objSpellBG, SpellBGAlpha);
			
			yield;
		}
	}

	task TextNazrin{
		CutInX = (GetCenterX*2)+256;
		CutInY = GetCenterY-128;
		SpellTextY = GetStgFrameHeight/6*4;
		SpellTextX = 0;
		SpellTextX2 = 0;
		SpellTextSize = 164;
		SpellAttackEffect(100, 1.5);
		let cyoff = -5;
		if(quality<=1){cyoff = 10}
		ObjSprite2D_SetDestCenter(objSpellCutIn);
		while(CutInTime<=206){
		
			if(CutInTime<21){CutInX-=20; CutInY+=5}
			if(CutInTime>=21 && CutInTime<110){CutInX--; CutInY+=0.5;}
			if(CutInTime>=110){CutInX-=20; CutInY+=5;}
			
			ObjRender_SetPosition(objSpellCutIn, CutInX, CutInY, 0);
			
			ObjRender_SetPosition(objSpellBG, 384+SpellTextX, SpellTextY, 0);
			ObjRender_SetPosition(objTxt, -24+SpellTextX2, SpellTextY+15, 0);
			
			
			if(SpellTextSize>0){
				SpellTextSize-=4.45;
				ObjSprite2D_SetDestRect(objSpellBG, -256-SpellTextSize, -SpellTextSize, 0, 36);
			}
			else{
				ObjSprite2D_SetDestRect(objSpellBG, -256, 0, 0, 36);
				if(CutInTime > 85){SpellTextY = max(SpellTextY-10, cyoff);}
			}
			
			if(SpellBGAlpha<255){SpellBGAlpha+=4.5}
			ObjRender_SetAlpha(objTxt, SpellBGAlpha);
			ObjRender_SetAlpha(objSpellBG, SpellBGAlpha);
			
			yield;
		}
	}

	task TextByakuren{
		CutInX = -256;
		CutInY = GetCenterY;
		SpellTextY = GetStgFrameHeight/6*4;
		SpellTextX = 0;
		SpellTextX2 = 0;
		SpellTextSize = 164;
		SpellAttackEffect(100, 1.5);
		ObjSprite2D_SetDestCenter(objSpellCutIn);
		while(CutInTime<=206){
		
			if(CutInTime<21){CutInX+=20;}
			if(CutInTime>=21 && CutInTime<110){CutInX++;}
			if(CutInTime>=110){CutInX+=20;}
			
			ObjRender_SetPosition(objSpellCutIn, CutInX, CutInY, 0);
			
			ObjRender_SetPosition(objSpellBG, 384+SpellTextX, SpellTextY, 0);
			ObjRender_SetPosition(objTxt, 70+SpellTextX2, SpellTextY+15, 0);
			
			
			if(SpellTextSize>0){
				SpellTextSize-=4.45;
				ObjSprite2D_SetDestRect(objSpellBG, -256-SpellTextSize, -SpellTextSize, 0, 36);
			}
			else{
				ObjSprite2D_SetDestRect(objSpellBG, -256, 0, 0, 36);
				if(SpellTextY>20 && CutInTime > 85){SpellTextY-=10;}
			}
			
			if(SpellBGAlpha<255){SpellBGAlpha+=4.5}
			ObjRender_SetAlpha(objTxt, SpellBGAlpha);
			ObjRender_SetAlpha(objSpellBG, SpellBGAlpha);
			
			yield;
		}
	}

	task TextAya{
		if(CutSpellName != ""){CutInS1(SnowEnemyObject, "TEXT", CutSpellName, NULL, 0, 0, 0, 0);}
		Obj_Delete(objSpellCutIn);
		Obj_Delete(objTxt);
		Obj_Delete(objSpellBG);
		PlaySound("charge");
		let objShootName= SetSpellCutInProperties;
		ObjRender_SetPosition(objShootName, GetCenterX+4, -CutY2*4, 0);
		ObjRender_SetBlendType(objShootName, BLEND_ALPHA);
		
		let objSpellShoot = SetSpellCutInProperties;
		ObjPrim_SetTexture(objSpellShoot, img_effect3);
		ObjSprite2D_SetSourceRect(objSpellShoot, 0, 0, 256, 64);
		ObjRender_SetPosition(objSpellShoot, GetCenterX+32, GetCenterY, 0);
		
		let objSpellShootBG = SetSpellCutInProperties;
		ObjRender_SetBlendType(objSpellShootBG, BLEND_ADD_RGB);
		ObjPrim_SetTexture(objSpellShootBG, img_effect3);
		Obj_SetRenderPriority(objSpellShootBG, 0.76);
		ObjSprite2D_SetSourceRect(objSpellShootBG, 0, 64, 512, 128);
		ObjRender_SetPosition(objSpellShootBG, GetCenterX+55*cos(335), GetCenterY+55*sin(335), 0);
		ObjRender_SetAngleZ(objSpellShootBG, 335);
		ObjSprite2D_SetDestCenter(objSpellShootBG);
		ObjRender_SetScaleXYZ(objSpellShootBG, 1.35, 1.35, 1);
		
		let g = 0;
		let b = 0;
		let g2 = 0;
		let b2 = 0;
		
		let alco = 105;
		ObjRender_SetColor(objSpellShootBG, alco, alco, alco);
		
		while(CutInTime<=206){
			if(CutInTime<60){
				if(CutInTime<30){
					g = min(128, g+16);
					ObjSprite2D_SetDestRect(objSpellShoot, -128, -g/4, 128*4-g*3, g/4);
					ObjSprite2D_SetDestRect(objSpellShootBG, -256, -g/4, 256*4-g*2*3, g/4);
					b=g;
				}
				if(CutInTime>=30){
					g = max(0, g-16);
					b = min((CutX2-CutX1)*2, b+24);
					ObjSprite2D_SetDestRect(objSpellShoot, -b, -g/6, 128, g/6);
				}
			}
			if(CutInTime==45){
				Obj_Delete(objSpellShoot);
				ObjRender_SetPosition(objSpellShoot, GetCenterX+4, -CutY2*4, 0);
				PlaySound("chargedown");
			}
			if(CutInTime>45 && CutInTime<120){
				ObjRender_SetPosition(objShootName, GetCenterX+4, GetCenterY, 0);
				if(CutInTime<75){
					g2 = min((CutX2-CutX1)/2, g2+24);
					ObjSprite2D_SetDestRect(objShootName, -(CutX2-CutX1)/2, -g2/6, (CutX2-CutX1)*2-g2*3, g2/6);
					b2=g2;
				}
				if(CutInTime>=75){
					g2 = max(0, g2-24);
					b2 = min((CutX2-CutX1)*2, b2+24);
					alco = max(0, alco-15);
					ObjSprite2D_SetDestRect(objShootName, -b2, -g2/6, (CutX2-CutX1)/2, g2/6);
					ObjSprite2D_SetDestRect(objSpellShootBG, -b2*2, -g2/4, 256, g2/4);
					ObjRender_SetColor(objSpellShootBG, alco, alco, alco);
				}
			}
			yield;
		}
	}

	task TextText{
		SpellTextY = GetStgFrameHeight/6*4;
		SpellTextX = 0;
		SpellTextX2 = 0;
		SpellTextSize = 164;
		while(CutInTime<=206){			
			ObjRender_SetPosition(objSpellBG, 384+SpellTextX, SpellTextY, 0);
			ObjRender_SetPosition(objTxt, 70+SpellTextX2, SpellTextY+15, 0);
			
			if(SpellTextSize>0){
				SpellTextSize-=4.45;
				ObjSprite2D_SetDestRect(objSpellBG, -256-SpellTextSize, -SpellTextSize, 0, 36);
			}
			else{
				ObjSprite2D_SetDestRect(objSpellBG, -256, 0, 0, 36);
				if(SpellTextY>40 && CutInTime > 85){SpellTextY-=10;}
			}
			
			if(SpellBGAlpha<255){SpellBGAlpha+=4.5}
			ObjRender_SetAlpha(objTxt, SpellBGAlpha);
			ObjRender_SetAlpha(objSpellBG, SpellBGAlpha);
			
			yield;
		}
	}

	task TextKyouko{
		CutInY = 120;
		SpellTextY = GetStgFrameHeight/6*4;
		SpellTextX = 0;
		SpellTextX2 = 0;
		SpellTextSize = 164;
		SpellAttackEffect(180, 1);
		ObjSprite2D_SetDestRect(objSpellCutIn, -CutX2/2, 0, CutX2/2, CutY2);
		
		while(CutInTime<119||CutInAlpha>0){
			if(CutInTime<120&&CutInAlpha<255){CutInAlpha+=3;CutInPosInc+=0.03;}
			if(CutInTime>119&&CutInAlpha>0){CutInAlpha-=3;CutInPosInc-=0.028;}
			
			ObjRender_SetPosition(objSpellCutIn, GetCenterX, CutInY, 0);
			ObjRender_SetAlpha(objSpellCutIn, CutInAlpha);
			
			ObjRender_SetPosition(objSpellBG, 384+SpellTextX, SpellTextY, 0);
			ObjRender_SetPosition(objTxt, 70+SpellTextX2, SpellTextY+15, 0);
			
			
			if(SpellTextSize>0){
				SpellTextSize-=4.45;
				ObjSprite2D_SetDestRect(objSpellBG, -256-SpellTextSize, -SpellTextSize, 0, 36);
			}
			else{
				ObjSprite2D_SetDestRect(objSpellBG, -256, 0, 0, 36);
				if(SpellTextY>20 && CutInTime > 85){SpellTextY-=10;}
			}
			
			if(SpellBGAlpha<255){SpellBGAlpha+=4.5}
			ObjRender_SetAlpha(objTxt, SpellBGAlpha);
			ObjRender_SetAlpha(objSpellBG, SpellBGAlpha);
			
			CutInY-=CutInPosInc;
			yield;
		}
	}
	
	function SetSpellBorderProperties{
		let SSBPtemp = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(SSBPtemp, BLEND_ALPHA);
		Obj_SetRenderPriority(SSBPtemp, 0.76);
		ObjPrim_SetTexture(SSBPtemp, img_effect2);
		ObjSprite2D_SetSourceRect(SSBPtemp, 0, 0, 1280, 80);
		ObjRender_SetPosition(SSBPtemp, GetStgFrameWidth, SpellTextY, 0);
		ObjSprite2D_SetDestRect(SSBPtemp, -280, -40, 1080, 40); //1.7
		return SSBPtemp;
	}	
	function SetSpellAttackProperties{
		let SSBPtemp = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(SSBPtemp, BLEND_ALPHA);
		Obj_SetRenderPriority(SSBPtemp, 0.75);
		ObjPrim_SetTexture(SSBPtemp, img_SpellAttack);
		ObjSprite2D_SetSourceRect(SSBPtemp, -768, 0, 768, 16);
		ObjSprite2D_SetDestCenter(SSBPtemp);
		return SSBPtemp;
	}
	
	function SetSpellCutInProperties{
		let tempobj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(tempobj, BLEND_ALPHA);
		ObjRender_SetAlpha(tempobj, 225);
		Obj_SetRenderPriority(tempobj, 0.77);
		ObjPrim_SetTexture(tempobj, CutSpellImage);
		ObjSprite2D_SetSourceRect(tempobj, CutX1, CutY1, CutX2, CutY2);
		ObjRender_SetPosition(tempobj, GetStgFrameWidth-30, 0, 0);
		while(CutX1>0){CutX1--;CutX2--;}
		while(CutY1>0){CutY1--;CutY2--;}
		ObjSprite2D_SetDestRect(tempobj, -CutX2, 0, 0, CutY2);
		return tempobj;
	}
	task SetSpellBGProperties{
		ObjRender_SetBlendType(objSpellBG, BLEND_ALPHA);
		Obj_SetRenderPriority(objSpellBG, 0.78);
		ObjPrim_SetTexture(objSpellBG, img_effect);
		ObjSprite2D_SetSourceRect(objSpellBG, 0, 256, 256, 292);
		ObjRender_SetPosition(objSpellBG, GetStgFrameWidth, SpellTextY, 0);
		ObjSprite2D_SetDestRect(objSpellBG, -256, 0, 0, 36);
	}
	task SetTextProperties{
		ObjText_SetText(objTxt,CutSpellName);
		ObjText_SetFontSize(objTxt,12);
		ObjText_SetFontColorTop(objTxt,254,254,254);
		ObjText_SetFontColorBottom(objTxt,255,119,119);
		ObjText_SetFontBorderType(objTxt,BORDER_FULL);
		ObjText_SetFontBorderColor(objTxt,0,0,64);
		ObjText_SetFontBorderWidth(objTxt,1);
		ObjText_SetHorizontalAlignment(objTxt, ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(objTxt, 400);
		ObjRender_SetPosition(objTxt, 70, SpellTextY+15, 0);
		Obj_SetRenderPriority(objTxt, 0.79);
	}

	task BorderOfSpiritEffect{
		let objSpellBorder = SetSpellBorderProperties;
		let objSpellBorder2 = SetSpellBorderProperties;
		let BorderAlpha = 0;
		let BorderPos = 0;
		ObjRender_SetAngleXYZ(objSpellBorder2, 0, 0, 90);
		while(Obj_IsDeleted(objSpellBorder) == false){
			BorderPos+=0.9;
			ObjRender_SetAlpha(objSpellBorder, BorderAlpha);
			ObjRender_SetAlpha(objSpellBorder2, BorderAlpha);
			ObjRender_SetPosition(objSpellBorder, BorderPos*2.4-500, 326-BorderPos*0.4, 0);
			ObjRender_SetPosition(objSpellBorder2, 256-BorderPos*0.5, -BorderPos*2.4, 0);
			if(CutInTime<120&&BorderAlpha<255){BorderAlpha+=3;}
			if(CutInTime>119&&BorderAlpha>0){BorderAlpha-=3;}
			if(CutInTime>119 && BorderAlpha == 0){Obj_Delete(objSpellBorder);Obj_Delete(objSpellBorder2);}
			yield;
		}
	}
	
	task SpellAttackEffect(speed, alphamod){
		let alpha = 0;
		Octagon(GetCenterX*2, GetCenterY*2, -1.15, 180, 1);
		Octagon(GetCenterX*2, GetCenterY*2, 1.05, 240, 0);
		Octagon(GetCenterX*2, GetCenterY*2, 1.05, 295, 0);
		Octagon(GetCenterX/5, GetCenterY/5, 0.75, 170, 1);
		
		ascent (i in 0..5){
			Line(GetCenterX, GetCenterY+i*75-75-95, 1.5);
		}
		ascent (i in 0..5){
			Line(GetCenterX, GetCenterY+i*75-37.5-95, -1.5);
		}
		
		while(CutInTime<speed||alpha>0){
			if(CutInTime<speed && CutInTime>15 && alpha<145){alpha+=5*alphamod}
			if(CutInTime>=speed && alpha>0){alpha-=5*alphamod}
			yield;
		}
		
		task Line(mx, my, posinc){
			let objSpellAttack = SetSpellAttackProperties;
			let LineX = 0;
			let LineY = 0;
			ObjRender_SetAngleZ(objSpellAttack, -35);
			while(CutInTime<180 || alpha>0){
				LineX = LineX+posinc*cos(-35);
				LineY = LineY+posinc*sin(-35);
				ObjRender_SetPosition(objSpellAttack, mx+LineX, my+LineY, 0);
				ObjRender_SetAlpha(objSpellAttack, alpha);
				yield;
			}
			Obj_Delete(objSpellAttack);
		}
	
		task Octagon(mx, my, spininc, dist, size){
		
			let countVertex = 16;
			let listRadius = [];
			loop(countVertex){
				listRadius = listRadius ~ [0];
			}

			let objOutline = ObjPrim_Create(OBJ_PRIMITIVE_2D);
			ObjPrim_SetPrimitiveType(objOutline, PRIMITIVE_TRIANGLESTRIP);
			ObjPrim_SetVertexCount(objOutline, countVertex);
			ObjRender_SetBlendType(objOutline, BLEND_ALPHA);
			Obj_SetRenderPriority(objOutline, 0.76);
			ObjPrim_SetTexture(objOutline, img_SpellAttack);
	
			ascent (iVert in 0..countVertex/2){
				let left = iVert * 128;
				let indexVert = iVert * 2;
				ObjPrim_SetVertexUVT(objOutline, indexVert + 0, left, 0);
				ObjPrim_SetVertexUVT(objOutline, indexVert + 1, left, 16);
			}			
	
			let frame = 0;
			let rRate = 1;
			let spin = 0;
	
			while(CutInTime<180 || alpha>0){
				spin+=spininc;
				VertexSize;
				ObjRender_SetPosition(objOutline, mx, my, 0);
				ObjRender_SetAngleZ(objOutline, spin);
				ObjRender_SetAlpha(objOutline, alpha);
				frame++;
				yield;
			}
			Obj_Delete(objOutline);
			
			task VertexSize{	
				if(frame>=35){return;}
				ascent (iVert in 0..countVertex/2){
					let indexVert = iVert * 2;
					let angle = (360 / (countVertex / 2 - 1) * iVert);

					let vx1 = listRadius[indexVert] * cos(angle);
					let vy1 = listRadius[indexVert] * sin(angle);
					ObjPrim_SetVertexPosition(objOutline, indexVert + 0, vx1, vy1, 0);

					let vx2 = listRadius[indexVert+1] * cos(angle);
					let vy2 = listRadius[indexVert+1] * sin(angle);
					ObjPrim_SetVertexPosition(objOutline, indexVert + 1, vx2, vy2, 0);

					let dr = (dist * rRate - listRadius[indexVert]) / 16;
					listRadius[indexVert] = listRadius[indexVert] + dr;
					if(frame>size){
						listRadius[indexVert + 1] = listRadius[indexVert + 1] + dr;
					}
				}
			}
		}
	}

	task BonusPoint{
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		let count = 0;
		let bonus = 10;
		ObjPrim_SetTexture(obj, img_effect2);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.8);
		while(!Obj_IsDeleted(SnowEnemyObject)){
			ObjSpriteList2D_ClearVertexCount(obj);
			ObjRender_SetAlpha(obj, SpellBGAlpha);
			
			ObjRender_SetScaleXYZ(obj, 1, 1, 1);
			ObjSpriteList2D_SetSourceRect(obj, 0, 95, 128, 107);
			ObjSpriteList2D_SetDestCenter(obj);
			ObjRender_SetPosition(obj, GetStgFrameWidth-130, SpellTextY + 36, 0);
			ObjSpriteList2D_AddVertex(obj);
			
			
			let objScene = GetEnemyBossSceneObjectID;
			bonus = min(99999999, ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
			count = GetNumSize(bonus);
			let listNum = DigitToArray(bonus, count);
			
			//Bonus Score
			if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) +
			ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
				ascent(iObj in 0 .. count){
					let num = listNum[iObj];
					ObjRender_SetX(obj, GetStgFrameWidth-94-(8*count) + iObj * 7);
					ObjSpriteList2D_SetSourceRect(obj, num * 8, 112, (num + 1) * 8, 124);
					ObjSpriteList2D_SetDestCenter(obj);
					ObjSpriteList2D_AddVertex(obj);
				}
			}else{
					ObjRender_SetX(obj, GetStgFrameWidth-131);
					ObjSpriteList2D_SetSourceRect(obj, 144, 95, 176, 107);
					ObjSpriteList2D_SetDestCenter(obj);
					ObjSpriteList2D_AddVertex(obj);
			}
			
			//History
			let attempt = min(SpellValueAttempt, 999);
			let get = min(SpellValueGet, 999);
			if(attempt < 100){count = 2;}else{count = 3;}
			listNum = DigitToArray(get, count) ~ [10] ~ DigitToArray(attempt, count);
				
			ascent(iObj in 0 .. count*2+1){
				let num = listNum[iObj];
				ObjRender_SetX(obj, GetStgFrameWidth-58 + iObj * 8);
				ObjSpriteList2D_SetSourceRect(obj, num * 8, 112, (num + 1) * 8, 124);
				ObjSpriteList2D_SetDestCenter(obj);
				ObjSpriteList2D_AddVertex(obj);
			}
			
			
			yield;
		}
		if(IsReplay == false){
			if(bonus>1){
				SpellValueGet++;
				SetAreaCommonData("SpellFunctions", SpellDataGet, SpellValueGet);
			}
			SaveCommonDataAreaA1("SpellFunctions");
		}
		Obj_Delete(obj);
	}
}


task ScreenShakeA1(shaketime, intensity){
	while(shaketime>0){
		Set2DCameraFocusX(GetStgFrameWidth/2 + rand(-intensity, intensity));
		Set2DCameraFocusY(GetStgFrameHeight/2 + rand(-intensity, intensity));
		shaketime--;
		yield;
	}
	Reset2DCamera;
	yield;
}
task ScreenShakeA2(shaketime, intensity){
	let ramp = 0;
	let fr = 0;
	while(shaketime>0){
		if(fr>=1){
			ramp = min(ramp+0.75, intensity);
			Set2DCameraFocusX(GetStgFrameWidth/2 + rand(-ramp, ramp));
			Set2DCameraFocusY(GetStgFrameHeight/2 + rand(-ramp, ramp));
			shaketime--;
		}else{
			
		}
		if(!IsTimeStopped){fr+=1/TimeSpeed;}
		yield;
	}
	Reset2DCamera;
	yield;
}

task ScreenFlash(objid, decay, alpha){
	let menuscreen = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(menuscreen, img_effect);
	ObjRender_SetBlendType(menuscreen, BLEND_ALPHA);
	Obj_SetRenderPriorityI(menuscreen, 69);
	ObjRender_SetAlpha(menuscreen, alpha);
	ObjSprite2D_SetSourceRect(menuscreen, 240, 234, 252, 246);
	ObjSprite2D_SetDestRect(menuscreen, -124, -124, 524, 524);
	
	while(alpha>0 && !Obj_IsDeleted(objid)){
		alpha+=decay;
		ObjRender_SetAlpha(menuscreen, alpha);
		yield;
	}
	
	Obj_Delete(menuscreen);
	
}

// snow did this
task ScreenDistort(SnowEnemyObject, AI, length){
	let renderTexture = GetReservedRenderTargetName(0);

	SetInvalidRenderPriorityA1(20, 79);

	let objCurentFrame = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(objCurentFrame, 80);

	if(length == -1){while(ObjEnemy_GetInfo(SnowEnemyObject, INFO_LIFE) > 0){PerformActions;yield;}}	
	if(length != -1){while(length>0){length--;PerformActions;yield;}}
	
	Obj_Delete(objCurentFrame);
	ClearInvalidRenderPriority;
	
	task PerformActions{
		let currentFrameTexture = renderTexture;
		RenderToTextureA1(currentFrameTexture, 20, 79, true);
		ObjPrim_SetTexture(objCurentFrame, currentFrameTexture);
		ObjSprite2D_SetSourceRect(objCurentFrame, 32, 16, 416, 464);
		ObjSprite2D_SetDestRect(objCurentFrame, rand(32, 36+AI), rand(16, 36+AI), rand(416-AI, 416), rand(464-AI, 464));
	}
}

task Shadow(x, y, incremental, alpha, colorR, colorG, colorB, stime){

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let ShadowTime = 0;
	let xBend = 1;
	let yBend = 1;
	let BendInc = 0.22;
	let ShadSet = 0;
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.69);
	ObjRender_SetAlpha(obj, alpha);
	ObjPrim_SetTexture(obj, img_effect2);
	ObjSprite2D_SetSourceRect(obj, 0, 130, 62, 192);
	ObjSprite2D_SetDestRect(obj, -xBend, -xBend, xBend, xBend);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjRender_SetColor(obj, colorR, colorG, colorB);
		while(Obj_IsDeleted(obj) == false){
		ShadowTime++;
		ObjSprite2D_SetDestRect(obj, -xBend, -xBend, xBend, xBend);
		
		if(xBend<1500&&ShadSet==0){
			xBend+=BendInc;
			BendInc+=incremental;
		}
		if(ShadowTime>stime&&ShadSet==0){
			BendInc=0;		
			ShadSet=2;
		}
		if(ShadowTime>stime&&ShadSet==2){
			xBend+=BendInc;
			BendInc-=incremental*1.75;
		}
		if(xBend<-20){Obj_Delete(obj);}
		yield;
	}
}

task SpellTime(SpellTimeSceneObjectID){
	//@Mainloop
	let GetTimer = ObjEnemyBossScene_GetInfo(SpellTimeSceneObjectID, INFO_TIMER);
	if(bosstime != GetTimer && GetTimer <11){
		if(GetTimer > 4){PlaySound("timeout")}
		if(GetTimer < 5 && GetTimer>-1){PlaySound("timeout2");}
		bosstime = GetTimer;
	}
}

task TimeStop(tX, tY, length){
	SetCommonData("TimeStop", 1);
	LastTimeStop = length;
	IsTimeStopped = true;
	Shadow(tX, tY, 1.45, 165, 1, 1, 1, length-25);
	ascent(time in 0..length){
		yield;
	}
	SetCommonData("TimeStop", 0);
	IsTimeStopped = false;
	ScreenFlash(ID_INVALID, -10, 50);
	ScreenShakeA1(15, 1.75);
}

task TimeSlow(divide, length){
	SetCommonData("TimeSlow", divide);
	ascent(time in 0..length){
		yield;
	}
	SetCommonData("TimeSlow", 0);
}

function CreateObjShotA1(x, y, spd, ang, graph, delay,r,g,b){
	let shot = ObjShot_Create(OBJ_SHOT);
	CreateObjShotZ1(shot, x, y, spd, ang, graph, delay,r,g,b);
	return shot;
}

function CreateObjShotM1(x, y, spd, ang, graph, delay,r,g,b,col){
	let shot = ObjShot_Create(OBJ_SHOT);
	CreateObjShotY1(shot, x, y, spd, ang, graph, delay,r,g,b,col);
	return shot;
}

task CreateObjShotZ1(objShot, x, y, spd, ang, graph, delay,r,g,b){
	ObjShot_Regist(objShot);
	ObjMove_SetPosition(objShot, x, y);
	ObjMove_SetAngle(objShot, ang);
	ObjShot_SetGraphic(objShot, graph);
	
	ObjShot_SetIntersectionEnable(objShot, false);
	let i = 0;
	while(i<delay&&!Obj_IsDeleted(objShot)){
		let alpf = i*(225/delay);
		let scl = (delay-i)*(1.75/delay);
		ObjRender_SetScaleXYZ(objShot, scl+1, scl+1, 1);
		ObjRender_SetAlpha(objShot, min(255, alpf-35));
		i+=1/TimeSpeed;
		yield;
	}
	ObjShot_SetIntersectionEnable(objShot, true);
	ObjRender_SetScaleXYZ(objShot, 1, 1, 1);
	ObjRender_SetAlpha(objShot, 255);
	ObjMove_SetSpeed(objShot, spd);	
	if(quality<=1){return;}
	while(!Obj_IsDeleted(objShot)){
		x = ObjRender_GetX(objShot);
		y = ObjRender_GetY(objShot);
		yield;
	}
	ObjShot_BulletBreak(x, y, r, g, b)
}

task CreateObjShotY1(objShot, x, y, spd, ang, graph, delay,r,g,b,col){
	if(GetPlayerState==STATE_DOWN){
		Obj_Delete(objShot);
		ObjShot_BulletBreak(x, y, r, g, b);
		return;
	}
	ObjShot_Regist(objShot);
	ObjMove_SetPosition(objShot, x, y);
	ObjMove_SetAngle(objShot, ang);
	ObjShot_SetGraphic(objShot, graph);
	
	ObjShot_SetIntersectionEnable(objShot, false);
	let i = 0;
	while(i<delay&&!Obj_IsDeleted(objShot)){
		let alpf = i*(225/delay);
		let scl = (delay-i)*(1.75/delay);
		ObjRender_SetScaleXYZ(objShot, scl+1, scl+1, 1);
		ObjRender_SetAlpha(objShot, min(255, alpf-35));
		i+=1/TimeSpeed;
		yield;
	}
	ObjShot_SetIntersectionEnable(objShot, true);
	ObjRender_SetScaleXYZ(objShot, 1, 1, 1);
	ObjRender_SetAlpha(objShot, 255);
	ObjMove_SetSpeed(objShot, spd);	
	if(quality<=1){return;}
	while(!Obj_IsDeleted(objShot)&&!EnemyDead&&GetPlayerState!=STATE_DOWN){
		x = ObjRender_GetX(objShot);
		y = ObjRender_GetY(objShot);
		yield;
	}
	Obj_Delete(objShot);
	FinalizeFairy(x, y, col);
}

task CreateArrowShotA1(x, y, spd, ang, graph, delay,r,g,b){
	let objShot = CreateShotA1(x, y, 0,  ang, graph, 0);
	ObjShot_SetIntersectionEnable(objShot, false);
	let i = 0;
	while(i<delay&&!Obj_IsDeleted(objShot)){
		let alpf = i*(225/delay);
		let scl = (delay-i)*(1.75/delay);
		ObjRender_SetScaleXYZ(objShot, scl+1, scl+1, 1);
		ObjRender_SetAlpha(objShot, min(255, alpf-35));
		i+=1/TimeSpeed;
		yield;
	}
	ObjShot_SetIntersectionEnable(objShot, true);
	ObjRender_SetScaleXYZ(objShot, 1, 1, 1);
	ObjRender_SetAlpha(objShot, 255);
	ObjMove_SetSpeed(objShot, spd);	
	let A = 0;
	while(!Obj_IsDeleted(objShot)){
		x = ObjMove_GetX(objShot);
		y = ObjMove_GetY(objShot);
		A = ObjMove_GetAngle(objShot);
		ObjShot_SetIntersectionCircleA2(objShot, x+8*cos(A),  y+8*sin(A), 2);
		yield;
	}
	if(quality<=1){return;}
	ObjShot_BulletBreak(x, y, r, g, b)
}

task ObjShot_ReserveBreak(obj,r,g,b){
	let x = ObjMove_GetX(obj);
	let y = ObjMove_GetY(obj);
	while(!Obj_IsDeleted(obj)){
		x = ObjMove_GetX(obj);
		y = ObjMove_GetY(obj);
		yield;
	}
	ObjShot_BulletBreak(x, y, r, g, b);
}

task ObjShot_BulletBreak(x, y, r, g, b){
	if(x<0||y<0||x>GetStgFrameWidth||y>GetStgFrameHeight){return;}
	while(IsTimeStopped){yield;}
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let btime = 0;
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	ObjPrim_SetTexture(obj, img_break);
	Obj_SetRenderPriority(obj, 0.49);
	ObjRender_SetAlpha(obj, 205);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 32, 32);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetColor(obj, r, g, b);
	ObjRender_SetPosition(obj, x+rand(-4,4)*cos(rand(0,360)), y+rand(-4,4)*sin(rand(0,360)), 0);
	ObjRender_SetAngleZ(obj, rand(0,360));
	while(btime<27){
		if(!IsTimeStopped){
			if(floor(btime)==3){ObjSprite2D_SetSourceRect(obj, 32, 0, 64, 32);ObjRender_SetAngleZ(obj, rand(0,360));}
			if(floor(btime)==6){ObjSprite2D_SetSourceRect(obj, 64, 0, 96, 32);ObjRender_SetAngleZ(obj, rand(0,360));}
			if(floor(btime)==9){ObjSprite2D_SetSourceRect(obj, 96, 0, 128, 32);ObjRender_SetAngleZ(obj, rand(0,360));}
			if(floor(btime)==12){ObjSprite2D_SetSourceRect(obj, 128, 0, 160, 32);ObjRender_SetAngleZ(obj, rand(0,360));}
			if(floor(btime)==15){ObjSprite2D_SetSourceRect(obj, 128, 0, 160, 32);ObjRender_SetAngleZ(obj, rand(0,360));}
			if(floor(btime)==18){ObjSprite2D_SetSourceRect(obj, 160, 0, 192, 32);ObjRender_SetAngleZ(obj, rand(0,360));}
			if(floor(btime)==21){ObjSprite2D_SetSourceRect(obj, 192, 0, 224, 32);ObjRender_SetAngleZ(obj, rand(0,360));}
			if(floor(btime)==24){ObjSprite2D_SetSourceRect(obj, 224, 0, 256, 32);ObjRender_SetAngleZ(obj, rand(0,360));}
			btime+=1/TimeSpeed;
		}
		yield;
	}
	Obj_Delete(obj);
}

task ObjShot_AddTimeStopA1(objID, spd){	
	let tspd = 1;
	while(!Obj_IsDeleted(objID)){
		tspd = GetCommonData("TimeSlow", 1);
		if(GetCommonData("TimeStop", 0) > 0){
			ObjMove_SetSpeed(objID, 0);
		}else{
			ObjMove_SetSpeed(objID, spd/tspd);
		}
		yield;
	}
}	

task ObjShot_AddCollisionA1(shotobjid, dX, dY){
	let X = ObjRender_GetX(shotobjid);
	let Y = ObjRender_GetY(shotobjid);
	let A = ObjMove_GetAngle(shotobjid);
	while(!Obj_IsDeleted(shotobjid)){
		X = ObjRender_GetX(shotobjid);
		Y = ObjRender_GetY(shotobjid);
		A = ObjMove_GetAngle(shotobjid);
		if(X<=dX-1 || X>=dX+1){
			ObjMove_SetAngle(shotobjid, 180-A);
		}	
		if(Y<=dY-1 || Y>=dY+1){	
			ObjMove_SetAngle(shotobjid, 360-A);
		}
		yield;
	}
}

task ObjShot_AddCollisionB1(shotobjid, radius){
	let X = ObjRender_GetX(shotobjid);
	let Y = ObjRender_GetY(shotobjid);
	let A = ObjMove_GetAngle(shotobjid);
	let barray = GetShotIdInCircleA2(X, Y, radius, TARGET_ENEMY);
	while(!Obj_IsDeleted(shotobjid)){
		X = ObjRender_GetX(shotobjid);
		Y = ObjRender_GetY(shotobjid);
		A = ObjMove_GetAngle(shotobjid);
		barray = GetShotIdInCircleA2(X, Y, radius, TARGET_ENEMY);
		if(length(barray)>0){
			let b = barray[0];
			let dX = ObjRender_GetX(b);
			let dY = ObjRender_GetY(b);
			if(X<=dX-1 || X>=dX+1){
				ObjMove_SetAngle(shotobjid, 180-A);
			}
			if(Y<=dY-1 || Y>=dY+1){	
				ObjMove_SetAngle(shotobjid, 360-A);
			}
		}
		yield;
	}
}

task ObjShot_AddCollisionB2(shotobjid, radius){
	let X = ObjRender_GetX(shotobjid);
	let Y = ObjRender_GetY(shotobjid);
	let A = ObjMove_GetAngle(shotobjid);
	let barray = GetShotIdInCircleA2(X, Y, radius, TARGET_ENEMY);
	let blength = length(barray);
	while(!Obj_IsDeleted(shotobjid)){
		X = ObjRender_GetX(shotobjid);
		Y = ObjRender_GetY(shotobjid);
		A = ObjMove_GetAngle(shotobjid);
		barray = GetShotIdInCircleA2(X, Y, radius, TARGET_ENEMY);
		blength = length(barray);
		if(blength>0){
			ascent (i in 0..blength){
				let b = barray[i];
				let dX = ObjRender_GetX(b);
				let dY = ObjRender_GetY(b);
				if(X<=dX-1 || X>=dX+1){
					ObjMove_SetAngle(shotobjid, 180-A);
					ObjMove_SetAngle(b, 180+(180-A));
				}
				if(Y<=dY-1 || Y>=dY+1){	
					ObjMove_SetAngle(shotobjid, 180-A);
					ObjMove_SetAngle(b, 180+(180-A));
				}
			}
		}
		yield;
	}
}

task TestSound(objid){
	while(!Obj_IsDeleted(objid)){yield;}
	PlaySound("timestop");
}

task ObjEnemy_OnHitBombA1(objid){
	if(quality<=1){return;}
	let hp = ObjEnemy_GetInfo(objid, INFO_LIFE);
	let hit = 0;
	while(Obj_IsDeleted(objid) == false){
		if(IsPlayerSpellActive == true){
			if(hp > ObjEnemy_GetInfo(objid, INFO_LIFE)){hit++; hp = ObjEnemy_GetInfo(objid, INFO_LIFE);}else{hp = ObjEnemy_GetInfo(objid, INFO_LIFE);}
			if(hit>7-quality){loop(quality*2){CreateEffect(ObjMove_GetX(objid), ObjMove_GetY(objid));} hit = 0;}
		}else{hit = 0;}
		yield;
	}
	task CreateEffect(deX, deY){
		let angZ = rand(0,360);
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.60);
		ObjPrim_SetTexture(obj, img_effect);
		ObjSprite2D_SetSourceRect(obj, 64, 16, 129, 80);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj, deX, deY, 0);
		
		let alpha = 205;
		let scale = 0.25;
		let scaleinc = rand(0.35, 0.45);
		let randX = rand(-500, 500);
		let randY = rand(-500, 500);
		let randspin = rand(6,10);
		while(Obj_IsDeleted(obj)==false && scale>0 && alpha>0){
			scaleinc += -0.05;
			scale += max(-0.05, scaleinc);
			alpha += -0.1;
			deX += randX/100-scaleinc;
			deY += randY/100-scaleinc;
			angZ += randspin;
			
			ObjRender_SetPosition(obj, deX, deY, 0);
			ObjRender_SetAngleZ(obj, angZ);
			ObjRender_SetAlpha(obj, alpha);
			ObjRender_SetScaleXYZ(obj, scale, scale, scale);
			
			yield;
		}
		Obj_Delete(obj);
}

}

task ImageOverImageA1(obj, path, InX, InY, radset){
	let countVertex = 64;
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, countVertex);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	ObjRender_SetAlpha(obj, 255);
	Obj_SetRenderPriority(obj, 0.3);
	ObjPrim_SetTexture(obj, path);
	ascent(iVert in 0..countVertex){
		let angle = (360 / (countVertex - 1) * iVert);
		let x = InX+radset*cos(angle);
		let y = InY+radset*sin(angle);
		ObjPrim_SetVertexUVT(obj, iVert, x, y);	
		x = radset*cos(angle);
		y = radset*sin(angle);
		ObjPrim_SetVertexPosition(obj, iVert , x, y, 0);
	}
}

task SetNewImageRender(obj, InX, InY, radset){
	let countVertex = 64;
	ascent(iVert in 0..countVertex){
		let angle = (360 / (countVertex - 1) * iVert);
		let x = InX+radset*cos(angle);
		let y = InY+radset*sin(angle);
		ObjPrim_SetVertexUVT(obj, iVert, x, y);	
		x = radset*cos(angle);
		y = radset*sin(angle);
		ObjPrim_SetVertexPosition(obj, iVert , x, y, 0);
	}
}

//Animation

//top left fairies 42x38 grid
//top right fairies 48x48 grid
//bottom 4 basic color fairies 32x32 grid
//bottom right; very bottom fairies 64x64 grid

task AnimateFairyA1(objID, presetColor){

	let anim_count = 0;
	let anim_type = 0;
	
	let xoffset = 0;
	let yoffset = 0;
	
	if(presetColor=="blue"){yoffset = 321}
	if(presetColor=="red"){yoffset = 353}
	if(presetColor=="green"){yoffset = 385}
	if(presetColor=="yellow"){yoffset = 417}
	
	loop{
		if(ObjMove_GetSpeed(objID) == 0){
			if(anim_type == 1){
				anim_type=2;
				anim_count = 0;
			}
		}
		if(ObjMove_GetSpeed(objID) > 3){
			if(anim_type != 1){
				anim_count = 0;
				anim_type = 1;
			}
		}
		if(CheckDirection(objID, "right") == true){ObjRender_SetScaleXYZ(objID, 1, 1, 1)}
		if(CheckDirection(objID, "left") == true){ObjRender_SetScaleXYZ(objID, -1, 1, 1)}
		//if(CheckDirection(objID, "none") == true){ObjRender_SetScaleXYZ(objID, 1, 1, 1)}
		
		if(anim_type==0){
			if(anim_count == 0){ObjSprite2D_SetSourceRect(objID, 0, yoffset, 32, yoffset+32);}
			if(anim_count == 5){ObjSprite2D_SetSourceRect(objID, 32, yoffset, 64, yoffset+32);}
			if(anim_count == 10){ObjSprite2D_SetSourceRect(objID, 64, yoffset, 96, yoffset+32);}
			if(anim_count == 15){ObjSprite2D_SetSourceRect(objID, 96, yoffset, 128, yoffset+32);}
			if(anim_count == 20){ObjSprite2D_SetSourceRect(objID, 64, yoffset, 96, yoffset+32);}
			if(anim_count == 25){ObjSprite2D_SetSourceRect(objID, 32, yoffset, 64, yoffset+32);}
			if(anim_count == 29){anim_count = 4;}
		}
		if(anim_type==1){
			if(anim_count == 0){ObjSprite2D_SetSourceRect(objID, 128, yoffset, 160, yoffset+32);}
			if(anim_count == 4){ObjSprite2D_SetSourceRect(objID, 160, yoffset, 192, yoffset+32);}
			if(anim_count == 8){ObjSprite2D_SetSourceRect(objID, 192, yoffset, 224, yoffset+32);}
			if(anim_count == 12){ObjSprite2D_SetSourceRect(objID, 224, yoffset, 256, yoffset+32);}
			if(anim_count == 16){ObjSprite2D_SetSourceRect(objID, 256, yoffset, 288, yoffset+32);}
			if(anim_count == 20){ObjSprite2D_SetSourceRect(objID, 288, yoffset, 320, yoffset+32);}
			if(anim_count == 24){ObjSprite2D_SetSourceRect(objID, 320, yoffset, 352, yoffset+32);}
			if(anim_count == 28){ObjSprite2D_SetSourceRect(objID, 352, yoffset, 384, yoffset+32);}
			if(anim_count == 31){anim_count = 11;}
		}
		if(anim_type==2){
			if(anim_count == 0){ObjSprite2D_SetSourceRect(objID, 224, yoffset, 256, yoffset+32);}
			if(anim_count == 3){ObjSprite2D_SetSourceRect(objID, 192, yoffset, 224, yoffset+32);}
			if(anim_count == 6){ObjSprite2D_SetSourceRect(objID, 160, yoffset, 192, yoffset+32);}
			if(anim_count == 9){ObjSprite2D_SetSourceRect(objID, 128, yoffset, 160, yoffset+32);}
			if(anim_count == 12){anim_count = 0;anim_type=0;}
		}
		
	
		ObjSprite2D_SetDestCenter(objID);
		anim_count++;
		yield;
	}
}

task AnimateBossA1(objID){
	//General Pre MoF
	let anim_count = 0;
	let anim_type = 0;
	
	let xoffset = 0;
	let yoffset = 0;
	
	let r = 7; // Frames yielded before moving to next frame
	let m = -6; // Initial Position - Movement Up/down 
	let x = 64; // X grid
	let y = 80; // Y grid
	
	MoveBoss(1, 0.01, 0.325);
	
	while(!Obj_IsDeleted(objID)){
		if(ObjMove_GetSpeed(objID) == 0){
			if(anim_type == 1){
				anim_count = 0;
				anim_type = 2;
			}
		}
		if(ObjMove_GetSpeed(objID) > 0){
			if(anim_type == 0){
				anim_count = 0;
				anim_type = 1;
			}
		}
		
		if(CheckDirection(objID, "right") == true){ObjRender_SetScaleXYZ(objID, 1, 1, 1)}
		if(CheckDirection(objID, "left") == true){ObjRender_SetScaleXYZ(objID, -1, 1, 1)}
		
		
		if(anim_type==0){ //Idle
			if(anim_count == 0){ObjSprite2D_SetSourceRect(objID, 0, yoffset, x, yoffset+y);}
			if(anim_count == r){ObjSprite2D_SetSourceRect(objID, x, yoffset, x*2, yoffset+y);}
			if(anim_count == r*2){ObjSprite2D_SetSourceRect(objID, x*2, yoffset, x*3, yoffset+y);}
			if(anim_count == r*3){ObjSprite2D_SetSourceRect(objID, x*3, yoffset, x*4, yoffset+y);}
			if(anim_count == r*4){ObjSprite2D_SetSourceRect(objID, x*3, yoffset, x*4, yoffset+y);}
			if(anim_count == r*5){ObjSprite2D_SetSourceRect(objID, x*2, yoffset, x*3, yoffset+y);}
			if(anim_count == r*6){ObjSprite2D_SetSourceRect(objID, x, yoffset, x*2, yoffset+y);}
			if(anim_count >= r*7-1){anim_count = -1;}
		}
		if(anim_type==1){ //Moving
			if(anim_count == 0){ObjSprite2D_SetSourceRect(objID, 0, yoffset+y, x, yoffset+y*2);}
			if(anim_count == r){ObjSprite2D_SetSourceRect(objID, x, yoffset+y, x*2, yoffset+y*2);}
			if(anim_count == r*2){ObjSprite2D_SetSourceRect(objID, x*2, yoffset+y, x*3, yoffset+y*2);}
			if(anim_count == r*3){ObjSprite2D_SetSourceRect(objID, x*3, yoffset+y, x*4, yoffset+y*2);}
			if(anim_count >= r*4-1){anim_count = r*3-1;}
		}
		if(anim_type==2){ //Moving to idle
			if(anim_count == 0){ObjSprite2D_SetSourceRect(objID, x*3, yoffset+y, x*4, yoffset+y*2);}
			if(anim_count == r){ObjSprite2D_SetSourceRect(objID, x*2, yoffset+y, x*3, yoffset+y*2);}
			if(anim_count == r*2){ObjSprite2D_SetSourceRect(objID, x, yoffset+y, x*2, yoffset+y*2);}
			if(anim_count == r*3){ObjSprite2D_SetSourceRect(objID, 0, yoffset+y, x, yoffset+y*2);}
			if(anim_count == r*4){anim_type=0; anim_count=0;}
		}
		
		ObjSprite2D_SetDestRect(objID, -x/2, -y/2+m, x/2, y/2+m);
		if(IsTimeStopped==false){anim_count++;}
		yield;
	}
	task MoveBoss(type, a, b){
		let ax2 = a;
		let bx2 = b;
		let obj_sizeset = 0;
		let sizeinc = 0;
		while(!Obj_IsDeleted(objID)){
			if(IsTimeStopped == false){
				if(obj_sizeset==0){sizeinc+=ax2}
				if(obj_sizeset==1){sizeinc-=ax2}		
				if(sizeinc<-bx2){obj_sizeset=0}
				if(sizeinc>bx2){obj_sizeset=1}
		
				m+=sizeinc;
			}
			yield;
		}	
	}
}




function CheckDirection(checkid, direc){
	let direction = false;
	let enemyang = absolute(ObjMove_GetAngle(checkid));
	let enemyspd = absolute(ObjMove_GetSpeed(checkid));
	
	
	while(enemyang>360){
		enemyang = enemyang-360;
	}

	if(enemyspd > 0){
		if(direc=="right"){
			if(enemyang > 270 || enemyang-270 < 90){
				direction=true;
			}
		}
		if(direc=="left"){
			if(enemyang < 270 && enemyang > 90){
				direction=true;
			}
		}
	}
	if(direc=="none"){
		if(enemyspd == 0){
			direction=true;
		}
	}
	
	return direction;
}

function CheckOutsideScreen(objectID, distance){
	return ObjRender_GetX(objectID)>GetStgFrameWidth+distance||ObjRender_GetX(objectID)<-distance||
		ObjRender_GetY(objectID)>GetStgFrameHeight+distance||ObjRender_GetY(objectID)<-distance;
}

function CheckOutsideScreenA2(x, y, distance){
	return x>GetStgFrameWidth+distance||x<-distance||y>GetStgFrameHeight+distance||y<-distance;
}

function DigitToArray(digit, count){
	let res = [];
	digit = truncate(digit);

	loop{
		let tnum = truncate(digit % 10);
		digit /= 10;
		res = [tnum] ~ res;
		if(truncate(digit) == 0){break;}
	}

	loop(max(0, count - length(res))){
		res = [0] ~ res;
	}

	return res;
}

function GetNumSize(value){
	let numsize = 1;
	value = truncate(value);
	if(value>=10&&value<100){numsize = 2;}
	if(value>=100&&value<1000){numsize = 3;}
	if(value>=1000&&value<10000){numsize = 4;}
	if(value>=10000&&value<100000){numsize = 5;}
	if(value>=100000&&value<1000000){numsize = 6;}
	if(value>=1000000&&value<10000000){numsize = 7;}
	if(value>=10000000&&value<100000000){numsize = 8;}
	if(value>=100000000&&value<1000000000){numsize = 9;}
	if(value>=1000000000&&value<10000000000){numsize = 10;}
	if(value>=10000000000&&value<100000000000){numsize = 11;}
	if(value>=1000000000000){numsize = 12;}
	return numsize;
}

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

function AngleToBoss(x, y){
	return atan2(EnemyY - y, EnemyX - x);
}

function GetAnyKeyStateA1(type){
	let skck = false;
	if(GetVirtualKeyState(VK_LEFT) == type){skck=true;}
	if(GetVirtualKeyState(VK_RIGHT) == type){skck=true;}
	if(GetVirtualKeyState(VK_UP) == type){skck=true;}
	if(GetVirtualKeyState(VK_DOWN) == type){skck=true;}
	return skck;
}

function IsAllKeysFree{
	let skck = false;
	if(GetVirtualKeyState(VK_LEFT) == KEY_FREE &&
	GetVirtualKeyState(VK_RIGHT) == KEY_FREE &&
	GetVirtualKeyState(VK_UP) == KEY_FREE &&
	GetVirtualKeyState(VK_DOWN) == KEY_FREE){skck=true;}
	return skck;
}

task FinalizeSpell{
	EnemyDead = true;
	PlaySound("spellfinal");
	Obj_Delete(Enemy);
	ClearBullets(EnemyX, EnemyY, TYPE_ITEM, 30, 10, 500, 0);
	loop(argument/4+10){
		CreateItemA1(ITEM_POINT_S, EnemyX+rand(-60, 60), EnemyY+rand(-60, 60), rand(360, 3600));
		CreateItemA1(ITEM_POWER_S, EnemyX+rand(-60, 60), EnemyY+rand(-60, 60), 0.02);
	}
}

task FinalizePlural(FinalX, FinalY){
	EnemyDead = true;
	let finalframe = 0;

	ObjMove_SetDestAtWeight(Enemy, FinalX-16, FinalY-12, 130, 1);
	ExplosionA1(FinalX, FinalY, 0, 0, 0);	
	loop(quality*20){ExplosionA2(FinalX, FinalY, rand(-360, 360), rand(-360, 360), rand(-360, 360), rand(1, 3));}
	ScreenShakeA1(45,24);
	ClearBullets(FinalX, FinalY, TYPE_ITEM, 30, 10, 500, 0);
	PlaySound("death");
	loop(100){
		if(finalframe>6){
			loop(quality+1){ExplosionA2(FinalX, FinalY, rand(-360, 360), rand(-360, 360), rand(-360, 360), rand(2, 5));}
			finalframe = 0;
			PlaySound("smbullet");
		}
		finalframe++;
		ScreenShakeA1(4,12);
		yield;
	}
	
	PlaySound("death");
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	loop(argument/2){
		CreateItemA1(ITEM_POINT_S, FinalX+rand(-60, 60), FinalY+rand(-60, 60), rand(360, 3600));
		CreateItemA1(ITEM_POWER_S, FinalX+rand(-60, 60), FinalY+rand(-60, 60), 0.15);
		ExplosionA2(FinalX, FinalY, rand(-360, 360), rand(-360, 360), rand(-360, 360), rand(1, 7));}
	ScreenShakeA1(30,32);
	ExplosionA1(FinalX, FinalY, 0, 0, 0);
	SetCommonData("StarX1", -400);
	SetCommonData("StarY1", -400);
	Obj_Delete(Enemy);
}

task FinalizeFairy(FinalX, FinalY, expcolor){
	if(CheckOutsideScreenA2(FinalX, FinalY, 32)){return;}
	let r = 128;
	let g = 128;
	let b = 128;
	if(expcolor=="blue"){r=50;g=84;b=255}
	if(expcolor=="green"){r=0;g=238;b=0}
	if(expcolor=="red"){r=255;g=102;b=0}
	if(expcolor=="yellow"){r=255;g=238;b=0}
	loop(max(1,quality)){ExplosionB1(FinalX, FinalY, expcolor, rand(-70, 70), rand(-70, 70), rand(-40, 40));}
	loop(quality*2){ExplosionB2(FinalX, FinalY, r, g, b, rand(1, 3));}
	PlaySound("death2");
}


