#TouhouDanmakufu[Player]
#Menu[Patchouli]
#Text[Patchouli Knowledge
Power Type

Unfocused Bomb: 
Eruption
Focused Bomb: 
Deluge]
#Image[.\ct.png]
#ReplayName[Patchouli]
#ScriptVersion[2]

script_player_main
{
	let gcsd = GetCurrentScriptDirectory;

	let boss = gcsd~"patchouli.png";
	let cutin = gcsd~"ct.png";
	let spellback = gcsd~"spell.png";

	let circle1 = gcsd~"circle2.png";

	let opttype = circle1;
	let opt1 = [-32, 32];
	let opt2 = [-64, 0];
	let opt3 = [64, 0];
	let opt4 = [32, 32];

	let optang = 0;


	task Option(which)
	{
		let xy = [0, 0];

		let objoption=Obj_Create(OBJ_EFFECT);
	  	Obj_SetAlpha(objoption,200);
  		ObjEffect_SetTexture(objoption,opttype); 
  		ObjEffect_SetRenderState(objoption,ALPHA);
  		ObjEffect_SetPrimitiveType(objoption,PRIMITIVE_TRIANGLEFAN);
  		ObjEffect_CreateVertex(objoption,4);         
  		ObjEffect_SetVertexUV(objoption,0,0,0);  
  		ObjEffect_SetVertexUV(objoption,1,16,0);   
  		ObjEffect_SetVertexUV(objoption,2,16,16);
  		ObjEffect_SetVertexUV(objoption,3,0,16);

		while(!Obj_BeDeleted(objoption))
		{
			if(which==1){xy = [opt1[0], opt1[1]];}
			if(which==2){xy = [opt2[0], opt2[1]];}
			if(which==3){xy = [opt3[0], opt3[1]];}
			if(which==4){xy = [opt4[0], opt4[1]];}

			ObjEffect_SetVertexXY(objoption,0,GetPlayerX+xy[0]-8,GetPlayerY+xy[1]-8);
    		  	ObjEffect_SetVertexXY(objoption,1,GetPlayerX+xy[0]+8,GetPlayerY+xy[1]-8);
		              ObjEffect_SetVertexXY(objoption,2,GetPlayerX+xy[0]+8,GetPlayerY+xy[1]+8);
      			ObjEffect_SetVertexXY(objoption,3,GetPlayerX+xy[0]-8,GetPlayerY+xy[1]+8);

			if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
			{
				if(count%6==2)
				{
					CreatePlayerShot01(GetPlayerX+xy[0],GetPlayerY+xy[1], 8, -120, 1, 1, 99);
					CreatePlayerShot01(GetPlayerX+xy[0],GetPlayerY+xy[1], 8, -90, 1, 1, 99);
					CreatePlayerShot01(GetPlayerX+xy[0],GetPlayerY+xy[1], 8, -60, 1, 1, 99);
				}
			}
			else
			{
				if(count%6==2)
				{
					CreatePlayerShot01(GetPlayerX+xy[0],GetPlayerY+xy[1], 8, -100, 1, 1, 96);
					CreatePlayerShot01(GetPlayerX+xy[0],GetPlayerY+xy[1], 8, -90, 1, 1, 96);
					CreatePlayerShot01(GetPlayerX+xy[0],GetPlayerY+xy[1], 8, -80, 1, 1, 96);
				}
			}

			yield;
		}
	}


	@Initialize
	{
		LoadGraphic(boss);
		LoadGraphic(cutin);
		LoadGraphic(spellback);

		LoadGraphic(circle1);

		LoadPlayerShotData(gcsd~"supershot.txt");
		SetPlayerLifeImage(boss, 32, 0, 64, 48);
		SetSpeed(3, 1.5);
		SetInitialBombCount(3);

		Option(1); Option(2); Option(3); Option(4);
	}

	let count=0;

	@MainLoop
	{
		SetIntersectionCircle(GetPlayerX, GetPlayerY, 1.5);


		if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && count==-1)
		{
    			count = 0;
  		}
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			if(count%6==0)
			{
				CreatePlayerShot01(GetPlayerX, GetPlayerY-16, 8, -80, 3, 1, 152);
				CreatePlayerShot01(GetPlayerX, GetPlayerY-16, 8, -100, 3, 1, 152);
				CreatePlayerShot01(GetPlayerX, GetPlayerY-16, 8, -70, 3, 1, 152);
				CreatePlayerShot01(GetPlayerX, GetPlayerY-16, 8, -110, 3, 1, 152);
				CreatePlayerShot01(GetPlayerX, GetPlayerY-16, 8, -90, 3, 1, 152);
			}
		}
		else
		{
			if(count%6==0)
			{
				CreatePlayerShot01(GetPlayerX+16, GetPlayerY-12, 8, -82, 3, 1, 237);
				CreatePlayerShot01(GetPlayerX-16, GetPlayerY-12, 8, -98, 3, 1, 237);
				CreatePlayerShot01(GetPlayerX+8, GetPlayerY-14, 8, -86, 3, 1, 237);
				CreatePlayerShot01(GetPlayerX-8, GetPlayerY-14, 8, -94, 3, 1, 237);
				CreatePlayerShot01(GetPlayerX, GetPlayerY-16, 8, -90, 3, 1, 237);
			}
		}

		if(count>=0){count++;}
		if(count>=6&&(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)){count=-1;}
		if(count>=6){count=-1;}

		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			if(opt1[0]<-16){opt1=[opt1[0]+0.5, opt1[1]];}
			if(opt2[0]<-32){opt2=[opt2[0]+1, opt2[1]];}
			if(opt3[0]>32){opt3=[opt3[0]-1, opt3[1]];}
			if(opt4[0]>16){opt4=[opt4[0]-0.5, opt4[1]];}
		}
		else
		{
			if(opt1[0]>-32){opt1=[opt1[0]-0.5, opt1[1]];}
			if(opt2[0]>-64){opt2=[opt2[0]-1, opt2[1]];}
			if(opt3[0]<64){opt3=[opt3[0]+1, opt3[1]];}
			if(opt4[0]<32){opt4=[opt4[0]+0.5, opt4[1]];}
		}
		
			yield;
	}

	@Missed
	{
	}

	@SpellCard
	{
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH||GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			SetSpeed(1.5, 0.5);
			UseSpellCard("Deluge", 0);
			CutIn(YOUMU, "Water & Moon Sign uDelugev", cutin);
		}
		else
		{
			SetSpeed(1.5, 0.5);
			UseSpellCard("Eruption", 0);
			CutIn(YOUMU, "Fire & Earth Sign uEruptionv", cutin);
		}
	}

	@DrawLoop
	{
		SetTexture(boss);
		SetGraphicRect(32, 0, 64, 48);
		DrawGraphic(GetPlayerX, GetPlayerY);
	}

	@Finalize
	{
		DeleteGraphic(boss);
		DeleteGraphic(cutin);
		DeleteGraphic(spellback);

		DeleteGraphic(circle1);
	}
}

script_spell Eruption
{
	let gcsd = GetCurrentScriptDirectory;
	let img = gcsd~"supershot.png";

	task run
	{
		SetPlayerInvincibility(240);
		ForbidShot(true);
		loop(45){yield;}

		let x = GetPlayerX;
		let xvar = 0;
		loop(6)
		{
			loop(9)
			{
				CreateFireball(x+xvar);
				CreateFireball(x-xvar);
				xvar+=2;
				loop(2){yield;}
			}
			xvar = 0;
		}

		ForbidShot(false);
		SetSpeed(3, 1.5);
		loop(90){yield;}
		End;
	}

	@Initialize
	{
		LoadGraphic(img);
		run;
	}

	@MainLoop
	{
		CollectItems;
		yield;
	}

	@Finalize
	{
	}

	task CreateFireball(let x)
	{
		let alpha = 50;
		let obj = Obj_Create(OBJ_SPELL);
		Obj_SetPosition(obj, x, GetClipMaxY);
		Obj_SetSpeed(obj, 6);
		Obj_SetAngle(obj, -90);
		ObjEffect_SetTexture(obj, img);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetVertexUV(obj, 0, 16, 47);
		ObjEffect_SetVertexUV(obj, 1, 32, 47);
		ObjEffect_SetVertexUV(obj, 2, 32, 63);
		ObjEffect_SetVertexUV(obj, 3, 16, 63);
		
		while(!Obj_BeDeleted(obj))
		{
			ObjEffect_SetVertexColor(obj, 0, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj, 1, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj, 2, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj, 3, alpha, 255, 255, 255);

			ObjEffect_SetVertexXY(obj, 0, 32*cos(135), 128*sin(135));
			ObjEffect_SetVertexXY(obj, 1, 32*cos(225), 128*sin(225));
			ObjEffect_SetVertexXY(obj, 2, 32*cos(315), 128*sin(315));
			ObjEffect_SetVertexXY(obj, 3, 32*cos(45), 128*sin(45));

			ObjSpell_SetIntersecrionCircle(obj,Obj_GetX(obj),Obj_GetY(obj),16,2,true);

			yield;
		}
	}
}

script_spell Deluge
{
	let gcsd = GetCurrentScriptDirectory;
	let img = gcsd~"supershot.png";

	task run
	{
		SetPlayerInvincibility(180);
		ForbidShot(true);
		loop(45){yield;}

		let ang = 0;
		loop(45)
		{
			ascent(a in 0..8)
			{
				CreateAmuletS(GetPlayerX+32*cos(a*45), GetPlayerY-32, -90+15*sin(ang));
				CreateAmuletS(GetPlayerX+32*cos(a*45), GetPlayerY-32, -90-15*sin(ang));
			}
			ang+=16;
			yield;
		}

		ForbidShot(false);
		SetSpeed(3, 1.5);
		loop(45){yield;}
		End;
	}

	@Initialize
	{
		LoadGraphic(img);
		run;
	}

	@MainLoop
	{
		yield;
	}

	@Finalize
	{
	}

	task CreateAmuletS(let x, let y, let a)
	{
		let alpha = 100;
		let obj = Obj_Create(OBJ_SPELL);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, 9);
		Obj_SetAngle(obj, a);
		ObjEffect_SetTexture(obj,img);
   	 	ObjEffect_SetRenderState(obj,ADD);
    		ObjEffect_CreateVertex(obj,4);
   	 	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetVertexUV(obj,0,96,310);
      		ObjEffect_SetVertexUV(obj,1,112,310);
      		ObjEffect_SetVertexUV(obj,2,112,324);
      		ObjEffect_SetVertexUV(obj,3,96,324);
		while(!Obj_BeDeleted(obj))
		{
			ObjEffect_SetVertexColor(obj, 0, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj, 1, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj, 2, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj, 3, alpha, 255, 255, 255);

			ObjEffect_SetVertexXY(obj, 0, 16*cos(135+a), 16*sin(135+a));
			ObjEffect_SetVertexXY(obj, 1, 16*cos(225+a), 16*sin(225+a));
			ObjEffect_SetVertexXY(obj, 2, 16*cos(315+a), 16*sin(315+a));
			ObjEffect_SetVertexXY(obj, 3, 16*cos(45+a), 16*sin(45+a));

			ObjSpell_SetIntersecrionCircle(obj,Obj_GetX(obj),Obj_GetY(obj),16,0.5,true);

			yield;
		}
	}
}





/*
SetGraphicRect(16, 0, 32, 14);
	  |
	 V
ObjEffect_CreateVertex(obj,4);
ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
ObjEffect_SetVertexUV(obj, 0, 16, 0);
ObjEffect_SetVertexUV(obj, 1, 32, 0);
ObjEffect_SetVertexUV(obj, 2, 32, 14);
ObjEffect_SetVertexUV(obj, 3, 16, 14);


