let playerAngle=GetAngleToPlayer(GetPlayerObjectID);
#include"./Lib_Files.dnh"
#include"./lib_sfx.txt"
#include"./Obj_Charge.txt"

//Include "./Cutin.txt"
//Include "./lib_BossAuraEffect.txt"
//Character Name
let Player = GetPlayerObjectID;
let def_diff = 1; // 1 easy 2 normal 3 hard 4 abnormal
let def_lang = 1; // 0 spanish 1 english
let def_eff = 2; // 0 all 1 minimum 2 none
let defchar = 0; // 0 Gusano 1 Lapros

let perfects = 0;
let perfectsB = 0;

task name(text,x,y){
InstallFont(GetCurrentScriptDirectory ~ "system/Russell Square Regular.ttf");
let objText = ObjText_Create();
ObjText_SetText(objText,text);
ObjText_SetFontType(objText,"Russell Square Regular");
ObjText_SetFontSize(objText, 12);
ObjText_SetFontBold(objText, false); //Negrita
ObjText_SetFontColorTop(objText, 0, 254, 0); //Color parte arriba
ObjText_SetFontColorBottom(objText, 0, 254, 0); // = parte abajo
ObjText_SetFontBorderType(objText, BORDER_FULL); //Borde, los otros son BORDER_FULL y BORDER_SHADOW
ObjText_SetFontBorderColor(objText,0, 0, 0); // color del borde
ObjText_SetFontBorderWidth(objText, 1); // ancho del borde
ObjText_SetMaxWidth(objText,348); //ancho max
ObjText_SetMaxHeight(objText,50); // alto max
Obj_SetRenderPriorityI(objText, 79); //prioridad
ObjRender_SetX(objText, x); //x
ObjRender_SetY(objText, y-10); //y
while(!Obj_IsDeleted(Enemy)){
yield; 
 }
Obj_Delete(objText);

}

function getAtanAngle(obj,obj2){
	let angle=atan2(ObjMove_GetY(obj2)-ObjMove_GetY(obj),ObjMove_GetX(obj2)-ObjMove_GetX(obj));
	return angle;
}
// en caso de multi-idioma, 0= Español/Spanish, 1= ingles/english
function GetLanguage{
return GetAreaCommonData("Config", "Idioma",def_lang);
}

function GetDifficulty{
return GetAreaCommonData("GAMEDATA","Dificultad",def_diff);
}

//Plays SE
function SE2(file){
LoadSound(file);
PlaySE(file);
}

task LoadSounds{
/*
let _accept = GetCurrentScriptDirectory ~ "../sfx/accept.wav";
let _boom00 = GetCurrentScriptDirectory ~ "../sfx/boom00.wav";
let _cancel = GetCurrentScriptDirectory ~ "../sfx/cancel.wav";
let _caution = GetCurrentScriptDirectory ~ "../sfx/caution.wav";
let _charge00 = GetCurrentScriptDirectory ~ "../sfx/charge00.wav";
let _enep = GetCurrentScriptDirectory ~ "../sfx/enep.wav";
let _kira00 = GetCurrentScriptDirectory ~ "../sfx/kira00.wav";
let _kira01 = GetCurrentScriptDirectory ~ "../sfx/kira01.wav";
let _kira02 = GetCurrentScriptDirectory ~ "../sfx/kira02.wav";
let _kira03 = GetCurrentScriptDirectory ~ "../sfx/kira03.wav";
let _laser = GetCurrentScriptDirectory ~ "../sfx/laser.wav";
let _laser2 = GetCurrentScriptDirectory ~ "../sfx/laser2.wav";
let _laser3 = GetCurrentScriptDirectory ~ "../sfx/laser3.wav";
let _select = GetCurrentScriptDirectory ~ "../sfx/select.wav";
let _spark = GetCurrentScriptDirectory ~ "../sfx/spark.wav";
let _spell = GetCurrentScriptDirectory ~ "../sfx/spell.wav";
let _tan00 = GetCurrentScriptDirectory ~ "../sfx/tan00.wav";
let _tan01 = GetCurrentScriptDirectory ~ "../sfx/tan01.wav";
let _tan02 = GetCurrentScriptDirectory ~ "../sfx/tan02.wav";
let _tan03 = GetCurrentScriptDirectory ~ "../sfx/tan03.wav";
let _tan04 = GetCurrentScriptDirectory ~ "../sfx/tan04.wav";
let _tan05 = GetCurrentScriptDirectory ~ "../sfx/tan05.wav";
let _timeout = GetCurrentScriptDirectory ~ "../sfx/timeout.wav";
let _timeout2 = GetCurrentScriptDirectory ~ "../sfx/timeout2.wav";
let _warp = GetCurrentScriptDirectory ~ "../sfx/warp.wav";

let _Gkira = GetCurrentScriptDirectory ~ "../sfx/g2314_sfx/se_kira.wav";
let _Glaser = GetCurrentScriptDirectory ~ "../sfx/g2314_sfx/se_laser.wav";
let _Gplayerdead = GetCurrentScriptDirectory ~ "../sfx/g2314_sfx/se_playerdead.wav";
let _Gtan = GetCurrentScriptDirectory ~ "../sfx/g2314_sfx/se_tan.wav";
let _Gtan2 = GetCurrentScriptDirectory ~ "../sfx/g2314_sfx/se_tan2.wav";
let _Gtan3 = GetCurrentScriptDirectory ~ "../sfx/g2314_sfx/se_tan3.wav";
*/
accept = SoundSFX(_accept);
boom00 = SoundSFX(_boom00);
cancel = SoundSFX(_cancel);
caution = SoundSFX(_caution);
 charge00 = SoundSFX(_charge00);
 enep = SoundSFX(_enep);
 kira00 = SoundSFX(_kira00);
 kira01 = SoundSFX(_kira01);
 kira02 = SoundSFX(_kira02);
 kira03 = SoundSFX(_kira03);
 laser = SoundSFX(_laser);
 laser2 = SoundSFX(_laser2);
 laser3 = SoundSFX(_laser3);
 select = SoundSFX(_select);
 spark = SoundSFX(_spark);
 spell = SoundSFX(_spell);
 tan00 = SoundSFX(_tan00);
 tan01 = SoundSFX(_tan01);
 tan02 = SoundSFX(_tan02);
 tan03 = SoundSFX(_tan03);
 tan04 = SoundSFX(_tan04);
 tan05 = SoundSFX(_tan05);
 timeout = SoundSFX(_timeout);
 timeout02 = SoundSFX(_timeout2);
 warp = SoundSFX(_warp);
 life = SoundSFX(_life);
 nuclear = SoundSFX(_nuclear);

 Gkira = SoundSFX(_Gkira);
 Glaser = SoundSFX(_Glaser);
 Gplayerdead = SoundSFX(_Gkira);
 Gtan = SoundSFX(_Gtan);
 Gtan2 = SoundSFX(_Gtan2);
 Gtan3 = SoundSFX(_Gtan3);
}


task SE(path){
let obj = ObjSound_Create();
    ObjSound_Load(obj,path);
    ObjSound_SetSoundDivision(obj, SOUND_SE);
    ObjSound_SetLoopTime(obj, 0,300);
	ObjSound_SetRestartEnable(obj,true);
    ObjSound_SetVolumeRate(obj,GetAreaCommonData("Config", "SFXVolume", 95));
    ObjSound_Play(obj);
}

        function GetX{
         return ObjMove_GetX(Enemy)
         }
         function GetY{
         return ObjMove_GetY(Enemy)
         }
         function GetCenterX{
         return GetStgFrameWidth/2
         }
         function GetCenterY{
         return GetStgFrameHeight/2
         }
		 
//Shoot Shape

function ShootShapeA(spawnX, spawnY, size, v, angle, num, bside, graphic, delay) {
	ascent(i in 0..num) {
		let sx = spawnX+cos(angle+i*360/num); 
		let sy = spawnY+sin(angle+i*360/num); 
		let sxN = spawnX+cos(angle+(i+1)*360/num); 
		let syN = spawnY+sin(angle+(i+1)*360/num);
		let a = atan2(sy-spawnY,sx-spawnX);
		CreateShotA1(spawnX+cos(angle+i*360/num)*size*(((sx-spawnX)^2+(sy-spawnY)^2)^0.5), spawnY+sin(angle+i*360/num)*size*(((sx-spawnX)^2+(sy-spawnY)^2)^0.5), v, angle, graphic, delay);
		ascent(j in 0..bside) {
			let toAngle = atan2(syN-sy,sxN-sx); 
			let toDist = (((sxN-sx)^2+(syN-sy)^2)^0.5); 
			let sx2 = sx+toDist/bside*j*cos(toAngle); 
			let sy2 = sy+toDist/bside*j*sin(toAngle);
			CreateShotA1(spawnX+cos(atan2(sy2-spawnY,sx2-spawnX))*size*(((sx2-spawnX)^2+(sy2-spawnY)^2)^0.5), spawnY+sin(atan2(sy2-spawnY,sx2-spawnX))*size*(((sx2-spawnX)^2+(sy2-spawnY)^2)^0.5), v, angle, graphic, delay);
		}
	}
}
function ShootShapeB(spawnX, spawnY, v, angle, num, bside, graphic, delay) {
	ascent(i in 0..num) {
		let sx = spawnX+cos(angle+i*360/num); let sy = spawnY+sin(angle+i*360/num); let sxN = spawnX+cos(angle+(i+1)*360/num); let syN = spawnY+sin(angle+(i+1)*360/num);
		CreateShotA1(spawnX, spawnY, v*(((sx-spawnX)^2+(sy-spawnY)^2)^0.5), atan2(sy-spawnY,sx-spawnX), graphic, delay);
		ascent(j in 0..bside) {
			let toAngle = atan2(syN-sy,sxN-sx); let toDist = (((sxN-sx)^2+(syN-sy)^2)^0.5); let sx2 = sx+toDist/bside*j*cos(toAngle); let sy2 = sy+toDist/bside*j*sin(toAngle);
			CreateShotA1(spawnX, spawnY, v*(((sx2-spawnX)^2+(sy2-spawnY)^2)^0.5), atan2(sy2-spawnY,sx2-spawnX), graphic, delay);
		}
	}
}

task SetDamageRateAtFrame(obj, shot,bomb,frame){//Talos
   ObjEnemy_SetDamageRate(obj, 0,0);
   let time=frame;
   while(IsPlayerSpellActive){ //Prevents Bomb Damage from previous attack
     time--;
     yield;
   }
   while(time>0){
     time--;
     yield;
   }
   ObjEnemy_SetDamageRate(obj,shot,bomb);
 }
 
 //Invoca a un enemigo normal
 function CreateEnemyA1(x,y,type){
let pig = ObjEnemy_Create(OBJ_ENEMY);
let acto;
ObjEnemy_Regist(pig);
ObjMove_SetPosition(pig,x,y);

return pig;
}

//Efecto de carga

task nTestCharge(x,y,flame,r1,g1,b1) //This is the Task youll be using for the effect!!
{
if(GetAreaCommonData("Config", "Effects", def_eff) < 2){	
	ascent(i in 0..5){
		lotemasLite(x+rand(-5,5),y+rand(-15,15),1*i,flame,r1,g1,b1,(1*i)/1); //Creates the Color Charge effect
		lotemas(x+rand(-5,5),y+rand(-15,15),1*i,flame,250,250,250,(1*i)); //Creates the Black charge effect
	}
	loop(flame-30){ //No dot effects will be spawned if the charge times is less then or equal to 30 frames.
		loop(rand(1,3)){
			oltahmas(x+rand(-5,5),y+rand(-5,5),30,r1,g1,b1); //Creates Dots of black and the designated colors randomly that fly in at the given position.
		}
		yield;
	}
	}
}

task lotemas(x,y,Edscale,flame,r1,g1,b1,fractal)
{
	let imgEff = ChargeEffNeito1;
	let scale = Edscale;
	let alpha = 0;
	let angle = rand(0,360);
	let angleR = rand(-3,3); 

	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
	ObjPrim_SetTexture(obj, imgEff);
	Obj_SetRenderPriority(obj, 0.23);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestRect(obj, -128, -128, 128, 128);
	ObjRender_SetAlpha(obj, 255);
	ObjRender_SetPosition(obj, x, y, 0);
	ascent(i in 0 .. flame){
		//if(Obj_IsDeleted(bossObj)==true){Obj_Delete(obj);}
		ObjRender_SetColor(obj, alpha*r1, alpha*g1, alpha*b1);
		ObjRender_SetScaleXYZ(obj,scale,scale,1.0);
		ObjRender_SetAngleXYZ(obj,0,0,angle);
		angle+=angleR;
		scale-= Edscale/flame;
		alpha+= (1/fractal)/(flame/Edscale);
		yield;
	}
	Obj_Delete(obj);
}
task lotemasLite(x,y,Edscale,flame,r1,g1,b1,fractal)
{
	let imgEff = ChargeEffNeito1;
	let scale = Edscale;
	let alpha = 0;
	let angle = rand(0,360);
	let angleR = rand(-3,3); 

	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	ObjPrim_SetTexture(obj, imgEff);
	Obj_SetRenderPriority(obj, 0.23);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestRect(obj, -128, -128, 128, 128);
	ObjRender_SetAlpha(obj, 255);
	ObjRender_SetPosition(obj, x, y, 0);
	ascent(i in 0 .. flame){
		//if(Obj_IsDeleted(bossObj)==true){Obj_Delete(obj);}
		ObjRender_SetColor(obj, alpha*r1, alpha*g1, alpha*b1);
		ObjRender_SetScaleXYZ(obj,scale,scale,1.0);
		ObjRender_SetAngleXYZ(obj,0,0,angle);
		angle+=angleR;
		scale-= Edscale/flame;
		alpha+= (1/fractal)/(flame/Edscale);
		yield;
	}
	Obj_Delete(obj);
}
task oltahmas(x,y,flame,r1,g1,b1)
{
	let imgEff = ChargeEffNeito2;
	let scaleStandard = rand(0.25,1);
	let scale = scaleStandard;
	let alpha = 0;
	let alphaDun = rand(0.1,1);

	let accer = rand(0.3, 0.4);
	let angle = rand(0, 360);
	let r = accer*(flame^2)/2;
	x += r*cos(angle);
	y += r*sin(angle);

	let ToF=0;
	ToF=rand(-1,1);

	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	if(ToF>0){
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	}else if(ToF<0){
		ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
	}
	ObjPrim_SetTexture(obj, imgEff);
	Obj_SetRenderPriority(obj, 0.23);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 64);
	ObjSprite2D_SetDestRect(obj, -32, -32, 32, 32);
	ObjRender_SetPosition(obj, x, y, 0);
	ascent(i in 0 .. flame){
		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetAlpha(obj, 255*alpha);
		//if(Obj_IsDeleted(bossObj)==true){Obj_Delete(obj);}
		ObjRender_SetColor(obj, alpha*r1, alpha*g1, alpha*b1);
		ObjRender_SetScaleXYZ(obj,scale,scale,1.0);
		x -= accer*i*cos(angle);
		y -= accer*i*sin(angle);
		if(alpha<alphaDun){
			alpha+= alphaDun/5;
		}
		scale-=scaleStandard/flame;
		yield;
	}
	Obj_Delete(obj);
}
/////////////////////////////////////////////////////////////////////////////
function GetDistance(x1,y1,x2,y2){
     return(((x2-x1)^2+(y2-y1)^2)^(1/2));
 }
 
 let DIR = GetCurrentScriptDirectory;



 //Distorsion effect
 let Dist_red		 = [224, 80, 64];
let Dist_orange		 = [224,128, 64];
let Dist_yellow		 = [224,224, 64];
let Dist_green		 = [ 64,224, 80];
let Dist_cyan		 = [ 32,224,196];
let Dist_blue		 = [ 64, 96,224];
let Dist_purple		 = [224, 32,196];
let Dist_white		 = [128,128,128];

let DistColor_Pattern08 = [
Dist_red,
Dist_orange,
Dist_yellow,
Dist_green,
Dist_cyan,
Dist_blue,
Dist_purple,
Dist_white,
];


task TWaveCircle_Shadertask(objEnemy,c)
{
if(GetAreaCommonData("Config", "Effects", def_eff) == 0){
	let color = DistColor_Pattern08[c];
	let r = color[0];
	let g = color[1];
	let b = color[2];
	
	
	let renderTexture = GetReservedRenderTargetName(0);

	let frame = 0; 
	let baseEffectRadius = 144; 
	let outerFluct = 16; 
	let effectRadius = 0; 


	let priEffectMin = 20; 
	let priEffectMax = 28; 

	

	let frameWidth = GetStgFrameWidth();
	let frameHeight = GetStgFrameHeight();
	let frameLeft = GetStgFrameLeft();
	let frameRight = frameLeft + frameWidth;
	let frameTop = GetStgFrameTop();
	let frameBottom = frameTop + frameHeight;

	blowDummy(priEffectMax);
	
	let objWave = ObjPrim_Create(OBJ_SPRITE_2D); 
	ObjPrim_SetTexture(objWave, renderTexture); 
	ObjSprite2D_SetSourceRect(objWave, frameLeft, frameTop, frameRight, frameBottom);
	ObjSprite2D_SetDestRect(objWave, 0, 0, frameWidth, frameHeight);
	Obj_SetRenderPriorityI(objWave, priEffectMax + 1);

	
	let pathShader = GetCurrentScriptDirectory ~ "SamplePS03_HLSL.txt";
	ObjShader_SetShaderF(objWave, pathShader);
	ObjShader_SetTechnique(objWave, "TecWave");


	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		
		effectRadius = baseEffectRadius + outerFluct * sin(frame*4)*0;

		let enemyX = ObjMove_GetX(objEnemy); 
		let enemyY = ObjMove_GetY(objEnemy); 

	
		RenderToTextureA1(renderTexture, priEffectMin, priEffectMax, true);

		
		ObjShader_SetFloat(objWave, "frame_", frame);
		ObjShader_SetFloat(objWave, "enemyX_", enemyX + frameLeft);
		ObjShader_SetFloat(objWave, "enemyY_", enemyY + frameTop);
		ObjShader_SetFloat(objWave, "waveRadius_", effectRadius);
		ObjShader_SetFloat(objWave, "waveC_R", r);
		ObjShader_SetFloat(objWave, "waveC_G", g);
		ObjShader_SetFloat(objWave, "waveC_B", b);

		frame++;
		yield;
	}
	ObjShader_ResetShader(objWave);
	
	Obj_Delete(objWave);
	ClearInvalidRenderPriority();
	
	task blowDummy(max)
	{
		
		let objShadow = ObjPrim_Create(OBJ_SPRITE_2D); 
		Obj_SetRenderPriorityI(objShadow,max); 
		ObjPrim_SetTexture(objShadow, imgBLACK); 
		ObjRender_SetBlendType(objShadow, BLEND_ADD_RGB);
		ObjSprite2D_SetSourceRect(objShadow, 0, 0, 640, 480); 
		ObjSprite2D_SetDestCenter(objShadow);
		ObjRender_SetScaleXYZ(objShadow, 1.2, 1.2, 0); 
		ObjRender_SetPosition(objShadow, 640/2, 480/2, 0);
		while(!Obj_IsDeleted(objEnemy)){yield;}
		Obj_Delete(objShadow);
	}
	}
}


//F‚ÌÝ’è
let Aura_red	 = [255,  0,  0];
let Aura_orange	 = [255,128,  0];
let Aura_yellow	 = [255,255,  0];
let Aura_green	 = [  0,255,  0];
let Aura_cyan	 = [  0,255,255];
let Aura_blue	 = [  0,  0,255];
let Aura_purple	 = [255,  0,255];
let Aura_white	 = [255,255,255];

let AuraColor_Pattern08 = [
Aura_red,
Aura_orange,
Aura_yellow,
Aura_green,
Aura_cyan,
Aura_blue,
Aura_purple,
Aura_white,
];

let aurascale = 0;
//ƒI[ƒ‰
task TAura(objEnemy,c)
{
if(GetAreaCommonData("Config", "Effects", def_eff) == 0){
	let color = AuraColor_Pattern08[c];
	let r = color[0];
	let g = color[1];
	let b = color[2];
	task auraDraw(n){
		let r2 = color[0];
		let g2 = color[1];
		let b2 = color[2];
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
		let exp = 0; let alp = 0;
		let an = rand(-20,20)*n;
		let scale = 1.35+n/2;

		Obj_SetRenderPriority(obj,0.29);
		ObjPrim_SetTexture(obj,imgBossEfect);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjSprite2D_SetSourceRect(obj,5,68,45,108);
		ObjRender_SetAlpha(obj, alp);
		if(r2==0){r2+=56;}
		if(g2==0){g2+=56;}
		if(b2==0){b2+=56;}
		
		while((exp <= 100))
		{
			if (ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 0){break;}
			ex = ObjMove_GetX(objEnemy);
			ey = ObjMove_GetY(objEnemy);
			ObjSprite2D_SetDestRect(obj,-20,0-min(exp/1.02,22*4),20,0);

			ObjRender_SetScaleXYZ(obj,scale,scale,1);
			ObjRender_SetColor(obj,r2*(alp/205)/4,g2*(alp/205)/4,b2*(alp/205)/4);
			ObjRender_SetPosition(obj,ex+an,ey-7.5-an/5,0);
			ObjRender_SetAlpha(obj, (1-n)*alp*0.75);
			if(exp < 25){alp += 205/5;}
			else if(exp > 50){alp -= 205/6;}

			exp += 5-1;
			yield;
		}
		Obj_Delete(obj);
	}

	task auraC{
		while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
		{	auraDraw(1/3);
			auraDraw(1/4);
			auraDraw(0);
			loop(6){yield;}
		}
	}
	
	task chageDraw_color(Blend_Type){
		let Angle = rand(0,360);

		let rc = 0;
		if(Blend_Type!=BLEND_ALPHA){rc = 64;}


		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);

		let objs = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriority(objs,0.29);
		ObjPrim_SetTexture(objs,imgBossEfect);
		ObjRender_SetBlendType(objs,BLEND_SUBTRACT);
		ObjSprite2D_SetSourceRect(objs,50,68,90,108);
		ObjSprite2D_SetDestRect(objs,-22,-22,22,22);
		ObjRender_SetAngleXYZ(objs,0,0,Angle);
		ObjRender_SetColor(objs,255-r,255-g,255-b);

		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriority(obj,0.29);
		ObjPrim_SetTexture(obj,imgBossEfect);
		ObjRender_SetBlendType(obj,Blend_Type);
		ObjSprite2D_SetSourceRect(obj,50,68,90,108);
		ObjSprite2D_SetDestRect(obj,-20,-20,20,20);
		ObjRender_SetAngleXYZ(obj,0,0,Angle);
		ObjRender_SetColor(obj,r,g,b);

		let scale = 1.82*0.5+2.25*0.5; let alp = 0; let count = 0;
		let an = rand(-15,15)/2;
		let an2 = rand(-15,15)/2;
		while((scale > 0.5))
		{
			if (ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 0){break;}
			ex = ObjMove_GetX(objEnemy);
			ey = ObjMove_GetY(objEnemy);

			ObjRender_SetPosition(obj, ex+cos(Angle)*absolute(an)*0.8, ey+sin(Angle)*absolute(an)*0.8,0);
			ObjRender_SetScaleXYZ(obj,max(scale,1),max(scale,1),1);

			ObjRender_SetAlpha(obj,alp/2.5);

			ObjRender_SetPosition(objs, ex+cos(Angle)*absolute(an)*0.8, ey+sin(Angle)*absolute(an)*0.8,0);
			ObjRender_SetScaleXYZ(objs,max(scale,1),max(scale,1),1);
			ObjRender_SetAlpha(objs,alp/5);
			if(alp<=111){alp += 111/6;}
			scale -= 3.5/45*0.5;
			count += 1;
			yield;
		}
		Obj_Delete(obj);
		Obj_Delete(objs);
	}
	task chageDraw_white{
		let Angle = rand(0,360);

		let rc = 0;

		let r_color = 222;

		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriority(obj,0.30);
		ObjPrim_SetTexture(obj,imgBossEfect);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjSprite2D_SetSourceRect(obj,50,68,90,108);
		ObjSprite2D_SetDestRect(obj,-22,-22,22,22);
		ObjRender_SetAngleXYZ(obj,0,0,Angle);
	//	ObjRender_SetColor(obj,r_color,r_color,r_color);

		let scale = 1.45; let alp = 0; let count = 0;
		let an = rand(-10,10)/2;
		let an2 = rand(-10,10)/2;
		while((scale > 0.5)){
			if (ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 0){break;}
			ex = ObjMove_GetX(objEnemy);
			ey = ObjMove_GetY(objEnemy);
			ObjRender_SetPosition(obj, ex, ey, 0);
			ObjRender_SetAlpha(obj,alp/5*255/r_color);
			ObjRender_SetScaleXYZ(obj,max(scale,1),max(scale,1),1);
			if(alp<=r_color){alp += r_color/6;}
			scale -= 3.5/45*0.5;
			count += 1;
			yield;
		}
		Obj_Delete(obj);
	}
	task chageC{
		let i = 0;
		while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
		{
			chageDraw_color(BLEND_ADD_ARGB);
			chageDraw_white;
			aurascale = min(aurascale+0.2,1.25);i++;
			loop(6){yield;}
		}
	}
	    chageC;
	    auraC;
}
}



let current = GetCurrentScriptDirectory;
let DEBUG = false;
let CutinDifficulty = "";

let Alpha_HUD = [255, 255]; //top, bottom

let NAZRIN = "NAZRIN";
let BYAKUREN = "BYAKUREN";
let KANAKO = "KANAKO";
let MOKOU = "MOKOU";
let AYA = "AYA";
let YABUSAME = "LENEN";

let LENEN = "LENEN";

//If you have any questions or requests, send them to gtbot/TheGtbot (I go by either on different places)
//Version 1.3


task ObjCutin_SetSpellcardS3(SpellName, R, G, B){
	let r = IntToString(R);
	let g = IntToString(G);
	let b = IntToString(B);
	let boss = GetEnemyBossObjectID[0];
	let spells = Obj_GetValueD(boss, "Spellcards", []);
	spells = spells~[[SpellName, r, g, b, "", ""]];
	Obj_SetValue(boss, "Spellcards", spells);
}

task ObjCutin_SetSpellcardS4(SpellName, image, cuttype, R, G, B){
	let r = IntToString(R);
	let g = IntToString(G);
	let b = IntToString(B);
	let boss = GetEnemyBossObjectID[0];
	let spells = Obj_GetValueD(boss, "Spellcards", []);
	spells = spells~[[SpellName, r, g, b, cuttype, image]];
	Obj_SetValue(boss, "Spellcards", spells);
}

task ObjCutin_LaunchS3(type, image, difficulty){
	CutinS3(type, image, difficulty);
}

task CutinS3(Type, mimage, difficulty){
	let spells = Obj_GetValueD(GetEnemyBossObjectID[0], "Spellcards", []);
	let boss = GetEnemyBossObjectID[0];
	let spcount = length(spells);
	CutinDifficulty = difficulty;
	let IsSpellAttackAnimation = false;
	if(!IsCommonDataAreaExists("cutin_History")){
		CreateCommonDataArea("cutin_History");
	}
	LoadCommonDataAreaA1("cutin_History");

	descent(i in 0..spcount){SpellText(6*i, i);}
	SpawnCutinImage(Type, mimage);
	
	
	let delay = 6;
	while(!Obj_IsDeleted(boss)){
		spells = Obj_GetValueD(GetEnemyBossObjectID[0], "Spellcards", []);
		if(length(spells)!=spcount&&delay==0){
			delay = 6;
			SpellText(0, spcount);
			let newtype = spells[spcount][4];
			if(newtype == ""){newtype = Type;}
			SpawnCutinImage(newtype, spells[spcount][5]);
			spcount++;
		}
		delay = max(delay-1, 0);
		yield;
	}
	
	
	
	task FireCutinA1(x, y, angle, ispeed, itime, mspeed, mtime, img){	
		if(IsSpellAttackAnimation){return;}	
		let SpellCutin = CreateSimple2DImageA1(0.29, img);
		ObjRender_SetPosition(SpellCutin, x, y, 0);
		ObjRender_SetAlpha(SpellCutin, 0);
		
		
		
		let len = itime;
		ascent(x in 0..len){
			let mod = x/len;
			let locs = [ObjRender_GetX(SpellCutin), ObjRender_GetY(SpellCutin)];
			ObjRender_SetPosition(SpellCutin, floor(locs[0]+ispeed*cos(angle)), floor(locs[1]+ispeed*sin(angle)), 0);
			
			let alph = min(255, 255*(mod*2));
			ObjRender_SetAlpha(SpellCutin, alph);
			yield;
		}
		
		len = mtime;
		let nx = ObjRender_GetX(SpellCutin);
		let ny = ObjRender_GetY(SpellCutin);
		ascent(x in 0..len){
			nx += mspeed*cos(angle);
			ny += mspeed*sin(angle);
			ObjRender_SetPosition(SpellCutin, floor(nx), floor(ny), 0);
			yield;
		}
		//return;
		len = mtime;
		ascent(x in 0..len){
			let mod = x/len;
			let locs = [ObjRender_GetX(SpellCutin), ObjRender_GetY(SpellCutin)];
			ObjRender_SetPosition(SpellCutin, floor(locs[0]+ispeed*cos(angle)), floor(locs[1]+ispeed*sin(angle)), 0);
			yield;
		}
		Obj_Delete(SpellCutin);
	}

	task FireCutinA2(x, y, alpha, img, details){
		if(IsSpellAttackAnimation){return;}
		//[spd, spdinc, ang, anginc, alphachange, time]
		let SpellCutin = CreateSimple2DImageA1(0.29, img);
		ObjRender_SetPosition(SpellCutin, x, y, 0);
		ObjRender_SetAlpha(SpellCutin, alpha);
		ObjRender_SetScaleXYZ(SpellCutin,0.4,0.4,0);
		
		ascent(i in 0..length(details)){
			let nx = ObjRender_GetX(SpellCutin);
			let ny = ObjRender_GetY(SpellCutin);
			let info = details[i];
			let len = info[5];
			let alphinc = -(alpha-info[4])/len;
			let spdinc = -(info[0]-info[1])/len;
			let mspeed = info[0];
			let cangle = info[2];
			ascent(x in 0..len){
				mspeed+=spdinc;
				cangle+=info[3];
				nx += mspeed*cos(cangle);
				ny += mspeed*sin(cangle);
				ObjRender_SetPosition(SpellCutin, nx, ny, 0);
				yield;
				alpha = min(max(alpha+alphinc, 0), 255);
				ObjRender_SetAlpha(SpellCutin, alpha);
			}
		}
		Obj_Delete(SpellCutin);
	}

	function SpawnCutinImage(type, image){
		//We use another "type" variable (lowercase t) so that
		//spellcards set after the root function is called will play the
		//new set cutin type as opposed to the original one
		// same for image
		if(type == "NAZRIN"){
			FireCutinA2(GetStgFrameWidth+208, GetStgFrameHeight/2-144, 0, image,
			[
				[20.6, 20.6, 158, 0, 255, 20],
				[0.65, 0.65, 158, 0, 255, 90],
				[20.6, 20.6, 158, 0, 255, 20]
			]
			);
			SpellAttackEffect(145);
		}
		else if(type == "KANAKO"){
			FireCutinA2(GetStgFrameWidth+180, GetStgFrameHeight/2-190, 0, image,
			[
				[30, 8, 144, 0, 192, 23],
				[8, 0, 144, 0, 255, 10],
				[0, 2.1, 270, 0, 255, 90],
				[2.1, 2.1, 270, 0, 255, 20],
				[2.1, 1, 270, 0, 0, 20]
			]
			);
			SpellAttackEffect(145);
		}
		else if(type == "BYAKUREN"){
			FireCutinA2(-256, GetStgFrameHeight/2, 0, image,
			[
				[14, 14, 0, 0, 255, 30],
				[0.5, 0.5, 0, 0, 255, 90],
				[14, 14, 0, 0, 0, 30]
			]
			);
			SpellAttackEffect(145);
		}
		else if(type == "LENEN" || type == "YABUSAME"){
			FireCutinA2(GetStgFrameWidth+256, GetStgFrameHeight/2+96, 0, image,
			[
				[32, 1, 182, 0.1, 255, 30],
				[1, 1.25, 180, 14, 255, 10],
				[1.25, 1.75, 315, 0, 255, 80],
				[2, 2.5, 340, -15.75, 192, 10],
				[2.5, 31, 182.5, 0, 0, 20],
			]
			);
			SpellAttackEffect(145);
		}
		else if(type == "AYA"){
			SpellAttackEffect(145);
		}
		else if(type == "MOKOU"){
		}
		else{RaiseError("Not a valid cutin type.");}
	}
	
	task SpellText(delay, num){
		let tspell = spells[num];
		let SpellName = tspell[0];
		let r = atoi(tspell[1]);
		let g = atoi(tspell[2]);
		let b = atoi(tspell[3]);
		
		let Colors = [[r,g,b]];
		
		//These are long-looking common data group names
		let SpellDataAttempt = SpellName~"|"~CutinDifficulty~"|"~GetPlayerID~"|"~"Attempt";
		let SpellDataGet = SpellName~"|"~CutinDifficulty~"|"~GetPlayerID~"|"~"Get";
		//This is actually the common data retrieval
		let SpellValueAttempt = GetAreaCommonData("cutin_History", SpellDataAttempt, 0);
		let SpellValueGet = GetAreaCommonData("cutin_History", SpellDataGet, 0);
		
		
		if(!IsReplay&&!DEBUG&&num==0){
			SpellValueAttempt++;
			SetAreaCommonData("cutin_History", SpellDataAttempt, SpellValueAttempt);
			SaveCommonDataAreaA1("cutin_History");
		}
	
	
		let SpellBG = CreateSimple2DImageA2(0.79+0.01*max(0, 1-num), SpellAttack_img, 0, 0, 255, 31);
		ObjSprite2D_SetDestRect(SpellBG, -224, -12, 32, 20);
		ObjRender_SetPosition(SpellBG, 340, 320+40*num, 0);
		ObjRender_SetAlpha(SpellBG, 0);
		ObjRender_SetColor(SpellBG, Colors[0][0], Colors[0][1], Colors[0][2]);
		
		let SpellText = ObjText_Create;
		ObjText_SetText(SpellText,SpellName);
		ObjText_SetFontSize(SpellText,12);
		ObjText_SetFontColorTop(SpellText,255,255,255);
		ObjText_SetFontColorBottom(SpellText, Colors[0][0], Colors[0][1], Colors[0][2]);
		ObjText_SetFontBorderType(SpellText,BORDER_FULL);
		ObjText_SetFontBorderColor(SpellText,32,32,32);
		ObjText_SetFontBorderWidth(SpellText,1);
		ObjText_SetHorizontalAlignment(SpellText, ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(SpellText, GetStgFrameWidth-24);
		Obj_SetRenderPriority(SpellText, 0.79+0.01*max(0, 1-num));
		ObjRender_SetPosition(SpellText, 0, 320+40*num, 0);
		ObjRender_SetAlpha(SpellText, 0);
		
		
		let SpellInfo = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		let bonus = 0;
		let count = GetNumSize(bonus);
		let scount = max(2, GetNumSize(SpellValueAttempt));
		ObjPrim_SetTexture(SpellInfo, SpellAttack_img);
		ObjRender_SetBlendType(SpellInfo, BLEND_ALPHA);
		Obj_SetRenderPriority(SpellInfo, 0.8);
		ObjRender_SetY(SpellInfo, 36);
		ObjRender_SetAlpha(SpellInfo, 0);
		
		//-------------Introduction--------------------------
		
		loop(delay){yield;}
		let len = 30;
		ascent(i in 0..len){
			let mod = i/len;
			let tmod = min(1, ((i*2)/len));
			ObjRender_SetScaleXYZ(SpellBG, 4-3*mod, 4-3*mod, 1);
			ObjRender_SetAlpha(SpellBG, 255*mod);
			ObjRender_SetX(SpellText, (GetStgFrameWidth-24)*(1-mod));
			//ObjRender_SetScaleXYZ(SpellText, 4-3*tmod, 4-3*tmod, 1);
			ObjRender_SetAlpha(SpellText, 255*tmod);
			yield;
		}
		loop(40){yield;}
		let mov = 0;
		
		if(Type == "MOKOU"){SpellcardDeclareMovement([ObjRender_GetY(SpellText), 48+32*num, 0.175, 9]);loop(60){yield;}}
		else{RegularSpellCardDeclare([ObjRender_GetY(SpellText), 32+32*num, 0.135, 12]);}
		//32 is the offset from the top of the screen
		//If using a system where the lifebar is on the boss rather than the top of the screen, 12 is a good value

		
		loop(delay*0.65){yield;}
		
		ascent(i in 0..80){
			let endspeed = 0.5+i/2.5;
			ObjRender_SetX(SpellBG, ObjRender_GetX(SpellBG)+endspeed);
			ObjRender_SetX(SpellText, ObjRender_GetX(SpellText)+endspeed);
			yield;
		}
		
		Obj_Delete(SpellBG);
		Obj_Delete(SpellText);
		
		function SpellcardDeclareMovement(dest){
			ObjRender_SetY(SpellInfo, 24+dest[1]);
			while(dest[0]>dest[1]){
				dest[0] = ObjRender_GetY(SpellText);
				mov = min(mov+dest[2], (dest[0]-dest[1])/dest[3]+0.125);
				ObjRender_SetY(SpellBG, dest[0]-mov);
				ObjRender_SetY(SpellText, dest[0]-mov);
				yield;
			}
		}
		
		function RegularSpellCardDeclare(dest){
			if(num!=0){Obj_Delete(SpellInfo);}
			SpellcardDeclareMovement(dest);
			ascent(i in 0..20){
				ObjRender_SetAlpha(SpellInfo, 255/20*i);
				DrawScoreBonus;
				yield;
			}
			let timerf = ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_ORGTIMERF);
			let startdiff = timerf-(timerf-5*60);
			while(!Obj_IsDeleted(boss)){
				ObjRender_SetAlpha(SpellBG, Alpha_HUD[0]);
				ObjRender_SetAlpha(SpellText, Alpha_HUD[0]);
				ObjRender_SetAlpha(SpellInfo, Alpha_HUD[0]);
				
			//	let modif = min(1, ((ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMERF))/(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_ORGTIMERF)-startdiff)));
			//	bonus = ((sscore*0.20)+(sscore*((modif)*0.80)));
				DrawScoreBonus;
				yield;
			}
			Obj_Delete(SpellInfo);
			
			if(bonus>=1&&ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMERF)>0){
			//	GotSpellCard(bonus);
			//	AddScore(bonus);
				if(!IsReplay&&!DEBUG&&num==0){
					SpellValueGet++;
					SetAreaCommonData("cutin_History", SpellDataGet, SpellValueGet);
					SaveCommonDataAreaA1("cutin_History");
				}
			}else{
			//	FailedSpellCard;
			}
		}
		sub DrawScoreBonus{
			if(GetPlayerY<128+32*length(spells)){Alpha_HUD[0] = max(Alpha_HUD[0]-10, 85);}else{Alpha_HUD[0] = min(Alpha_HUD[0]+11, 255);}
			
			ObjSpriteList2D_ClearVertexCount(SpellInfo);
				
			ObjSpriteList2D_SetSourceRect(SpellInfo, 0, 48, 128, 60);
			ObjSpriteList2D_SetDestCenter(SpellInfo);
			ObjRender_SetX(SpellInfo, 382-130);
			ObjSpriteList2D_AddVertex(SpellInfo);
			//Bonus Score
			bonus = ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_SPELL_SCORE);
			count = GetNumSize(bonus);
			let listNum = DigitToArray(min(99999999, bonus), count);
			let objScene = GetEnemyBossSceneObjectID;
			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(SpellInfo, 382-94-(8*count) + iObj * 7);
					ObjSpriteList2D_SetSourceRect(SpellInfo, num * 8, 64, (num + 1) * 8, 76);
					ObjSpriteList2D_SetDestCenter(SpellInfo);
					ObjSpriteList2D_AddVertex(SpellInfo);
				}
			}else{
					bonus = 0;
					ObjRender_SetX(SpellInfo, 382-131);
					ObjSpriteList2D_SetSourceRect(SpellInfo, 144, 48, 176, 60);
					ObjSpriteList2D_SetDestCenter(SpellInfo);
					ObjSpriteList2D_AddVertex(SpellInfo);
			}
			//History
			listNum = DigitToArray(SpellValueGet, scount) ~ [10] ~ DigitToArray(SpellValueAttempt, scount);
				
			ascent(iObj in 0 .. scount*2+1){
				let num = listNum[iObj];
				ObjRender_SetX(SpellInfo, 382-58 + iObj * 8);
				ObjSpriteList2D_SetSourceRect(SpellInfo, num * 8, 64, (num + 1) * 8, 76);
				ObjSpriteList2D_SetDestCenter(SpellInfo);
				ObjSpriteList2D_AddVertex(SpellInfo);
			}
		}
	}
	
	task SpellAttackEffect(alphamax){
		if(IsSpellAttackAnimation){return;}
		IsSpellAttackAnimation = true;
		let alpha = 1;
		let GetCenterX = GetStgFrameWidth/2;
		let GetCenterY = GetStgFrameHeight/2;
		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);
		}
		
		loop(15){yield;}
		ascent(i in 0..20){
			alpha = 0.1+alphamax/20*i;
			yield;
		}
		loop(110){yield;}
		descent(i in 0..20){
			alpha = alphamax/20*i;
			yield;
		}
		
		IsSpellAttackAnimation = false;
		
		task Line(mx, my, posinc){
			let objSpellAttack = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjRender_SetBlendType(objSpellAttack, BLEND_ALPHA);
			Obj_SetRenderPriority(objSpellAttack, 0.75);
			ObjPrim_SetTexture(objSpellAttack, img_SpellAttack);
			ObjSprite2D_SetSourceRect(objSpellAttack, 0, 0, 512, 16);
			ObjSprite2D_SetDestRect(objSpellAttack, -256, -8, 256, 8);
			let LineX = 0;
			ObjRender_SetPosition(objSpellAttack, mx, my, 0);
			ObjRender_SetAngleZ(objSpellAttack, -35);
			while(alpha>0){
				LineX += posinc;
				ObjSprite2D_SetSourceRect(objSpellAttack, LineX, 0, 512+LineX, 16);
				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(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 FadeInA1(obj, ftime){
	ascent(i in 0..ftime){
		ObjRender_SetAlpha(obj, 255/ftime*i);
		yield;
	}
}
task FadeInB1(obj, alpha, ftime){
	ascent(i in 0..ftime){
		ObjRender_SetAlpha(obj, alpha/ftime*i);
		yield;
	}
}

task FadeOutA1(obj, ftime){
	descent(i in 0..ftime){
		ObjRender_SetAlpha(obj, 255/ftime*i);
		yield;
	}
}

task FadeOutB1(obj, initalpha, ftime){
	descent(i in 0..ftime){
		ObjRender_SetAlpha(obj, initalpha/ftime*i);
		yield;
	}
}



function CreateSimple2DImageA1(pri, image){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, pri);
	ObjPrim_SetTexture(obj, image);
	let test = [GetTextureWidth(image), GetTextureHeight(image)];
	ObjSprite2D_SetSourceRect(obj, 0, 0, test[0]-1, test[1]-1);
	ObjSprite2D_SetDestRect(obj, -(test[0]/2+0.5), -(test[1]/2), (test[0]/2), (test[1]/2));
	return obj;
}

function CreateSimple2DImageA2(pri, image, x1, y1, x2, y2){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, pri);
	ObjPrim_SetTexture(obj, image);
	ObjSprite2D_SetSourceRect(obj, x1, y1, x2, y2);
	ObjSprite2D_SetDestCenter(obj);
	return obj;
}


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){
	if(value<=1){return 1;}
	else{return truncate(log10(value))+1;}
}





task PlaySound(str,v,w){
	let s = ObjSound_Create;
	if(str == "tan00"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/tan00.wav");}
	if(str == "tan01"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/tan01.wav");}
	if(str == "tan02"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/tan02.wav");}
	if(str == "tan03"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/tan03.wav");}
	if(str == "tan04"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/tan04.wav");}
    if(str == "tan05"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/tan05.wav");}
    if(str == "boom00"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/boom00.wav");}
    if(str == "boom01"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/boom01.wav");}
	if(str == "caution"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/caution.wav");}
	if(str == "charge00"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/charge00.wav");}
	if(str == "enep"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/enep.wav");}
	if(str == "kira00"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/kira00.wav");}
	if(str == "kira01"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/kira01.wav");}
	if(str == "kira02"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/kira02.wav");}
	if(str == "kira03"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/kira03.wav");}
	if(str == "laser"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/laser.wav");}
	if(str == "laser2"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/laser2.wav");}
	if(str == "laser3"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/laser3.wav");}
	if(str == "nuclear"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/nuclear.wav");}
	if(str == "spark"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/spark.wav");}
	if(str == "spell"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/spell.wav");}
	if(str == "timeout"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/timeout.wav");}
	if(str == "timeout02"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/timeout02.wav");}
	if(str == "warp"){ObjSound_Load(s,GetCurrentScriptDirectory~"./../sfx/warp.wav");}
	loop(w){yield;}
	ObjSound_SetSoundDivision(s,SOUND_SE);
	ObjSound_SetVolumeRate(s,v);
	ObjSound_Play(s);
	
	
	loop(631){yield;}
	
	
	Obj_Delete(s);
}



task LifeCircleBar_Marker(enemy,movelong) {

	let marker	= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let m_angle	= -90+360*movelong;
	let m_scale	= 1.0;
	let type	= 0;

	LoadTexture(imgbar2);

	ObjPrim_SetTexture(marker,imgbar2);
	ObjRender_SetAngleXYZ(marker,0,0,m_angle-90);
	ObjRender_SetBlendType(marker,BLEND_ALPHA);
	ObjPrim_SetPrimitiveType(marker,PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(marker,4);
	ObjRender_SetScaleXYZ(marker,m_scale*0.83,m_scale,1);
	Obj_SetRenderPriorityI(marker,70);
	ObjPrim_SetVertexPosition(marker,0,-4,-4,0);
	ObjPrim_SetVertexPosition(marker,1,-4, 4,0);
	ObjPrim_SetVertexPosition(marker,2, 4,-4,0);
	ObjPrim_SetVertexPosition(marker,3, 4, 4,0);
	ObjPrim_SetVertexUVT(marker,0,0+8*type, 4);
	ObjPrim_SetVertexUVT(marker,1,0+8*type,12);
	ObjPrim_SetVertexUVT(marker,2,8+8*type, 4);
	ObjPrim_SetVertexUVT(marker,3,8+8*type,12);
	ObjPrim_SetVertexColor(marker,0,255,255,255);
	ObjPrim_SetVertexColor(marker,1,255,255,255);
	ObjPrim_SetVertexColor(marker,2,255,255,255);
	ObjPrim_SetVertexColor(marker,3,255,255,255);
        ObjPrim_SetVertexAlpha(marker,0,255);
	ObjPrim_SetVertexAlpha(marker,1,255);
	ObjPrim_SetVertexAlpha(marker,2,255);
	ObjPrim_SetVertexAlpha(marker,3,255);

	while(!Obj_IsDeleted(enemy)) {
		ObjRender_SetPosition(marker,ObjMove_GetX(enemy)+cos(m_angle)*64,ObjMove_GetY(enemy)+sin(m_angle)*64,0);
		yield;
	}
        Obj_Delete(marker);
}

task LifeCircleBar_MarkerEx(enemy,movelong,delete) {

	let marker	= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let m_angle	= -90+360*movelong;
	let m_scale	= 1.0;
	let m_alpha	= 255;
	let type	= 0;
        let maxlife	= ObjEnemy_GetInfo(enemy,INFO_LIFE);

	LoadTexture(imgbar2);

	ObjPrim_SetTexture(marker,imgbar2);
	ObjRender_SetAngleXYZ(marker,0,0,m_angle+90);
	ObjRender_SetBlendType(marker,BLEND_ALPHA);
	ObjPrim_SetPrimitiveType(marker,PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(marker,4);
	ObjRender_SetScaleXYZ(marker,m_scale*0.83,m_scale,1);
	Obj_SetRenderPriorityI(marker,70);
	ObjPrim_SetVertexPosition(marker,0,-4,-4,0);
	ObjPrim_SetVertexPosition(marker,1,-4, 4,0);
	ObjPrim_SetVertexPosition(marker,2, 4,-4,0);
	ObjPrim_SetVertexPosition(marker,3, 4, 4,0);
	ObjPrim_SetVertexUVT(marker,0,0+8*type, 4);
	ObjPrim_SetVertexUVT(marker,1,0+8*type,12);
	ObjPrim_SetVertexUVT(marker,2,8+8*type, 4);
	ObjPrim_SetVertexUVT(marker,3,8+8*type,12);
	ObjPrim_SetVertexColor(marker,0,255,255,255);
	ObjPrim_SetVertexColor(marker,1,255,255,255);
	ObjPrim_SetVertexColor(marker,2,255,255,255);
	ObjPrim_SetVertexColor(marker,3,255,255,255);
        ObjPrim_SetVertexAlpha(marker,0,255);
	ObjPrim_SetVertexAlpha(marker,1,255);
	ObjPrim_SetVertexAlpha(marker,2,255);
	ObjPrim_SetVertexAlpha(marker,3,255);

	while(delete < ObjEnemy_GetInfo(enemy,INFO_LIFE)/maxlife) {
		ObjRender_SetPosition(marker,ObjMove_GetX(enemy)+cos(m_angle)*64,ObjMove_GetY(enemy)+sin(m_angle)*64,0);
		yield;
	}
	loop(30) {
		ObjRender_SetPosition(marker,ObjMove_GetX(enemy)+cos(m_angle)*64,ObjMove_GetY(enemy)+sin(m_angle)*64,0);
                ObjPrim_SetVertexAlpha(marker,0,m_alpha);
        	ObjPrim_SetVertexAlpha(marker,1,m_alpha);
        	ObjPrim_SetVertexAlpha(marker,2,m_alpha);
        	ObjPrim_SetVertexAlpha(marker,3,m_alpha);
		m_alpha -= 255/30;
		yield;
	}
	Obj_Delete(marker);
}


task LifeCircleBar_A(enemy,long,slide,direct) {

	let bar1	= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let bar2	= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let maxlife	= ObjEnemy_GetInfo(enemy,INFO_LIFE);
	let vertex	= 722.0;
	let type	= 0;
	let i1		= 0;
	let i2		= -180.0;
	let i3		= 0;
	let i4		= 0;

	LoadTexture(imgbar2);

	ObjRender_SetPosition(bar1,ObjMove_GetX(enemy),ObjMove_GetY(enemy),0);
	ObjPrim_SetTexture(bar1,imgbar2);
        ObjRender_SetBlendType(bar1,BLEND_ALPHA);
	ObjPrim_SetPrimitiveType(bar1,PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(bar1,vertex);
        ObjRender_SetScaleXYZ(bar1,1.0,1.0,1);
        ObjRender_SetAngleXYZ(bar1,0,0,0);
	Obj_SetRenderPriorityI(bar1,70);

	ObjRender_SetPosition(bar2,ObjMove_GetX(enemy)+GetStgFrameLeft,ObjMove_GetY(enemy)+GetStgFrameTop,0);
	ObjPrim_SetTexture(bar2,imgbar2);
        ObjRender_SetBlendType(bar2,BLEND_ALPHA);
	ObjPrim_SetPrimitiveType(bar2,PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(bar2,vertex);
        ObjRender_SetScaleXYZ(bar2,1.0,1.0,1);
        ObjRender_SetAngleXYZ(bar2,0,0,0);
	Obj_SetRenderPriorityI(bar2,70);

	loop(vertex) {
		ObjPrim_SetVertexPosition(bar1,i1  ,sin(i2)*68,cos(i2)*68,0);
		ObjPrim_SetVertexPosition(bar1,i1+1,sin(i2)*60,cos(i2)*60,0);
		ObjPrim_SetVertexUVT(bar1,i1  , 1+8*type,15);
		ObjPrim_SetVertexUVT(bar1,i1+1, 6+8*type,32);
		ObjPrim_SetVertexColor(bar1,i3,255,255,255);
		ObjPrim_SetVertexAlpha(bar1,i3,255);

		ObjPrim_SetVertexPosition(bar2,i1  ,sin(i2)*67,cos(i2)*67,0);
		ObjPrim_SetVertexPosition(bar2,i1+1,sin(i2)*61,cos(i2)*61,0);
		ObjPrim_SetVertexUVT(bar2,i1  , 1+8*type,39);
		ObjPrim_SetVertexUVT(bar2,i1+1, 6+8*type,56);
		ObjPrim_SetVertexColor(bar2,i3,255,255,255);
		ObjPrim_SetVertexAlpha(bar2,i3,0);

		i1 += 2;
		i2 += vertex/720.0;
		i3++;
	}	

	if(!direct) { loop(vertex) { ObjPrim_SetVertexColor(bar2,i4,255,255,255); ObjPrim_SetVertexAlpha(bar2,i4,255); i4++; }}

	loop(60) {
		if(direct){ yield; }
		ObjRender_SetPosition(bar1,ObjMove_GetX(enemy),ObjMove_GetY(enemy),0);
		ObjRender_SetPosition(bar2,ObjMove_GetX(enemy),ObjMove_GetY(enemy),0);
//ObjEffect_ResizeVertexCount(bar2,vertex);
		loop(vertex/60) { ObjPrim_SetVertexColor(bar2,i4,255,255,255); ObjPrim_SetVertexAlpha(bar2,i4,255); i4++; }
	}

	i1 = 0;
	i2 = ((vertex/2.0)*slide)-180.0;
	i3 = 0;

	loop(720) {
		ObjPrim_SetVertexPosition(bar1,i1  ,sin(i2)*68,cos(i2)*68,0);
		ObjPrim_SetVertexPosition(bar1,i1+1,sin(i2)*60,cos(i2)*60,0);
		ObjPrim_SetVertexUVT(bar1,i1  ,1+8*type,16);
		ObjPrim_SetVertexUVT(bar1,i1+1,6+8*type,31);
		ObjPrim_SetVertexColor(bar1,i3,255,255,255);
                ObjPrim_SetVertexAlpha(bar1,i3,255);

		ObjPrim_SetVertexPosition(bar2,i1  ,sin(i2)*67,cos(i2)*67,0);
		ObjPrim_SetVertexPosition(bar2,i1+1,sin(i2)*61,cos(i2)*61,0);
		ObjPrim_SetVertexUVT(bar2,i1  , 1+8*type,40);
		ObjPrim_SetVertexUVT(bar2,i1+1, 6+8*type,55);
		ObjPrim_SetVertexColor(bar2,i3,255,255,255);
                ObjPrim_SetVertexAlpha(bar2,i3,255);

		i1 += 2;
		i2 += vertex/720.0;
		i3++;
	}

	while(!Obj_IsDeleted(enemy)) {
	        i1 = 0;
	        i2 = ((vertex/2.0)*slide)-180.0;
	        i3 = 0;
                let resize = (ObjEnemy_GetInfo(enemy,INFO_LIFE)/maxlife)*vertex*long;
		ObjRender_SetPosition(bar1,ObjMove_GetX(enemy),ObjMove_GetY(enemy),0);
		ObjRender_SetPosition(bar2,ObjMove_GetX(enemy),ObjMove_GetY(enemy),0);
//ObjEffect_ResizeVertexCount(bar2,(GetLife/maxlife)*vertex*long);
                ObjPrim_SetVertexCount(bar2,resize );
                loop(resize){
                       ObjPrim_SetVertexPosition(bar2,i1  ,sin(i2)*67,cos(i2)*67,0);
		       ObjPrim_SetVertexPosition(bar2,i1+1,sin(i2)*61,cos(i2)*61,0);
		       ObjPrim_SetVertexUVT(bar2,i1  , 1+8*type,40);
		       ObjPrim_SetVertexUVT(bar2,i1+1, 6+8*type,55);
		       ObjPrim_SetVertexColor(bar2,i3,255,255,255);
                       ObjPrim_SetVertexAlpha(bar2,i3,255);
		       i1 += 2;
		       i2 += vertex/720.0;
	               i3++;
                }
		yield;
	}
        Obj_Delete(bar1);
        Obj_Delete(bar2);
}


task LifeCircleBar_B(enemy,long,slide,direct) {

	let bar		= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let maxlife	= ObjEnemy_GetInfo(enemy,INFO_LIFE);
	let vertex	= 730.0;
	let type	= 0;
	let i1		= 0;
	let i2		= ((vertex/2.0)*slide)-180;
	let i3		= 0;

	LoadTexture(imgbar2);

	ObjRender_SetPosition(bar,ObjMove_GetX(enemy),ObjMove_GetY(enemy),0);
	ObjPrim_SetTexture(bar,imgbar2);
        ObjRender_SetBlendType(bar,BLEND_ALPHA);
	ObjPrim_SetPrimitiveType(bar,PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(bar,vertex*long);
        ObjRender_SetScaleXYZ(bar,1.0,1.0,1);
        ObjRender_SetAngleXYZ(bar,0,0,0);
	Obj_SetRenderPriorityI(bar,70);

	loop(vertex) {
		ObjPrim_SetVertexPosition(bar,i1  ,sin(i2)*67,cos(i2)*67,0);
		ObjPrim_SetVertexPosition(bar,i1+1,sin(i2)*61,cos(i2)*61,0);
		ObjPrim_SetVertexUVT(bar,i1  , 1+8*type,40);
		ObjPrim_SetVertexUVT(bar,i1+1, 6+8*type,55);
		ObjPrim_SetVertexColor(bar,i3,255,255,255);
                ObjPrim_SetVertexAlpha(bar,i3,0);

		i1 += 2;
		i2 += vertex/720.0;
		i3++;
	}	

	i3 = 0;
	if(direct) { loop(60) { yield; } }
	loop(vertex) { ObjPrim_SetVertexColor(bar,i3,255,255,255); ObjPrim_SetVertexAlpha(bar,i3,255); i3++; }

	while(!Obj_IsDeleted(enemy)) {
		ObjRender_SetPosition(bar,ObjMove_GetX(enemy),ObjMove_GetY(enemy),0);
//ObjEffect_ResizeVertexCount(bar,vertex*long);
		yield;
	}
        Obj_Delete(bar);
}

function LifeStock(nam,type) {

	let obj_x	= -5;
	let direct2	= false;

	if(type==0) { direct2 = true; } 
	if(type==2) { LifeStockBreak(nam); }
	loop(nam) {
		LifeStockDraw(obj_x,direct2);
		obj_x += 10;
	}

}


task LifeStockDraw(X,direct) {

	let star	= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let s_alpha	= 0;
	let pY		= 0;	// _—ì•_ˆÈ~‚Ì•\Ž¦‚É‚µ‚½‚¢ê‡‚Í"-14"‚É
        let enemy = GetEnemyBossObjectID[0];
        let gsft = GetStgFrameTop;
        let gsfl = GetStgFrameLeft;

	LoadTexture(imgstar);

	ObjRender_SetPosition(star,42+X-gsfl,33+pY-gsft,0);
	ObjPrim_SetTexture(star,imgstar);
	ObjRender_SetBlendType(star,BLEND_ALPHA);
	ObjPrim_SetPrimitiveType(star,PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(star,4);
	Obj_SetRenderPriorityI(star,70);
	ObjPrim_SetVertexPosition(star,0,-8,-8,0);
	ObjPrim_SetVertexPosition(star,1,-8, 8,0);
	ObjPrim_SetVertexPosition(star,2, 8,-8,0);
	ObjPrim_SetVertexPosition(star,3, 8, 8,0);
	ObjPrim_SetVertexUVT(star,0, 0, 0);
	ObjPrim_SetVertexUVT(star,1, 0,16);
	ObjPrim_SetVertexUVT(star,2,16, 0);
	ObjPrim_SetVertexUVT(star,3,16,16);
	ObjPrim_SetVertexColor(star,0,255,255,255);
	ObjPrim_SetVertexColor(star,1,255,255,255);
	ObjPrim_SetVertexColor(star,2,255,255,255);
	ObjPrim_SetVertexColor(star,3,255,255,255);
	ObjPrim_SetVertexAlpha(star,0,255);
	ObjPrim_SetVertexAlpha(star,1,255);
	ObjPrim_SetVertexAlpha(star,2,255);
	ObjPrim_SetVertexAlpha(star,3,255);

	loop(30) {
		s_alpha += 255/30;	
                ObjPrim_SetVertexAlpha(star,0,s_alpha);	
                ObjPrim_SetVertexAlpha(star,1,s_alpha);	
                ObjPrim_SetVertexAlpha(star,2,s_alpha);	
                ObjPrim_SetVertexAlpha(star,3,s_alpha);	
		if(direct){ yield; }
	}
        while(!Obj_IsDeleted(enemy)) {yield;}
        Obj_Delete(star);
}


task LifeStockBreak(nam) {

	let star	= ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let s_alpha	= 255;
	let s_scale	= 1.0;
	let pY		= 0;	// _—ì•_ˆÈ~‚Ì•\Ž¦‚É‚µ‚½‚¢ê‡‚Í"-14"‚É
        let enemy = GetEnemyBossObjectID[0];
        let gsft = GetStgFrameTop;
        let gsfl = GetStgFrameLeft;

	LoadTexture(imgstar);

	ObjRender_SetAngleZ(star,45);                                 
//	Obj_SetSpeed(star,0.25);
	ObjRender_SetPosition(star,42+nam*10-gsfl,33+pY-gsft,0);
	ObjPrim_SetTexture(star,imgstar);
	ObjRender_SetBlendType(star,BLEND_ALPHA);
	ObjPrim_SetPrimitiveType(star,PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(star,4);
	Obj_SetRenderPriorityI(star,70);
	ObjPrim_SetVertexPosition(star,0,-8,-8,0);
	ObjPrim_SetVertexPosition(star,1,-8, 8,0);
	ObjPrim_SetVertexPosition(star,2, 8,-8,0);
	ObjPrim_SetVertexPosition(star,3, 8, 8,0);
	ObjPrim_SetVertexUVT(star,0, 0, 0);
	ObjPrim_SetVertexUVT(star,1, 0,16);
	ObjPrim_SetVertexUVT(star,2,16, 0);
	ObjPrim_SetVertexUVT(star,3,16,16);

	loop(30) {
		s_alpha -= 255/30;
		s_scale += 1.0/30;

		ObjRender_SetScaleXYZ(star,s_scale,s_scale,1);
		ObjPrim_SetVertexAlpha(star,0,s_alpha);
		ObjPrim_SetVertexAlpha(star,1,s_alpha);
		ObjPrim_SetVertexAlpha(star,2,s_alpha);
		ObjPrim_SetVertexAlpha(star,3,s_alpha);
                ObjRender_SetPosition(star,ObjRender_GetX(star)+0.25*cos(45),ObjRender_GetY(star)+0.25*sin(45),0);
		yield;		
	}
        Obj_Delete(star);
}

task BGMTitle(number,language){

}

task BFX_ExplosionA1(x,y,radius,particlespritepath,time) {
	loop (time) {
		if(Obj_IsDeleted(Enemy)){break;}
		_BFX_ParticleA1(x,y,particlespritepath,rand(radius / 160,radius / 80),rand(0,360),rand(0,360),255,1,255 / 80,rand(0.022,0.024),BLEND_ADD_ARGB,rand(-3,3));
		yield;
	}
}

task BFX_ExplosionA2(x,y,radius,particlespritepath,ringspritepath,time) {
	let ringalarm = 0;
	loop (time) {
		if(Obj_IsDeleted(Enemy)){break;}
		_BFX_ParticleA1(x,y,particlespritepath,rand(radius / 160,radius / 80),rand(0,360),rand(0,360),255,1,255 / 80,rand(0.022,0.024),BLEND_ADD_ARGB,rand(-3,3));
		if (ringalarm == 0) {
			BFX_ShockwaveA1(x,y,ringspritepath,rand(0,360),255,0.1,0.04,radius * 1.5,40,BLEND_ADD_ARGB,0,rand(0,360),255);
			ringalarm = 4;
		}
		ringalarm -= 1;
		yield;
	}
}

task BFX_ReleaseA1(x,y,radius,particlespritepath,beamspritepath,time) {
	let count = time;
	let angle;
	let speed = 4;
	_BFX_FocusBeam(x,y,radius,beamspritepath,rand(0,360),-1,time / 4,time / 2);
	_BFX_FocusBeam(x,y,radius,beamspritepath,rand(0,360),1,time / 4,time / 2);
	loop (count) {
		if(Obj_IsDeleted(Enemy)){break;}
		_BFX_ParticleA1(x,y,particlespritepath,rand(0,radius / 20),rand(0,360),rand(0,360),255,0.25,255 / 20,rand(0.1,0.12),BLEND_ADD_ARGB,rand(-3,3));
		yield;
	}
}

task BFX_FocusA1(x,y,radius,particlespritepath,beamspritepath,time) {
	let count = time;
	let angle;
	let speed = 4;
	_BFX_FocusBeam(x,y,radius,beamspritepath,rand(0,360),-1,time / 4,time / 2);
	_BFX_FocusBeam(x,y,radius,beamspritepath,rand(0,360),1,time / 4,time / 2);
	loop (count) {
		if(Obj_IsDeleted(Enemy)){break;}
		angle = rand(0,360);
		_BFX_FocusPart(x + cos(angle) * radius,y + sin(angle) * radius,particlespritepath,x,y,speed,rand(0,360),2,rand(-2,2),radius);
		yield;
	}
}

task BFX_ShockwaveA1(x,y,spritepath,angle,alpha,xscale,yscale,radius,time,blending,angvel,hue,saturation) {
	let sprite = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(sprite,spritepath);
	let width = GetTextureWidth(spritepath);
	let height = GetTextureHeight(spritepath);
	ObjSprite2D_SetSourceRect(sprite,0,0,width,height);
	ObjSprite2D_SetDestCenter(sprite);
	ObjRender_SetBlendType(sprite,blending);
	ObjRender_SetColorHSV(sprite,hue,saturation,255);
	ObjRender_SetX(sprite,x);
	ObjRender_SetY(sprite,y);
	let alp = alpha;
	let xscl = xscale;
	let yscl = yscale;
	let largest = max(xscale,yscale);
	let maxscale = (radius * 2) / max(width,height);
	let sspd = (maxscale - max(xscl,yscl)) / time;
	let xsclspd = sspd * (xscl / largest);
	let ysclspd = sspd * (yscl / largest);
	let ang = angle;
	while (alp > 0) {
		ObjRender_SetAlpha(sprite,alp);
		ObjRender_SetScaleXYZ(sprite, xscl, yscl, 1);
		ObjRender_SetAngleZ(sprite,ang);
		alp = (1 - max(xscl,yscl) / maxscale) * alpha;
		xscl += xsclspd;
		yscl += ysclspd;
		ang += angvel;
		yield;
	}
	Obj_Delete(sprite);
}

task _BFX_ParticleA1(x,y,spritepath,speed,direction,angle,alpha,scale,fadespeed,scalespeed,blending,angvel) {
	let sprite = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(sprite,spritepath);
	let width = GetTextureWidth(spritepath);
	let height = GetTextureHeight(spritepath);
	ObjSprite2D_SetSourceRect(sprite,0,0,width,height);
	ObjSprite2D_SetDestCenter(sprite);
	ObjRender_SetBlendType(sprite,blending);
	let px = x;
	let py = y;
	let dir = direction;
	let spd = speed;
	let fspd = fadespeed;
	let sspd = scalespeed;
	let alp = alpha;
	let scl = scale;
	let ang = angle;
	while (alp > 0) {
		ObjRender_SetX(sprite,px);
		ObjRender_SetY(sprite,py);
		ObjRender_SetAlpha(sprite,alp);
		ObjRender_SetScaleXYZ(sprite, scl, scl, 1);
		ObjRender_SetAngleZ(sprite,ang);
		px += cos(dir) * spd;
		py += sin(dir) * spd;
		alp -= fspd;
		scl += sspd;
		ang += angvel;
		yield;
	}
	Obj_Delete(sprite);
}

task _BFX_ParticleA2(x,y,spritepath,speed,direction,angle,alpha,scale,fadespeed,scalespeed,blending,angvel,hue,saturation) {
	let sprite = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(sprite,spritepath);
	let width = GetTextureWidth(spritepath);
	let height = GetTextureHeight(spritepath);
	ObjSprite2D_SetSourceRect(sprite,0,0,width,height);
	ObjSprite2D_SetDestCenter(sprite);
	ObjRender_SetBlendType(sprite,blending);
	ObjRender_SetColorHSV(sprite,hue,saturation,255);
	let px = x;
	let py = y;
	let dir = direction;
	let spd = speed;
	let fspd = fadespeed;
	let sspd = scalespeed;
	let alp = alpha;
	let scl = scale;
	let ang = angle;
	while (alp > 0) {
		ObjRender_SetX(sprite,px);
		ObjRender_SetY(sprite,py);
		ObjRender_SetAlpha(sprite,alp);
		ObjRender_SetScaleXYZ(sprite, scl, scl, 1);
		ObjRender_SetAngleZ(sprite,ang);
		px += cos(dir) * spd;
		py += sin(dir) * spd;
		alp -= fspd;
		scl += sspd;
		ang += angvel;
		yield;
	}
	Obj_Delete(sprite);
}

task _BFX_FocusPart(x,y,spritepath,tox,toy,speed,angle,scale,angvel,radius) {
	let sprite = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(sprite,spritepath);
	let width = GetTextureWidth(spritepath);
	let height = GetTextureHeight(spritepath);
	ObjSprite2D_SetSourceRect(sprite,0,0,width,height);
	ObjSprite2D_SetDestCenter(sprite);
	ObjRender_SetBlendType(sprite,BLEND_ADD_ARGB);
	let fadein = 8;
	let px = x;
	let py = y;
	let alp = 0;
	let scl = scale;
	let ang = angle;
	let dir;
	let dist;
	loop (fadein) {
		ObjRender_SetX(sprite,px);
		ObjRender_SetY(sprite,py);
		ObjRender_SetAlpha(sprite,alp);
		ObjRender_SetScaleXYZ(sprite, scl, scl, 1);
		ObjRender_SetAngleZ(sprite,ang);
		dir = atan2(toy - py,tox - px);
		dist = ((px - tox) ^ 2 + (py - toy) ^ 2) ^ 0.5;
		px += cos(dir) * min(speed,dist);
		py += sin(dir) * min(speed,dist);
		alp += 255 / fadein;
		scl = scale * ((dist / radius) ^ 0.6);
		ang += angvel;
		yield;
	}
	let radius2 = dist;
	alp = 255;
	while (alp > 0) {
		ObjRender_SetX(sprite,px);
		ObjRender_SetY(sprite,py);
		ObjRender_SetAlpha(sprite,alp);
		ObjRender_SetScaleXYZ(sprite, scl, scl, 1);
		ObjRender_SetAngleZ(sprite,ang);
		dir = atan2(toy - py,tox - px);
		dist = ((px - tox) ^ 2 + (py - toy) ^ 2) ^ 0.5;
		px += cos(dir) * min(speed,dist);
		py += sin(dir) * min(speed,dist);
		if (dist < speed) {
			alp = 0;
		}
		alp = (((dist) / radius2) ^ 0.7) * 255;
		scl = scale * ((dist / radius) ^ 0.6);
		ang += angvel;
		yield;
	}
	Obj_Delete(sprite);
}

task _BFX_FocusBeam(x,y,radius,spritepath,angle,angvel,fadetime,lifetime) {
	let sprite = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(sprite,spritepath);
	let width = GetTextureWidth(spritepath);
	let height = GetTextureHeight(spritepath);
	ObjSprite2D_SetSourceRect(sprite,0,0,width,height);
	ObjSprite2D_SetDestCenter(sprite);
	ObjRender_SetScaleXYZ(sprite,(radius * 2) / width,(radius * 2) / height,1);
	ObjRender_SetBlendType(sprite,BLEND_ADD_ARGB);
	ObjRender_SetPosition(sprite,x,y,0);
	let alpha = 0;
	let ang = angle;
	let adelta = 255 / fadetime;
	loop (fadetime) {
		ObjRender_SetAlpha(sprite,alpha);
		ObjRender_SetAngleZ(sprite,ang);
		alpha += adelta;
		ang += angvel;
		yield;
	}
	alpha = 255;
	loop (lifetime) {
		ObjRender_SetAngleZ(sprite,ang);
		ang += angvel;
		yield;
	}
	loop (fadetime) {
		ObjRender_SetAlpha(sprite,alpha);
		ObjRender_SetAngleZ(sprite,ang);
		ang += angvel;
		alpha -= adelta;
		yield;
	}
	Obj_Delete(sprite);
}

task CharacterTitle(x,y,character,lang){

let Dimg;
let fanobj = ObjPrim_Create(OBJ_SPRITE_2D);
let alph = 0;
if(lang == 0){
    
	if(character == 1){
    Dimg = RokaCard;
	}
	if(character == 2){
    Dimg = RokaCard;
	}
	if(character == 3){
    Dimg = MichaelCardEs;
	}
	if(character == 4){
    Dimg = MarcoCardEs;
	}
	if(character == 5){
    Dimg = MatteoCardEs;
	}
	if(character == 6){
    Dimg = SetsCardEs;
	}
	
	}
	else{
	
		if(character == 1){
    Dimg = RokaCard;
	}
	if(character == 2){
    Dimg = KaoriCard;
	}
	if(character == 3){
    Dimg = MichaelCardEn;
	}
	if(character == 4){
    Dimg = MarcoCardEn;
	}
	if(character == 5){
    Dimg = MatteoCardEn;
	}
	if(character == 6){
    Dimg = SetsCardEn;
	}
	}
	LoadTexture(Dimg);
    ObjPrim_SetTexture(fanobj,Dimg);
    ObjSprite2D_SetSourceRect(fanobj,0,0,256,128);
    ObjSprite2D_SetDestCenter(fanobj);
    //ObjSprite2D_SetDestRect(fanobj,-256,-150,256,150);
    Obj_SetRenderPriorityI(fanobj,70);
    ObjRender_SetPosition(fanobj,x,y,0);
    ObjRender_SetScaleXYZ(fanobj,0.7,0.7,0.7);
     ObjRender_SetAlpha(fanobj,0);
	 
	 loop(30){
	 ObjRender_SetAlpha(fanobj,alph);
	 alph+= 255/30;
	 yield;
	 }
	 
	 loop(120){yield;}
	 
	 loop(30){
	 ObjRender_SetAlpha(fanobj,alph);
	 alph-= 255/30;
	 yield;
	 }
	Obj_Delete(fanobj);

}


//Enemy Marker. By Sparen


task EnemyMarker(obj, bossobj){
  let imgnumber = GetCurrentScriptDirectory~"./img/number.png"; //Not ./ because the file is in scripts
  let objEnemy = ObjPrim_Create(OBJ_SPRITE_2D);
  ObjRender_SetPosition(objEnemy, GetCenterX, GetStgFrameHeight+32, 1); 
  ObjPrim_SetPrimitiveType(objEnemy, PRIMITIVE_TRIANGLESTRIP);
  ObjRender_SetBlendType(objEnemy, BLEND_ALPHA);
  Obj_SetRenderPriority(objEnemy, 0.85);
  ObjPrim_SetTexture(objEnemy, imgnumber);
  ObjRender_SetAlpha(objEnemy, 255);
  ObjSprite2D_SetSourceRect(objEnemy, 192, 7, 242, 41);//With enemy
  ObjSprite2D_SetDestRect(objEnemy, -25, -17, 25, 17);
  //ObjSprite2D_SetSourceRect(objEnemy, 192, 24, 242, 41);//W/o enemy
  //ObjSprite2D_SetDestRect(objEnemy, -25, -14, 25, 3);
  while(ObjEnemy_GetInfo(bossobj,INFO_LIFE)>0){
    ObjRender_SetPosition(objEnemy, ObjMove_GetX(obj)+32, GetStgFrameHeight+32, 1); //+25 b/c centered weird
    yield;
  }
  //wait(12);//It can only handle 12 yields, currently, before the script is closed.
  Obj_Delete(objEnemy);
}