let ITEM_POINT=0;
let ITEM_BOMB=1;
let ITEM_1UP=2;
let ITEM_MULTI=3;

task SetItem(let sx,let sy,let type)
{
	let flg=false;
	let vy=-2.5;
	let rect=[97,0,111,16];
	let layer=3;
	alternative(type)
	case(ITEM_BOMB){rect=[112,0,128,16];layer=4;}
	case(ITEM_MULTI){rect=[129,0,143,16];}
	case(ITEM_1UP){rect=[144,0,160,16];layer=4;}
	others{}
	
	let obj=SetEffectObject(tex[TEX_SYSTEM],layer);
	SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
	ObjEffect_SetRenderState(obj,ALPHA);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj,sx,sy);
		if(!flg)
		{
			alternative(type)
			case(ITEM_MULTI)
			{
				if(vy>0){flg=true;}
				vy+=0.05;
			}
			case(ITEM_POINT)
			{
				if(vy<2){vy+=0.05;}
				if(type==ITEM_POINT)
				{
					if(GetPlayerY<itemborder){flg=true;}
					if(itemconv_flg&&GetGapLength(sx,sy,GetPlayerX,GetPlayerY)<=64)
					{
						Obj_Delete(obj);
						SetItem(sx,sy,ITEM_MULTI);
						multiply_delay+=30;
					}
				}
			}
			others
			{
				if(vy<2){vy+=0.05;}
				if(GetGapLength(sx,sy,GetPlayerX,GetPlayerY)<=64){flg=true;}
			}
			
			
			if(GetGapLength(sx,sy,GetPlayerX,GetPlayerY)<=15)
			{
				Get;
				Obj_Delete(obj);
			}
			sy+=vy;
		}
		else
		{
			if(GetGapLength(sx,sy,GetPlayerX,GetPlayerY)<=5)
			{
				Get;
				Obj_Delete(obj);
			}
			if(type==ITEM_POINT)
			{
				if(itemconv_flg&&GetGapLength(sx,sy,GetPlayerX,GetPlayerY)<=64)
				{
					Obj_Delete(obj);
					loop(2){SetItem(sx,sy,ITEM_MULTI);}
					multiply_delay+=30;
				}
			}
			let speed=8;
			let angle=atan2(GetPlayerY-sy,GetPlayerX-sx);
			sx+=speed*cos(angle);
			sy+=speed*sin(angle);
		}
		
		if(Obj_GetY(obj)>=480){Obj_Delete(obj);}
		yield;
	}
	
	function Get
	{
		alternative(type)
		case(ITEM_POINT)
		{
			let rate=GetCommonData("Rate");
			let point=itempoint*(rate*rate);
			let score=GetCommonDataDefault("Score",0);
			score+=point;
			SetCommonData("Score",score);
			itempoint+=10;
			if(flg){itempoint+=10;}
			itempoint_getcount++;
			itempoint_totalcount++;
			if(red_alpha>10)
			{
				let d=ceil((red_num+1)/500);
				if(red_num<5000){d=1;}
				red_num+=ceil(5+ceil(rate/30)/d);
			}
			PlaySE("seScore.wav");
		}
		case(ITEM_MULTI)
		{
			PlaySE(se[SE_ITEM_MULTI]);
			itemrate_num+=1;
			itemmulti_getcount++;
			itemmulti_totalcount+=0.5;
			if(red_alpha>10)
			{
				red_num-=10;
			}
		}
		case(ITEM_BOMB)
		{
			PlaySE(se[SE_ITEM_BOMB]);
			AddBomb(1);
		}
		case(ITEM_1UP)
		{
			PlaySE(se[SE_ITEM_1UP]);
			ExtendPlayer(1);
		}
		multiply_delay+=50;
		multiply_num=1000;
	}
}


task ConvCircle
{
	itemconv_flg=true;
	let rect=[0,128,128,256];
	let obj=SetEffectObject(tex[TEX_SYSTEM],3);
	SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
	ObjEffect_SetRenderState(obj,ALPHA);
	let alpha=0;
	while(!Obj_BeDeleted(obj))
	{
		let color=255;
		ascent(a in 0..4)
		{
			ObjEffect_SetVertexColor(obj,a,alpha,color,color,color);
		}
		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
		if(alpha<192){alpha+=5;}
		if(GetKeyState(VK_SHOT)==KEY_PUSH)
		{
			itemconv_flg=false;
			Obj_Delete(obj);
		}
		yield;
	}
}

task ItemBorderLine
{
	Msg;
	let rect=[0,104,384,112];
	let obj=SetEffectObject(tex[TEX_SYSTEM],3);
	SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
	ObjEffect_SetRenderState(obj,ADD);
	let alpha=5;
	let count=0;
	while(!Obj_BeDeleted(obj))
	{
		let color=255;
		ascent(a in 0..4)
		{
			ObjEffect_SetVertexColor(obj,a,alpha,color,color,color);
		}
		Obj_SetPosition(obj,cenX,itemborder);
		if(count<200)
		{
			if(alpha<240){alpha+=10;}
		}
		else
		{
			if(alpha>64){alpha-=2;}
		}
		if(alpha<0){Obj_Delete(obj);}
		count++;
		yield;
	}
	
	task Msg
	{
		let rect=[144,112,240,128];
		let obj=SetEffectObject(tex[TEX_SYSTEM],3);
		SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
		ObjEffect_SetRenderState(obj,ALPHA);
		let alpha=5;
		let count=0;
		while(!Obj_BeDeleted(obj))
		{
			let color=255;
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(obj,a,alpha,color,color,color);
			}
			Obj_SetPosition(obj,cenX,itemborder+8);
			if(count<200)
			{
				if(alpha<240){alpha+=10;}
			}
			else{alpha-=2;}
			if(alpha<0){Obj_Delete(obj);}
			count++;
			yield;
		}
	}
}