#東方弾幕風[Player]
#ScriptVersion[2]
#Menu[選択してゲームを開始してください]
#Text[]
#Image[]
#ReplayName[pl00]
script_player_main {
AddArchiveFile( GetCurrentScriptDirectory ~ "pl00_th10.dat" );

//サブショットの威力設定　火力の調整にどうぞ
	let pl00_main_damage	=1;//メインショット
	let pl00_Asub_damage	=1.5;//A装備サブショット(未使用、書き換えれば使える)
	let pl00_Bsub_damage01	=2.7;//B装備サブショット(高速時)
	let pl00_Bsub_damage02	=2;//B装備サブショット(低速時)

#include_function".\txt\System.txt"
#include_function ".\effectdata\Obj_Shot_th10.txt"


	@Initialize{
	LoadGraphic(LifeIcon);
	SetPlayerLifeImage(LifeIcon,0,0,48,48);
	LoadSE(shot);
	LoadSE(se_spell);
	SetItemCollectLine(144);
	SetRebirthFrame(8);
	LoadGraphic(pl00b);
	LoadGraphic(imgPlayer2);
	LoadGraphic(imgeffect);
	LoadGraphic(imgcircle);
	LoadGraphic(pl00_spell);
	LoadGraphic(csd~".\img\Effect03.png");
	SetAutoEffect(false);
	LoadPlayerShotData(csd~".\ShotData.txt");
	SetInitialBombCount(4);
	SetCommonData("PlayerItemCollectLine",144);
	StartTask;
	SetSpeed(4.5,1.7);
	}
	task StartTask{
	MainShot;
	SubShot;
	Missedtask;
	ScaleControl;
	if(PowerSystem=="Enable"){PowerUpTask;}
	}


	task Missedtask{//被弾時のエフェクト
		loop{
		if(OnMissed!=false){
			while(IsLastSpell){yield;}
			if(OnBomb){Missedtask;return;}
			EnemyBreakDown_th14();
			if(!OnBomb&&PowerSystem=="Enable"){SetPlayerPower(300);}
			loop(172){if(!OnMissed){break;}yield;}
			}
		yield;
		}
	}
	task MainShot{
	loop{
	loop(3){yield;}
	if(GetKeyState(VK_SHOT)==KEY_HOLD){
		if(OnMissed!=false){}
		else{PlaySE(shot);}
		PlayerShot01(GetPlayerX+10, GetPlayerY,270);
		PlayerShot01(GetPlayerX-10, GetPlayerY,270);
			}
		}
	}
	task SubShot{
	let count=0;
	loop{
	count++;
		if(GetKeyState(VK_SHOT)==KEY_HOLD){
		if(GetKeyState(VK_SLOWMOVE)==KEY_FREE&&count%5==0){
			if(GetPower>=100&&GetPower<200){
			HomingShot(X1,Y1,270,dmgA,10);
				}
			if(GetPower>=200&&GetPower<300){
			HomingShot(X1,Y1,270,dmgA,10);
			HomingShot(X2,Y2,270,dmgA,10);
				}
			if(GetPower>=300&&GetPower<400){
			HomingShot(X1,Y1,270,dmgA,10);
			HomingShot(X2,Y2,270,dmgA,10);
			HomingShot(X3,Y3,270,dmgA,10);
				}
			if(GetPower>=400){
			HomingShot(X1,Y1,270,dmgA,10);
			HomingShot(X2,Y2,270,dmgA,10);
			HomingShot(X3,Y3,270,dmgA,10);
			HomingShot(X4,Y4,270,dmgA,10);
				}
			if(GetPower>=500){
			HomingShot(X1,Y1,300,dmgA,10);
			HomingShot(X2,Y2,240,dmgA,10);
			HomingShot(X3,Y3,285,dmgA,10);
			HomingShot(X4,Y4,255,dmgA,10);
				}
			}
		if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD&&count%3==0){
			if(GetPower>=100&&GetPower<200){
			HomingShot(X1,Y1,270,dmgB,5);
				}
			if(GetPower>=200&&GetPower<300){
			HomingShot(X1,Y1,270,dmgB,5);
			HomingShot(X2,Y2,270,dmgB,5);
				}
			if(GetPower>=300&&GetPower<400){
			HomingShot(X1,Y1,270,dmgB,5);
			HomingShot(X2,Y2,270,dmgB,5);
			HomingShot(X3,Y3,270,dmgB,5);
				}
			if(GetPower>=400){
			HomingShot(X1,Y1,270,dmgB,5);
			HomingShot(X2,Y2,270,dmgB,5);
			HomingShot(X3,Y3,270,dmgB,5);
			HomingShot(X4,Y4,270,dmgB,5);
				}
			if(GetPower>=500){
			HomingShot(X1,Y1,300,dmgB,5);
			HomingShot(X2,Y2,240,dmgB,5);
			HomingShot(X3,Y3,285,dmgB,5);
			HomingShot(X4,Y4,255,dmgB,5);
				}
			}
		}
	yield;}
	}

task PowerUpTask{
	let PowerSE=[100,200,300,400,500,9999];
	let playerpower=0;
	if(GetPower>=100){playerpower=1;}
	if(GetPower>=200){playerpower=2;}
	if(GetPower>=300){playerpower=3;}
	if(GetPower>=400){playerpower=4;}
	if(GetPower>=500){playerpower=5;}
	loop(30){yield;}
	loop{
		if(GetPower>=PowerSE[playerpower]){
		playerpower++;
		if(!OnMissed){PlaySE(se_powerup);}
		}
		if(GetPower<PowerSE[4]){playerpower=4;}
		if(GetPower<PowerSE[3]){playerpower=3;}
		if(GetPower<PowerSE[2]){playerpower=2;}
		if(GetPower<PowerSE[1]){playerpower=1;}
		if(GetPower<PowerSE[0]){playerpower=0;}
		if(playerpower>=5){playerpower=5;}
		yield;
	}
}


	@MainLoop{
	if( PowerSystem == "Disable" ){SetPlayerPower(500);}
		let t = [3,3][isFocusing];
		isFocusing = GetKeyState(VK_SLOWMOVE)!=KEY_FREE;
		X1+=(GetPlayerX+xt[0]*[1,0][AsKoishi]-X1)/t;
		X2+=(GetPlayerX+xt[1]*[1,0][AsKoishi]-X2)/t;
		X3+=(GetPlayerX+xt[2]*[1,0][AsKoishi]-X3)/t;
		X4+=(GetPlayerX+xt[3]*[1,0][AsKoishi]-X4)/t;
		Y1+=(GetPlayerY+yt[0]*[1,0][AsKoishi]-Y1)/t;
		Y2+=(GetPlayerY+yt[1]*[1,0][AsKoishi]-Y2)/t;
		Y3+=(GetPlayerY+yt[2]*[1,0][AsKoishi]-Y3)/t;
		Y4+=(GetPlayerY+yt[3]*[1,0][AsKoishi]-Y4)/t;
		s+=([1,0][AsKoishi]-s)/8;
	if(GetPower<100){
	xt = [[0, 0, 0, 0],[0, 0, 0, 0]][isFocusing];
	yt = [[3000, 3000, 3000, 3000],[3000,3000, 3000, 3000]][isFocusing];
	shot_damage=pl00_main_damage*4;
	}if(GetPower>=100){
	xt = [[0, 0, 0, 0],[0, 0, 0, 0]][isFocusing];
	yt = [[-32, 3000, 3000, 3000],[-24,3000, 3000, 3000]][isFocusing];
	dmgA=pl00_Bsub_damage01*1.75;
	dmgB=pl00_Bsub_damage02*1.75;
	shot_damage=pl00_main_damage*2;
	}if(GetPower>=200){
	xt = [[-32, 32, 0, 0],[-16, 16, 0, 0]][isFocusing];
	yt = [[0, 0, 3000, 3000],[24, 24, 3000, 3000]][isFocusing];
	dmgA=pl00_Bsub_damage01*1.5;
	dmgB=pl00_Bsub_damage02*1.5;
	shot_damage=pl00_main_damage*1.5;
	}if(GetPower>=300){
	xt = [[-32, 32, 0, 0],[-16, 16, 0, 0]][isFocusing];
	yt = [[0, 0, 32, 3000],[24, 24, 32,3000]][isFocusing];
	dmgA=pl00_Bsub_damage01*1.2;
	dmgB=pl00_Bsub_damage02*1.2;
	shot_damage=pl00_main_damage*1.25;
	}if(GetPower>=400){
	dmgA=pl00_Bsub_damage01;
	dmgB=pl00_Bsub_damage02;
	shot_damage=pl00_main_damage;
	xt = [[-32, 32, -16, 16],[-16, 16, -8, 8]][isFocusing];
	yt = [[0, 0, 32, 32],[24, 24, 32, 32]][isFocusing];
	}
	if(GetCommonDataDefault("ShotHit",0)!=0){SetCommonData("ShotHit",0);}
	SetItemCollectLine(144);
	SetIntersectionCircle(GetPlayerX, GetPlayerY,0.5);
	SetGrazeCircle(70);
	AnimTime++;
	if(GetTimeOfPlayerInvincibility > 0) { if(colF==0) { col++; col%=2; } colF++; colF%=2; } else { col = 0; colF = 0; }
	if(AnimTime%6==0){
		AnimNo++;
		if(AnimNo>=2){AnimNo=0;}
		}
	if(PowerSystem=="Enable"){
		if(GetPower<100){SetPlayerSpell(0);}
		if(GetPower>=100){SetPlayerSpell(1);}
		}
	yield;
	}
	@Missed{if(!IsLastSpell){SetPlayerInvincibility(300);}MainLoop;}
	@SpellCard{if(IsLastSpell==true){UseSpellCard("Reigeki_L",0);}else{UseSpellCard("Reigeki",0);}}
	@DrawLoop{
	anglebase+=2;

		SetGraphicAngle( 0, 0, anglebase*2);
		SetRenderState(ALPHA);
		SetTexture(pl00b);
		SetGraphicScale(1,1);
		SetAlpha(255);
		//SetGraphicRect(64,144, 80,160);
		SetGraphicRect(22,161,38,177);
		DrawGraphic(X1,Y1);
		DrawGraphic(X2,Y2);
		DrawGraphic(X3,Y3);
		DrawGraphic(X4,Y4);
		SetGraphicAngle( 0, 0, 0);
		SetRenderState(ALPHA);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetTexture(pl00b);
		SetColor(128+127*((-1)^col), 128+127*((-1)^col), 255);
		/*
		if(GetKeyState(VK_RIGHT)==KEY_HOLD){
			alternative(AnimNo)
			case(0){SetGraphicRect(  0, 96, 32,144);}
			case(1){SetGraphicRect( 32, 96, 64,144);}
			case(2){SetGraphicRect( 64, 96, 96,144);}
			case(3){SetGraphicRect( 96, 96,128,144);}
			case(4){SetGraphicRect(128, 96,160,144);}
			case(5){SetGraphicRect(128, 96,160,144);}
			case(6){SetGraphicRect(160, 96,192,144);}
			case(7){SetGraphicRect(160, 96,192,144);}
			case(8){SetGraphicRect(192, 96,224,144);}
			case(9){SetGraphicRect(192, 96,224,144);}
			case(10){SetGraphicRect(224, 96,256,144);}
			case(11){SetGraphicRect(224, 96,256,144);}
			case(12){SetGraphicRect(128, 96,160,144);}
			}
		else if(GetKeyState(VK_LEFT)==KEY_HOLD){
			alternative(AnimNo)
			case(0){SetGraphicRect(  0, 48, 32,96);}
			case(1){SetGraphicRect( 32, 48, 64,96);}
			case(2){SetGraphicRect( 64, 48, 96,96);}
			case(3){SetGraphicRect( 96, 48,128,96);}
			case(4){SetGraphicRect(128, 48,160,96);}
			case(5){SetGraphicRect(128, 48,160,96);}
			case(6){SetGraphicRect(160, 48,192,96);}
			case(7){SetGraphicRect(160, 48,192,96);}
			case(8){SetGraphicRect(192, 48,224,96);}
			case(9){SetGraphicRect(192, 48,224,96);}
			case(10){SetGraphicRect(224, 48,256,96);}
			case(11){SetGraphicRect(224, 48,256,96);}
			case(12){SetGraphicRect(128, 48,160,96);}
			}
		else {
			alternative(AnimNo)
			case(0){SetGraphicRect(0, 0, 32,48);}
			case(1){SetGraphicRect(32,0,64,48);}
			case(2){SetGraphicRect(64, 0, 96,48);}
			case(3){SetGraphicRect(96,0,128,48);}
			case(4){SetGraphicRect(128, 0, 160,48);}
			case(5){SetGraphicRect(160,0,192,48);}
			case(6){SetGraphicRect(192, 0, 224,48);}
			case(7){SetGraphicRect(224,0,256,48);}
			}
		*/
		if(GetKeyState(VK_RIGHT)==KEY_HOLD){
			alternative(AnimNo)
			case(0){SetGraphicRect(0, 96, 48,144);}
			case(1){SetGraphicRect(48,96,96,144);}
			case(2){SetGraphicRect(0, 96, 48,144);}
			}
		else if(GetKeyState(VK_LEFT)==KEY_HOLD){
			alternative(AnimNo)
			case(0){SetGraphicRect(0, 48, 48,96);}
			case(1){SetGraphicRect(48,48,96,96);}
			case(2){SetGraphicRect(0, 48, 48,96);}
			}
		else {
			alternative(AnimNo)
			case(0){SetGraphicRect(0, 0, 48,48);}
			case(1){SetGraphicRect(48,0,96,48);}
			case(2){SetGraphicRect(0, 0, 48,48);}
			}
		DrawGraphic(GetPlayerX, GetPlayerY);
		SetColor(255,255,255);
		if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
		SetGraphicAngle(0,0,ang2);
		SetRenderState(ALPHA);
		SetTexture(imgcircle);
		SetGraphicScale(scale2/2,scale2/2);
		SetGraphicRect(0,0,256,256);
		SetAlpha(255);
		DrawGraphic(GetPlayerX, GetPlayerY);
		SetGraphicAngle( 0, 0,-ang2);
		SetRenderState(ALPHA);
		SetTexture(imgcircle);
		SetGraphicScale(scale2/2,scale2/2);
		SetGraphicRect(0,0,256,256);
		SetAlpha(255);
		DrawGraphic(GetPlayerX, GetPlayerY);
		if(Alpha!=255){Alpha+=15}
			HitBox(scale2*2);
			}
		else {Alpha=0;}
	}
//スクリプト終了
	@Finalize{}
	task ScaleControl{
		let ang=0;
		let count=0;
		loop{
			if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH){scale2=0.0;}
			if(GetKeyState(VK_SLOWMOVE)==KEY_PULL){scale2=0.0;count=0;ang=0;ang2=0;}
			if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
			if(count<=12){
			scale2=0.6+0.1*sin(ang);
			ang+=20;
			ang%=360;
			count++;
				}
			else{ang2+=2;scale2=0.5;}
			}
			yield;
		}
	}
	task HitBox(sca){
	let obj = Obj_Create(OBJ_EFFECT);
	let L=0;
	let T=0;
	let R=16;
	let B=16;
	let width = R-L;
	let height = B-T;
	let alpha = 255;
	let r = 255;
	let g = 255;
	let b = 255;

	ObjEffect_SetTexture(obj,imgeffect);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetLayer(obj,5);
	ObjEffect_SetAngle(obj,0,0,0);
	ObjEffect_SetScale(obj,sca,sca);
	Obj_SetPosition(obj,GetPlayerX,GetPlayerY);

	ObjEffect_SetVertexXY(obj, 0,-width/2,-height/2);
	ObjEffect_SetVertexXY(obj, 1, width/2,-height/2);
	ObjEffect_SetVertexXY(obj, 2, width/2, height/2);
	ObjEffect_SetVertexXY(obj, 3,-width/2, height/2);

	ObjEffect_SetVertexUV(obj, 0, L, T);
	ObjEffect_SetVertexUV(obj, 1, R, T);
	ObjEffect_SetVertexUV(obj, 2, R, B);
	ObjEffect_SetVertexUV(obj, 3, L, B);

	ObjEffect_SetVertexColor(obj, 0, alpha, r, g, b);
	ObjEffect_SetVertexColor(obj, 1, alpha, r, g, b);
	ObjEffect_SetVertexColor(obj, 2, alpha, r, g, b);
	ObjEffect_SetVertexColor(obj, 3, alpha, r, g, b);
	yield;
	Obj_Delete(obj);
	}
task EnemyBreakDown_th14(){
	let pos	= [GetPlayerX,GetPlayerY];
	let blend	= ADD;
	EnemyBreakDownC_th14(pos,[48,0],blend,60);
	EnemyBreakDownC_th14(pos,[-48,0],blend,60);
	EnemyBreakDownC_th14(pos,[0,48],blend,60);
	EnemyBreakDownC_th14(pos,[0,-48],blend,60);
	loop(24){ yield; }
	EnemyBreakDownC_th14(pos,[0,0],blend,60-32);
}
task EnemyBreakDownC_th14(posD,posM,blend,long){
	let id			= Obj_Create(OBJ_EFFECT);
	let pos			= [ posD[0]+posM[0], posD[1]+posM[1] ];
	let sca1		= 0;
	let scaA		= 0;
	let alpha		= 255;
	Obj_SetPosition(id, pos[0], pos[1] );
	ObjEffect_SetTexture(id, csd~".\img\Effect03.png" );
	ObjEffect_SetRenderState(id,blend);
	ObjEffect_SetAngle(id, 0, 0,0) ;
	ObjEffect_SetScale(id, sca1, sca1 );
	ObjSprite2D_SetSourceRect(id, PRIMITIVE_TRIANGLESTRIP,0, 0, 512, 512 );
	ObjEffect_SetLayer(id,4);
	ObjRender_SetColor(id,alpha,alpha,alpha);
	while( !Obj_BeDeleted(id) && sca1 < 1 ){
		if( sca1 < 1 ){ sca1 += scaA; }
		if( scaA < 1 ){ scaA += 0.0008; }
		ObjEffect_SetScale(id, sca1*4.8, sca1*4.8 );
		ObjRender_SetColor(id,alpha,alpha,alpha);
		ObjEffect_SetAngle(id,  0,  0,sca1*360) ;
		alpha-=2.5;
		yield;
	}
	loop(long){
	ObjRender_SetColor(id,alpha,alpha,alpha);
	alpha-=5;
		if( Obj_BeDeleted(id) ){ break; }
		yield;
	}
	Obj_Delete(id);
}

	task ObjSprite2D_SetSourceRect(obj,type,x1,y1,x2,y2){//2つにのみ対応
	let x3=x2-x1;
	let y3=y2-y1;
	ObjEffect_CreateVertex(obj,4);
	if(type==0){
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetVertexXY(obj,0,-x3/2,-y3/2);
	ObjEffect_SetVertexXY(obj,1, x3/2,-y3/2);
	ObjEffect_SetVertexXY(obj,2, x3/2, y3/2);
	ObjEffect_SetVertexXY(obj,3,-x3/2, y3/2);
	ObjEffect_SetVertexUV(obj,0,x1,y1);
	ObjEffect_SetVertexUV(obj,1,x2,y1);
	ObjEffect_SetVertexUV(obj,2,x2,y2);
	ObjEffect_SetVertexUV(obj,3,x1,y2);
		}
	else{
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_SetVertexXY(obj,0,-x3/2,-y3/2);
	ObjEffect_SetVertexXY(obj,1,-x3/2, y3/2);
	ObjEffect_SetVertexXY(obj,2, x3/2,-y3/2);
	ObjEffect_SetVertexXY(obj,3, x3/2, y3/2);
	ObjEffect_SetVertexUV(obj,0,x1,y1);
	ObjEffect_SetVertexUV(obj,1,x1,y2);
	ObjEffect_SetVertexUV(obj,2,x2,y1);
	ObjEffect_SetVertexUV(obj,3,x2,y2);
		}
	}
	task ObjRender_SetColor(obj,r,g,b){
	let alpha=(r+g+b)/3;
	ObjEffect_SetVertexColor(obj,0,alpha,r,g,b);
	ObjEffect_SetVertexColor(obj,1,alpha,r,g,b);
	ObjEffect_SetVertexColor(obj,2,alpha,r,g,b);
	ObjEffect_SetVertexColor(obj,3,alpha,r,g,b);
	}
}
script_spell Reigeki {
	#include_function".\txt\System.txt"
		let Y=8;
	@Initialize { SetPlayerInvincibility(300); PlaySE(se_spell); SetPlayerPower(GetPower-100); CreateBomb; }
	let size = [1, 1/3][GetArgument];
	@MainLoop {
		yield;
	}
	task CreateBomb {
		let obj = Obj_Create(OBJ_SPELL);
		let num = 32; let repeat = 4;
		ObjEffect_SetTexture(obj, imgPlayer2);
		ObjEffect_SetLayer(obj, 3);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj, 2*(num+1));
		ObjEffect_SetRenderState(obj, ADD);
		let angle = rand(0,360);
		let r = 0;
		Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
		let alpha = 0;
		ascent(n in 0..240) {
			Obj_SetY(obj, Obj_GetY(obj)-3/Y*size);
			ascent(i in 0..num+1) {
				ObjEffect_SetVertexUV(obj, i*2+0, 0, 64+(i*128*repeat/num)%128);
				ObjEffect_SetVertexUV(obj, i*2+1, 32, 64+(i*128*repeat/num)%128);
				ObjEffect_SetVertexXY(obj, i*2+0, (128+8)*cos(angle+i*360/num), (128+8)*sin(angle+i*360/num));
				ObjEffect_SetVertexXY(obj, i*2+1, (128-8)*cos(angle+i*360/num), (128-8)*sin(angle+i*360/num));
				ObjEffect_SetVertexColor(obj, i*2+0, 255, alpha*255, alpha*255, alpha*255);
				ObjEffect_SetVertexColor(obj, i*2+1, 255, alpha*255, alpha*255, alpha*255);
			}
			ObjEffect_SetScale(obj, r*size, r*size);
			ObjSpell_SetIntersecrionCircle(obj, Obj_GetX(obj), Obj_GetY(obj), 128*r*size, 5*size, true);
			if(n < 30) { r+=1/30; alpha+=1/30; } else if(n >= 210) { alpha-=1/30; }
			if(n%15 == 0 && n < 120) { CreateBombP(Obj_GetX(obj), Obj_GetY(obj)); }
			if(n > 30 && n<180) { let a = rand(0,360); loop(2) { ascent(n in 0..2) { CreateBombL(Obj_GetX(obj)+(128+rand(-5,5))*r*size*cos(a), Obj_GetY(obj)+(128+rand(-5,5))*r*size*sin(a), a, n); } } }
			angle+=(pi^3)/5; angle%=360;
			yield;
		}
		Obj_Delete(obj); End;
	}
	task CreateBombP(x,y) {
		let obj = Obj_Create(OBJ_EFFECT);
		let num = 16; let repeat = 4;
		ObjEffect_SetTexture(obj, imgPlayer2);
		ObjEffect_SetLayer(obj, 3);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj, 2*(num+1));
		ObjEffect_SetRenderState(obj, ADD);
		let angle = rand(0,360);
		let r = 0; let r2 = 1+rand(-1,1)/10;
		Obj_SetPosition(obj, x, y);
		let alpha = 0;
		ascent(n in 0..120) {
			Obj_SetY(obj, Obj_GetY(obj)-3/Y*size);
			ascent(i in 0..num+1) {
				ObjEffect_SetVertexUV(obj, i*2+0, 0, 64+(i*128*repeat/num)%128);
				ObjEffect_SetVertexUV(obj, i*2+1, 32, 64+(i*128*repeat/num)%128);
				ObjEffect_SetVertexXY(obj, i*2+0, (128+8)*cos(angle+i*360/num), (128+8)*sin(angle+i*360/num));
				ObjEffect_SetVertexXY(obj, i*2+1, (128-8)*cos(angle+i*360/num), (128-8)*sin(angle+i*360/num));
				ObjEffect_SetVertexColor(obj, i*2+0, 255, alpha*255, alpha*0, alpha*255);
				ObjEffect_SetVertexColor(obj, i*2+1, 255, alpha*255, alpha*0, alpha*255);
			}
			ObjEffect_SetScale(obj, r*size, r*size);
			if(n < 30) { alpha+=1/30; } else if(n >= 90) { alpha-=1/30; }
			if(n < 60) { r+=r2/60; }
			angle+=(pi^3)/5; angle%=360;
			yield;
		}
		Obj_Delete(obj);
	}
	task CreateBombL(x,y,ang, n) {
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgPlayer2);
		ObjEffect_SetLayer(obj, 3);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetVertexUV(obj, 0, 0, 192+32*n);
		ObjEffect_SetVertexUV(obj, 1, 32, 192+32*n);
		ObjEffect_SetVertexUV(obj, 2, 32, 224+32*n);
		ObjEffect_SetVertexUV(obj, 3, 0, 224+32*n);
		ObjEffect_SetVertexXY(obj, 0, -16, -16);
		ObjEffect_SetVertexXY(obj, 1, 16, -16);
		ObjEffect_SetVertexXY(obj, 2, 16, 16);
		ObjEffect_SetVertexXY(obj, 3, -16, 16);
		ObjEffect_SetAngle(obj, 0, 0, rand(0,360));
		let angle = rand(-1,1);
		let r = 1;
		Obj_SetPosition(obj, x, y);
		loop(30) {
			Obj_SetPosition(obj, Obj_GetX(obj)+2*((-1)^n)*cos(ang), Obj_GetY(obj)+2*((-1)^n)*sin(ang)); ang+=angle;
			ObjEffect_SetScale(obj, r*size, r*size);
			r-=1/30;
			yield;
		}
		Obj_Delete(obj);
	}
}
script_spell Reigeki_L {
	#include_function".\txt\System.txt"
		let Y=8;
	@Initialize { SetPlayerInvincibility(300); PlaySE(se_spell); SetPlayerPower(GetPower-100);CreateBomb; }
	let size = [1.5, 1/3][GetArgument];
	@MainLoop {
		yield;
	}
	task CreateBomb {
		let obj = Obj_Create(OBJ_SPELL);
		let num = 32; let repeat = 4;
		ObjEffect_SetTexture(obj, imgPlayer2);
		ObjEffect_SetLayer(obj, 3);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj, 2*(num+1));
		ObjEffect_SetRenderState(obj, ADD);
		let angle = rand(0,360);
		let r = 0;
		Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
		let alpha = 0;
		ascent(n in 0..240) {
			Obj_SetY(obj, Obj_GetY(obj)-3/Y*size);
			ascent(i in 0..num+1) {
				ObjEffect_SetVertexUV(obj, i*2+0, 0, 64+(i*128*repeat/num)%128);
				ObjEffect_SetVertexUV(obj, i*2+1, 32, 64+(i*128*repeat/num)%128);
				ObjEffect_SetVertexXY(obj, i*2+0, (128+8)*cos(angle+i*360/num), (128+8)*sin(angle+i*360/num));
				ObjEffect_SetVertexXY(obj, i*2+1, (128-8)*cos(angle+i*360/num), (128-8)*sin(angle+i*360/num));
				ObjEffect_SetVertexColor(obj, i*2+0, 255, alpha*255, alpha*255, alpha*255);
				ObjEffect_SetVertexColor(obj, i*2+1, 255, alpha*255, alpha*255, alpha*255);
			}
			ObjEffect_SetScale(obj, r*size, r*size);
			ObjSpell_SetIntersecrionCircle(obj, Obj_GetX(obj), Obj_GetY(obj), 128*r*size, 5*size, true);
			if(n < 30) { r+=1/30; alpha+=1/30; } else if(n >= 210) { alpha-=1/30; }
			if(n%15 == 0 && n < 120) { CreateBombP(Obj_GetX(obj), Obj_GetY(obj)); }
			if(n > 30 && n<180) { let a = rand(0,360); loop(2) { ascent(n in 0..2) { 
CreateBombL(Obj_GetX(obj)+(128+rand(-5,5))*r*size*cos(a), Obj_GetY(obj)+(128+rand(-5,5))*r*size*sin(a), a, n); 
} } }
			angle+=(pi^3)/5; angle%=360;
			yield;
		}
		Obj_Delete(obj); End;
	}
	task CreateBombP(x,y) {
		let obj = Obj_Create(OBJ_EFFECT);
		let num = 16; let repeat = 4;
		ObjEffect_SetTexture(obj, imgPlayer2);
		ObjEffect_SetLayer(obj, 3);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj, 2*(num+1));
		ObjEffect_SetRenderState(obj, ADD);
		let angle = rand(0,360);
		let r = 0; let r2 = 1+rand(-1,1)/10;
		Obj_SetPosition(obj, x, y);
		let alpha = 0;
		ascent(n in 0..120) {
			Obj_SetY(obj, Obj_GetY(obj)-3/Y*size);
			ascent(i in 0..num+1) {
				ObjEffect_SetVertexUV(obj, i*2+0, 0, 64+(i*128*repeat/num)%128);
				ObjEffect_SetVertexUV(obj, i*2+1, 32, 64+(i*128*repeat/num)%128);
				ObjEffect_SetVertexXY(obj, i*2+0, (128+8)*cos(angle+i*360/num), (128+8)*sin(angle+i*360/num));
				ObjEffect_SetVertexXY(obj, i*2+1, (128-8)*cos(angle+i*360/num), (128-8)*sin(angle+i*360/num));
				ObjEffect_SetVertexColor(obj, i*2+0, 255, alpha*255, alpha*0, alpha*255);
				ObjEffect_SetVertexColor(obj, i*2+1, 255, alpha*255, alpha*0, alpha*255);
			}
			ObjEffect_SetScale(obj, r*size, r*size);
			if(n < 30) { alpha+=1/30; } else if(n >= 90) { alpha-=1/30; }
			if(n < 60) { r+=r2/60; }
			angle+=(pi^3)/5; angle%=360;
			yield;
		}
		Obj_Delete(obj);
	}
	task CreateBombL(x,y,ang, n) {
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgPlayer2);
		ObjEffect_SetLayer(obj, 3);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetVertexUV(obj, 0, 0, 192+32*n);
		ObjEffect_SetVertexUV(obj, 1, 32, 192+32*n);
		ObjEffect_SetVertexUV(obj, 2, 32, 224+32*n);
		ObjEffect_SetVertexUV(obj, 3, 0, 224+32*n);
		ObjEffect_SetVertexXY(obj, 0, -16, -16);
		ObjEffect_SetVertexXY(obj, 1, 16, -16);
		ObjEffect_SetVertexXY(obj, 2, 16, 16);
		ObjEffect_SetVertexXY(obj, 3, -16, 16);
		ObjEffect_SetAngle(obj, 0, 0, rand(0,360));
		let angle = rand(-1,1);
		let r = 1;
		Obj_SetPosition(obj, x, y);
		loop(30) {
			Obj_SetPosition(obj, Obj_GetX(obj)+2*((-1)^n)*cos(ang), Obj_GetY(obj)+2*((-1)^n)*sin(ang)); ang+=angle;
			ObjEffect_SetScale(obj, r*size, r*size);
			r-=1/60;
			yield;
		}
		Obj_Delete(obj);
	}
}