
task TSpellA{
	let current = GetCurrentScriptDirectory();
	let imgEffect = current ~ "./img/Default_Player_MagicCircle.png";

	SetPlayerInvincibilityFrame(300);//無敵時間を設定

	let angle = rand(0, 360);

	_PlaySE(SE_SPELL1);
	ascent(i in 0 .. 4){
		_PlaySE(SE_SPELL2);
		Spell(angle + 22.5*i);
		loop(10){yield;}
	}
	loop(210){
		yield;
	}
	Obj_Delete(GetSpellManageObject());

	task Spell(angle){
		let r = 0;
		let rate2 = 2^0.5;

		ascent(i in 0 .. 4){
			Laser(angle + 90*i);
		}
		sikaku(angle);
		ascent(i in 0 .. 60){
			r += 6 - 5.0*i/60;
			yield;
		}
		loop(120){
			r += 1.0;
			yield;
		}

		task sikaku(angle){
			let x = GetPlayerX;
			let y = GetPlayerY;
			let objSpl = ObjSpell_Create();
			ObjSpell_Regist(objSpl);
			ObjSpell_SetDamage(objSpl, 1.5);
			angle += 45;
			loop(150){
				ObjSpell_SetIntersectionLine(objSpl, x+(r*rate2/2-15)*cos(angle), y+(r*rate2/2-15)*sin(angle),
				x-(r*rate2/2-15)*cos(angle), y-(r*rate2/2-15)*sin(angle), r*rate2-30);
				yield;
			}
			Obj_Delete(objSpl);
		}
		
		task Laser(angle){
			let x = GetPlayerX;
			let y = GetPlayerY;
			let objL = CreateStraightLaserA1(x, y, angle+135, 0, 30, 9999, 1, 0);
			Effect(angle);
			ObjLaser_SetIntersectionWidth(objL, 30);
			ObjRender_SetColor(objL, 0, 0, 0);
			ObjShot_SetDamage(objL, 3.0);
			ObjShot_SetEraseShot(objL, true);
			ObjShot_SetSpellFactor(objL, true);
			loop(150){
				ObjMove_SetPosition(objL, x+r*cos(angle), y+r*sin(angle));
				ObjLaser_SetLength(objL, r*rate2);
				ObjLaser_SetInvalidLength(objL, 0, 0);
				yield;
			}
			Obj_Delete(objL);

			//エフェクト
			task Effect(angle){
				let objEfc = ObjPrim_Create(OBJ_PRIMITIVE_2D);
				let render_x = 0;
	
				let alpha = 191;
				ObjRender_SetColor(objEfc, alpha, alpha, alpha);
				ObjPrim_SetTexture(objEfc, imgEffect);
				ObjPrim_SetPrimitiveType(objEfc, PRIMITIVE_TRIANGLESTRIP);
				ObjPrim_SetVertexCount(objEfc, 4);
				Obj_SetRenderPriority(objEfc, 0.6);
				ObjRender_SetBlendType(objEfc, BLEND_ADD_RGB);
				ObjRender_SetAngleZ(objEfc, angle+135);
	
				while(! Obj_IsDeleted(objL)){
					ObjRender_SetPosition(objEfc, x+r*cos(angle), y+r*sin(angle), 0);
					SetVertex(r*rate2, render_x);
					render_x += 48;
					yield;
				}
				descent(i in 1 .. 31){
					let alpha = 191*i/30;
					ObjRender_SetPosition(objEfc, x+r*cos(angle), y+r*sin(angle), 0);
					ObjRender_SetColor(objEfc, alpha, alpha, alpha);
					SetVertex(r*rate2, render_x);
					render_x += 48;
					yield;
				}
				Obj_Delete(objEfc);

				function SetVertex(r, render_x){
					ObjPrim_SetVertexPosition(objEfc, 0,-12,-12, 0);
					ObjPrim_SetVertexPosition(objEfc, 1, 12, 12, 0);
					ObjPrim_SetVertexPosition(objEfc, 2, 12+r,-12, 0);
					ObjPrim_SetVertexPosition(objEfc, 3,-12+r, 12, 0);
					ObjPrim_SetVertexUVT(objEfc, 0, render_x, 0);
					ObjPrim_SetVertexUVT(objEfc, 1, render_x, 64);
					ObjPrim_SetVertexUVT(objEfc, 2, render_x+1024, 0);
					ObjPrim_SetVertexUVT(objEfc, 3, render_x+1024, 64);
				}
			}
		}
	}
}

