script_shot P_Item
{//パワーアイテム

	let imgItem=GetCurrentScriptDirectory~"img\effect_tiny.png";
	let imgScore =GetCurrentScriptDirectory~"img\imgScore.png";
	let speed=3;
	let PN= 5;
	let Rect= [0,172,12,188];
	let EndSwich = false;
	if(GetArgument==1){
		PN  = 100;
		Rect= [0,192,15,208];
	}
	@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){
				let N = GetCommonData("Power");
				SetCommonData("Power",N+PN);
				PlaySE("seScore.wav");
				let S = GetCommonData("Score");
				SetCommonData("Score",S+100);//点追加
				Score();		//自機近くに表示
				EndSwich = true;	//描画停止
				break;
			}
			yield;
		}
	}

	@Finalize
	{

	}
	
	@DrawLoop
	{//描画
		if(EndSwich==true){break;}
		SetTexture(imgItem);
		SetGraphicRect(Rect[0],Rect[1],Rect[2],Rect[3]);
		DrawGraphic(GetX(),GetY());
	}
	task Score{
		let ran = rand(-10,5);
		ScoreNun(GetPlayerX   +ran,GetPlayerY+ran,1);
		ScoreNun(GetPlayerX+ 8+ran,GetPlayerY+ran,0);
		ScoreNun(GetPlayerX+16+ran,GetPlayerY+ran,0);
	}

	task ScoreNun(PX,PY,i){//数字を表示
		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_SetVertexColor(obj,3,255,255,255,255);
		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);
		ObjEffect_SetScale(obj,1.5,1.5);
		Obj_SetPosition(obj,PX,PY);
		loop(30){
			Obj_SetPosition(obj,PX,PY);
			PY-=1;
			yield;
		}
		Obj_Delete(obj);
		End;
	}
}