#TouhouDanmakufu[Player]
#Menu[Keine]
#Text[Keine Kamishirasawa
Spread Type

Unfocused Bomb: 
Sacred Orb
Focused Bomb: 
Sacred Mirror

Special:
Can change the familiars' formation by pressing C]
#Image[.\ct2.png]
#ReplayName[Keine]
#ScriptVersion[2]

script_player_main
{
	let gcsd = GetCurrentScriptDirectory;

	let boss = gcsd~"keine.png";
	let cutin = gcsd~"ct2.png";
	let spellback = gcsd~"spell.png";

	let fam = gcsd~"fam.png";

	let tangent = [20, 80];
	let maxid = 8;
	let optang = 0;
	let fluc = 0;

	task Familiar(id)
	{
		let objoption=Obj_Create(OBJ_EFFECT);
  		ObjEffect_SetTexture(objoption,fam); 
  		ObjEffect_SetRenderState(objoption,ALPHA);
  		ObjEffect_SetPrimitiveType(objoption,PRIMITIVE_TRIANGLEFAN);
  		ObjEffect_CreateVertex(objoption,4);         
  		ObjEffect_SetVertexUV(objoption,0,0,0);  
  		ObjEffect_SetVertexUV(objoption,1,48,0);   
  		ObjEffect_SetVertexUV(objoption,2,48,48);
  		ObjEffect_SetVertexUV(objoption,3,0,48);

		while(!Obj_BeDeleted(objoption))
		{
			ObjEffect_SetVertexXY(objoption,0,GetPlayerX+tangent[1]*cos(optang+(360/maxid)*id)-12,GetPlayerY+tangent[0]*sin(optang+(360/maxid)*id)-12);
    		  	ObjEffect_SetVertexXY(objoption,1,GetPlayerX+tangent[1]*cos(optang+(360/maxid)*id)+12,GetPlayerY+tangent[0]*sin(optang+(360/maxid)*id)-12);
		              	ObjEffect_SetVertexXY(objoption,2,GetPlayerX+tangent[1]*cos(optang+(360/maxid)*id)+12,GetPlayerY+tangent[0]*sin(optang+(360/maxid)*id)+12);
      			ObjEffect_SetVertexXY(objoption,3,GetPlayerX+tangent[1]*cos(optang+(360/maxid)*id)-12,GetPlayerY+tangent[0]*sin(optang+(360/maxid)*id)+12);

			let angch = optang+(360/maxid)*id;
			while(angch<0){angch+=360;}
			while(angch>360){angch-=360;}

			if(angch>180&&angch<360)
			{
				ObjEffect_SetLayer(objoption, 2);
			}
			else
			{
				ObjEffect_SetLayer(objoption, 3);
			}

			if(count%12==6&&count!=0)
			{
				CreateNormalShot(GetPlayerX+tangent[1]*cos(optang+(360/maxid)*id), GetPlayerY+tangent[0]*sin(optang+(360/maxid)*id), -90, 45, 4);
			}			

			yield;
		}
	}

	task CreateNormalShot(let x, let y, let a, let g, let d)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, 12);
		Obj_SetAngle(obj, a);
		Obj_SetAlpha(obj, 100);
		ObjShot_SetGraphic(obj, g);
		ObjShot_SetDamage(obj, d);
		ObjShot_SetPenetration(obj, 1);
		while(!Obj_BeDeleted(obj))
		{
			yield;
		}
	}


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

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

		Familiar(0); Familiar(1); Familiar(2); Familiar(3); Familiar(4); Familiar(5); Familiar(6); Familiar(7);
	}

	let count=0;

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


		if(GetKeyState(VK_SLOWMOVE)!=KEY_HOLD&&OnBomb==false)
		{
			optang+=2;
		}
		if(GetKeyState(VK_USER)==KEY_PUSH)
		{
			fluc++;
			if(fluc>2){fluc=0;}
		}
		if(fluc==0){tangent = [20, 80];}
		if(fluc==1){tangent = [50, 50];}
		if(fluc==2){tangent = [80, 20];}
		if(fluc==3){tangent = [0+120*sin(optang), 0-120*sin(optang)];}


		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)
			{
				ascent(a in -2..3)
				{
					CreateNormalShot(GetPlayerX, GetPlayerY-12, -90+a*5, 47, 1);
					CreateNormalShot(GetPlayerX-48, GetPlayerY-12, -90+a*5, 47, 1);
					CreateNormalShot(GetPlayerX+48, GetPlayerY-12, -90+a*5, 47, 1);
				}
			}
		}
		else
		{
			if(count%6==0)
			{
				ascent(a in -2..3)
				{
					CreateNormalShot(GetPlayerX, GetPlayerY-12, -90+a*20, 47, 1);
					CreateNormalShot(GetPlayerX-24, GetPlayerY-12, -90+a*20, 47, 1);
					CreateNormalShot(GetPlayerX+24, GetPlayerY-12, -90+a*20, 47, 1);
				}
			}
		}

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

	@Missed
	{
	}

	@SpellCard
	{
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH||GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			SetSpeed(2.5, 2.5);
			UseSpellCard("Orb", 0);
			CutIn(YOUMU, "Sacred Treasure uOrbv", cutin);
		}
		else
		{
			SetSpeed(2.5, 2.5);
			UseSpellCard("Mirror", 0);
			CutIn(YOUMU, "Sacred Treasure uMirrorv", cutin);
		}
	}

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

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

		DeleteGraphic(fam);
	}
}

script_spell Orb
{
	let gcsd = GetCurrentScriptDirectory;
	let img = gcsd~"fam.png";

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

		CreateShotZ(1.5, -90, 120, 160, 0, 0, 0);

		ForbidShot(false);
		SetSpeed(4.5, 2.5);
		loop(180){yield;}
		End;
	}

	@Initialize
	{
		LoadGraphic(img);
		run;
	}

	@MainLoop
	{
		CollectItems;
		yield;
	}

	@Finalize
	{
	}

	task CreateShotZ(let v, let a, let t, let size, let sb, let x, let y)
	{
		let timer = t;
		let newsize = size/2;
		let obj = Obj_Create(OBJ_SPELL);
		if(sb==0){Obj_SetPosition(obj, GetPlayerX, GetPlayerY);}
		else{Obj_SetPosition(obj, x, y);}
		Obj_SetSpeed(obj, v);
		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,0,0);
      		ObjEffect_SetVertexUV(obj,1,48,0);
      		ObjEffect_SetVertexUV(obj,2,48,48);
      		ObjEffect_SetVertexUV(obj,3,0,48);
		while(!Obj_BeDeleted(obj))
		{
			timer--;
			if(timer==0)
			{
				if(newsize>10)
				{
					ascent(b in 0..8)
					{
						CreateShotZ(8, b*45, 10, newsize, 1, Obj_GetX(obj), Obj_GetY(obj));
					}
				} 
				Obj_Delete(obj);
			}

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

			if(sb==0){ObjSpell_SetIntersecrionCircle(obj,Obj_GetX(obj),Obj_GetY(obj),size/1.7,0.5,true);}
			else{ObjSpell_SetIntersecrionCircle(obj,Obj_GetX(obj),Obj_GetY(obj),size/1.7,2.5,true);}

			yield;
		}
	}
}

script_spell Mirror
{
	let gcsd = GetCurrentScriptDirectory;
	let img = gcsd~"fam.png";
	let avar = 0;
	let alpha = 255;

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

		loop(15)
		{
			ascent(a in 0..12){CreateShot(a*30+avar);CreateShot(a*30-avar);}
			avar+=2;
			loop(2){yield;}
		}

		loop(90){yield;}

		ForbidShot(false);
		SetSpeed(4.5, 2.5);
		loop(90){yield;alpha-=3;if(alpha<0){alpha=0;}}
		End;
	}

	@Initialize
	{
		LoadGraphic(img);
		run;
	}

	@MainLoop
	{
		CollectItems;
		yield;
	}

	@Finalize
	{
	}

	task CreateShot(let a)
	{
		let obj = Obj_Create(OBJ_SPELL);
		Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
		Obj_SetSpeed(obj, 8);
		Obj_SetAngle(obj, a);
		ObjEffect_SetTexture(obj,img);
   	 	ObjEffect_SetRenderState(obj,ALPHA);
    		ObjEffect_CreateVertex(obj,4);
   	 	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetVertexUV(obj,0,0,0);
      		ObjEffect_SetVertexUV(obj,1,48,0);
      		ObjEffect_SetVertexUV(obj,2,48,48);
      		ObjEffect_SetVertexUV(obj,3,0,48);
		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));

			if(Obj_GetX(obj)>GetClipMaxX||Obj_GetX(obj)<GetClipMinX){Obj_SetAngle(obj, 180-Obj_GetAngle(obj)+rand(-5, 5));}
			if(Obj_GetY(obj)>GetClipMaxY||Obj_GetY(obj)<GetClipMinY){Obj_SetAngle(obj, -Obj_GetAngle(obj)+rand(-5, 5));}

			ObjSpell_SetIntersecrionCircle(obj,Obj_GetX(obj),Obj_GetY(obj),16,0.6,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);


