#include"./system/AllStarShot_Const.txt"
#include"./system/Sound.txt"
#include"./system/Music.txt"

let objScene = GetEnemyBossSceneObjectID;
let objEnemy;
let enmx;
let enmy;

let FLOW_MAIN = 0;
let FLOW_WINK = 1;
let FLOW_SMUG1 = 2;
let FLOW_SMUG2 = 3;
let FLOW_EVIL = 4;
let FLOW_SAD1 = 5;
let FLOW_SAD2 = 6;
let FLOW_MAD = 7;
let FLOW_RISE = 8;
let FLOW_FALL = 9;

let OKU_MAIN = 0;
let OKU_SPELL = 1;

let YUK_MAIN = 0;
let YUK_SPELL = 1;

let KOI_MAIN = 0;
let KOI_HAT = 1;
let KOI_ARM = 2;
let KOI_SPIN1 = 3;
let KOI_SPIN2 = 4;
let KOI_BALL1 =5;
let KOI_BALL2 = 6;

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToShot(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),32);
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),32);
	yield;
}

task TCaution(type)
{
	let obj = [];
	ascent(i in 0..2)
		{
		obj = obj ~ [ObjPrim_Create(OBJ_SPRITE_2D)];
		if(type == 0)	
			{
			ObjPrim_SetTexture(obj[i],GetCurrentScriptDirectory ~ "img/survival.png")
			}
		else
			{
			ObjPrim_SetTexture(obj[i],GetCurrentScriptDirectory ~ "img/rave.png")
			}		
		let y = 40;
		if(i == 1)
			{
			y = GetScreenHeight-64;
			}
		}
	let timeM = [90,30];
	let numb = 0;
	let alpha = 0;
	let counter = -1;
	let count = 0;
	descent(dir in -1..2)
		{
		let time = timeM[absolute(dir)];
		loop(time)
			{
			counter+=1;
			if(counter%55 == 0 && count < 3)
				{
				PlaySound("se_Caution",100);
				count+=1;
				}
			alpha+=dir*255/time;
			numb+=2;
			ascent(i in 0..length(obj))
				{
				let dirA = (i%2)*2-1;
				ObjRender_SetAlpha(obj[i],alpha);
				ObjSprite2D_SetSourceRect(obj[i],dirA*numb,0,4*256+dirA*numb,36);
				let y = 40;
				if(i == 1)
					{
					y = GetScreenHeight-64;
					}
				ObjSprite2D_SetDestRect(obj[i],-8,y,GetScreenWidth+8,y+36);
				}
			yield;
			}
		}
	ascent(i in 0..length(obj))
		{
		Obj_Delete(obj[i]);
		}
}

task ObjRender_SetAlpha2(obj,alpha)
{
	ObjRender_SetAlpha(obj,alpha);
	Obj_SetValue(obj,"ALPHA",alpha);
}
function ObjRender_GetAlpha(obj)
{
	return Obj_GetValueD(obj,"ALPHA",255);
}
function CreateTrain(x,y,speed,dir,scale)
	{
	let xA = 554;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "img/train.png");
	Obj_SetRenderPriority(obj,0.45);
	ObjSprite2D_SetSourceRect(obj,1,1,xA-1,175);
	ObjRender_SetScaleXYZ(obj,scale,scale,0);
	ObjSprite2D_SetDestCenter(obj);
	TMove;
	return obj;

	task TMove
		{
		x-=dir*xA*0.5*scale;
		ObjRender_SetPosition(obj,x,y,0);
		while(!Obj_IsDeleted(obj))
			{
			x+=dir*speed;
			ObjRender_SetPosition(obj,x,y,0);
			if(GetPlayerX < x+xA*0.45*scale && GetPlayerX > x-xA*0.45*scale && GetPlayerY < y+62*scale && GetPlayerY > y-80*scale)
				{
				let spam = CreateShotA1(GetPlayerX,GetPlayerY,0,0,BUBBLE_RED,0);
				Obj_SetVisible(spam,false);
				Obj_DelayDelete(spam,2);
				}
			if((dir > 0 && x > GetStgFrameWidth+xA+32) || (dir < 0 && x < -xA-32) || Obj_IsDeleted(objEnemy))
				{
				Obj_Delete(obj);
				}
			yield;
			}
		}
	}

function TBubble(x,y,dir)
	{
	let bubble = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(bubble,GetCurrentScriptDirectory ~ "img/bubble.png");
	ObjSprite2D_SetSourceRect(bubble,1,0,99,66);
	ObjRender_SetScaleXYZ(bubble,dir[0],dir[1],0);
	ObjSprite2D_SetDestCenter(bubble);
	ObjRender_SetPosition(bubble,x,y,0);
	Obj_SetRenderPriority(bubble, 0.35);
	TMove;
	return bubble;
	task TMove
		{
		let scale = 0;
		while(scale < 0.99)
			{
			scale += (1-scale)/5;
			ObjRender_SetScaleXYZ(bubble,1.8,1.5*scale,0);
			yield;
			}
		}
	}

task DeleteBubble(obj)
	{
	let scale = 1;
	while(scale > 0.01)
		{
		scale += (0-scale)/3;
		ObjRender_SetScaleXYZ(obj,1.8,1.5*scale,0);
		yield;
		}
	Obj_Delete(obj);
	}

function FDialogue(x,y,textA,se,time)
	{
	let objText = ObjText_Create;
	ObjText_SetFontSize(objText, 18);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontType(objText,"Century Gothic");
	ObjText_SetFontColorTop(objText, 0,0,0);
	ObjText_SetFontColorBottom(objText, 0,0,0);
	ObjText_SetMaxWidth(objText, 98*1.75);
	ObjRender_SetPosition(objText,x-98*0.55,y-66*0.55,0);
	ObjText_SetLinePitch(objText,2);
	Obj_SetRenderPriority(objText, 0.37);
	let text = [];
	ascent(i in 0..length(textA))
		{
		let textB = textA[i];
		if([textB] != "_")
			{
			text = text ~ [textB];
			ObjText_SetText(objText,text);	
			if([textB] != ['_'])
				{
				alternative(se)	
					case(0)
						{
						PlaySound("se_FloweyNice",85);
						}
					case(1)
						{
						PlaySound("se_FloweyEvil",85);
						}
				}
			}
		if([textB] != [' '])
			{
			loop(time){yield;}
			}
		}
	while(IsOkPush == true){yield;}
	while(IsOkPush == false){yield;}
	Obj_Delete(objText);
	while(IsOkPush == true){yield;}
	}

function IsOkPush
	{
	let val = false;
	if(GetVirtualKeyState(VK_SHOT) == KEY_PUSH || GetVirtualKeyState(VK_SHOT) == KEY_HOLD)
		{
		val = true;
		}
	return val;
	}

task ObjEnemy_SetRender(obj,type)
{
	Obj_SetValue(obj,"IMG",type);
}
function ObjEnemy_GetRender(obj)
{
	return Obj_GetValueD(obj,"IMG",0);
}
task ObjEnemy_SetGlow(obj,type)
{
	Obj_SetValue(obj,"GLOW",type);
}
function ObjEnemy_GetGlow(obj)
{
	return Obj_GetValueD(obj,"GLOW",true);
}

task ObjEnemy_RenderYuk(boss)
{
	let img = GetCurrentScriptDirectory ~ "img/boss/Yukari.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,img);
	Obj_SetRenderPriority(obj,0.35);
	let x;
	let y;
	let xA = 768/6;
	let yA = 512/4;	
	let count = 1/8;
	let counter = -1;

	let animM = [];
	ascent(i in 0..2)
		{
		animM = animM ~ [0];
		}
	let move = 0;

	while(!Obj_IsDeleted(obj))
		{		
		counter+=1;
		let type = ObjEnemy_GetRender(boss);
		ascent(i in 0..length(animM))
			{
			if(type != i)
				{
				animM[i] = 0;
				}
			}
		animM[type]=animM[type]+count;
		if(type != YUK_MAIN)
			{
			move =  0;
			}
		alternative(type)
			case(YUK_MAIN)
				{
				if(cos(ObjMove_GetAngle(obj)) > cos(25) && ObjMove_GetSpeed(obj) > 0)
					{
					animM[type] = 0;
					if(move < 1)
						{
						move+=count;
						}
					x = 2;
					y = 2+floor(move);
					}
				else if(cos(ObjMove_GetAngle(obj)) < cos(155) && ObjMove_GetSpeed(obj) > 0)
					{
					animM[type] = 0;
					if(move < 1)
						{
						move+=count;
						}
					x = 2;
					y = floor(move);
					}
				else
					{	
					move = 0;
					x = 0;		
					let anim = floor(animM[type]);
					if(anim%4 < 3)
						{
						y = anim%4;
						}
					else
						{
						y = 1;
						}
					}
				}
			case(YUK_SPELL)
				{
				let anim = floor(animM[type]);
				x = 5;
				if(anim < 2)
					{
					y = anim;
					}
				else
					{
					animM[type] = 2;
					y = 1;
					}
				}
		ObjRender_SetAlpha2(obj,ObjRender_GetAlpha(boss));
		Obj_SetRenderPriority(obj,Obj_GetRenderPriorityI(boss)/100);
		ObjSprite2D_SetSourceRect(obj,x*xA,y*yA,(x+1)*xA,(y+1)*yA);	
		ObjRender_SetScaleXYZ(obj,ObjRender_GetScaleX(boss),ObjRender_GetScaleY(boss),0);
		ObjRender_SetPosition(obj,ObjMove_GetX(boss),ObjMove_GetY(boss)+2*sin(counter*3),0);
		ObjSprite2D_SetDestCenter(obj);
		if(ObjEnemy_GetGlow(boss) == true && counter%3 == 0)
			{
			TGlow;
			}	
		if(Obj_IsDeleted(boss))
			{
			Obj_Delete(obj);
			}
		yield;
		}
	task TGlow
		{
		let glw = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(glw,img);
		ObjSprite2D_SetSourceRect(glw,x*xA,y*yA,(x+1)*xA,(y+1)*yA);
		ObjSprite2D_SetDestCenter(glw);
		ObjRender_SetPosition(glw,ObjRender_GetX(obj),ObjRender_GetY(obj),0);
		Obj_SetRenderPriority(glw,0.28);
		ObjRender_SetBlendType(glw,BLEND_ADD_ARGB);
		let time = 20;
		let xS = ObjRender_GetScaleX(boss);
		let yS = ObjRender_GetScaleY(boss);
		ascent(t in 0..time)
			{
			ObjRender_SetColorHSV(glw,300-t*60/time,255,255);
			ObjRender_SetAlpha(glw,(time-t)*ObjRender_GetAlpha(boss)/time);
			ObjRender_SetScaleXYZ(glw,(1+t*1/time)*xS,(1+t*1/time)*yS,0);
			if(Obj_IsDeleted(boss))
				{
				Obj_Delete(glw);
				}
			yield;
			}
		Obj_Delete(glw);
		}
}
task ObjEnemy_RenderKoiPlayer(boss)
{
	let img = GetCurrentScriptDirectory ~ "img/boss/koi_player.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,img);
	Obj_SetRenderPriority(obj,0.35);
	let x;
	let y;
	let xA = 256/8;
	let yA = 144/3;	
	let count = 1/4;
	let counter = -1;

	let animM = 0;
	let move = 0;

	while(!Obj_IsDeleted(obj))
		{		
		counter+=1;
		if(ObjMove_GetSpeed(obj) > 0 || move > 0 || move < 0)
			{
			animM = 0;
			if(ObjMove_GetSpeed(obj) > 0)
				{
				if(cos(ObjMove_GetAngle(obj)) > cos(25) && move < 7)
					{
					move+=count;
					}
				else if(cos(ObjMove_GetAngle(obj)) < cos(155) && move > -7)
					{
					move-=count;
					}
				}
			else
				{
				if(move > 0)
					{
					move-=count;
					}
				else if(move < 0)
					{
					move+=count;
					}
				}
			x = absolute(trunc(move));
			if(move < 0)
				{
				y = 1;
				}
			else
				{
				y = 2;
				}
			}
		else
			{
			move = 0;
			animM+=count;
			y = 0;
			x = floor(animM)%8;
			}
		ObjRender_SetAlpha2(obj,ObjRender_GetAlpha(boss));
		Obj_SetRenderPriority(obj,Obj_GetRenderPriorityI(boss)/100);
		ObjSprite2D_SetSourceRect(obj,x*xA,y*yA,(x+1)*xA,(y+1)*yA);
		ObjRender_SetPosition(obj,ObjMove_GetX(boss),ObjMove_GetY(boss)+2*sin(counter*3),0);
		ObjSprite2D_SetDestCenter(obj);
		if(ObjEnemy_GetGlow(boss) == true && counter%4 == 0)
			{
			TGlow;
			}	
		if(Obj_IsDeleted(boss))
			{
			Obj_Delete(obj);
			}
		yield;
		}
	task TGlow
		{
		let glw = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(glw,img);
		ObjSprite2D_SetSourceRect(glw,x*xA,y*yA,(x+1)*xA,(y+1)*yA);
		ObjSprite2D_SetDestCenter(glw);
		ObjRender_SetPosition(glw,ObjRender_GetX(obj),ObjRender_GetY(obj),0);
		Obj_SetRenderPriority(glw,0.28);
		ObjRender_SetBlendType(glw,BLEND_ADD_ARGB);
		let time = 20;
		ascent(t in 0..time)
			{
			ObjRender_SetColorHSV(glw,120-t*80/time,255,255);
			ObjRender_SetAlpha(glw,(time-t)*ObjRender_GetAlpha(boss)/time);
			ObjRender_SetScaleXYZ(glw,1+t*1.5/time,1+t*1.5/time,0);
			if(Obj_IsDeleted(boss))
				{
				Obj_Delete(glw);
				}
			yield;
			}
		Obj_Delete(glw);
		}
}
task ObjEnemy_RenderOku(boss)
{
	let img = GetCurrentScriptDirectory ~ "img/boss/Oku.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,img);
	Obj_SetRenderPriority(obj,0.35);
	let x;
	let y;
	let xA = 768/6;
	let yA = 512/4;	
	let count = 1/8;
	let counter = -1;

	let animM = [];
	ascent(i in 0..2)
		{
		animM = animM ~ [0];
		}
	let move = 0;

	while(!Obj_IsDeleted(obj))
		{		
		counter+=1;
		let type = ObjEnemy_GetRender(boss);
		ascent(i in 0..length(animM))
			{
			if(type != i)
				{
				animM[i] = 0;
				}
			}
		animM[type]=animM[type]+count;
		if(type != OKU_MAIN)
			{
			move =  0;
			}
		alternative(type)
			case(OKU_MAIN)
				{
				if(cos(ObjMove_GetAngle(obj)) > cos(25) && ObjMove_GetSpeed(obj) > 0)
					{
					animM[type] = 0;
					if(move < 1)
						{
						move+=count;
						}
					x = 2;
					y = 2+floor(move);
					}
				else if(cos(ObjMove_GetAngle(obj)) < cos(155) && ObjMove_GetSpeed(obj) > 0)
					{
					animM[type] = 0;
					if(move < 1)
						{
						move+=count;
						}
					x = 2;
					y = floor(move);
					}
				else
					{	
					move = 0;
					x = 0;		
					let anim = floor(animM[type]);
					y = anim%3;
					}
				}
			case(OKU_SPELL)
				{
				let anim = floor(animM[type]);
				x = 5;
				if(anim < 3)
					{
					y = anim;
					}
				else
					{
					animM[type] = 1;
					y = 1;
					}
				}
		ObjRender_SetAlpha2(obj,ObjRender_GetAlpha(boss));
		Obj_SetRenderPriority(obj,Obj_GetRenderPriorityI(boss)/100);
		ObjSprite2D_SetSourceRect(obj,x*xA,y*yA,(x+1)*xA,(y+1)*yA);
		ObjRender_SetPosition(obj,ObjMove_GetX(boss),ObjMove_GetY(boss)+2*sin(counter*3),0);
		ObjSprite2D_SetDestCenter(obj);
		if(ObjEnemy_GetGlow(boss) == true && counter%3 == 0)
			{
			TGlow;
			}	
		if(Obj_IsDeleted(boss))
			{
			Obj_Delete(obj);
			}
		yield;
		}
	task TGlow
		{
		let glw = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(glw,img);
		ObjSprite2D_SetSourceRect(glw,x*xA,y*yA,(x+1)*xA,(y+1)*yA);
		ObjSprite2D_SetDestCenter(glw);
		ObjRender_SetPosition(glw,ObjRender_GetX(obj),ObjRender_GetY(obj),0);
		Obj_SetRenderPriority(glw,0.28);
		ObjRender_SetBlendType(glw,BLEND_ADD_ARGB);
		let time = 20;
		ascent(t in 0..time)
			{
			ObjRender_SetColorHSV(glw,60-t*40/time,255,255);
			ObjRender_SetAlpha(glw,(time-t)*ObjRender_GetAlpha(boss)/time);
			ObjRender_SetScaleXYZ(glw,1+t*1.5/time,1+t*1.5/time,0);
			if(Obj_IsDeleted(boss))
				{
				Obj_Delete(glw);
				}
			yield;
			}
		Obj_Delete(glw);
		}
}

task ObjEnemy_RenderKoi(boss)
{
	let img = GetCurrentScriptDirectory ~ "img/boss/Koi.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,img);
	Obj_SetRenderPriority(obj,0.35);
	let x;
	let y;
	let xA = 1024/8;
	let yA = 512/4;	
	let count = 1/10;
	let counter = -1;

	let animM = [];
	ascent(i in 0..7)
		{
		animM = animM ~ [0];
		}
	let move = 0;

	while(!Obj_IsDeleted(obj))
		{		
		counter+=1;
		let type = ObjEnemy_GetRender(boss);
		ascent(i in 0..length(animM))
			{
			if(type != i)
				{
				animM[i] = 0;
				}
			}
		animM[type]=animM[type]+count;
		if(type != KOI_MAIN)
			{
			move =  0;
			}
		alternative(type)
			case(KOI_MAIN)
				{
				if(cos(ObjMove_GetAngle(obj)) > cos(25) && ObjMove_GetSpeed(obj) > 0)
					{
					animM[type] = 0;
					if(move < 1)
						{
						move+=count;
						}
					x = 1;
					y = floor(move);
					}
				else if(cos(ObjMove_GetAngle(obj)) < cos(155) && ObjMove_GetSpeed(obj) > 0)
					{
					animM[type] = 0;
					if(move < 1)
						{
						move+=count;
						}
					x = 2;
					y = floor(move);
					}
				else
					{	
					move = 0;
					x = 0;		
					let anim = floor(animM[type]);
					y = anim%2;
					}
				}
			case(KOI_HAT)
				{
				x = 4;
				let anim = floor(animM[type]);
				if(anim < 3)
					{
					y = anim;
					}
				else if(anim < 5)
					{
					y = 4-anim;
					}
				else
					{
					ObjEnemy_SetRender(boss,KOI_MAIN);
					}
				}
			case(KOI_ARM)
				{
				x = 5;
				let anim = floor(animM[type]);
				if(anim < 2)
					{
					y = anim;
					}
				else if(anim < 3)
					{
					y = 1;
					}
				else
					{
					ObjEnemy_SetRender(boss,KOI_MAIN);
					}
				}
			case(KOI_SPIN1)
				{
				let anim = floor(animM[type]);
				if(anim < 4)
					{
					x = 6;
					y = anim;
					}
				else if(anim < 7)
					{
					x = 4;
					y = 6-anim;
					}
				else
					{
					ObjEnemy_SetRender(boss,KOI_MAIN);
					}
				}
			case(KOI_SPIN2)
				{
				let anim = floor(animM[type]);
				if(anim < 4)
					{
					x = 6;
					y = anim;
					}
				else
					{
					animM[type] = 4;
					x = 4;
					y = 2;
					}
				}
			case(KOI_BALL1)
				{
				x = 7;
				let anim = floor(animM[type]);
				if(anim < 2)
					{
					y = anim;
					}
				else if(anim < 3)
					{
					y = 1;
					}
				else
					{
					ObjEnemy_SetRender(boss,KOI_MAIN);
					}
				}
			case(KOI_BALL2)
				{
				let anim = floor(animM[type]);
				if(anim < 4)
					{
					y = anim;
					x = 7;
					}
				else if(anim < 7)
					{
					y = 6-anim;
					x = 4;
					}
				else
					{
					ObjEnemy_SetRender(boss,KOI_MAIN);
					}
				}
		ObjRender_SetAlpha2(obj,ObjRender_GetAlpha(boss));
		Obj_SetRenderPriority(obj,Obj_GetRenderPriorityI(boss)/100);
		ObjSprite2D_SetSourceRect(obj,x*xA,y*yA,(x+1)*xA,(y+1)*yA);
		ObjRender_SetPosition(obj,ObjMove_GetX(boss),ObjMove_GetY(boss)+2*sin(counter*3),0);
		ObjSprite2D_SetDestCenter(obj);
		if(ObjEnemy_GetGlow(boss) == true && counter%3 == 0)
			{
			TGlow;
			}	
		if(Obj_IsDeleted(boss))
			{
			Obj_Delete(obj);
			}
		yield;
		}
	task TGlow
		{
		let glw = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(glw,img);
		ObjSprite2D_SetSourceRect(glw,x*xA,y*yA,(x+1)*xA,(y+1)*yA);
		ObjSprite2D_SetDestCenter(glw);
		ObjRender_SetPosition(glw,ObjRender_GetX(obj),ObjRender_GetY(obj),0);
		Obj_SetRenderPriority(glw,0.28);
		ObjRender_SetBlendType(glw,BLEND_ADD_ARGB);
		let time = 20;
		ascent(t in 0..time)
			{
			ObjRender_SetColorHSV(glw,120-t*40/time,255,255);
			ObjRender_SetAlpha(glw,(time-t)*ObjRender_GetAlpha(boss)/time);
			ObjRender_SetScaleXYZ(glw,1+t*1.5/time,1+t*1.5/time,0);
			if(Obj_IsDeleted(boss))
				{
				Obj_Delete(glw);
				}
			yield;
			}
		Obj_Delete(glw);
		}
}
task ObjEnemy_RenderFlow(obj)
{
	let imgRise = GetCurrentScriptDirectory ~ "img/boss/rise.png";
	let imgMain = GetCurrentScriptDirectory ~ "img/boss/main.png";
	let img = "";
	let x;
	let y;
	let xA;
	let yA;

	let rise = 0;

	while(!Obj_IsDeleted(obj))
		{
		let type = ObjEnemy_GetRender(obj);
		if(type == FLOW_RISE || type == FLOW_FALL)
			{
			if(img != imgRise)
				{
				img = imgRise;
				ObjPrim_SetTexture(obj,imgRise);
				}	
			if(type == FLOW_RISE)
				{
				if(rise < 8)
					{
					rise+=1/5;
					}
				else
					{
					ObjEnemy_SetRender(obj,FLOW_MAIN);
					}
				}	
			else
				{
				if(rise > 0)
					{
					rise-=1/5;
					}
				else
					{
					rise = 0;
					ObjMove_SetPosition(obj,-900,-900);
					}
				}
			x = (floor(rise)%4);
			y = floor(rise/4);
			xA = 368/4;
			yA = 324/3;
			}
		else
			{
			rise = 8;
			if(img != imgMain)
				{
				img = imgMain;
				ObjPrim_SetTexture(obj,imgMain);
				}
			x = type%4;
			y = floor(type/4)%2;
			xA = 376/4;
			yA = 196/2;
			}
		ObjSprite2D_SetSourceRect(obj,x*xA,y*yA,(x+1)*xA,(y+1)*yA);
		ObjSprite2D_SetDestCenter(obj);
		yield;
		}
}

function GetDistance(x,y,x2,y2)
{
	return (((x2-x)^2)+((y2-y)^2))^(1/2);
}

task Obj_DelayDelete(target,time)
{
	loop(time){yield;}
	Obj_Delete(target);
}

task TXY
{
	while(!Obj_IsDeleted(objEnemy))
		{
		enmx = ObjMove_GetX(objEnemy);
		enmy = ObjMove_GetY(objEnemy);
		yield;
		}
}

function GetAngleToObject(target1,target2)
{
	let angle = atan2(ObjMove_GetY(target2)-ObjMove_GetY(target1),ObjMove_GetX(target2)-ObjMove_GetX(target1));
	return angle;
}

function CreateLaserA2(x,y,speed,angle,dist,width,del,graph,delay)
{
	let laserObj = CreateStraightLaserA1(x,y,angle,dist,width,del,graph,delay);
	TGrow;
	return laserObj;
	task TGrow
		{
		let distA = 0;
		while(distA < dist)
			{
			if(Obj_IsDeleted(laserObj))
				{
				distA = dist;
				}
			else
				{
				distA+=speed;
				ObjLaser_SetLength(laserObj,distA);
				}
			yield;
			}
		ObjLaser_SetLength(laserObj,dist);
		ObjStLaser_SetSource(laserObj,false);
		}
}

task ObjEnemy_Move(obj,weight,speed,x,y,distm,dir)
{	
	let numb =  round(rand(0,1))*2-1;
	if(dir == 2 && cos(GetAngleToPlayer(obj)) != 0)
		{
		numb = absolute(cos(GetAngleToPlayer(obj)))/cos(GetAngleToPlayer(obj));
		}
	else if(dir != 0)
		{
		numb = dir;
		}
	if(ObjMove_GetX(obj)-x < distm)
		{
		numb =1;	
		}
	else if (ObjMove_GetX(obj)+x > GetStgFrameWidth-distm)
		{	
		numb = -1;
		}
	y = GetStgFrameHeight/2-y;
	x *= numb;
	ObjMove_SetDestAtWeight(obj,ObjMove_GetX(obj)+x,y,weight,speed);
}

task TSongName(name)
{
	let x = 180;
	let y = 430;
	let z = 0;
	let song = ObjText_Create;
	ObjText_SetText(song, name);
	ObjText_SetFontBorderWidth(song,0.5);
	ObjText_SetFontBorderColor(song,0,0,0);
	ObjText_SetFontBorderType(song,BORDER_SHADOW);
	ObjText_SetHorizontalAlignment(song, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(song, GetStgFrameWidth);
	ObjText_SetFontSize(song,14);
	Obj_SetRenderPriorityI(song,75);
	ObjText_SetFontType(song,0);
	loop(90)
		{
		ObjRender_SetPosition(song,GetStgFrameWidth-GetStgFrameWidth*cos(x),y,0);
		x+=2;
		yield;
		}
	loop(60){yield;}
	loop(90)
		{
		ObjRender_SetPosition(song,GetStgFrameWidth-GetStgFrameWidth*cos(x),y,0);
		x+=2;
		yield;
		}
	Obj_Delete(song);
	
}


task TEnd
{
	while(!Obj_IsDeleted(objEnemy))
		{
		yield;
		if(ObjEnemyBossScene_GetInfo(objScene,INFO_TIMERF) == 0 || ObjEnemy_GetInfo(objEnemy,INFO_LIFE) <= 0)
			{
			break;
			}
		}
	Obj_Delete(objEnemy);
	loop(1){yield;}
	CloseScript(GetOwnScriptID);
	DeleteShotAll(TYPE_ALL,TYPE_ITEM);
}

task TSpellName(text)
{
	PlaySound("se_SpellStart",95);
	let spell = ObjText_Create;
	ObjText_SetText(spell,text);
	ObjText_SetFontColorTop(spell,250,230,250);
	ObjText_SetFontColorBottom(spell,215,205,215);
	ObjText_SetFontBorderWidth(spell,1);
	ObjText_SetFontBorderColor(spell,0,0,0);
	ObjText_SetFontBorderType(spell,BORDER_FULL);
	ObjText_SetHorizontalAlignment(spell, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(spell, GetStgFrameWidth);
	ObjText_SetFontType(spell,"Century Gothic");
	ObjText_SetFontSize(spell, 16);
	ObjRender_SetScaleX(spell,1.125);
	Obj_SetRenderPriorityI(spell,75);
	ObjText_SetFontBold(spell,true);
	ObjText_SetSidePitch(spell,1);
	ObjRender_SetScaleXYZ(spell,0.875,1.35,0);
	let xM = (ObjText_GetTotalWidth(spell));
	let x = 0;
	let y = GetStgFrameHeight*0.5+60;
	let alpha = 0;
	let alphaM = 1;
	let counter = -1;

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "./system/img/Default_System.png");	
	ObjSprite2D_SetSourceRect(obj,0,53,256,90);
	ObjRender_SetScaleXYZ(obj,1.4,1.4,0);
	Obj_SetRenderPriorityI(obj,74);
	ObjRender_SetPosition(spell,x,y,0);
	ObjRender_SetPosition(obj,x,y+3,0);
	while(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)>0)
		{
		counter+=1;
		if(counter < 10)
			{
			alpha+=255/10;
			}
		else if(counter > 19)
			{
			y+=(35-y)/18;
			}
		if(GetPlayerY < GetStgFrameHeight/4)
			{
			if(alphaM > 0.2)	
				{
				alphaM -=0.8/10;
				}
			else
				{
				alphaM = 0.2;
				}
			}
		else
			{
			if(alphaM < 1)	
				{
				alphaM +=0.8/10;
				}
			else
				{
				alphaM = 1;
				}
			}
		ObjRender_SetAlpha(spell,alpha*alphaM);
		ObjRender_SetAlpha(obj,alpha*alphaM);
		ObjRender_SetPosition(spell,x+16,y,0);
		ObjRender_SetPosition(obj,-256+GetStgFrameWidth*1.1,y+6,0);
		ObjSprite2D_SetDestCenter(obj);
		yield;
		}
	Obj_Delete(spell);
	Obj_Delete(obj);
}
