#TouhouDanmakufu[Player]
#ScriptVersion[3]
#ID["NUE"]
#Title["Nue Houjou"]
#Text["Undefined Type"]
#Image["./Face.png"]
#ReplayName["Nue"]
#include "./../functions1.txt"

PlayerSpeed = [4,1.85];

task TMain
{
}

task TShot
{
	let spread = 4;
	let counter = 0;
	let soundS = false;

	let IsShooting = false;
	let IsFocus = false;

	let angleOM = 0;
	let angleO1 = angleOM;
	let angleO2 = 0;
	let angleO3 = 0;
	let distOM = 0;
	let distO = 0;	
	let type = 0;

	ascent(i in 0..2)
		{
		TOption(i*2-1);
		}
	loop
		{
		if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD)
			{
			if(IsFocus == false)
				{
				type = 2;	
				spread = 4;
				}	
			IsFocus = true;
			}
		else
			{
			if(IsFocus == true)
				{
				type = 0;	
				spread = 5;
				}
			IsFocus = false;
			}
		if(type == 0)
			{
			angleO3 = 45;
			angleO2 = 0.25*angleO3/spread;
			angleOM = 45;
			distOM = 30;
			}
		else if(type == 1)
			{
			angleO2 = -35;
			angleO3 = 7.5;
			angleOM = 100;
			distOM = 80;
			}
		else if(type == 2)
			{
			angleO2 = 150;
			angleO3 = 45;
			angleOM = 150;
			distOM = 30;
			}
		distO += (distOM-distO)/5;
		angleO1 += (16+4*(1-ceil(type/2)))*sin(angleOM-angleO1);
		if((GetVirtualKeyState(VK_SHOT) == KEY_PUSH || GetVirtualKeyState(VK_SHOT) == KEY_HOLD))
			{
			if(GetPlayerState == STATE_NORMAL && IsPermitPlayerShot == true && ShotPermit == true)
				{
				if(counter%5 == 0)
					{
					PlaySound("se_PlayerShot1",120);
					ascent(i1 in 0..2)
						{
						i1 = i1-2/2+0.5;
						ascent(i2 in 0..2)
							{
							TSpam(GetPlayerX+i1*12,GetPlayerY-8+i2*30,140-i2*50,270+i1);
							}
						}
					}
				IsShooting = true;
				}
			else
				{
				IsShooting = false;
				}
			counter+=1;
			}
		else if(counter%5 != 0)
			{
			counter+=1;
			IsShooting = false;
			}
		else
			{
			IsShooting = false;
			}
		yield;
		}

	task TSpam(x,y,alpha,angle)
		{
		if(IsPermitPlayerShot == false){return;}		
		let graph = AMULET_RED;
		let damage = 2;
		if(type == 1)
			{
			graph = AMULET_BLUE;
			}
		if(type == 2)
			{
			graph = AMULET_GREEN;
			}
		let shot = CreatePlayerShotA1(x,y,20,angle,damage,1,graph);

		let shotPrior = 0.3;
		let shotDestRect = [-16,-16,16,16];
		let shotScale = [1.25,1.5];
		let shotColor = [0,0,255];

		Obj_SetRenderPriority(shot,shotPrior);
		ObjSprite2D_SetDestRect(shot,shotDestRect[0],shotDestRect[1],shotDestRect[2],shotDestRect[3]);
		ObjRender_SetScaleXYZ(shot,shotScale[0],shotScale[1],0);	
		ObjRender_SetColorHSV(shot,shotColor[0],shotColor[1],shotColor[2]);
		ObjRender_SetAlpha(shot,alpha);
		
		if(Effect >= 2){return;}
		while(!Obj_IsDeleted(shot))
			{	
			x = ObjMove_GetX(shot);	
			y = ObjMove_GetY(shot);
			angle = ObjMove_GetAngle(shot);
			yield;
			}
		if(IsPermitPlayerShot == false || Effect >= 2 || y < -64 || y > GetStgFrameHeight+64  || y < -64 || y > GetStgFrameWidth+64){return;}	
		let obj = CreatePlayerShotA1(x,y,0,angle,0,10^10,graph);

		Obj_SetRenderPriority(obj,shotPrior);
		ObjSprite2D_SetDestRect(obj,shotDestRect[0],shotDestRect[1],shotDestRect[2],shotDestRect[3]);
		ObjRender_SetScaleXYZ(obj,shotScale[0],shotScale[1],0);	
		ObjRender_SetColorHSV(obj,shotColor[0],shotColor[1],shotColor[2]);
		ObjRender_SetAlpha(obj,alpha);	
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		loop(30)
			{
			alpha-=100/30;
			x+=cos(angle);
			y+=sin(angle);
			ObjRender_SetAlpha(obj,alpha);
			ObjMove_SetPosition(obj,x,y);
			yield;
			}
		Obj_Delete(obj);
		}

	task TOption(dir)
		{
		let angleZ = 0;
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "Sprite.png");
		let scale = 9;
		ObjSprite2D_SetDestRect(obj,-(100/64)*scale,-scale,(100/64)*scale,scale);
		ObjRender_SetScaleXYZ(obj,dir,1,0);
		Obj_SetRenderPriority(obj,0.31);
		ObjRender_SetColorHSV(obj,0,0,175);		
		ObjRender_SetAlpha(obj,165);
		let counter = 0;
		while(PlayerDead == false)
			{
			let x = GetPlayerX+distO*cos(270+dir*angleO1);
			let y = GetPlayerY+distO*sin(270+dir*angleO1);
			angleZ+=4;
			ObjRender_SetPosition(obj,x,y,0);
			ObjRender_SetAngleZ(obj,12*sin(angleZ));
			Obj_SetVisible(obj,Obj_IsVisible(objPlayer));
			let graph = 0;
			if(IsShooting == true)
				{
				graph = 0.5;
				if(counter%5 == 0)
					{
					if(type == 2)
						{
						ascent(t in 0..1)
							{
							TSpam2(x,y-25*t,270);
							}
						}
					ascent(i in 0..spread)
						{
						ascent(t in 0..1)
							{
							let angle = 270+dir*(angleO2+i*angleO3/spread);
							TSpam2(x+t*25*cos(angle),y+t*25*sin(angle),angle);
							}
						}
					counter+=1;
					}
				else if(counter%5 != 0)
					{
					counter+=1;
					}
				}
			ObjSprite2D_SetSourceRect(obj,(type+graph)*84,145,(type+0.5+graph)*84,175);
			yield;
			}
		Obj_Delete(obj);
		task TSpam2(x,y,angle)
			{
			if(IsPermitPlayerShot == false){return;}		
			let graph = AMULET_RED;
			let damage =3.75;
			if(type == 1)
				{
				graph = AMULET_BLUE;
				damage = 2.75;
				}
			if(type == 2)
				{
				graph = AMULET_GREEN;
				damage = 4;
				}

			let shot = CreatePlayerShotA1(x,y,25,angle,damage,1,graph);
	
			let shotPrior = 0.3;
			let shotDestRect = [-16,-16,16,16];
			let shotScale = [1,1.5];
			let shotColor = [0,0,255];
			let alpha = 105;
	
			Obj_SetRenderPriority(shot,shotPrior);
			ObjSprite2D_SetDestRect(shot,shotDestRect[0],shotDestRect[1],shotDestRect[2],shotDestRect[3]);
			ObjRender_SetScaleXYZ(shot,shotScale[0],shotScale[1],0);		
			ObjRender_SetColorHSV(shot,shotColor[0],shotColor[1],shotColor[2]);
			ObjRender_SetAlpha(shot,alpha);

			if(Effect >= 2){return;}
			while(!Obj_IsDeleted(shot))
				{		
				x = ObjMove_GetX(shot);	
				y = ObjMove_GetY(shot);
				yield;
				}	
			if(IsPermitPlayerShot == false || Effect >= 2 || y < -64 || y > GetStgFrameHeight+64  || y < -64 || y > GetStgFrameWidth+64){return;}	
			let obj = CreatePlayerShotA1(x,y,0,angle,0,10^10,graph);
	
			Obj_SetRenderPriority(obj,shotPrior);
			ObjSprite2D_SetDestRect(obj,shotDestRect[0],shotDestRect[1],shotDestRect[2],shotDestRect[3]);
			ObjRender_SetScaleXYZ(obj,shotScale[0],shotScale[1],0);	
			ObjRender_SetColorHSV(obj,shotColor[0],shotColor[1],shotColor[2]);
			ObjRender_SetAlpha(obj,alpha);	
			ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
			loop(30)
				{
				alpha-=100/30;	
				x+=cos(angle);
				y+=sin(angle);
				ObjRender_SetAlpha(obj,alpha);
				ObjMove_SetPosition(obj,x,y);
				ObjMove_SetAngle(obj,angle);
				yield;
				}
			Obj_Delete(obj);
			}	

		}
}