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 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){
	let timer = ObjEnemyBossScene_GetInfo(obj, INFO_TIMER);
	loop{
	timer = ObjEnemyBossScene_GetInfo(obj, INFO_TIMER);
	if(timer<11){break;}
	yield;}
	
	loop(11){
	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);
	}
}

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

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 = 0;
	let 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);
	ObjRender_SetAlpha(obj,90);
	if(start==true){
		ascent(i in 0..40){
		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_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);
	}
	