let imgPlayer = GetCurrentScriptDirectory() ~ "./../img/marisa.png";

task TImage(obj){
	TMagicCircle;
	ObjPrim_SetTexture(obj, imgPlayer);
	Obj_SetRenderPriority(obj, 0.35);

	let RectY = 0;
	let A_time = 0;
	loop{
		if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_LEFT) == KEY_HOLD){
			RectY = 1;
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_RIGHT) == KEY_HOLD){
			RectY = 2;
		}
		else{
			RectY = 0
		}

		let InvFrame = GetPlayerInvincibilityFrame()%2;
		let RectX = (truncate(A_time/5))%3;
		A_time++;
		
		ObjSprite2D_SetSourceRect(obj, 48*RectX, 48*RectY, 48*RectX + 48, 48*RectY + 48);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetAlpha(obj, 255-223*InvFrame);
		yield;
	}

	task TMagicCircle{
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(obj, imgPlayer);
		Obj_SetRenderPriority(obj, 0.7);
		let angle = 22.5;
		let scale = 3.2;
		let alpha = 0;
		loop{
			ObjSpriteList2D_ClearVertexCount(obj);
			if((GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD)
			&& GetPlayerState() == STATE_NORMAL){
				TRender;
				if(scale > 1.2){
					scale -= 2.0/10;
					alpha += 255/10;
					angle+= 3;
				}
			}else{
				angle = 22.5;
				scale = 3.2;
				alpha = 0;
			}
			angle+= 3;
			yield;
		}

		function TRender{
			//魔方陣１
			ObjSpriteList2D_SetSourceRect(obj, 64, 192, 128, 256);
			ObjSpriteList2D_SetDestRect(obj, -32, -32, 32, 32);
			ObjRender_SetX(obj, GetPlayerX);
			ObjRender_SetY(obj, GetPlayerY);
			ObjRender_SetAngleZ(obj, angle);
			ObjRender_SetScaleXYZ(obj,scale, scale, 1.0);
			ObjRender_SetAlpha(obj, alpha);
			ObjSpriteList2D_AddVertex(obj);
			//魔方陣２ With 当たり判定表示
			ObjSpriteList2D_SetSourceRect(obj, 0, 192, 64, 256);
			ObjSpriteList2D_SetDestRect(obj, -32, -32, 32, 32);
			ObjRender_SetX(obj, GetPlayerX);
			ObjRender_SetY(obj, GetPlayerY);
			ObjRender_SetAngleZ(obj, -angle);
			ObjRender_SetScaleXYZ(obj,scale, scale, 1.0);
			ObjRender_SetAlpha(obj, alpha);
			ObjSpriteList2D_AddVertex(obj);
		}
	}
}

function Option(type){
	let imgPlayer = GetCurrentScriptDirectory() ~ "./../img/marisa.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, imgPlayer);
	Obj_SetRenderPriority(obj, 0.29);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(obj, 20*type, 160, 20*type+20, 180);
	ObjSprite2D_SetDestRect(obj, -10, -10, 10, 10);

	return obj;
}
