#e
#Title[Xmas(2) -N-]
#Text[΂Ɛ]
#ScriptVersion[2]


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

    let name        = "PuZCg[Xv";

    let wIni    = 100;

    @Initialize {
        SetX(GetCenterX);
        SetY(GetClipMinY + 120);
	
        _CutIn(name);
        SetLife(1225);		//Ct
        SetTimer(99);		//^C}[
        SetScore(12251224);	//{[iXXRA
	
        _LoadGraphic();
	
        SetTexture(imgBoss);
        SetInvincibility(wIni);
        SetDamageRate(35, 35);

        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;
    }

    //ʏVbg
    task Shot{
	let f = 180;	//
	let id = 1001;	//eID
	let arg = 6;
	let dist = 60;

	yield;
	

	loop{
		let width = GetClipMaxX - GetClipMinX;
		let x1 = 0;
		let y1 = 0;
		let x2 = 0;
		let y2 = 0;
		let an1 = 270;
		let an2 = 270;
		PlaySE(SE_BUN);
		dist += 10;
		if(dist > 140){ dist /= 2; }
		ascent(let i in 0..(180/arg)){	//60
			PlaySE(SE_SHOT1);
			x1 = GetX + cos(an1)*dist + rand(-10,10);
			y1 = GetY + sin(an1)*dist + rand(-10,10) + dist;
			x2 = GetX + cos(an2)*dist + rand(-10,10);
			y2 = GetY + sin(an2)*dist + rand(-10,10) + dist;
			
			SetTreeShot(x1, y1, an1);
			SetTreeShot(x2, y2, an2);
			yield;
			an1 -= arg;
			an2 += arg;
		}
		BossMoveEX(50);
		__wait(f);
	}
    }


    //tϒe
    task SetTreeShot(let x, let y, let angle){
	let f = 1;
	let tk = 3;
	let way = 3;
	let id = 1002;
	
	yield;
	//angle:e̐ݒupx
	//angle2:e̊
	//angle3:e̐̌
	let angle2 = rand(-165,165) + angle;
	ascent(let i in 0..way){
		ascent(let j in 0..tk){
			let angle3 = angle2 + (80/way)*i - 40;
			let x2 = x + cos(angle3) * 10;
			let y2 = y + sin(angle3) * 10;
			CreateShotA(id, x2, y2, 5);
			SetShotDataA(id, 0, 0, angle3, 0, 0, 0, US_RICE_S_GREEN);
			SetShotDataA(id, 90, NULL, NULL, 0, 0.2 + tk*0.03, 1 + tk*0.3, US_LIGHT2_RED);
			PlaySEdelay(SE_SHOT2, 90);
			FireShot(id);
		}
		yield;
	}
    }


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