let bSpell=false;
let GCSD=GetCurrentScriptDirectory();

@Initialize{
	TCallBg;
}

@MainLoop{
	let objScene=GetEnemyBossSceneObjectID();
	if(objScene!=ID_INVALID&&ObjEnemyBossScene_GetInfo(objScene,INFO_IS_SPELL)){
		bSpell=true;
	}else{
		bSpell=false;
	}
	yield;
}

task TCallBg{
	while(!Obj_IsDeleted(GetEnemyBossSceneObjectID())){
	/*if(bSpell==false){
		TNormalBackground;
		}*/
	while(bSpell==false){ yield; }
	if(bSpell==true){
		TSpellBackground;
		}
	while(bSpell==true){ yield; }
	}
	TNormalBackground2;
}


task TNormalBackground{
	/*let bg=GCSD~"img/bg.png";
	LoadTexture(bg);
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	Obj_SetRenderPriority(obj,0.21);
	ObjPrim_SetTexture(obj,bg);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetAlpha(obj,128);
	ObjRender_SetColor(obj,128,32,32);
	ObjRender_SetScaleXYZ(obj,0.75,2,1);
	ObjRender_SetX(obj,GetStgFrameWidth()/2);
	ObjRender_SetY(obj,GetStgFrameHeight()/2);
	let s=0;
	let a=0;
	TAction;
	while(bSpell==false){ yield; }
	let alpha=128;
	loop(20){
		alpha-=128/20;
		ObjRender_SetAlpha(obj,alpha);
		yield;
		}
	Obj_Delete(obj);
	task TAction{
		loop{
		ObjSprite2D_SetSourceRect(obj,0,0-a,512,512-a+512);
		ObjRender_SetAngleXYZ(obj,45,0,sin(s)*11.25);
		s+=0.5;
		a+=10;
		yield;
		}
	}*/
}

task TNormalBackground2{
	let bg=GCSD~"img/bg.png";
	LoadTexture(bg);
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	Obj_SetRenderPriority(obj,0.21);
	ObjPrim_SetTexture(obj,bg);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetAlpha(obj,255);
	ObjRender_SetColor(obj,128,32,32);
	ObjRender_SetScaleXYZ(obj,0.75,2,1);
	ObjRender_SetX(obj,GetStgFrameWidth()/2);
	ObjRender_SetY(obj,GetStgFrameHeight()/2);
	let s=0;
	let a=0;
	loop{
	ObjSprite2D_SetSourceRect(obj,0,0-a,512,512-a+512);
	ObjRender_SetAngleXYZ(obj,45,0,sin(s)*11.25);
	s+=0.5;
	a+=10;
	yield;
	}
	Obj_Delete(obj);
}

task TSpellBackground{
	let bg2=GCSD~"img/stone.png";
	LoadTexture(bg2);
	let obj2=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj2,BLEND_ALPHA);
	Obj_SetRenderPriority(obj2,0.21);
	ObjPrim_SetTexture(obj2,bg2);
	ObjSprite2D_SetDestRect(obj2,0,0,512,512);
	ObjSprite2D_SetSourceRect(obj2,0,0,512,512);
	ObjRender_SetAlpha(obj2,0);
	ObjRender_SetColor(obj2,128,32,32);
	ObjRender_SetScaleXYZ(obj2,1,1,1);

	let bg=GCSD~"img/stone.png";
	LoadTexture(bg);
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	Obj_SetRenderPriority(obj,0.21);
	ObjPrim_SetTexture(obj,bg);
	ObjSprite2D_SetDestRect(obj,0,0,512,512);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjRender_SetAlpha(obj,0);
	ObjRender_SetColor(obj,128,128,128);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	TAlpha(obj);
	TAlpha(obj2);
	let s=0;
	let s2=0;
	TAction;
	while(bSpell==true){ yield; }
	Obj_Delete(obj);
	Obj_Delete(obj2);
	task TAlpha(obj){
		let alpha=0;
		loop(20){
			ObjRender_SetAlpha(obj,alpha);
			alpha+=128/20;
			yield;
		}
	}
	task TAction{
		loop{
		ObjSprite2D_SetSourceRect(obj,0,0+s,512,512+s);
		ObjSprite2D_SetSourceRect(obj2,0,0+s2,512,512+s2);
		s+=2;
		s2+=3;
		yield;
		}
	}
}