//画像パス&読み込み(ファイルの構成が違う時は要変更)
	let imgHoutou_Beam_White = [GetCurrentScriptDirectory ~ "img\Houtou2_Beam_alpha.png",
								GetCurrentScriptDirectory ~ "img\Houtou2_Beam_add.png"];

	let imgHoutou_Beam_Black = [GetCurrentScriptDirectory ~ "img\Houtou2_Beam_alpha_B.png",
								GetCurrentScriptDirectory ~ "img\Houtou2_Beam_subtract.png"];

	let imgHoutou_Fire_White = GetCurrentScriptDirectory ~ "img\Houtou2_Fire_add.png";
	let imgHoutou_Fire_Black = GetCurrentScriptDirectory ~ "img\Houtou2_Fire_subtract.png";

	ascent(i in 0..2) {
		LoadGraphic(imgHoutou_Beam_White[i]);
		LoadGraphic(imgHoutou_Beam_Black[i]);
	}
	LoadGraphic(imgHoutou_Fire_White);
	LoadGraphic(imgHoutou_Fire_Black);



//画像破棄(画像を破棄しないと気になる人用・コピーして使って下さい)
//	ascent(i in 0..2) {
//		DeleteGraphic(imgHoutou_Beam_White[i]);
//		DeleteGraphic(imgHoutou_Beam_Black[i]);
//	}
//	DeleteGraphic(imgHoutou_Fire_White);
//	DeleteGraphic(imgHoutou_Fire_Black);



//宝塔ビーム(IDを返す)
//引数 1: X座標
//	   2: Y座標
//	   3: 角度
//	   4: 色(0〜7→赤〜白、8→虹色、9〜16→黒赤〜黒、17→黒虹)
//	   5: 遅延
//	   6: 消滅までの時間(フレーム指定)
//	   7: ビーム部分の描画方法(0→半透明描画、1→加算・減算)
	function Houtou(x, y, angle, color, delay, delTime, Render) {
		let Obj    = Obj_Create(OBJ_EFFECT);

		Houtou_Beam(Obj, x, y, angle, color, delay, delTime, Render);
		return Obj;
	}



//宝塔ビーム制御
	task Houtou_Beam(Obj, x, y, angle, Color, delay, delTime, Render) {
		let Laser  = Obj_Create(OBJ_LASER);
		let Detail = Obj_Create(OBJ_EFFECT);
		let Fire   = Obj_Create(OBJ_EFFECT);

		let Length  = 0;
		let width   = 1;
		let grazeC  = 0;
		let color   = Color;
		let clrPlus = 0.25;
		let count   = 0;

		let Fire_count = 0;
		let Fire_scale = 1.5;
		let Fire_sclct = 0;

		let Rainbow = false;

		if(color >= 9) { color -= 9; }

		if(Color == 8 || Color == 17) {
			color = 0;
			Rainbow = true;
		}

		let u = 0;
		let uPlus = -12.5;

//----------------------------------------------------------------------------------------------------
//基本設定

		Obj_SetPosition(Obj, x, y);
		ObjEffect_SetTexture(Obj, imgHoutou_Beam_White[Render]);
		ObjEffect_SetRenderState(Obj, ALPHA);
		ObjEffect_SetPrimitiveType(Obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetScale(Obj, 1, width/40);
		ObjEffect_SetLayer(Obj, 2);

		Obj_SetPosition(Detail, x, y);
		ObjEffect_SetTexture(Detail, imgHoutou_Beam_White[Render]);
		ObjEffect_SetRenderState(Detail, ALPHA);
		ObjEffect_SetPrimitiveType(Detail, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetScale(Detail, 1, width/40);
		ObjEffect_SetLayer(Detail, 2);

		Obj_SetPosition(Fire, Obj_GetX(Obj), Obj_GetY(Obj));
		ObjEffect_SetTexture(Fire, imgHoutou_Fire_White);
		ObjEffect_SetRenderState(Fire, ADD);
		ObjEffect_SetPrimitiveType(Fire, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetScale(Fire, Fire_scale, Fire_scale);
		ObjEffect_SetLayer(Fire, 2);

		Obj_SetPosition(Laser, Obj_GetX(Obj), Obj_GetY(Obj));
		Obj_SetAngle(Laser, Obj_GetAngle(Obj));
		Obj_SetAlpha(Laser, 0);
		Obj_SetAutoDelete(Laser, false);
		ObjShot_SetGraphic(Laser, RED01);
		ObjShot_SetDelay(Laser, 0);
		ObjShot_SetBombResist(Laser, true);
		ObjShot_ToItem(Laser, false);
		ObjLaser_SetLength(Laser, 768);
		ObjLaser_SetWidth(Laser, width*(3/4));
		ObjLaser_SetSource(Laser, false);

		if(Render == 1) { ObjEffect_SetRenderState(Obj, ADD); }

		if(Color >= 9) {
			ObjEffect_SetTexture(Obj,    imgHoutou_Beam_Black[Render]);
			ObjEffect_SetTexture(Detail, imgHoutou_Beam_Black[Render]);
			ObjEffect_SetTexture(Fire,   imgHoutou_Fire_Black);

			if(Render == 1) { ObjEffect_SetRenderState(Obj,  SUBTRACT); }
			ObjEffect_SetRenderState(Fire, SUBTRACT);
		}

//----------------------------------------------------------------------------------------------------
//エフェクト表示等の設定

		Obj_SetAngle(Obj, angle);
		ObjEffect_CreateVertex(Obj, 4);
		ObjEffect_SetVertexXY(Obj, 0,   0+5, -20);
		ObjEffect_SetVertexXY(Obj, 1,   0+5,  20);
		ObjEffect_SetVertexXY(Obj, 2, 768+5, -20);
		ObjEffect_SetVertexXY(Obj, 3, 768+5,  20);
		ObjEffect_SetVertexUV(Obj, 0, 128+(trunc(color)*16)   , 368);
		ObjEffect_SetVertexUV(Obj, 1, 128+(trunc(color)*16)+16, 368);
		ObjEffect_SetVertexUV(Obj, 2, 128+(trunc(color)*16)   , 384);
		ObjEffect_SetVertexUV(Obj, 3, 128+(trunc(color)*16)+16, 384);
		ObjEffect_SetAngle(Obj, 0, 0, Obj_GetAngle(Obj));

		ObjEffect_CreateVertex(Detail, 4);
		ObjEffect_SetVertexXY(Detail, 0,   0, -15);
		ObjEffect_SetVertexXY(Detail, 1,   0,  15);
		ObjEffect_SetVertexXY(Detail, 2, 768, -15);
		ObjEffect_SetVertexXY(Detail, 3, 768,  15);
		ObjEffect_SetVertexUV(Detail, 0,   0, 330);
		ObjEffect_SetVertexUV(Detail, 1,   0, 360);
		ObjEffect_SetVertexUV(Detail, 2, 768, 330);
		ObjEffect_SetVertexUV(Detail, 3, 768, 360);
		ObjEffect_SetAngle(Detail, 0, 0, Obj_GetAngle(Obj));

		ObjEffect_CreateVertex(Fire, 4);
		ObjEffect_SetVertexXY(Fire, 0,  -3, -64);
		ObjEffect_SetVertexXY(Fire, 1,  -3,  64);
		ObjEffect_SetVertexXY(Fire, 2, 124, -64);
		ObjEffect_SetVertexXY(Fire, 3, 124,  64);
		ObjEffect_SetAngle(Fire, 0, 0, Obj_GetAngle(Obj));

//----------------------------------------------------------------------------------------------------
//待機時間の処理部分

//		PlaySE(SEAppear);

		loop(delay) {
			if(Obj_BeDeleted(Obj) == true) { break; }
			if(Obj_BeDeleted(Laser)) { Laser = Obj_Create(OBJ_LASER); }

			ObjEffect_SetAngle(Obj, 0, 0, Obj_GetAngle(Obj));

			Obj_SetPosition(Detail, Obj_GetX(Obj), Obj_GetY(Obj));
			ObjEffect_SetAngle(Detail, 0, 0, Obj_GetAngle(Obj));

			if(trunc(Fire_count)%2 == 0) {
				ObjEffect_SetVertexUV(Fire, 0,  trunc(color/4)*256    ,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 1,  trunc(color/4)*256    , ((trunc(color)%4)*128)+128);
				ObjEffect_SetVertexUV(Fire, 2,  trunc(color/4)*256+127,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+127, ((trunc(color)%4)*128)+128);
			} else if(trunc(Fire_count)%2 == 1) {
				ObjEffect_SetVertexUV(Fire, 0,  trunc(color/4)*256+128,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 1,  trunc(color/4)*256+128, ((trunc(color)%4)*128)+128);
				ObjEffect_SetVertexUV(Fire, 2,  trunc(color/4)*256+255,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+255, ((trunc(color)%4)*128)+128);
			}

			Obj_SetPosition(Fire, Obj_GetX(Obj), Obj_GetY(Obj));
			ObjEffect_SetScale(Fire, Fire_scale+1.5*(1-Fire_sclct), Fire_scale*Fire_sclct);
			ObjEffect_SetAngle(Fire, 0, 0, Obj_GetAngle(Obj));

			Obj_SetPosition(Laser, Obj_GetX(Obj), Obj_GetY(Obj));
			Obj_SetAngle(Laser, Obj_GetAngle(Obj));
			ObjLaser_SetWidth(Laser, width*(5/4));

			Fire_count += 0.5;
			if(Fire_sclct < 1) { Fire_sclct += 0.2; }
			if(Rainbow) { color += clrPlus; }
			if(Rainbow && color >= 7)  { color = 0; }
			yield;
		};

//----------------------------------------------------------------------------------------------------
//発射する処理部分

		ObjEffect_SetScale(Obj, (Length/768), 1);
		ObjEffect_SetVertexUV(Obj, 0,      0, (trunc(color)*40)+5);
		ObjEffect_SetVertexUV(Obj, 1,      0, (trunc(color)*40)+45);
		ObjEffect_SetVertexUV(Obj, 2, Length, (trunc(color)*40)+5);
		ObjEffect_SetVertexUV(Obj, 3, Length, (trunc(color)*40)+45);
		ObjEffect_SetScale(Fire, Fire_scale, Fire_scale);
//		PlaySE(SELaser);

		loop(30) {
			if(Obj_BeDeleted(Obj) == true) { break; }
			if(Obj_BeDeleted(Laser)) { Laser = Obj_Create(OBJ_LASER); }

			Length += 20;
			if(width < 40) { width  += (39/15); } else { width = 40; }
			u += uPlus;

/*
			if( Collision_Line_Circle(Obj_GetX(Obj), Obj_GetY(Obj), x + 1000*cos(Obj_GetAngle(Obj)), y + 1000*sin(Obj_GetAngle(Obj)), width*(3/4), GetPlayerX, GetPlayerY, 0 ) == true &&
				GetTimeOfPlayerInvincibility == 0) {
					ShootDownPlayer;
			}

			if( Collision_Line_Circle(Obj_GetX(Obj), Obj_GetY(Obj), x + 1000*cos(Obj_GetAngle(Obj)), y + 1000*sin(Obj_GetAngle(Obj)), width*1.5, GetPlayerX, GetPlayerY, 0 ) == true &&
				GetTimeOfPlayerInvincibility == 0) {
					if(grazeC%6 == 0) { AddGraze(1); PlaySE("seGraze.wav"); }
					grazeC++;
			} else {
				grazeC = 0;
			}
*/

			ObjEffect_SetScale(Obj, (Length/768), width/40);
			ObjEffect_SetAngle(Obj, 0, 0, Obj_GetAngle(Obj));
			ObjEffect_SetVertexUV(Obj, 0,      0+(u/2), (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 1,      0+(u/2), (trunc(color)*40)+45);
			ObjEffect_SetVertexUV(Obj, 2, Length+(u/2), (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 3, Length+(u/2), (trunc(color)*40)+45);

			Obj_SetPosition(Detail, Obj_GetX(Obj), Obj_GetY(Obj));
			ObjEffect_SetScale(Detail, 1, width/40);
			ObjEffect_SetAngle(Detail, 0, 0, Obj_GetAngle(Obj));
			ObjEffect_SetVertexUV(Detail, 0,   0+u, 330);
			ObjEffect_SetVertexUV(Detail, 1,   0+u, 360);
			ObjEffect_SetVertexUV(Detail, 2, 768+u, 330);
			ObjEffect_SetVertexUV(Detail, 3, 768+u, 360);

			if(trunc(Fire_count)%2 == 0) {
				ObjEffect_SetVertexUV(Fire, 0,  trunc(color/4)*256    ,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 1,  trunc(color/4)*256    , ((trunc(color)%4)*128)+128);
				ObjEffect_SetVertexUV(Fire, 2,  trunc(color/4)*256+127,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+127, ((trunc(color)%4)*128)+128);
			} else if(trunc(Fire_count)%2 == 1) {
				ObjEffect_SetVertexUV(Fire, 0,  trunc(color/4)*256+128,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 1,  trunc(color/4)*256+128, ((trunc(color)%4)*128)+128);
				ObjEffect_SetVertexUV(Fire, 2,  trunc(color/4)*256+255,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+255, ((trunc(color)%4)*128)+128);
			}

			Obj_SetPosition(Fire, Obj_GetX(Obj), Obj_GetY(Obj));
			ObjEffect_SetAngle(Fire, 0, 0, Obj_GetAngle(Obj));

			Obj_SetPosition(Laser, Obj_GetX(Obj), Obj_GetY(Obj));
			Obj_SetAngle(Laser, Obj_GetAngle(Obj));
			ObjLaser_SetWidth(Laser, width*(5/4));

			Fire_count += 0.5;
			if(Rainbow) { color += clrPlus; }
			if(Rainbow && color >= 7)  { color = 0; }
			yield;
		}

//----------------------------------------------------------------------------------------------------
//発射し続ける処理部分

		Length = 768;
		ObjEffect_SetScale(Obj, (Length/768), 1);

		while(!Obj_BeDeleted(Obj)) {
			if(count >= delTime && delTime >= 0) { break; }
			if(Obj_BeDeleted(Laser)) { Laser = Obj_Create(OBJ_LASER); }
			u += uPlus;

/*
			if( Collision_Line_Circle(Obj_GetX(Obj), Obj_GetY(Obj), x + 1000*cos(Obj_GetAngle(Obj)), y + 1000*sin(Obj_GetAngle(Obj)), width*(3/4), GetPlayerX, GetPlayerY, 0 ) == true &&
				GetTimeOfPlayerInvincibility == 0) {
					ShootDownPlayer;
			}

			if( Collision_Line_Circle(Obj_GetX(Obj), Obj_GetY(Obj), x + 1000*cos(Obj_GetAngle(Obj)), y + 1000*sin(Obj_GetAngle(Obj)), width*1.5, GetPlayerX, GetPlayerY, 0 ) == true &&
				GetTimeOfPlayerInvincibility == 0) {
					if(grazeC%6 == 0) { AddGraze(1); PlaySE("seGraze.wav"); }
					grazeC++;
			} else {
				grazeC = 0;
			}
*/

			ObjEffect_SetAngle(Obj, 0, 0, Obj_GetAngle(Obj));
			ObjEffect_SetVertexUV(Obj, 0,      0+(u/2), (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 1,      0+(u/2), (trunc(color)*40)+45);
			ObjEffect_SetVertexUV(Obj, 2, Length+(u/2), (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 3, Length+(u/2), (trunc(color)*40)+45);

			Obj_SetPosition(Detail, Obj_GetX(Obj), Obj_GetY(Obj));
			ObjEffect_SetAngle(Detail, 0, 0, Obj_GetAngle(Obj));
			ObjEffect_SetVertexUV(Detail, 0,   0+u, 330);
			ObjEffect_SetVertexUV(Detail, 1,   0+u, 360);
			ObjEffect_SetVertexUV(Detail, 2, 768+u, 330);
			ObjEffect_SetVertexUV(Detail, 3, 768+u, 360);

			if(trunc(Fire_count)%2 == 0) {
				ObjEffect_SetVertexUV(Fire, 0,  trunc(color/4)*256    ,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 1,  trunc(color/4)*256    , ((trunc(color)%4)*128)+128);
				ObjEffect_SetVertexUV(Fire, 2,  trunc(color/4)*256+127,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+127, ((trunc(color)%4)*128)+128);
			} else if(trunc(Fire_count)%2 == 1) {
				ObjEffect_SetVertexUV(Fire, 0,  trunc(color/4)*256+128,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 1,  trunc(color/4)*256+128, ((trunc(color)%4)*128)+128);
				ObjEffect_SetVertexUV(Fire, 2,  trunc(color/4)*256+255,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+255, ((trunc(color)%4)*128)+128);
			}

			Obj_SetPosition(Fire, Obj_GetX(Obj), Obj_GetY(Obj));
			ObjEffect_SetAngle(Fire, 0, 0, Obj_GetAngle(Obj));

			Obj_SetPosition(Laser, Obj_GetX(Obj), Obj_GetY(Obj));
			Obj_SetAngle(Laser, Obj_GetAngle(Obj));
			ObjLaser_SetWidth(Laser, width*(5/4));

			Fire_count += 0.5;
			if(Rainbow) { color += clrPlus; }
			if(Rainbow && color >= 7)  { color = 0; }
			if(delTime >= 0) { count++; }
			yield;
		}

//----------------------------------------------------------------------------------------------------
//消滅処理部分

		loop(30) {
			if(Obj_BeDeleted(Obj) == true) { break; }
			if(Obj_BeDeleted(Laser)) { Laser = Obj_Create(OBJ_LASER); }

			width -= (4/3);
			u += uPlus;

/*
			if( Collision_Line_Circle(Obj_GetX(Obj), Obj_GetY(Obj), x + 1000*cos(Obj_GetAngle(Obj)), y + 1000*sin(Obj_GetAngle(Obj)), width*(3/4), GetPlayerX, GetPlayerY, 0 ) == true &&
				GetTimeOfPlayerInvincibility == 0) {
					ShootDownPlayer;
			}

			if( Collision_Line_Circle(Obj_GetX(Obj), Obj_GetY(Obj), x + 1000*cos(Obj_GetAngle(Obj)), y + 1000*sin(Obj_GetAngle(Obj)), width*1.5, GetPlayerX, GetPlayerY, 0 ) == true &&
				GetTimeOfPlayerInvincibility == 0) {
					if(grazeC%6 == 0) { AddGraze(1); PlaySE("seGraze.wav"); }
					grazeC++;
			} else {
				grazeC = 0;
			}
*/

			ObjEffect_SetScale(Obj, 1, width/40);
			ObjEffect_SetAngle(Obj, 0, 0, Obj_GetAngle(Obj));
			ObjEffect_SetVertexUV(Obj, 0,      0+(u/2), (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 1,      0+(u/2), (trunc(color)*40)+45);
			ObjEffect_SetVertexUV(Obj, 2, Length+(u/2), (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 3, Length+(u/2), (trunc(color)*40)+45);

			Obj_SetPosition(Detail, Obj_GetX(Obj), Obj_GetY(Obj));
			ObjEffect_SetScale(Detail, 1, width/40);
			ObjEffect_SetAngle(Detail, 0, 0, Obj_GetAngle(Obj));
			ObjEffect_SetVertexUV(Detail, 0,   0+u, 330);
			ObjEffect_SetVertexUV(Detail, 1,   0+u, 360);
			ObjEffect_SetVertexUV(Detail, 2, 768+u, 330);
			ObjEffect_SetVertexUV(Detail, 3, 768+u, 360);

			Obj_SetPosition(Fire, Obj_GetX(Obj), Obj_GetY(Obj));
			ObjEffect_SetAngle(Fire, 0, 0, Obj_GetAngle(Obj));
			ObjEffect_SetScale(Fire, Fire_scale, Fire_scale*(width/40));

			if(trunc(Fire_count)%2 == 0) {
				ObjEffect_SetVertexUV(Fire, 0,  trunc(color/4)*256    ,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 1,  trunc(color/4)*256    , ((trunc(color)%4)*128)+128);
				ObjEffect_SetVertexUV(Fire, 2,  trunc(color/4)*256+127,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+127, ((trunc(color)%4)*128)+128);
			} else if(trunc(Fire_count)%2 == 1) {
				ObjEffect_SetVertexUV(Fire, 0,  trunc(color/4)*256+128,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 1,  trunc(color/4)*256+128, ((trunc(color)%4)*128)+128);
				ObjEffect_SetVertexUV(Fire, 2,  trunc(color/4)*256+255,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+255, ((trunc(color)%4)*128)+128);
			}

			Obj_SetPosition(Laser, Obj_GetX(Obj), Obj_GetY(Obj));
			Obj_SetAngle(Laser, Obj_GetAngle(Obj));
			ObjLaser_SetWidth(Laser, width*(5/4));

			if(Rainbow) { color += clrPlus; }
			if(Rainbow && color >= 7)  { color = 0; }
			yield;
		}

		Obj_Delete(Obj);
		Obj_Delete(Fire);
		Obj_Delete(Detail);
		Obj_Delete(Laser);
	}
