#e[Player]
#ScriptVersion[2]
#Menu[얲@Aˑ]
#Text[
VbgFuLv`j[hv
{F아uz@ցv
VbgЗ́F
Vbǵ͈F
{З́F@@
ړxF@@]
#ReplayName[reimu1]	
script_player_main
{
	let current = GetCurrentScriptDirectory();
	let player= current~"dot_reimu.png";
	let slow= current~"slow_effect.png";
	let angle=0;
	let alpha=0;
	let shotCount = -1;
	let bNextShot = false;
	let op=0;
	let opx=[0];
	let opy=[0];
	let ppower=100;
	let misscount=0;
	@Initialize
	{
		SetPlayerLifeImage(player,1,150,25,175);
		LoadGraphic(player);
		LoadGraphic(slow);
		SetSpeed(4, 1.6);
		LoadPlayerShotData(current~"reimuShotData.txt");
		SetItemCollectLine(160);
		SetAutoEffect(false);
		shottask;
		optask;
	}
	
	@MainLoop
	{
		SetIntersectionCircle(GetPlayerX,GetPlayerY,0);
		yield;
	}
	@Missed
	{
		misscount++;
		if(misscount==74)
		{
			ppower-=100;
			misscount=-1;
		}
	}
	@SpellCard
	{
		UseSpellCard("musouhuuinen",0);
	}
	
	@DrawLoop
	{
		let i=0;
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(player);
		if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD)
		{
			SetGraphicRect(1,101,50,150);
		}
		else if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD)
		{
			SetGraphicRect(1,51,50,100);
		}
		else 
		{
			SetGraphicRect(1,1,50,50);
		}
		SetGraphicAngle(0,0,0);
		if(GetTimeOfPlayerInvincibility>0)
		{
			SetAlpha(96);
		}
		else
		{
			SetAlpha(255);
		}
		DrawGraphic(GetPlayerX,GetPlayerY);
		loop(op)
		{
			SetTexture(player);
			SetGraphicRect(1,151,25,175);
			SetGraphicAngle(0,0,angle);
			if(GetTimeOfPlayerInvincibility>0)
			{
				SetAlpha(96);
			}
			else
			{
				SetAlpha(255);
			}
			DrawGraphic(opx[i],opy[i]);
			i++;
		}
		SetTexture(slow);
		SetGraphicRect(0,0,61,61);
		SetGraphicAngle(0,0,angle);
		if(GetTimeOfPlayerInvincibility>0)
		{
			SetAlpha(alpha/3);
		}
		else
		{
			SetAlpha(alpha);
		}
		DrawGraphic(GetPlayerX,GetPlayerY);
		angle+=2;
		SetFontColor(255,255,255,255,255,128);
		DrawText(NumToString(ppower/100)~"/4.00",GetClipMinX,GetClipMaxY-64,18,255);
		DrawText("",GetClipMinX,GetClipMaxY-83,18,255);
		SetFontColor(255,255,255,255,255,255);
	}
	@Finalize
	{
		DeleteGraphic(player);
		DeleteGraphic(slow);
	}
	task shottask
	{
		loop(2)
		{
			yield;
		}
		loop
		{
			if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD || bNextShot==true)&&shotCount==-1)
			{
				shotCount=0;
				bNextShot=false;
			}
			if(GetKeyState(VK_SHOT)==KEY_HOLD&&shotCount>0)
			{
				bNextShot=true;
			}
			if(shotCount%5==0)
			{
				let i=0;
				CreatePlayerShot01(GetPlayerX-10,GetPlayerY,15,270,4,1,1);
				CreatePlayerShot01(GetPlayerX+10,GetPlayerY,15,270,4,1,1);
				loop(op)
				{
					if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
					{
						CreatePlayerShot01(opx[i]-5,opy[i],15,270,2,1,2);
						CreatePlayerShot01(opx[i]+5,opy[i],15,270,2,1,2);
					}
					else
					{
						CreatePlayerShot01(opx[i]-5,opy[i],15,267,2,1,2);
						CreatePlayerShot01(opx[i]+5,opy[i],15,273,2,1,2);
					}
					i++;
				}
			}
			if(shotCount >= 0)
			{
				shotCount++;
			}
			if(shotCount == 30)
			{
				shotCount=-1;
			}
			yield;
		}
	}
	task optask
	{
		let gp=0;
		let r=50;
		loop
		{
			ppower+=(GetPoint-gp)*5;
			op=trunc(ppower/100);
			if(op>4)
			{
				op=4;
			}
			if(op<1)
			{
				op=1;
			}
			if(ppower>400)
			{
				ppower=400;
			}
			if(ppower<100)
			{
				ppower=100;
			}
			if(op==1)
			{
				opx=[GetPlayerX+r*cos(270)];
				opy=[GetPlayerY+r*sin(270)];
			}
			if(op==2)
			{
				opx=[GetPlayerX+r*cos(0),GetPlayerX+r*cos(180)];
				opy=[GetPlayerY+r*sin(0),GetPlayerY+r*sin(180)];
			}
			if(op==3)
			{
				opx=[GetPlayerX+r*cos(0),GetPlayerX+r*cos(180),GetPlayerX+r*cos(270)];
				opy=[GetPlayerY+r*sin(0),GetPlayerY+r*sin(180),GetPlayerY+r*sin(270)];
			}
			if(op==4)
			{
				opx=[GetPlayerX+r*cos(0),GetPlayerX+r*cos(180),GetPlayerX+r*cos(240),GetPlayerX+r*cos(300)];
				opy=[GetPlayerY+r*sin(0),GetPlayerY+r*sin(180),GetPlayerY+r*sin(240),GetPlayerY+r*sin(300)];
			}
			if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
			{
				if(r>30)
				{
					r-=2;
				}
				if(alpha<255)
				{
					alpha+=15;
				}
			}
			else
			{
				if(r<50)
				{
					r+=2;
				}
				if(alpha>0)
				{
					alpha-=15;
				}
			}
			gp=GetPoint;
			yield;
		}
	}
	function NumToString(let num)
	{
		let leng = trunc(log10(num))+1;
		if(num==0){leng = 0}
		let string = ToString(num);
		let str = " ";
		let zero =ToString(0);
		times(1-leng)
		{
			string = str ~ string;
		}
		if(num==0)
		{
				string = zero~ string;
			loop(3)
			{
				string = str ~ string;
			}
		}
		return string[0..4];
	}
}

script_spell musouhuuinen
{
	let current=GetCurrentScriptDirectory();
	let bomb=current~"reimu_bomb.png";

	@Initialize
	{
		LoadGraphic(bomb);
		SetPlayerInvincibility(420);
		run();
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
		DeleteGraphic(bomb);
	}
	task run()
	{
		let angle=180;
		let time=180;
		loop(8)
		{
			musouhuuin(angle,time);
			angle+=75;
			time-=10;
		loop(10){;yield;}
		}
		loop(300){;yield;}
		End();
	}
	task musouhuuin(angle,time)
	{
		let x=GetPlayerX;
		let y=GetPlayerY;
		let r=0;
		let count=0;
		let scale=1;
		let obj = Obj_Create(OBJ_SPELL);
		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
		Obj_SetSpeed(obj,0);
		ObjEffect_SetTexture(obj,bomb);
		ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_SetScale(obj,scale,scale);
		ObjEffect_CreateVertex(obj,4);
		ObjEffect_SetVertexXY(obj,0,-15,-15);
		ObjEffect_SetVertexXY(obj,1,-15,15);
		ObjEffect_SetVertexXY(obj,2,15,-15);
		ObjEffect_SetVertexXY(obj,3,15,15);
		ObjEffect_SetVertexUV(obj,0,0,0);
		ObjEffect_SetVertexUV(obj,1,0,148);
		ObjEffect_SetVertexUV(obj,2,148,0);
		ObjEffect_SetVertexUV(obj,3,148,148);
		while(!Obj_BeDeleted(obj))
		{
			SetIntersectionCircle(Obj_GetX(obj),Obj_GetY(obj),15*scale,1.5*scale,true);
			Obj_SetPosition(obj,x+r*cos(angle),y+r*sin(angle));
			ObjEffect_SetScale(obj,scale,scale);
			ObjEffect_SetAngle(obj,0,0,angle*3);
			angle+=3;
			if(count<60)
			{
				r+=2;
				scale+=0.07;
			}

			if(count>time)
			{
				r+=5;
			}
			else
			{
				x=GetPlayerX;
				y=GetPlayerY;
			}
			count++;
			yield;
		}
	}
}
