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

task PlaySound(route, volume, time){
	wait(time);
	let seobj = ObjSound_Create;
	ObjSound_Load(seobj,route);
	ObjSound_Play(seobj);
	ObjSound_SetVolumeRate(seobj,volume);
	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, 0);
	yield;
	}
	if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)<cap){
	PlaySound(GetCurrentScriptDirectory ~ "se/damage2.wav", vol, 0);
	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, 0);}
	if(timer < 5 && timer > -1){PlaySound(GetCurrentScriptDirectory ~ "se/timeout2.wav", 150, 0);}
	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/System.png");
  ObjRender_SetAlpha(obj, 255);
  ObjSprite2D_SetSourceRect(obj, 0, 643, 25, 643+22);
  ObjSprite2D_SetDestCenter(obj);
  
  while(ObjEnemy_GetInfo(tar,INFO_LIFE)>0){
	if(ObjEnemy_GetInfo(tar,INFO_SHOT_HIT_COUNT)>0){
	ObjRender_SetColor(obj, 0, 0, 0);
	}
    ObjRender_SetPosition(obj, ObjMove_GetX(tar)+32, GetStgFrameHeight+26, 1);
    yield;
	ObjRender_SetColor(obj, 255, 255, 255);
  }
 loop(12){yield;}
  Obj_Delete(obj);
}

task DamageReduction(tar, time){
ObjEnemy_SetDamageRate(tar, 0, 0);
wait(time);
ObjEnemy_SetDamageRate(tar, 90, 60);
}

task BorderLineIcon{
	let text = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(text, 30);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/System.png");
	ObjSprite2D_SetSourceRect(text,17,583,17+161,583+21);
	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/System.png");
	ObjSprite2D_SetSourceRect(bar,0,610,0+170,610+10);
	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/System.png");
	ObjSprite2D_SetSourceRect(bar2,0,610,0+170,610+10);
	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/System.png");
	ObjSprite2D_SetSourceRect(text,372,182,372+146,182+55);
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2, 125, 0);
	ObjRender_SetAlpha(text, 0);
	ObjRender_SetScaleXYZ(text, 1, 1, 1);
	
	let text2 = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(text2, 30);
	ObjPrim_SetTexture(text2,GetCurrentScriptDirectory ~ "/img/System.png");
	ObjSprite2D_SetSourceRect(text2,372,182,372+146,182+55);
	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 StageClear(score){
AddScore(score);

	let text = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriority(text, 0.7);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/System.png");
	ObjSprite2D_SetSourceRect(text,373,268,373+201,268+56);
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2, 125, 0);
	ObjRender_SetAlpha(text, 255);
	ObjRender_SetScaleXYZ(text, 1, 1, 1);

	let strScore = "+" ~ IntToString(score);
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, strScore);
	ObjText_SetFontType(objScore, "Modern No. 20");
	ObjText_SetFontSize(objScore, 28);
	ObjText_SetFontBold(objScore, false);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 255, 255);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,0, 0, 0);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.6);
	ObjRender_SetX(objScore, 120);
	ObjRender_SetY(objScore, 180);

}

task Difficulty(diff){
	let text = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let X = 0;
	if(diff == 0){X = 0;}
	if(diff == 1){X = -40;}
	if(diff == 2){X = -15;}
	if(diff == 2){X = 0;}
	
	Obj_SetRenderPriority(text, 1);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/System.png");

	if(diff == 0){ObjSprite2D_SetSourceRect(text,11,405,11+171,405+36);}
	if(diff == 1){ObjSprite2D_SetSourceRect(text,12,447,12+171,447+36);}
	if(diff == 2){ObjSprite2D_SetSourceRect(text,11,488,11+171,488+36);}
	if(diff == 3){ObjSprite2D_SetSourceRect(text,11,531,11+171,531+36);}
	
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2+65+X, 15, 0);
	ObjRender_SetAlpha(text, 255);
	ObjRender_SetScaleXYZ(text, 0.75, 0.75, 1);
	
	loop(90){yield;}
	
	ascent(i in 0..30){
	ObjRender_SetAlpha(text, 255-(i*255/30));
	yield;
	}
	ObjRender_SetX(text, 428+30+75+35+X);
	ObjRender_SetY(text, 30);
	ascent(i in 0..30){
	ObjRender_SetAlpha(text, 0+(i*255/30));
	yield;
	}
}

task Highscore{
	let text = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(text, 30);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/System.png");
	ObjSprite2D_SetSourceRect(text,378,131,378+177,131+47);
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2, 75, 0);
	ObjRender_SetAlpha(text, 0);
	ObjRender_SetScaleXYZ(text, 1, 1, 1);
	
	ascent(i in 0..120){
	ObjRender_SetAlpha(text, 0+i*10);
	yield;
	}
}