
task CreateItem(x,y,type)
{
	let AnimeFrame=0;
	let AnimeCount=floor(rand(0,16));
	let obj=ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/ItemStar.png");
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

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

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

	ObjRender_SetPosition(obj,x,y,0);
	let Scale=0.5;
	let speed=-4;
	let Angle=90;
	let R=255;let G=255;let B=255;
	alternative(type)
	case(1){R=150;G=150;B=255;Scale=0.5;}
	case(2){R=150;G=150;B=255;Scale=0.25;}
	case(3){R=255;G=150;B=150;Scale=0.5;}
	case(4){R=255;G=150;B=150;Scale=0.25;}
	case(5){R=150;G=255;B=150;Scale=0.5;}
	case(6){R=150;G=255;B=150;Scale=0.25;}
	ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
	let Alpha=0.5;
	ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
	Get;
	Delete;
	let MoveType=0;

	while(!Obj_IsDeleted(obj))
	{
		ObjPrim_SetVertexUVT(obj, 0, 0+64*floor(AnimeCount/8) , 0+64*AnimeFrame);
		ObjPrim_SetVertexUVT(obj, 1, 64+64*floor(AnimeCount/8), 0+64*AnimeFrame);
		ObjPrim_SetVertexUVT(obj, 2, 64+64*floor(AnimeCount/8), 64+64*AnimeFrame);
		ObjPrim_SetVertexUVT(obj, 3, 0+64*floor(AnimeCount/8) , 64+64*AnimeFrame);

		if(MoveType==0)
		{
		speed+=4/60;
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(Angle),ObjRender_GetY(obj)+speed*sin(Angle),0);
		}
		if(Scale==0.25)
		{
		speed+=4/60;
		}
		if(speed>=0){break;}
		AnimeCount+=1;
		AnimeFrame=AnimeCount;
		if(AnimeCount>=8)
		{
			AnimeFrame=15-AnimeCount;
		}
		if(AnimeCount==16){AnimeCount=0;}
		yield;
	}
	while(!Obj_IsDeleted(obj))
	{
		ObjPrim_SetVertexUVT(obj, 0, 0+64*floor(AnimeCount/8) , 0+64*AnimeFrame);
		ObjPrim_SetVertexUVT(obj, 1, 64+64*floor(AnimeCount/8), 0+64*AnimeFrame);
		ObjPrim_SetVertexUVT(obj, 2, 64+64*floor(AnimeCount/8), 64+64*AnimeFrame);
		ObjPrim_SetVertexUVT(obj, 3, 0+64*floor(AnimeCount/8) , 64+64*AnimeFrame);
		if(Scale==0.25)
		{
			let S=15;
			let A=atan2(GetPlayerY-ObjRender_GetY(obj),GetPlayerX-ObjRender_GetX(obj));
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+S*cos(A),ObjRender_GetY(obj)+S*sin(A),0);
		}

		if(MoveType==0)
		{
		speed+=2/60;
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(Angle),ObjRender_GetY(obj)+speed*sin(Angle),0);
		}
		AnimeCount+=1;
		AnimeFrame=AnimeCount;
		if(AnimeCount>=8)
		{
			AnimeFrame=15-AnimeCount;
		}
		if(AnimeCount==16){AnimeCount=0;}
		yield;
	}

	task Get
	{
	let Dis;
	while(!Obj_IsDeleted(obj))
	{
		Dis=(GetPlayerY-ObjRender_GetY(obj))^2+(GetPlayerX-ObjRender_GetX(obj))^2;
		MoveType=0;

		if(Dis<=6400)
		{
			if(GetPlayerState==STATE_NORMAL)
			{
			MoveType=1;
			let S=7.5;
			let A=atan2(GetPlayerY-ObjRender_GetY(obj),GetPlayerX-ObjRender_GetX(obj));
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+S*cos(A),ObjRender_GetY(obj)+S*sin(A),0);
			}
		}
		if(Dis<=900)
		{
			if(GetPlayerState==STATE_NORMAL)
			{
			alternative(type)
			case(1)
			{
				let point=GetCommonData("SpiritPoint",10000);
				if(ObjRender_GetY(obj)<=160)
				{
					AddScore(point);
				}
				else if(ObjRender_GetY(obj)<=384)
				{
					AddScore(point*0.25+point*0.75*(1-(ObjRender_GetY(obj)-160)/224));
				}
				else
				{
					AddScore(point*0.25);
				}
				SetCommonData("SpiritPoint",GetCommonData("SpiritPoint",10000)+100);
			}
			case(2)
			{
				let point=GetCommonData("SpiritPoint",10000)/100;
				if(ObjRender_GetY(obj)<=128)
				{
					AddScore(point);
				}
				else if(ObjRender_GetY(obj)<=384)
				{
					AddScore(point*0.5+point*0.5*(1-(ObjRender_GetY(obj)-128)/256));
				}
				else
				{
					AddScore(point*0.5);
				}
				SetCommonData("SpiritPoint",GetCommonData("SpiritPoint",10000)+1);
			}
			case(3)
			{
				SetCommonData("LifeNecessary",GetCommonData("LifeNecessary",0)-1);
				SetCommonData("SpiritPoint",GetCommonData("SpiritPoint",10000)+100);
			}
			case(5)
			{
				SetCommonData("BombNecessary",GetCommonData("BombNecessary",0)-1);
				SetCommonData("SpiritPoint",GetCommonData("SpiritPoint",10000)+100);
			}
			Obj_Delete(obj);
			}
		}
		yield;
	}
	}
	task Delete
	{
	while(!Obj_IsDeleted(obj))
	{
		if(ObjRender_GetY(obj)>=480){Obj_Delete(obj);}
		yield;
	}
	}
}