//宝塔ビーム(IDを返す)
//引数 1: X座標
//	   2: Y座標
//	   4: 角度
//	   5: 色(0〜7→赤〜白、8→虹色)
//	   6: 遅延
//	   7: 消滅までの時間(フレーム指定)
	function Houtou(x, y, angle, color, delay, delTime) {
		let Obj    = Obj_Create(OBJ_EFFECT);

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



//宝塔ビーム制御
	task Houtou_Beam(Obj, x, y, angle, Color, delay, delTime) {
		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;

		if(Color == 8) {
			color = 0;
		}

		let u = 0;
		let uPlus = -10;

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

		Obj_SetPosition(Obj, x, y);
		ObjEffect_SetTexture(Obj, imgBeam);
		ObjEffect_SetRenderState(Obj, ADD);
		ObjEffect_SetPrimitiveType(Obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetScale(Obj, 1, width/40);
		ObjEffect_SetLayer(Obj, 2);

		Obj_SetPosition(Detail, x, y);
		ObjEffect_SetTexture(Detail, imgBeam);
		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, imgFire);
		ObjEffect_SetRenderState(Fire, ADD);
		ObjEffect_SetPrimitiveType(Fire, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetScale(Fire, Fire_scale, Fire_scale);
		ObjEffect_SetLayer(Fire, 2);

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

		Obj_SetAngle(Obj, angle);
		ObjEffect_CreateVertex(Obj, 4);
		ObjEffect_SetVertexXY(Obj, 0,   0, -20);
		ObjEffect_SetVertexXY(Obj, 1,   0,  20);
		ObjEffect_SetVertexXY(Obj, 2, 768, -20);
		ObjEffect_SetVertexXY(Obj, 3, 768,  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,  -1, -64);
		ObjEffect_SetVertexXY(Fire, 1,  -1,  64);
		ObjEffect_SetVertexXY(Fire, 2, 127, -64);
		ObjEffect_SetVertexXY(Fire, 3, 127,  64);
		ObjEffect_SetAngle(Fire, 0, 0, Obj_GetAngle(Obj));

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

//		PlaySE(SEAppear);

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

			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+128,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+128, ((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+256,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+256, ((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));

			Fire_count += 0.5;
			if(Fire_sclct < 1) { Fire_sclct += 0.2; }
			if(Color == 8) { color += clrPlus; }
			if(Color == 8 && 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, 256, (trunc(color)*40)+5);
		ObjEffect_SetVertexUV(Obj, 3, 256, (trunc(color)*40)+45);
		ObjEffect_SetScale(Fire, Fire_scale, Fire_scale);
//		PlaySE(SELaser);

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

			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), 1);
			ObjEffect_SetAngle(Obj, 0, 0, Obj_GetAngle(Obj));
			ObjEffect_SetVertexUV(Obj, 0,   0, (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 1,   0, (trunc(color)*40)+45);
			ObjEffect_SetVertexUV(Obj, 2, 256, (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 3, 256, (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+128,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+128, ((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+256,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+256, ((trunc(color)%4)*128)+128);
			}

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

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

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

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

		while(!Obj_BeDeleted(Obj)) {
			if(count >= delTime && delTime >= 0) { break; }
			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, (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 1,   0, (trunc(color)*40)+45);
			ObjEffect_SetVertexUV(Obj, 2, 256, (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 3, 256, (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+128,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+128, ((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+256,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+256, ((trunc(color)%4)*128)+128);
			}

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

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

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

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

			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, (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 1,   0, (trunc(color)*40)+45);
			ObjEffect_SetVertexUV(Obj, 2, 256, (trunc(color)*40)+5);
			ObjEffect_SetVertexUV(Obj, 3, 256, (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+128,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+128, ((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+256,  (trunc(color)%4)*128);
				ObjEffect_SetVertexUV(Fire, 3,  trunc(color/4)*256+256, ((trunc(color)%4)*128)+128);
			}

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

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