task TShadow
	{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "../system/img/WhiteSquare.png");	
	ObjSprite2D_SetSourceRect(obj,0,0,1,1);
	ObjSprite2D_SetDestRect(obj,-64,-64,GetStgFrameWidth+64,GetStgFrameHeight+64);
	ObjRender_SetColorHSV(obj,0,0,0);
	Obj_SetRenderPriority(obj,0.25);
	ascent(t in 1..36)
		{
		ObjRender_SetAlpha(obj,t*255/35);
		yield;
		}
	while(SpellSwitch == false){yield;}
	loop(25){yield;}
	descent(t in 0..20)
		{
		ObjRender_SetAlpha(obj,t*255/20);
		yield;
		}
	Obj_Delete(obj);
	}

task TCirSpell
{
	let spell = GetSpellManageObject();
	SpellSwitch = false;
	ShotPermit = false;
	let graze = GrazeMultiply;
	GrazeMultiply*=3;
	TShadow;

	SetPlayerInvincibilityFrame(285);
	let scale1 = -1;
	let scale2 = -1;

	ShotPermit = false;
	TWall;

	loop(30)
		{
		scale1+=GetStgFrameHeight*1.5/30;
		yield;
		}
	loop(150){yield;}
	scale1 = -2;
	loop(20)
		{
		scale2+=GetStgFrameHeight*1.5/20;
		yield;
		}
	loop(15){yield;}

	PlaySound("se_Die5",120);
	SpellSwitch = true;
	ShotPermit = true;
	GrazeMultiply = graze;

	loop(20){yield;}
	Obj_Delete(spell);

	task TWall
		{
		let count = 16;
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "../system/img/WhiteSquare.png");
		ObjPrim_SetVertexCount(obj,(count+1)*2);
		ObjSprite2D_SetSourceRect(obj,0,0,1,1);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		Obj_SetRenderPriority(obj,0.3);
		let counter = -1;
		while(SpellSwitch == false)
			{
			counter+=1;
			let x = ObjMove_GetX(objPlayer);
			let y = ObjMove_GetY(objPlayer);
			if(counter < 165)
				{
				let array = GetShotIdInCircleA2(x,y,scale1,TARGET_ENEMY);
				ascent(i in 0..length(array))
					{
					let shot = array[i];
					if(!Obj_IsDeleted(shot) && ObjShot_IsSpellResist(shot) == false)
						{
						TSpam(shot,ObjMove_GetX(shot),ObjMove_GetY(shot),ObjMove_GetSpeed(shot),ObjMove_GetAngle(shot));
						}
					}	
				}
			if(scale1 > -2)
				{
				ascent(i in 0..count+1)
					{
					let angle = i*360/count;
					let color = rand(0.975,1.025);
					ObjPrim_SetVertexColor(obj,i*2,color*25,color*25,color*175);
					ObjPrim_SetVertexAlpha(obj,i*2,rand(125,135));
					ObjPrim_SetVertexPosition(obj,i*2,x+(scale1+1)*cos(angle),y+(scale1+1)*sin(angle),0);
					}
				}
			ascent(i in 0..count+1)
				{
				let angle = i*360/count;
				let color = rand(0.975,1.025);
				ObjPrim_SetVertexColor(obj,i*2+1,color*25,color*25,color*175);
				ObjPrim_SetVertexAlpha(obj,i*2+1,rand(125,135));
				ObjPrim_SetVertexPosition(obj,i*2+1,x+(scale2+1)*color*cos(angle),y+(scale2+1)*color*sin(angle),0);
				}
			yield;
			}
		Obj_Delete(obj);
		}

	task TSpam(obj,x,y,speed,angle)
		{
		ObjShot_SetSpellResist(obj,true);
		ObjMove_SetSpeed(obj,speed);
		ObjMove_SetAngle(obj,angle);
		ObjMove_SetAngularVelocity(obj,0);
		ObjMove_SetAcceleration(obj,-speed/20);
		ObjMove_SetMaxSpeed(obj,0);
		loop(60)
			{
			yield;
			if(Obj_IsDeleted(obj)){return;}
			if(SpellSwitch == true){break;}
			}
		let shot = CreatePlayerShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0,rand(0,360),2,10^10,BL_SMALL_GRAY);
		ObjRender_SetColorHSV(shot,210,15,255);
		ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
		ObjMove_SetAcceleration(shot,1/60);
		ObjMove_SetMaxSpeed(shot,100);
		Obj_Delete(obj);
		let counter = 0;
		let scale = 0;
		let alpha = 255;
		while(!Obj_IsDeleted(shot))
			{
			counter+=1;
			if(counter < 20)
				{
				scale+=1.125/20;
				}
			if(counter == 20)
				{
				ObjMove_SetAcceleration(shot,1/15);
				}
			ObjRender_SetScaleXYZ(shot,scale,scale,0);
			if(SpellSwitch == true && alpha > 25)
				{
				alpha-=230/20;
				ObjRender_SetAlpha(shot,alpha);
				}		
			yield;
			}
		}

}
