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 heart(boss){
	let heart = GetCurrentScriptDirectory ~ "../../default_system/img/status_life.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let maxhp = ObjEnemy_GetInfo(boss, INFO_LIFE);
	let hp = ObjEnemy_GetInfo(boss, INFO_LIFE);
	
	let difference = 0; 
	
	ObjPrim_SetTexture(obj, heart);
	Obj_SetRenderPriorityI(obj,60);
	ObjSprite2D_SetSourceRect(obj, 0 ,1, 170/2, 79);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, 0.7, 0.7, 0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetAlpha(obj,0);
	ObjRender_SetColorHSV(obj, 50, 255, 255);	
	
	ascent(i in 0..255/5){
	ObjRender_SetAlpha(obj, i*5);
	ObjRender_SetPosition(obj,ObjMove_GetX(boss),ObjMove_GetY(boss)-75,0);
	
	hp = ObjEnemy_GetInfo(boss, INFO_LIFE);
	difference = (hp/maxhp)*100;
	ObjRender_SetScaleXYZ(obj, difference/150, difference/150, 0);
	yield;
	}
	while(!Obj_IsDeleted(boss)){
		hp = ObjEnemy_GetInfo(boss, INFO_LIFE);
		difference = (hp/maxhp)*100;
		ObjRender_SetScaleXYZ(obj, difference/150, difference/150, 0);
		ObjRender_SetPosition(obj,ObjMove_GetX(boss),ObjMove_GetY(boss)-75,0);
		yield;
	}
	Obj_Delete(obj);
}
