script_shot TenItem
{//点アイテム

	let imgItem  =GetCurrentScriptDirectory~"img\effect_tiny.png";
	let imgScore =GetCurrentScriptDirectory~"img\imgScore.png";
	let EndSwich = false;
	let speed=3;
	@Initialize
	{
		SetAngle(-90);
		SetBombResist;
                Tmain;
	}
	
	@MainLoop
	{
		yield;
	}

        task Tmain{
		Move;
		loop{
			if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
				if(GetX<=GetPlayerX+48&&
				   GetX>=GetPlayerX-48&&
			 	   GetY<=GetPlayerY+48&&
			 	   GetY>=GetPlayerY-48){
			 	   GetMove(4);
				   break;
				}
			}
			if(GetX<=GetPlayerX+28&&
			   GetX>=GetPlayerX-28&&
		 	   GetY<=GetPlayerY+28&&
			   GetY>=GetPlayerY-28){
				GetMove(4);
				break;
			}
			if(GetPlayerY<=150){//上部回収
				GetMove(12);
				break;
			}
			yield;
		}
        }
	task Move{//自由落下
		loop{
             		if(GetY>GetClipMaxY+32){End;}
			if(speed>=-2){speed-=0.04;}
			SetSpeed(speed);
			yield;
		}
	}
	task GetMove(Mspeed){//低速時のアイテム吸収モーション
		speed=-Mspeed;//同時に自由落下停止
		loop{
			SetAngle(GetAngleToPlayer+180);
			if(GetX<=GetPlayerX+18&&
			   GetX>=GetPlayerX-18&&
		 	   GetY<=GetPlayerY+18&&
			   GetY>=GetPlayerY-18){
				GetEnd;
				break;
			}
			yield;
		}
	}

	task GetEnd{//アイテム収得して終了
		let IceScore = GetCommonData("GetIce");
		let PS;			//加算される点数
		let Cs = GetCommonData("C");
		EndSwich = true;	//描画停止
		if(GetPlayerY<=150){
		   PS = 200000 + GetGraze * 20 + IceScore + truncate(GetScore / 10);
		}
		if(GetPlayerY>150){
		   PS = truncate( (GetClipMaxY - GetPlayerY) * 35/ 10)*50;
		}
		AddPoint(1);		//取得ポイント増加
		PlaySE("seScore.wav");	//効果音
		Score(PS);		//自機近くに表示
		loop(60){
			let S = GetCommonData("Score");
			SetCommonData("Score",S+PS/60);//点追加
			yield;
		}
		End;
		
	}

	@Finalize
	{

	}
	
	@DrawLoop
	{//描画
		if(EndSwich==true){break;}
		SetTexture(imgItem);
		SetGraphicRect(16,176,28,188);
		DrawGraphic(GetX(),GetY());
	}

	task Score(PS){
		let ran = rand(-20,5);
		let S0 = truncate(PS/100000)-truncate(PS/1000000)*10;
		let S1 = truncate(PS/10000)- truncate(PS/100000)*10;
		let S2 = truncate(PS/1000)-  truncate(PS/10000)*10;
		let S3 = truncate(PS/100)-   truncate(PS/1000)*10;
		let S4 = truncate(PS/10)-    truncate(PS/100)*10;
		let S5 = truncate(PS/1)-     truncate(PS/10)*10;
		let col = false;
		if(PS>=200000){col = true;}
		if(PS>=100000){ScoreNun(GetPlayerX   +ran,GetPlayerY+ran,S0,col);}
		if(PS>=10000) {ScoreNun(GetPlayerX+ 8+ran,GetPlayerY+ran,S1,col);}
		if(PS>=1000)  {ScoreNun(GetPlayerX+16+ran,GetPlayerY+ran,S2,col);}
		ScoreNun(GetPlayerX+24+ran,GetPlayerY+ran,S3,col);
		ScoreNun(GetPlayerX+32+ran,GetPlayerY+ran,S4,col);
		ScoreNun(GetPlayerX+40+ran,GetPlayerY+ran,S5,col);
	}

	task ScoreNun(PX,PY,i,col2){//数字を表示
		let X=[128,138,148,158,168,178,188,198,208,218];
		let Y=[ 32,  0,  0,  0,  0,  0,  0,  0,  0, 32];
		let obj=Obj_Create(OBJ_EFFECT);
		Obj_SetAutoDelete(obj,false);
		ObjEffect_SetTexture(obj,imgScore);
		ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj,4);
		ObjEffect_SetVertexXY(obj,0,-5,-6);
		ObjEffect_SetVertexXY(obj,1, 5,-6);
		ObjEffect_SetVertexXY(obj,2,-5, 7);
		ObjEffect_SetVertexXY(obj,3, 5, 7);
		ObjEffect_SetVertexColor(obj,0,255,255,255,255);
		ObjEffect_SetVertexColor(obj,1,255,255,255,255);
		ObjEffect_SetVertexColor(obj,2,255,255,255,255);
		ObjEffect_SetScale(obj,1.5,1.5);
		if(col2 ==true){
			ObjEffect_SetVertexColor(obj,0,255,255,255,255/2);
			ObjEffect_SetVertexColor(obj,1,255,255,255,255/2);
			ObjEffect_SetVertexColor(obj,2,255,255,255,255/2);
			ObjEffect_SetVertexColor(obj,3,255,255,255,255/2);
		}
		ObjEffect_SetVertexUV(obj,0,X[i]  ,82);
		ObjEffect_SetVertexUV(obj,1,X[i]+9,82);
		ObjEffect_SetVertexUV(obj,2,X[i]  ,95);
		ObjEffect_SetVertexUV(obj,3,X[i]+9,95);
		ObjEffect_SetLayer(obj,8);
		Obj_SetPosition(obj,PX,PY);
		loop(30){
			Obj_SetPosition(obj,PX,PY);
			PY-=1;
			yield;
		}
		Obj_Delete(obj);
	}
}