
let bSpell = false;
let current = GetCurrentScriptDirectory();
let t=0; let alpha=0;
@Initialize
{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(600);
	SetCameraElevationAngle(15);
	SetCameraAzimuthAngle(-90);

	TNormalBackground();
	Higanbana(3);
	Smoke();
	TSpellBackground();
	TSpellBackground2();
	//TSpellBackground3();
	
}

@MainLoop
{

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

	yield;
}



task TNormalBackground
{
SetFogEnable(true);
let param=0;
let wave=0;
let angwave=-90;
SetCameraFocusXYZ(GetScreenWidth/2, GetScreenHeight/2, -280);
WaveBG;
Background1; 
SettleIn;
task WaveBG{
	loop(180){yield;}
	loop{
		SetCameraAzimuthAngle(-90+wave);
		
		wave+=0.07*sin(angwave);
		angwave+=0.5;
	yield;}
}
task SettleIn{
let c=(1720-param)/120;
let ang=0;
loop(120){
SetCameraElevationAngle(-55*sin(ang));
ang+=120/180;
param+=c;
SetFogParam(param, 2000, 252, 55, 127);
yield;}
}
	task Background1{
	let bg=ObjPrim_Create(OBJ_SPRITE_3D);
	let t=0;
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"/img/stg3bg1.png");
	ObjSprite3D_SetSourceDestRect(bg, 0, 0, 1024, 1024);
	Obj_SetRenderPriorityI(bg, 5);
	ObjRender_SetColor(bg,244, 101, 66);
	let alpha=255;
	ObjRender_SetScaleXYZ(bg, 1, 1, 1);

	ObjRender_SetPosition(bg, GetScreenWidth/2, GetScreenHeight/2, -120);
	while(!Obj_IsDeleted(bg)){
if (bSpell==false&&alpha<255){alpha+=15;}
if (bSpell==true&&alpha>0){alpha-=5;}
ObjRender_SetAlpha(bg, alpha);
	t+=1.5; 
	ObjSprite3D_SetSourceDestRect(bg, 0, t, 4096, 4096+t);
	yield;}
	}
	
}

task Smoke
{
SetFogEnable(true);
let param=0;
SetCameraFocusXYZ(GetScreenWidth/2, GetScreenHeight/2, -220);

Background1; 

	task Background1{
	let bg=ObjPrim_Create(OBJ_SPRITE_3D);
	let t=0;
	let t2=0;
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"/img/stg3bg2.png");
	ObjSprite3D_SetSourceDestRect(bg, 0, 0, 1024, 1024);
	Obj_SetRenderPriorityI(bg, 5);
	
	let alpha=255;
	ObjRender_SetScaleXYZ(bg, 1, 1, 1);
	ObjRender_SetPosition(bg, GetScreenWidth/2, GetScreenHeight/2, -120);
	
	while(!Obj_IsDeleted(bg)){
if (bSpell==false&&alpha<255){alpha+=15;}
if (bSpell==true&&alpha>0){alpha-=5;}
ObjRender_SetAlpha(bg, alpha-130);
	t+=1.75; 
	t2+=1.75;
	ObjSprite3D_SetSourceDestRect(bg, 0, t, 4096+t2, 4096+t);
	yield;}
	}
	
}


task Higanbana(speed)
{
	loop
	{
		let t = 5;
		ShadowParticle2;
		ShadowParticle;
		Particle;
		Particle2;
		
		while(t>0)
		{
			t-=speed;
			loop(35){yield;}
		}
	}

	task Particle{
		let wi=256;
		let he=256;
		let timer=0;
		let obj = ObjPrim_Create(OBJ_SPRITE_3D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~ "/img/world13b.png");
		Obj_SetRenderPriority(obj,0.2);
		ObjRender_SetAngleZ(obj,180);
		//ObjRender_SetScaleY(obj,0.5);
		ObjRender_SetY(obj,750);
		ObjRender_SetX(obj,round(rand(70,290)));
		ObjRender_SetZ(obj,round(rand(-130,10)));
		
		ObjSprite3D_SetSourceDestRect(obj,0+1,0,wi,he-1);
		
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		let x = 120;
		let y = 0;
		let z =0;
		let alpha=255;
		let ang=0;
		let a=0;
		let scale=round(rand(1.5,2.25));
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		while(true)
		{
			if (bSpell==false&&alpha<255){alpha+=15;}
			if (bSpell==true&&alpha>0){alpha-=5;}
			let a = ((1250-ObjRender_GetY(obj))/12)-130;
			ObjRender_SetY(obj,ObjRender_GetY(obj)-speed);
			ObjRender_SetAlpha(obj,alpha*cos(a));
			ObjRender_SetAngleXYZ(obj,x,y,z+ang);
			ang+=0.15*sin(a);
			a+=0.5;
			timer++;
			if(timer>=360){break;}
			yield;
		}
		Obj_Delete(obj);
	}
	
	task Particle2{
		let wi=256;
		let he=256;
		let timer=0;
		let obj = ObjPrim_Create(OBJ_SPRITE_3D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~ "/img/world13b.png");
		Obj_SetRenderPriority(obj,0.2);
		ObjRender_SetAngleZ(obj,0);
		//ObjRender_SetScaleY(obj,0.5);
		ObjRender_SetY(obj,750);
		ObjRender_SetX(obj,round(rand(550,700)));
		ObjRender_SetZ(obj,round(rand(-130,0)));
		
		ObjSprite3D_SetSourceDestRect(obj,0+1,0,wi,he-1);
		
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		let x = 120;
		let y = 0;
		let z =0;
		let ang=0;
		let alpha=255;
		let a=0;
		let scale=round(rand(1.5,2.25));
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		while(true)
		{
		
			if (bSpell==false&&alpha<255){alpha+=15;}
			if (bSpell==true&&alpha>0){alpha-=5;}
			let a = ((1250-ObjRender_GetY(obj))/12)-130;
			ObjRender_SetY(obj,ObjRender_GetY(obj)-speed);
			ObjRender_SetAlpha(obj,alpha*cos(a));
			ObjRender_SetAngleXYZ(obj,x,y,(z+5)-ang);
			ang+=0.11*sin(a);
			a+=0.5;
			if(timer>=360){break;}
			yield;
		}
		Obj_Delete(obj);
	}
	
	task ShadowParticle{
		let wi=256;
		let he=256;
		let timer=0;
		let obj = ObjPrim_Create(OBJ_SPRITE_3D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~ "/img/world13b.png");
		Obj_SetRenderPriority(obj,0.19);
		ObjRender_SetAngleZ(obj,180);
		//ObjRender_SetScaleY(obj,0.5);
		ObjRender_SetY(obj,750);
		ObjRender_SetX(obj,round(rand(70,290)));
		ObjRender_SetZ(obj,400);
		ObjRender_SetColor(obj,22,22,22);
		ObjSprite3D_SetSourceDestRect(obj,0+1,0,wi,he-1);
		
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		let x = 0;
		let y = 0;
		let z =0;
		let alpha=125;
		let ang=0;
		ObjRender_SetScaleXYZ(obj,2.5,2.5,0);
		while(true)
		{
			if (bSpell==false&&alpha<255){alpha+=15;}
			if (bSpell==true&&alpha>0){alpha-=5;}
			let a = ((1250-ObjRender_GetY(obj))/12)-130;
			ObjRender_SetY(obj,ObjRender_GetY(obj)-speed);
			ObjRender_SetAlpha(obj,alpha*cos(a));
			ObjRender_SetAngleXYZ(obj,x,y,z);
			if(timer>=300){break;}
			yield;
		}
		Obj_Delete(obj);
	}
	
	task ShadowParticle2{
		let wi=256;
		let he=256;
		let timer=0;
		let obj = ObjPrim_Create(OBJ_SPRITE_3D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~ "/img/world13b.png");
		Obj_SetRenderPriority(obj,0.19);
		ObjRender_SetAngleZ(obj,0);
		//ObjRender_SetScaleY(obj,0.5);
		ObjRender_SetY(obj,750);
		ObjRender_SetX(obj,round(rand(550,850)));
		ObjRender_SetZ(obj,400);
		ObjRender_SetColor(obj,22,22,22);
		ObjSprite3D_SetSourceDestRect(obj,0+1,0,wi,he-1);
		
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		let x = 0;
		let y =0;
		let z =180;
		let ang=rand(0,360);
		let alpha=125;
		ObjRender_SetScaleXYZ(obj,2.5,2.5,0);
		while(true)
		{
		
			if (bSpell==false&&alpha<255){alpha+=15;}
			if (bSpell==true&&alpha>0){alpha-=5;}
			let a = ((1250-ObjRender_GetY(obj))/12)-130;
			ObjRender_SetY(obj,ObjRender_GetY(obj)-speed);
			ObjRender_SetAlpha(obj,alpha*cos(a));
			ObjRender_SetAngleXYZ(obj,x,y,z);
			
			if(timer>=300){break;}
			yield;
		}
		Obj_Delete(obj);
	}
	
}



task Particles(speed)
{
	loop
	{
		let t = 9;
		Particle(round(rand(1,4)));
		while(t>0)
		{
			t-=speed;
			loop(2){yield};
		}
	}

	task Particle(eff)
	{
		let wi=32;
		let he=32;
		let obj = ObjPrim_Create(OBJ_SPRITE_3D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~ "/img/particles.png");
		Obj_SetRenderPriority(obj,0.2);
		ObjRender_SetAngleZ(obj,180);
		ObjRender_SetScaleY(obj,0.5);
		ObjRender_SetY(obj,1024);
		ObjRender_SetX(obj,rand(-256,1024));
		ObjRender_SetZ(obj,rand(-300,100));
		if(eff==1){
		ObjSprite3D_SetSourceDestRect(obj,0,0,wi,he);}
		else if(eff==2){
		ObjSprite3D_SetSourceDestRect(obj,wi,0,wi*2,he);
		}
		else if(eff==3){
		ObjSprite3D_SetSourceDestRect(obj,0,he,wi,he*2);
		}
		else if(eff==4){
		ObjSprite3D_SetSourceDestRect(obj,wi,he,wi*2,he*2);
		}
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		let x = rand(0,360);
		let y = rand(0,360);
		let z = rand(0,360);
		let xa = rand(-2,2);
		let ya = rand(-2,2);
		let za = rand(-2,2);
		let alpha=210;
		ObjRender_SetScaleXYZ(obj,rand(1,1.25),rand(1,1.25),0);
		while(true)
		{
			if (bSpell==false&&alpha<255){alpha+=15;}
			if (bSpell==true&&alpha>0){alpha-=5;}
			let a = ((1024-ObjRender_GetY(obj))/6)-180;
			ObjRender_SetY(obj,ObjRender_GetY(obj)-speed);
			ObjRender_SetAlpha(obj,alpha*cos(a));
			ObjRender_SetAngleXYZ(obj,x,y,z);
			x+=xa;
			y+=ya;
			z+=za;
			if(a>=90){break;}
			yield;
		}
		Obj_Delete(obj);
	}
}



task TSpellBackground
{
	
let obj=ObjPrim_Create(OBJ_SPRITE_2D);


ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/cdbg03a.png");


ObjRender_SetPosition(obj, GetScreenWidth/2, GetScreenHeight/2, 0);


ObjSprite2D_SetSourceRect(obj, 0, 0, 512, 512);
ObjRender_SetBlendType(obj, BLEND_ALPHA);

ObjRender_SetScaleXYZ(obj, 1.15, 1.15, 1.15);

ObjSprite2D_SetDestCenter(obj);



Obj_SetRenderPriorityI(obj, 0);

let t=0;
let t2=0;
let angle=0;
let alpha=255;

while(!Obj_IsDeleted(obj)){


if (bSpell==true&&alpha<200){alpha+=5;}
if (bSpell==false&&alpha>0){alpha-=15;}
ObjRender_SetAlpha(obj, alpha);

t2+=0.1;
ObjRender_SetAngleZ(obj,t2);
//ObjSprite2D_SetSourceRect(obj, 0, t, 4096+t2, 4096+t);
yield;}
}


task TSpellBackground2
{
let obj=ObjPrim_Create(OBJ_SPRITE_2D);


ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/cdbg03b.png");


ObjRender_SetPosition(obj, GetScreenWidth/2, GetScreenHeight/2, 0);


ObjSprite2D_SetSourceRect(obj, 0, 0, 512, 512);
ObjRender_SetBlendType(obj, BLEND_SUBTRACT);

ObjRender_SetScaleXYZ(obj, 1,1,1);

ObjSprite2D_SetDestCenter(obj);



Obj_SetRenderPriorityI(obj, 0);

let t=0;
let t2=0;
let angle=0;
let alpha=255;

while(!Obj_IsDeleted(obj)){

if (bSpell==true&&alpha<200){alpha+=5;}
if (bSpell==false&&alpha>0){alpha-=15;}
ObjRender_SetAlpha(obj, alpha-120);

t2+=-0.15;
ObjSprite2D_SetSourceRect(obj, 0, t2, 512, 512+t2);
//ObjSprite2D_SetSourceRect(obj, 0, t, 4096+t2, 4096+t);
yield;}
}
