function wait(time){
	loop(time){
	yield;
	}
}

task PlaySound(route, volume){
	let seobj = ObjSound_Create;
	ObjSound_Load(seobj,route);
	ObjSound_Play(seobj);
	ObjSound_SetVolumeRate(seobj,volume);
	loop(120){yield;}
	RemoveSound(route);
}

task PlaySoundTime(route, volume, time){
	wait(time);
	let seobj = ObjSound_Create;
	ObjSound_Load(seobj,route);
	ObjSound_Play(seobj);
	ObjSound_SetVolumeRate(seobj,volume);
	loop(120){yield;}
	RemoveSound(route);
}

task HitSound(obj,vol,cap){
	while(!Obj_IsDeleted(obj)) {
	if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)>cap){
	PlaySound(GetCurrentScriptDirectory ~ "se/damage1.wav", vol);
	yield;
	}
	if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)<cap){
	PlaySound(GetCurrentScriptDirectory ~ "se/damage2.wav", vol);
	yield;
	}
	yield;
	}
}

task TimerCountdown(obj){
wait(60);
	let timer = ObjEnemyBossScene_GetInfo(obj, INFO_TIMER);
	while(!Obj_IsDeleted(obj)){
	timer = ObjEnemyBossScene_GetInfo(obj, INFO_TIMER);
	if(timer<11){break;}
	yield;}
	
	loop(11){
	if(Obj_IsDeleted(obj)){break;}
	timer = ObjEnemyBossScene_GetInfo(obj, INFO_TIMER);
	if(timer < 11 && timer > 4){PlaySound(GetCurrentScriptDirectory ~ "se/timeout.wav", 150);}
	if(timer < 5 && timer > -1){PlaySound(GetCurrentScriptDirectory ~ "se/timeout2.wav", 150);}
	wait(60);
	}
}

task EnemyMarker(tar){
  let obj = ObjPrim_Create(OBJ_SPRITE_2D);
  
  //ObjRender_SetPosition(objMarker, GetCenterX, GetStgFrameHeight+32, 1); 
  ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
  ObjRender_SetBlendType(obj, BLEND_ALPHA);
  Obj_SetRenderPriority(obj, 0.85);
  ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/marker.png");
  ObjRender_SetAlpha(obj, 255);
  ObjSprite2D_SetSourceRect(obj, 0, 0, 48, 16);
  ObjSprite2D_SetDestRect(obj, -25, -8, 25, 8);
  
  while(ObjEnemy_GetInfo(tar,INFO_LIFE)>0){
    ObjRender_SetPosition(obj, ObjMove_GetX(tar)+32, GetStgFrameHeight+28, 1);
    yield;
  }
 loop(12){yield;}
  Obj_Delete(obj);
}

task MagicRing(tar,start){
	let frame = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let Xscale = 1;
	let Yscale = 1;
	let alpha = 0;
	if(start){
	Xscale = 0;
	Yscale = 0;
	}
	
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/ring.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 256, 256);
	Obj_SetRenderPriorityI(obj,25);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	if(start==true){
		ascent(i in 0..40){
		ObjRender_SetAlpha(obj,alpha);
		alpha = GetCommonData("BossAlpha",90)/2;
		if(alpha > 90){alpha = 90;}
		ObjRender_SetPosition(obj,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
		ObjRender_SetScaleXYZ(obj, Xscale+0.2*sin(frame*3), Yscale+0.2*sin(frame*3),1);
		ObjRender_SetAngleXYZ(obj,0,0,frame*5);
		frame++;
		Xscale = (i/40);
		Yscale = (i/40);
		yield;
		}
	}
	while(!Obj_IsDeleted(tar)){
		frame++;
		ObjRender_SetScaleXYZ(obj,Xscale+0.2*sin(frame*3),Yscale+0.2*sin(frame*3),1);
		ObjRender_SetAngleXYZ(obj,0,0,frame*5);
		ObjRender_SetAlpha(obj,alpha);
		alpha = GetCommonData("BossAlpha",90)/2;
		if(alpha > 90){alpha = 90;}
		//ObjRender_SetPosition(obj,ObjRender_GetX(obj)+mx,ObjRender_GetY(obj)+my,0);
		ObjRender_SetPosition(obj,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
		yield;
	}
	Obj_Delete(obj);
}

task DrawName(name, color, size){
	let objText = ObjText_Create();
	ObjText_SetText(objText, name);
	ObjText_SetFontSize(objText, size);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, color[0], color[1], color[2]);
	ObjText_SetFontBorderType(objText, BORDER_SHADOW);
	ObjText_SetFontBorderColor(objText,0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 2);
	ObjRender_SetPosition(objText,4,1,0);
	
		loop{
		if(GetCommonData("NameDelete", 0)==1){
		Obj_Delete(objText);
		break;
		}
		yield;
		}
	}
	
task FlameAura(tobj,color,scale){	
	let angle = rand(0,360);
	
	while(!Obj_IsDeleted(tobj)){
		flame(tobj,color,scale);
		flamebase(tobj,color,scale,angle);
		angle+=rand(45,90);
		wait(10);}
}

task flame(tobj,color,scale){
	let frame = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let Xscale = scale/2;
	let Yscale = scale/6;
	let trans = GetCommonData("BossAlpha",255);
	
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Aura.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 48, 64);
	ObjRender_SetScaleXYZ(obj,Xscale,Yscale,1);
	Obj_SetRenderPriorityI(obj,23);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,ObjMove_GetX(tobj),ObjMove_GetY(tobj),0);
	ObjRender_SetAngleXYZ(obj,0,0,rand(-5,5));
	ObjRender_SetColor(obj,color[0],color[1],color[2]);
	loop(30){
		if(trans > 255){trans = 255;}
		ObjRender_SetScaleXYZ(obj,Xscale,Yscale,1);
		ObjRender_SetAlpha(obj,trans);
		ObjRender_SetPosition(obj,ObjMove_GetX(tobj),ObjMove_GetY(tobj),0);
		trans-=255/30;
		Xscale+=(scale/4)/30;
		Yscale+=(scale*2)/30;
		yield;
	}
	Obj_Delete(obj);
}

task flamebase(tobj,color,scale,angle){
	let frame = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let Xscale = scale/6;
	let Yscale = scale/6;
	let trans = GetCommonData("BossAlpha",255);
	
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Aura.png");
	ObjSprite2D_SetSourceRect(obj,48, 0, 96, 48);
	ObjRender_SetScaleXYZ(obj,Xscale,Yscale,1);
	Obj_SetRenderPriorityI(obj,23);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,ObjMove_GetX(tobj),ObjMove_GetY(tobj),0);
	ObjRender_SetAngleXYZ(obj,0,0,angle);
	ObjRender_SetColor(obj,color[0],color[1],color[2]);
	loop(30){
		if(trans > 255){trans = 255;}
		ObjRender_SetScaleXYZ(obj,Xscale,Yscale,1);
		ObjRender_SetAlpha(obj,trans);
		ObjRender_SetPosition(obj,ObjMove_GetX(tobj),ObjMove_GetY(tobj)+20,0);
		trans-=255/30;
		Xscale+=scale*1.1/30;
		Yscale+=scale*1.1/30;
		yield;
	}
	Obj_Delete(obj);
}

task DamageReduction(tar, spell){
ObjEnemy_SetDamageRate(tar, 0, 0);
if(spell == 0){wait(60);}
if(spell == 1){wait(180);}
ObjEnemy_SetDamageRate(tar, 90, 60);
}

task BorderLineIcon{
	let text = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(text, 30);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/frame2.png");
	ObjSprite2D_SetSourceRect(text,24,260,184,282);
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2, 125, 0);

	let bar = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(bar, 30);
	ObjPrim_SetTexture(bar,GetCurrentScriptDirectory ~ "/img/frame2.png");
	ObjSprite2D_SetSourceRect(bar,9,290,174,294);
	ObjSprite2D_SetDestCenter(bar);
	ObjRender_SetPosition(bar, GetStgFrameWidth/2+170, 125, 0);
	
	let bar2 = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(bar2, 30);
	ObjPrim_SetTexture(bar2,GetCurrentScriptDirectory ~ "/img/frame2.png");
	ObjSprite2D_SetSourceRect(bar2,9,290,174,294);
	ObjSprite2D_SetDestCenter(bar2);
	ObjRender_SetPosition(bar2, GetStgFrameWidth/2-170, 125, 0);
	
	loop(120){yield;}
	
	let scale = 1;
	ascent(i in 0..60){
	ObjRender_SetAlpha(bar, 255-i*15); ObjRender_SetAlpha(bar2, 255-i*15);
	ObjRender_SetScaleY(text, scale);
	scale-=1/10;
	if(scale<=0.1){Obj_Delete(text);}
	yield;
	}
	
}

task Extend{
	let text = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(text, 30);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/frame2.png");
	ObjSprite2D_SetSourceRect(text,15,225,99,251);
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2, 125, 0);
	ObjRender_SetAlpha(text, 0);
	ObjRender_SetScaleXYZ(text, 1.25, 1.25, 1);
	
	let text2 = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(text2, 30);
	ObjPrim_SetTexture(text2,GetCurrentScriptDirectory ~ "/img/frame2.png");
	ObjSprite2D_SetSourceRect(text2,15,225,99,251);
	ObjSprite2D_SetDestCenter(text2);
	ObjRender_SetPosition(text2, GetStgFrameWidth/2, 125, 0);
	ObjRender_SetScaleXYZ(text2, 0, 0, 1);
	ObjRender_SetAlpha(text, 255);

	ascent(i in 0..120){
	ObjRender_SetAlpha(text, 0+i*10);
	ObjRender_SetAlpha(text2, 255-i*15);
	ObjRender_SetScaleXYZ(text2, i/2, i/2, 1);
	yield;
	}
	
	let scale = 1;
	ascent(i in 0..60){
	ObjRender_SetScaleY(text, scale);
	scale-=1/10;
	if(scale<=0.1){Obj_Delete(text);}
	yield;
	}
	Obj_Delete(text); Obj_Delete(text2);
	
}

task SongName(num){
	let angle = 90;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	
	Obj_SetRenderPriorityI(obj, 45);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/Music.png");
	if(num == 0){
	ObjSprite2D_SetSourceRect(obj,0,0,1261,113);
	}
	if(num == 1){
	ObjSprite2D_SetSourceRect(obj,0,113,1261,238);
	}
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, GetStgFrameWidth/2, GetStgFrameHeight-25, 0);
	ObjRender_SetAlpha(obj, 255);
	ObjRender_SetScaleXYZ(obj, 0.3, 0.3, 1);
	

	ascent(i in 0..45){
	ObjRender_SetAngleX(obj, angle);
	angle-=2;
	yield;
	}
	wait(180);
	ascent(i in 0..45){
	ObjRender_SetAngleX(obj, angle);
	angle+=2;
	yield;
	}
	
	Obj_Delete(obj);
	
}