
task TImage
{
yield;
while(GetCommonData("Title",false)){yield;}
	let OnMove=false;
	let imgpath = GetCurrentScriptDirectory() ~ "img/v8-marisa.png";
	ObjPrim_SetTexture(objPlayer, imgpath);
	let imgFrameCount=0;
	let FrameStep=0;

	SetCharaDirection;

	BlurEffect;

	loop
	{
	ObjSprite2D_SetSourceRect(objPlayer, FrameStep*32, CharaDirection*32, 32+FrameStep*32, (1+CharaDirection)*32);
	Obj_SetRenderPriorityI(objPlayer,50);
	ObjSprite2D_SetDestCenter(objPlayer);

	imgFrameCount+=1;
	if(imgFrameCount>=60){imgFrameCount=0;}
	FrameStep=floor(imgFrameCount/15);
/*
	if(imgFrameCount%15==0 && OnMove==true)
	{
		Obj_PlaySE(GetCurrentScriptDirectory~"se/step13b.wav");
	}
*/
	yield;
	}


	task SetCharaDirection
	{
	loop
	{
	if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_FREE)
	{
		if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_LEFT) == KEY_HOLD)
		{
			if(GetVirtualKeyState(VK_UP) == KEY_PUSH || GetVirtualKeyState(VK_UP) == KEY_HOLD)
			{
			CharaDirection=7;
			}
			else if(GetVirtualKeyState(VK_DOWN) == KEY_PUSH || GetVirtualKeyState(VK_DOWN) == KEY_HOLD)
			{
			CharaDirection=5;
			}
			else
			{
			CharaDirection=6;
			}
			OnMove=true;;
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_RIGHT) == KEY_HOLD)
		{
			if(GetVirtualKeyState(VK_UP) == KEY_PUSH || GetVirtualKeyState(VK_UP) == KEY_HOLD)
			{
			CharaDirection=1;
			}
			else if(GetVirtualKeyState(VK_DOWN) == KEY_PUSH || GetVirtualKeyState(VK_DOWN) == KEY_HOLD)
			{
			CharaDirection=3;
			}
			else
			{
			CharaDirection=2;
			}
		}
		else if(GetVirtualKeyState(VK_UP) == KEY_PUSH || GetVirtualKeyState(VK_UP) == KEY_HOLD)
		{
			CharaDirection=0;
		}
		else if(GetVirtualKeyState(VK_DOWN) == KEY_PUSH || GetVirtualKeyState(VK_DOWN) == KEY_HOLD)
		{
			CharaDirection=4;
		}
		else
		{
			OnMove=false;
		}
	}
		yield;
	}
	}

	task BlurEffect
	{
	loop
	{
		if(OnDash)
		{
		Blur;
		}
		yield;
	}

	task Blur
	{
	let imgpath = GetCurrentScriptDirectory() ~ "img/v8-marisa.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgpath);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,20);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -16, -16, 0);
	ObjPrim_SetVertexPosition(obj, 1, 16, -16, 0);
	ObjPrim_SetVertexPosition(obj, 2, 16, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -16, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, FrameStep*32, CharaDirection*32);
	ObjPrim_SetVertexUVT(obj, 1, FrameStep*32+32, CharaDirection*32);
	ObjPrim_SetVertexUVT(obj, 2, FrameStep*32+32, (1+CharaDirection)*32);
	ObjPrim_SetVertexUVT(obj, 3, FrameStep*32, (1+CharaDirection)*32);

	ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);

	let Alpha=1;
	ObjRender_SetColor(obj,64,64,128*Alpha);

	loop(15)
	{
		ObjRender_SetColor(obj,64*Alpha,64*Alpha,255*Alpha);
		Alpha-=1/15;
		let sr=Obj_GetValue(GetPlayerObjectID,"Move_Right");
		let sl=Obj_GetValue(GetPlayerObjectID,"Move_Left");
		let su=Obj_GetValue(GetPlayerObjectID,"Move_Up");
		let sd=Obj_GetValue(GetPlayerObjectID,"Move_Down");
		if(sr!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sr);
		}
		if(sl!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sl);
		}
		if(su!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-su);
		}
		if(sd!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-sd);
		}
		yield;
	}

	Obj_Delete(obj);
	}
	}
}

task TMagicCircle
{
	//無敵時間の魔法陣
	//頂点奇数：偶数：円の外側、円の内側
	let countVertex = 64;
	let listRadius = [];
	loop(countVertex)
	{
		listRadius = listRadius ~ [0];
	}

	let path = current ~ "img/Default_Player_MagicCircle.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(obj, countVertex);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.60);
	ObjPrim_SetTexture(obj, path);
	ascent(iVert in 0..countVertex / 2)
	{
		let left = iVert * 128;
		let indexVert = iVert * 2;
		ObjPrim_SetVertexUVT(obj, indexVert + 0, left, 0);
		ObjPrim_SetVertexUVT(obj, indexVert + 1, left, 64);		
	}

	let cx = 0;
	let cy = 0;
	let maxRadius = 128;
	let alpha = 0;
	let frame = 0;
	let angleRender = 0;
	let frameInvOld = 0;

	while(true)
	{
		let frameInv = GetPlayerInvincibilityFrame();

		if(frameInv <= 0)
		{
			Obj_SetVisible(obj, false);
			frameInvOld = 0;
		}
		else
		{
			if(frameInvOld == 0)
			{
				//初期化
				ascent(iVert in 0..countVertex)
				{
					listRadius[iVert] = 0;
				}
				alpha = 0;
				frame = 0;
			}
			frameInvOld = frameInv;

			let px = GetPlayerX();
			let py = GetPlayerY();

			alpha += 1 / 120;
			alpha = min(alpha, 1);
			angleRender += 360 / countVertex / 2;
			Obj_SetVisible(obj, true);

			frameInv = min(100, frameInv);
			let rRate = frameInv / 100;

			ascent(iVert in 0..countVertex / 2)
			{
				let indexVert = iVert * 2;
				let angle = 360 / (countVertex / 2 - 1) * iVert;

				let vx1 = listRadius[indexVert] * cos(angle);
				let vy1 = listRadius[indexVert] * sin(angle);
				ObjPrim_SetVertexPosition(obj, indexVert + 0, vx1, vy1, 0);

				let vx2 = listRadius[indexVert+1] * cos(angle);
				let vy2 = listRadius[indexVert+1] * sin(angle);
				ObjPrim_SetVertexPosition(obj, indexVert + 1, vx2, vy2, 0);

				//魔方陣拡大
				if(frame >= 0)
				{//外側
					let dr = (maxRadius * rRate - listRadius[indexVert]) / 8;
					listRadius[indexVert] = listRadius[indexVert] + dr;
				}
				if(frame > 10)
				{//内側
					let rRateIn = rRate - 0.12;
					if(rRateIn < 0){rRateIn=0;}
					let dr= (maxRadius * rRateIn - listRadius[indexVert + 1]) / 16;
					listRadius[indexVert + 1] = listRadius[indexVert + 1] + dr;
				}

			}

			ObjRender_SetColor(obj, 192 * alpha, 192 * alpha, 255 * alpha);
			ObjRender_SetPosition(obj, px, py, 0);
			ObjRender_SetAngleZ(obj, angleRender);

			frame++;
		}

		yield;
	}
}

task TSpell
{
	SetPlayerInvincibilityFrame(60);//無敵時間を設定

	let objManage = GetSpellManageObject();
	wait(45);
	Obj_Delete(objManage);
}

task SpiritPointLack
{
	if(SpiritPointLackDrawing==false)
	{
		SetCommonData("PointLackFlag",GetCommonData("PointLackFlag",0)+1);
		SpiritPointLackDrawing=true;
	}
	else
	{
		return;
	}
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Spirit xx");
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 196);
	ObjText_SetFontColorBottom(objText, 255, 255, 196);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 70);
	ObjRender_SetX(objText, GetPlayerX-6);
	ObjRender_SetY(objText, GetPlayerY-10);

	loop(30)
	{
		ObjRender_SetX(objText, GetPlayerX-6);
		ObjRender_SetY(objText, GetPlayerY-10);
		yield;
	}
	Obj_Delete(objText);
	wait(30);
	SpiritPointLackDrawing=false;
}

task SpellPointLack
{
	if(SpiritPointLackDrawing==false)
	{
		SetCommonData("PointLackFlag",GetCommonData("PointLackFlag",0)+1);
		SpiritPointLackDrawing=true;
	}
	else
	{
		return;
	}
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Spell xx");
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 196, 255, 196);
	ObjText_SetFontColorBottom(objText, 196, 255, 196);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 70);
	ObjRender_SetX(objText, GetPlayerX-0);
	ObjRender_SetY(objText, GetPlayerY-10);

	loop(30)
	{
		ObjRender_SetX(objText, GetPlayerX-5);
		ObjRender_SetY(objText, GetPlayerY-10);
		yield;
	}
	Obj_Delete(objText);
	wait(30);
	SpiritPointLackDrawing=false;
}

task LevelUpEffect
{
	let Letter="Level Up";
	ascent(i in 0..8)
	{
	DrawLetter(Letter[i],7*i+5);
	wait(1);
	}

	task DrawLetter(text,x)
	{
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 196);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 70);
	ObjRender_SetX(objText, GetPlayerX+x);
	ObjRender_SetY(objText, GetPlayerY-10);

	let Scale=1.5;

	ObjRender_SetScaleY(objText,0.9);
	loop(30)
	{
		if(Scale>1.0)
		{
			Scale-=0.5/5;
		}
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetX(objText, GetPlayerX+x);
		ObjRender_SetY(objText, GetPlayerY-10);
		yield;
	}
	let alpha=255;
	loop(5)
	{
		Scale+=0.5/5;
		alpha-=255/5;
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetAlpha(objText,alpha);
		ObjRender_SetX(objText, GetPlayerX+x);
		ObjRender_SetY(objText, GetPlayerY-10);
		yield;
	}
	Obj_Delete(objText);
	}
}

task LevelUpLearn
{
alternative(PlayerLevel)
case(2)
{
	NewSkillEffect;
	let SkillAll=GetCommonData("SkillType_All",["マジックショット","マジックナパーム","ダッシュ","魔符｢スターダスト｣"]);
	SkillAll=SkillAll~["オーレリー"];
	SetCommonData("SkillType_All",SkillAll);

	let SkillEnchant=GetCommonData("SkillType_Enchant",["ダッシュ"]);
	SkillEnchant=SkillEnchant~["オーレリー"];
	SetCommonData("SkillType_Enchant",SkillEnchant);
}
case(5)
{
	NewSkillEffect;
	let SkillAll=GetCommonData("SkillType_All",["マジックショット","マジックナパーム","ダッシュ","魔符｢スターダスト｣"]);
	SkillAll=SkillAll~["イリュージョンレーザー"];
	SetCommonData("SkillType_All",SkillAll);

	let SkillAttack=GetCommonData("SkillType_Attack",["マジックショット","マジックナパーム"]);
	SkillAttack=SkillAttack~["イリュージョンレーザー"];
	SetCommonData("SkillType_Attack",SkillAttack);
}
others
{

}

}

task NewSkillEffect
{
	wait(60);
	let Letter="New Skill";
	ascent(i in 0..9)
	{
	DrawLetter(Letter[i],7*i+3);
	wait(1);
	}

	task DrawLetter(text,x)
	{
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 196);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 70);
	ObjRender_SetX(objText, GetPlayerX+x);
	ObjRender_SetY(objText, GetPlayerY-10);

	let Scale=1.5;

	ObjRender_SetScaleY(objText,0.9);
	loop(30)
	{
		if(Scale>1.0)
		{
			Scale-=0.5/5;
		}
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetX(objText, GetPlayerX+x);
		ObjRender_SetY(objText, GetPlayerY-10);
		yield;
	}
	let alpha=255;
	loop(5)
	{
		Scale+=0.5/5;
		alpha-=255/5;
		ObjRender_SetScaleXYZ(objText,Scale,Scale*0.9,0);
		ObjRender_SetAlpha(objText,alpha);
		ObjRender_SetX(objText, GetPlayerX+x);
		ObjRender_SetY(objText, GetPlayerY-10);
		yield;
	}
	Obj_Delete(objText);
	}
}

function wait(w)
{
loop(w){yield;}
}

task ShotForbitTime(time)
{
	loop(time)
	{
		SetForbidPlayerShot(true);
		yield;
	}
	SetForbidPlayerShot(false);
}

	task DrawText(let text, let mx, let my,size,alpha,color)
	{
		let obj = ObjText_Create();
		ObjText_SetText(obj, text);
		ObjText_SetFontSize(obj, size);
		ObjText_SetFontBold(obj, true);
		ObjText_SetFontColorTop(obj, 196, 196, 255);
		ObjText_SetFontColorBottom(obj, 128, 128, 255);
		ObjText_SetFontBorderType(obj, BORDER_NONE);
		ObjText_SetFontBorderColor(obj,255, 255, 255);
		ObjText_SetFontBorderWidth(obj, 0);
		Obj_SetRenderPriorityI(obj, 100);
		ObjRender_SetX(obj, mx);
		ObjRender_SetY(obj, my);
		ObjText_SetFontType(obj,"ＭＳ 明朝");

		ObjText_SetMaxWidth(obj,200);

		if(length(text)>=24)
		{
			ObjRender_SetY(obj, my-8);
		}

		if(length(color)!=0)
		{
		ObjText_SetFontColorTop(obj, (color[0]+255)/2, (color[1]+255)/2,(color[2]+255)/2);
		ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
		}

	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjRender_SetAlpha(obj,alpha);
		yield;

		Obj_Delete(obj);
	}

task EndEffect
{
Effect1;
Effect2;

task Effect1
{
	ascent(i in 0..5)
	{
	ExEffect(0,i);
	//wait(3);
	}
}
task Effect2
{
	loop(60)
	{
		FragEffect([rand(100,150),rand(100,150),rand(200,255)]);
	}
	loop(60)
	{
		FragEffect([rand(100,150),rand(100,150),rand(200,255)]);
		yield;
	}
}
	task ExEffect(ad,num)
	{
		let imgWhite = GetCurrentScriptDirectory() ~ "img/effects.png";
		let obje = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obje, imgWhite);
		ObjPrim_SetPrimitiveType(obje, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obje, 4);
		ObjRender_SetBlendType(obje, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obje,30);
		ObjRender_SetAngleZ(obje,0);

		ObjPrim_SetVertexPosition(obje, 0, -64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 1, 64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obje, 3,-64, 64, 0);

		ObjPrim_SetVertexUVT(obje, 0, 0, 0);
		ObjPrim_SetVertexUVT(obje, 1, 128, 0);
		ObjPrim_SetVertexUVT(obje, 2, 128, 128);
		ObjPrim_SetVertexUVT(obje, 3, 0, 128);

		let ox=GetPlayerX;
		let oy=GetPlayerY;
		let Speed=rand(2,10);
		let Angle=rand(0,360);

		let Scale=0;

		let Xangle=rand(0,360)*ad;
		let Yangle=rand(0,360)*ad;
		let Zangle=rand(0,360)*ad;

		let XanglePlus=rand(-10,10)*ad;
		let YanglePlus=rand(-10,10)*ad;
		let ZanglePlus=rand(-10,10)*ad;

		ObjRender_SetPosition(obje,ox,oy,0);

		let Alpha=1-0.2*num;
		let BAlpha=Alpha;
		ObjRender_SetColor(obje,64,64,128*Alpha);

		loop(30)
		{
			ObjRender_SetAngleXYZ(obje,Xangle,Yangle,Zangle);
			ObjRender_SetScaleXYZ(obje,Scale,Scale,Scale);
			ObjRender_SetColor(obje,255*Alpha,128*Alpha,128*Alpha);
			Alpha-=BAlpha/30;
			Scale+=(1-0.1*num)/15;
			Xangle+=XanglePlus;
			Yangle+=YanglePlus;
			Zangle+=ZanglePlus;
			yield;
		}
		Obj_Delete(obje);
	}

	task FragEffect(color)
	{
	let AnimeFrame=0;
	let Anime=0;
	let imgBer = GetCurrentScriptDirectory() ~ "img/Light.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,21);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 1, 16, -16, -0);
	ObjPrim_SetVertexPosition(obj, 2, 16, 16, 0);
	ObjPrim_SetVertexPosition(obj, 3, -16, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 32, 0);
	ObjPrim_SetVertexUVT(obj, 2, 32, 32);
	ObjPrim_SetVertexUVT(obj, 3, 0, 32);

	ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);

	ObjRender_SetColor(obj,color[0],color[1],color[2]);
	let Scale=1;
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
	let speed=rand(1,10);
	let angle=rand(0,360);
	loop(60)
	{
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
		Scale-=1/60;
		yield;
	}
	Obj_Delete(obj);
	}

}

function rand_int(min,max)
{
	return(floor(rand(min,max+1)));
}
