#e
#Title[Xmas(3) -L-]
#Text[2326̋E]
#ScriptVersion[2]


script_enemy_main {
    //ʏݒ
    #include_function ".\INCLUDE\BOSS_INI.txt"

    let name        = "uzCgNX}Xv";

    let wIni    = 100;
    let crazy	= 1;
	let tMx = GetClipMinX;	//̍Ww
    let tMy = GetClipMinY;	//̍Wx
    let bMx = GetClipMaxX;	//E̍Ww
    let bMy = GetClipMaxY;	//E̍Wx
    @Initialize {
        SetX(GetCenterX);
        SetY(GetClipMinY + 120);
	
        _CutIn(name);
        SetLife(1225);		//Ct
        SetTimer(99);		//^C}[
        SetScore(12251224);	//{[iXXRA
	
        _LoadGraphic();
	
        SetTexture(imgBoss);
        SetInvincibility(wIni);
        SetDamageRate(20, 20);

        TMain;
    }

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

        yield; 
    }

    @DrawLoop {
        BossDraw(1);
    }

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    @BackGround {
	BgDraw;
    }

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

    // C^XNiʂ͂ȍ~ҏWĂj
    task TMain {
        yield;
        loop(wIni) { yield; }
	Shot;
	phcon;
	SnowShot;
	SetRedShot();
	SetGreenShot();
	SetYellowShot();
    }

    //phase control
    task phcon{
		yield;
		loop{
			if(GetEnemyLife < 400){
				crazy = 4;
			}else if(GetEnemyLife < 600){
				crazy = 3;
			}else if(GetEnemyLife < 1000){
				crazy = 2;
			}else{
				crazy = 1;
			}
			yield;
		}
    }

    //ʏVbg
    task Shot{
	let f = 180;	//
	let id = 1001;	//eID
	let way = 5;
	yield;
	

	loop{
		if(crazy > 1){
			ascent(let i in 0..way){
				CreateShot01(GetX, GetY, 1, (50/way)*i + GetAngleToPlayer - 25, US_BALL_L_BLUE, 15);
			}
		}
		
		BossMoveEX(50);
		__wait(f);
	}
    }




    //Ԓe
    task SetRedShot{
	let f = 3;
	let lps = 0;
	
	yield;
	loop{
		while(crazy <= 0){ yield;}
		lps++;
		CreateShot01(GetX, GetY, 1.2, lps*10, US_CRYSTAL_RED, 15);
		__wait(f);
	}
    }


    //Βe
    task SetGreenShot{
	let f = 3;
	let lps = 0;
	
	yield;
	loop{
		while(crazy <= 2){ yield;}
		lps++;
		CreateShot01(GetX, GetY, 1.75, lps*10 + 180, US_CRYSTAL_GREEN, 15);
		__wait(f);
	}
    }

    //e
    task SetYellowShot{
	let f = 3;
	let lps = 0;
	
	yield;
	loop{
		while(crazy <= 3){ yield;}
		lps++;
		CreateShot01(GetX, GetY, 2.5, lps*20, US_CRYSTAL_YELLOW, 15);
		__wait(f);
	}
    }
	
    // ォUĂẽ^XN
    task SnowShot { 
        let f = 8; 	// e̔ˊԊu
	let tk = 4;	// ォ瓯ɉe
	let dar = 4;	// PVbgŉxpxς邩
	let dim = 6;	// dar̃_ωpxi|dim`{dim̒lj
	let frl = 0;	// ɌXĂ邩EɌXĂ邩A[]=>0 [E]=>1
	let c = 0;	// ɉXAEɉXA[]=>@[E]=>
	let wrl = 30;	// AE̍őpx@0ɋ߂ȂƐʂɍ~Ă銴@l傫ȂƎ@ɂ܂e~ȂȂ
	let sp = 0;

        yield;


        loop {
		let width = (bMx - tMx) / tk;			//eXe[W̕߂āAˌϓɔzu
		if(crazy == 2){
			tk = 5;
			sp = 0.5;
		}else if(crazy == 3){
			tk = 7;
			sp = 0.75;
		}else if(crazy == 4){
			tk = 10;
			sp = 1;
		}
		
		
	    if(frl == 0){
		//90߈ȏXXEɕύX
		if(c * dar < -wrl){
			frl = 1;
			c += 1;
		}else{
			c -= 1;
		}
	    }else{
		//E90߈ȏXXɕύX
		if(c * dar > wrl){
			frl = 0;
			c -= 1;
		}else{
			c += 1;
		}
	    }

	    //㕔ʊOe
	    ascent(let i in 0..tk){
		CreateShot02(tMx + width * i + rand(-50,50), tMy - rand(4,12),1.8 + rand(0.1,0.4) + sp,c * dar + 90 + rand(-dim,+dim),0,0,US_BALL_SS_WHITE,0);
	    }
	    PlaySE(SE_SHOT1);
	    loop(f) { yield; }
        }
    } 

//==========================================================================================
    // w t[҂
    function __wait(w) {
        loop(w) { yield; }
    }
}