#東方弾幕風
#Title[気象「真夜中の先駆放電」(Lunatic)]
#Text[適当に弾幕を作る程度の能力]
#ScriptVersion[2]


script_enemy_main {
    //共通初期設定
    #include_function ".\INCLUDE\BOSS_INI.txt"

    let name        = "気象「真夜中の先駆放電」";

    let wIni    = 100;
	let signal = false;
	let sigangle = 0;

    @Initialize {
        SetMovePosition02(GetCenterX, GetClipMinY + 120, wIni);
        SetX(GetCenterX);
        SetY(GetClipMinY + 120);

        thMCutIn(1,name);
        SetLife(2400);		//ライフ
        SetTimer(70);		//タイマー
        SetScore(4000000);	//ボーナススコア

        LoadGraphicthM;
        SetTexture(imgBoss);

        SetInvincibility(wIni);
        SetDamageRate(50, 50);

        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 24);
        SetCollisionB(GetX, GetY, 24);

        yield; 
    }

    @DrawLoop {
        BossDraw(1);
    }

    @Finalize {
	SpellClear;
        DeleteGraphic(imgBoss);
    }

    @BackGround {
	BgDraw;
    }

//==========================================================================================

    // メインタスク（普通はここ以降から編集してください）
    task TMain {
        yield;
        loop(wIni) { yield; }

	Shot;
    }

    //弾
    task Shot{
	let f = 60;	//発射間隔
	let id = 1001;	//弾ID
	let tid = 1002;	//追加弾ID
	let tk = 60;
	let w = 5;
	let phase = 0;
	
	let nLeft = GetClipMinX + 40;
	let nRight  = GetClipMaxX - 40;
	
	let nTop = GetClipMinY - 20;
	let nBottom = GetClipMaxY + 20;
	
	SubShot;
	yield;
	BossMoveEXloop(20, 120);
	loop{
		alternative(phase)
		case(0){
			CreateShotA(id, nLeft, nTop + rand(-5, +5), 5);
			SetShotDataA(id, 0, 5, 90, 0, 0, 0, US_BALL_L_YELLOW);
			ascent(let i in 0..tk){
				ascent(let j in 0..3){
					CreateShotA(tid, 0, 0, 25);
					SetShotDataA(tid, 0, 0, 15, 0, 0, 0, US_LIGHT2_YELLOW);
					SetShotDataA(tid, 80+j*5, 0, NULL, 0, +0.1, 8, US_LIGHT2_YELLOW);
					AddShot(i*w, id, tid, 0);
					CreateShotA(tid, 0, 0, 25);
					SetShotDataA(tid, 0, 0, 165, 0, 0, 0, US_LIGHT2_YELLOW);
					SetShotDataA(tid, 80+j*5, 0, NULL, 0, +0.1, 8, US_LIGHT2_YELLOW);
					AddShot(i*w, id, tid, 0);
				}
			}
			FireShot(id);
		}
		case(1){
			CreateShotA(id, nRight, nBottom + rand(-5, +5), 5);
			SetShotDataA(id, 0, 5, 270, 0, 0, 0, US_BALL_L_YELLOW);
			ascent(let i in 0..tk){
				ascent(let j in 0..3){
					CreateShotA(tid, 0, 0, 25);
					SetShotDataA(tid, 0, 0, 15, 0, 0, 0, US_LIGHT2_YELLOW);
					SetShotDataA(tid, 80+j*5, 0, NULL, 0, +0.1, 8, US_LIGHT2_YELLOW);
					AddShot(i*w, id, tid, 0);
					CreateShotA(tid, 0, 0, 25);
					SetShotDataA(tid, 0, 0, 165, 0, 0, 0, US_LIGHT2_YELLOW);
					SetShotDataA(tid, 80+j*5, 0, NULL, 0, +0.1, 8, US_LIGHT2_YELLOW);
					AddShot(i*w, id, tid, 0);
				}
			}
			FireShot(id);
		}
		phase = (phase + 1) % 2;
		__wait(f);
	}
    }


    //サブショット
    task SubShot{
	let f = 90;	//発射間隔
	
	loop{
		CreateShotNway02(GetX, GetY, 5, GetAngleToPlayer, 0, -0.1, 1, US_SCALE_BLUE, 10, 25, 5, 12);
		__wait(f);
	}
    }

//==========================================================================================
    // w フレームだけ待つ
    function __wait(w) {
        loop(w) { yield; }
    }


}