//Cut-In Library by Zhan Fox
//Version 1.00
//Do not use or distribute without written permission.

task CutIn_Right(path,text){
	if(!Obj_IsDeleted(bossObj)){
		taskImage(path,-22,350,-240,120,100);
		taskText(text);
		taskEffect(-22, 20,100, 0,430,2.4,-1);
		taskBonus;
	}
}

task CutIn_Left(path,text){
	if(!Obj_IsDeleted(bossObj)){
		taskImage(path,22,34,240,120,100);
		taskText(text);
		taskEffect(22, 350,90, 350,415, -2.4,-1);
		taskBonus;
	}
}

task taskImage(path,angle,x1,x2,y1,y2){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriorityI(obj, 70);
	ObjRender_SetAngleZ(obj, angle);
	TMovement;

	ascent(i in 0..30){
		ObjSprite2D_SetSourceRect(obj, 0, 120-i*4, 1200, 120+i*4);
		ObjSprite2D_SetDestRect(obj, -600, -i*4, 600, i*4);
		if(Obj_IsDeleted(bossObj)){break;}
	yield;
	}
	loop(70){
		if(Obj_IsDeleted(bossObj)){break;}
		yield;}
	ascent(i in 0..31){
		ObjSprite2D_SetSourceRect(obj, 0, i*4, 1200, 240-i*4);
		ObjSprite2D_SetDestRect(obj, -600, -120+i*4, 600, 120-i*4);
		if(Obj_IsDeleted(bossObj)){break;}
	yield;
	}
	Obj_Delete(obj);

	task TMovement{
		ascent(i in 0..121){
			ObjRender_SetPosition(obj, x1+x2*cos(120-i), y1+y2*cos(120-i), 0);
		if(Obj_IsDeleted(bossObj)){break;}
		yield;
		}
	}
}

task taskText(text){
	let obj = ObjText_Create();
	ObjText_SetText(obj, text);
	ObjText_SetFontSize(obj, 16);
	ObjText_SetFontBold(obj, true);
	ObjText_SetFontType(obj,"Blogger Sans");
	ObjText_SetFontBorderType(obj, BORDER_FULL);
	ObjText_SetFontBorderColor(obj, 25, 25, 25);
	ObjText_SetFontBorderWidth(obj, 1);
	Obj_SetRenderPriorityI(obj, 71);
	Obj_SetVisible(obj, false);
	ObjText_SetHorizontalAlignment(obj, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(obj, GetStgFrameWidth-24);
	ObjRender_SetPosition(obj, 0, 330, 0);
	
	loop(6){
		TTextEffect;
	loop(5){
		if(Obj_IsDeleted(bossObj)){break;}
		yield;}}
	loop(55){
		if(Obj_IsDeleted(bossObj)){break;}
		yield;}
	Obj_SetVisible(obj, true);
	loop(30){
		if(Obj_IsDeleted(bossObj)){break;}
		yield;}
	let y = 11;
	loop(60){
		if(Obj_IsDeleted(bossObj)){break;}
		ObjRender_SetPosition(obj,0,ObjRender_GetY(obj)-y,0);
		y-=0.2;
	yield;}

	let objScene = GetEnemyBossSceneObjectID;
	while(GetPlayerLife > -1){
		if(Obj_IsDeleted(bossObj)){break;}
		if(ObjEnemyBossScene_GetInfo(objScene,INFO_CURRENT_LIFE) <= 0){break;}
	yield;}
	Obj_Delete(obj);
	
	task TTextEffect{
		let scale = 4;
		let alpha = 0;
		let obj2 = ObjText_Create();
		ObjText_SetText(obj2, text);
		ObjText_SetFontSize(obj2, 16);
		ObjText_SetFontBold(obj2, true);
		ObjText_SetFontType(obj2,"Blogger Sans");
		ObjText_SetFontBorderType(obj2, BORDER_FULL);
		ObjText_SetFontBorderColor(obj2, 25, 25, 25);
		ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);
		ObjText_SetFontBorderWidth(obj2, 1);
		Obj_SetRenderPriorityI(obj2, 75);
		ObjText_SetHorizontalAlignment(obj2, ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(obj2, GetStgFrameWidth-24);
		ObjRender_SetPosition(obj2, 0, 330, 0);
		loop(61){
			if(Obj_IsDeleted(bossObj)){break;}
			ObjRender_SetScaleXYZ(obj2, scale, scale, 0);
			ObjRender_SetAlpha(obj2,alpha);
			scale-=3/60;
			alpha+=255/60;
			yield;
		}
		Obj_Delete(obj2);
	}
}

task taskEffect(angle,x1,y1,x2,y2,move1,move2){
	TTestLine(x1,y1);
	TTestLine(x2,y2);

	task TTestLine(x,y){
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "./effect.png");
		ObjSprite2D_SetSourceRect(obj, 0, 0, 850*3, 144);
		ObjSprite2D_SetDestRect(obj, -425*3, -72, 425*3, 72);
		ObjRender_SetScaleXYZ(obj, 0.3, 0.3, 0);
		Obj_SetRenderPriorityI(obj, 75);
		ObjRender_SetAngleZ(obj, angle);
		TMovement;
	
		let alpha = 0;
		loop(30){
			if(Obj_IsDeleted(bossObj)){break;}
			ObjRender_SetAlpha(obj,alpha);
			alpha+=255/30;
		yield;}
		loop(60){
			if(Obj_IsDeleted(bossObj)){break;}
			yield;}
		loop(30){
			if(Obj_IsDeleted(bossObj)){break;}
			ObjRender_SetAlpha(obj,alpha);
			alpha-=255/30;
		yield;}
		Obj_Delete(obj);

		task TMovement{
			ascent(i in 0..121){
				if(Obj_IsDeleted(bossObj)){break;}
				ObjRender_SetPosition(obj, x+i*move1, y+i*move2, 0);
			yield;
			}
		}
	}
}

task taskHistory(){
}

task taskBonus(){
	let obj = ObjText_Create();
	ObjText_SetFontSize(obj, 14);
	ObjText_SetFontBold(obj, true);
	ObjText_SetFontType(obj,"Blogger Sans");
	ObjText_SetFontBorderType(obj, BORDER_FULL);
	ObjText_SetFontBorderColor(obj, 25, 25, 25);
	ObjText_SetFontBorderWidth(obj, 1);
	Obj_SetRenderPriorityI(obj, 71);
	ObjRender_SetY(obj, 430);
	TMovement;
	
	let bonus;
	let text = "";
	let alpha = 255;
	let objScene = GetEnemyBossSceneObjectID;
	
	while((GetPlayerLife) > 0){
		if(ObjEnemyBossScene_GetInfo(objScene,INFO_CURRENT_LIFE) <= 0){
			Obj_Delete(obj);
			break;}
	
		bonus = ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_SPELL_SCORE);
		text = "Bonus:" ~ vtos("02d", bonus);
		
		ObjRender_SetAlpha(obj, alpha);
		ObjText_SetText(obj, text);
		
		if(GetPlayerX < 150 && GetPlayerY > 400){alpha-=10;}
		else{alpha+=10;}
		if(alpha >= 255){alpha = 255;}
		if(alpha <= 100){alpha = 100;}
	yield;}
	
	if(GetPlayerLife < 1){
	ObjText_SetText(obj, "Bonus: Failed");
	let objSprite = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objSprite, GetCurrentScriptDirectory ~ "./../../system/img/front16.png");
	ObjSprite2D_SetSourceRect(objSprite, 512, 770, 840, 840);
	ObjSprite2D_SetDestRect(objSprite, 100, 150, 100+328/1.6, 150+70/1.6);
	Obj_SetRenderPriorityI(objSprite, 75);
	let alphaSprite = 0;
	loop(30){
		ObjRender_SetAlpha(objSprite,alphaSprite);
		alphaSprite+=255/30;
		yield;
	}
	loop(30){yield;}
	loop(30){
		ObjRender_SetAlpha(objSprite,alphaSprite);
		alphaSprite-=255/30;
		yield;
	}
	Obj_Delete(objSprite);
	Obj_Delete(obj);}
	
	
	task TMovement{
		ascent(i in 0..90){
			ObjRender_SetX(obj, -174+i*2);
		yield;
		}
	}
}
