#TouhouDanmakufu[Player]
#ScriptVersion[3]
#ID["TRES_JUNKO_A"]
#Title["Junko"]
#Image["./Face.png"]
#ReplayName["Junko"]

#include "./../main.txt"
#include "./Shot_Const.txt"

task TMain
{
	PlayerPath1 = GetCurrentScriptDirectory ~ "Sprite0.png";
	PlayerPath2 = GetCurrentScriptDirectory ~ "Sprite0.png";
	PlayerSpeed = [4,2];

	textureO = textureO ~ [GetCurrentScriptDirectory ~"img/shot.png"];
	textureO = textureO ~ [GetCurrentScriptDirectory ~"img/spell.png"];
	textureO = textureO ~ [GetCurrentScriptDirectory ~"img/face.png"];
	textureO = textureO ~ [GetCurrentScriptDirectory ~"img/face2.png"];
	ascent(i in 0..length(textureO))
		{
		LoadTexture(textureO[i]);
		}
}

task TShot
{	

	let pow = 0;

	let IsShooting = false;

	let count = 4;
	let counter = 0;
	
	loop
		{	
		pow = min(Pmax,GetPlayerPower);
		if(IsKeyState([VK_SHOT],[KEY_PUSH,KEY_HOLD]))
			{
			if(GetPlayerState == STATE_NORMAL && IsPermitPlayerShot == true && ShotPermit == true)
				{
				if(counter%count == 0)
					{
					PlaySound("se_PlayerShot1",100);
					let enm = FHomingEnemy(GetPlayerX,GetPlayerY,10000,10000,true);
					let a = FAngleToHomingEnemy(enm,GetPlayerX,GetPlayerY,270,0);
					ascent(i in -1..2)
						{
						TSpam(a+i*3);
						}
					}
				IsShooting = true;
				}
			else
				{
				IsShooting = false;
				}
			counter+=1;
			}
		else if(counter%count != 0)
			{
			counter+=1;
			IsShooting = false;
			}
		else
			{
			IsShooting = false;
			}
		yield;
		}

	task TSpam(a)
		{
		if(IsPermitPlayerShot == false){return;}
		let shot = CreatePlayerShotA1(GetPlayerX,GetPlayerY,26,a,75*count*(1/3)*sdr/60,1,PURE_1);
		ObjRender_SetAlpha(shot,205);
		ObjRender_SetScaleXYZ(shot,0.67,0.67,0);

		Obj_SetRenderPriority(shot,0.32);
		}
}

function FSpell
{
	SpellSwitch = true;	
	ShotPermit = false;

	let time = 240;
	SetPlayerInvincibilityFrame(time);

	let xP = GetPlayerX;
	let yP = GetPlayerY;

	let spell = ObjSpell_Create;
	ObjSpell_Regist(spell);
	ObjSpell_SetEraseShot(spell,true);
	ObjSpell_SetDamage(spell,75*bdr/60);

	TFace;

	let back = ObjPrim_Create(OBJ_SPRITE_2D);	
	ObjPrim_SetTexture(back,textureO[1]);
	ObjSprite2D_SetSourceRect(back,0,4,424,600);
	ObjSprite2D_SetDestRect(back,0,0,GetStgFrameWidth,GetStgFrameHeight);
	Obj_SetRenderPriority(back,0.29);
	Obj_SetVisible(back,false);

	ascent(t in 0..time)
		{
		if(t == 5)
			{
			Obj_SetVisible(back,true);
			}
		ObjSpell_SetIntersectionLine(spell,GetStgFrameWidth*0.5,-64,GetStgFrameWidth*0.5,GetStgFrameHeight+64,GetStgFrameWidth*0.5+64);
		yield;
		}			
	
	Obj_Delete(back);
	Obj_Delete(spell);
	ShotPermit = true;
	
	task TFace
		{
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(obj,textureO[3]);
		ObjSpriteList2D_SetSourceRect(obj,0,0,320,213);
		Obj_SetRenderPriority(obj, 0.3);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);

		let face = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(face,textureO[2]);
		ObjSpriteList2D_SetSourceRect(face,0,0,320,213);
		Obj_SetRenderPriority(face, 0.3);

		let flash = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(flash,"");
		ObjSprite2D_SetSourceRect(flash,0,0,1,1);
		ObjSprite2D_SetDestRect(flash,-64,-64,GetStgFrameWidth+64,GetStgFrameHeight+64);
		Obj_SetRenderPriority(flash, 0.3);
		ObjRender_SetColorHSV(flash,0,0,225);
		ObjRender_SetAlpha(flash,205);
	
		let s = 1.67;

		let spread = 28;
		let a = 90;

		ascent(t in 0..time)
			{
			ObjSpriteList2D_ClearVertexCount(obj);
			ObjSpriteList2D_ClearVertexCount(face);
			if(t%15 == 14 && t < time-30)
				{
				PlaySound("se_Shot4",50);	
				let x = rand(0.25,0.75)*GetStgFrameWidth;
				let y = rand(0.25,0.75)*GetStgFrameHeight;
				if(IsPermitPlayerShot == true)
					{
					ascent(i in 0..spread)
						{
						let shot = CreatePlayerShotA1(x,y,1,i*360/spread+a,0,10^10,PURE_2);
						ObjMove_SetAcceleration(shot,1/3);
						ObjMove_SetMaxSpeed(shot,10);
						}
					}
				a+=180/spread;
				}
			if(t >= 60)
				{
				descent(i in 0..3)
					{
					let shot = obj;
					if(i == 0)
						{
						shot = face;
						}
					ObjRender_SetScaleXYZ(shot,s,s,0);
					let x = -320*s+min(112,(t-60-i*15))*(GetStgFrameWidth+s*320*0.55)/112;
					ObjRender_SetPosition(shot,x,GetStgFrameHeight-212*0.75,0);
					ObjSpriteList2D_SetDestCenter(shot);
					ObjSpriteList2D_AddVertex(shot);
					}
				}
			if((t >= 5 && t < 11) || (t >= 25 && t < 31) || (t >= 50 && t < 52) || (t >= 85 && t < 91)|| (t >= 105 && t < 111) || (t >= 160 && t < 170) || (t >= 200 && t < 202) || (t >= 220 && t < 228))
				{	
				Obj_SetVisible(flash,true);
				}
			else
				{	
				Obj_SetVisible(flash,false);
				}
			yield;
			}
		Obj_Delete(obj);
		Obj_Delete(face);
		}
}

function FFlash
{
	return;
}