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

task BossShotSound(tar,vol,cap){
	while(!Obj_IsDeleted(tar)) {
	if(ObjEnemy_GetInfo(tar,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(tar,INFO_LIFE)>cap){
	SE_Play(GetCurrentScriptDirectory ~ "sfx/damage1.wav", vol);
	yield;
	}
	if(ObjEnemy_GetInfo(tar,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(tar,INFO_LIFE)<cap){
	SE_Play(GetCurrentScriptDirectory ~ "sfx/damage2.wav", vol);
	yield;
	}
	yield;
	}
}

task TimerCountdown(obj){
	loop{
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==11){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==10){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==9){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==8){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==7){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==6){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout2.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==5){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout2.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==4){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout2.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==3){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout2.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==2){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout2.wav", 150);}
	if(ObjEnemyBossScene_GetInfo(obj, INFO_TIMER)==1){SE_Play(GetCurrentScriptDirectory ~ "sfx/timeout2.wav", 150);}
	wait(60);
	}
}

let blurswitch = false;

task MotionBlur //totally not stolen from sample
{
	let renderTexture = [GetReservedRenderTargetName(0), GetReservedRenderTargetName(1)];
	
	SetInvalidRenderPriorityA1(20, 79);


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

	let objOldFrame = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(objOldFrame, 0);
	ObjRender_SetPermitCamera(objOldFrame, false);
	ObjRender_SetAlpha(objOldFrame, 200);
	Obj_SetVisible(objOldFrame, true);

	let frame = 0;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0)
	{
		let currentFrameTexture = renderTexture[frame % 2];

		RenderToTextureA1(currentFrameTexture, 20, 79, true);

		if(frame >= 1) 
		{
			let oldFrameTexture = renderTexture[(frame - 1) % 2];
			ObjPrim_SetTexture(objOldFrame, oldFrameTexture);
			ObjSprite2D_SetSourceRect(objOldFrame, 32, 16, 416, 464);
			ObjSprite2D_SetDestRect(objOldFrame, 32, 16, 416, 464);
			RenderToTextureB1(currentFrameTexture, objOldFrame, false);
		}
		if(blurswitch==true){break;}
		ObjPrim_SetTexture(objCurentFrame, currentFrameTexture);
		ObjSprite2D_SetSourceRect(objCurentFrame, 32, 16, 416, 464);
		ObjSprite2D_SetDestRect(objCurentFrame, 32, 16, 416, 464);

		frame++;
		yield;
	}
	Obj_Delete(objCurentFrame);
	Obj_Delete(objOldFrame);
	ClearInvalidRenderPriority();
}

task SE_Play(let path, let vl){
let seobj = ObjSound_Create;
ObjSound_Load(seobj,path);
ObjSound_Play(seobj);
ObjSound_SetVolumeRate(seobj,vl);
loop(120){yield;}
RemoveSound(path);
}

task MoveFunction(obj, speed, angle, acceleration, maxspeed){
	ObjMove_SetSpeed(obj, speed);
	ObjMove_SetAngle(obj, angle);
	ObjMove_SetAcceleration(obj, acceleration);
	ObjMove_SetMaxSpeed(obj, maxspeed);
}

task widehearts{
	let heart = GetCurrentScriptDirectory ~ "./img/heart.png";
	let bomb = GetCurrentScriptDirectory ~ "./img/bomb.png";
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, heart);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		Obj_SetRenderPriorityI(obj,22);
		ObjSprite2D_SetSourceRect(obj,0,0,170/2,80);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetScaleXYZ(obj,0.25,0.25,0);
		ObjRender_SetAlpha(obj,255);	
		ObjRender_SetX(obj, 25);
		ObjRender_SetY(obj, 430);
		
		let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj2, bomb);
		ObjRender_SetBlendType(obj2,BLEND_ALPHA);
		Obj_SetRenderPriorityI(obj2,22);
		ObjSprite2D_SetSourceRect(obj2,0,0,230/2,110);
		ObjSprite2D_SetDestCenter(obj2);
		ObjRender_SetScaleXYZ(obj2,0.25,0.25,0);
		ObjRender_SetAlpha(obj2,255);	
		ObjRender_SetX(obj2, 25);
		ObjRender_SetY(obj2, 460);
		
		
		let counter = ObjText_Create();
		ObjText_SetFontSize(counter, 15);
		ObjText_SetFontBold(counter, true);
		ObjText_SetFontColorTop(counter, 255, 255, 255);
		ObjText_SetFontColorBottom(counter, 255, 255, 255);
		ObjText_SetFontBorderType(counter, BORDER_FULL);
		ObjText_SetFontBorderColor(counter,128, 128, 128);
		ObjText_SetFontBorderWidth(counter, 2);
		Obj_SetRenderPriorityI(counter, 22);
		ObjRender_SetX(counter, 45);
		ObjRender_SetY(counter, 420);
		
		let counterbomb = ObjText_Create();
		ObjText_SetFontSize(counterbomb, 15);
		ObjText_SetFontBold(counterbomb, true);
		ObjText_SetFontColorTop(counterbomb, 255, 255, 255);
		ObjText_SetFontColorBottom(counterbomb, 255, 255, 255);
		ObjText_SetFontBorderType(counterbomb, BORDER_FULL);
		ObjText_SetFontBorderColor(counterbomb,128, 128, 128);
		ObjText_SetFontBorderWidth(counterbomb, 2);
		Obj_SetRenderPriorityI(counterbomb, 22);
		ObjRender_SetX(counterbomb, 45);
		ObjRender_SetY(counterbomb, 450);
		
	while(true){
	let counting = IntToString(GetPlayerLife());
	let counting2 = IntToString(GetPlayerSpell());
	ObjText_SetText(counter, "X" ~counting);
	ObjText_SetText(counterbomb, "X" ~counting2);
	yield;
	}
	}