// Ƀ{X̏ݒsCN[hpXNvgł
// {X̊eXyJĂ΂܂

//---------------------------------------------------------------------------------

//SetDefaultStatusVisible(false);

//Ăяop萔
//fBNg
let csd = GetCurrentScriptDirectory;

//蔻摜
let setcol = csd ~ "\img\col.png";

//wi摜
let bg3uzu = csd ~ "\img\bguzu.png";

//CN[hpXNvgĂ
/*
 *@ALL		FׂẴXNvgɋʂėp֐
 *@SE		Fʉ炷
 *@DRAW	F`֌W
 *@EFFECT	FGtFNg֌W
 *
 */
#include_function ".\INCLUDE\ALL.txt"
#include_function ".\INCLUDE\SE.txt"
#include_function ".\INCLUDE\SHOT.txt"
#include_function ".\_index_UserShot.dnh"

//eNX`萔
let mAlpha = 255;	//x
let bgframe = 0;	//wit[

//[U`e摜̃fBNg
let shotAll = csd ~ "\shot_All.dnh";

//hbg摜
let imgBoss = csd ~ "\img\dot2.png";
SetGraphicRect(0, 0, 52, 88);

//Rate\ɂ
SetRateScoreSystemEnable(false);

//Expert[h(fobOL[gȂ[h)ɂ@_ł̓fobOL[͕KvȂ̂ŃRgAEgĂ܂
//Expert;

//O
SpellCount;
HitBoss;
PlayerCol;

//---------------------------------------------------------------------------------

//{XJbgC
function thMCutIn(let Bossno,let name){

	let Cdir = "";
	if(Bossno == 1){
		//Cdir = csd ~ "\img\m.png";
	}else{
		//Cdir = csd ~ "\img\y.png";
	}
	
	CutIn(YOUMU, name, "Ȃ", 0, 0, 0, 0);
}

//{XUJnƂɎs^XN
task AtStart{

}

//XyJ^C}[
task SpellCount{
	let count = 0;

	loop{
		if(!(count == GetTimer)){
			if(GetTimer <= 5){
				PlaySE(SE_TIME2);
			}else if(GetTimer <= 10){
				PlaySE(SE_TIME1);
			}
		}
		count = GetTimer;
		yield;
	}
}

//{XHPɂđւ̃Vbg̓艹ς^XN(O...)
task HitBoss{
	yield;
	let life = GetEnemyLife;
	let maxlife = life;
	yield;

	loop{
		if(!(GetEnemyLife == life)){
			life = GetEnemyLife;	

			//Ct5%A10%؂
			if(life < (maxlife * 10 / 100)){
				PlaySE(SE_HIT1);
			}else{
				PlaySE(SE_HIT2);
			}
		}
		loop(5){ yield; }
	}
}

//{X̍UIƂɎs鋤ʃ^XN(XyJ)
task SpellClear{
	//ɋʂ^XNĂяo
	SpellClearCom;

	//{Xj
	PlaySE(SE_SHOT1);
	if(GotSpellCardBonus){
		PlaySE(SE_BONUS);
		PlaySE(SE_CARD);
	}
}

//{X̍UIƂɎs鋤ʃ^XN(ʏ)
task SpellClear2{
	//ɋʂ^XNĂяo
	SpellClearCom;

	//{Xj
	PlaySE(SE_SHOT1);
	if(GetMissCountInThisSpell == 0){
		PlaySE(SE_BONUS);
	}
}

//{X̍UIƂɎs鋤ʃ^XN()
task SpellClearCom{
	
}

//{^XN
task Bom {
	yield; 
	loop {
		let bom = OnBomb;
		if(bom==true){
			SetInvincibility(50);
		}
		loop(1) { yield; }
	}
}

//摜ǂݍ݃^XN
task LoadGraphicthM {
	LoadUserShotData(shotAll);
        LoadGraphic(imgBoss);
	LoadGraphic(bg3uzu);
}

//lpGtFNgIuWFNg^XN
task CreateSquareEffectObject(let mObj,let nLeft,let nTop,let nRight,let nBottom,let ConText){
	mObj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetPrimitiveType(mObj, PRIMITIVE_TRIANGLESTRIP);//v~eBu^Cvݒ
	ObjEffect_CreateVertex(mObj, 4);//_4
	ObjEffect_SetTexture(mObj,ConText);
	//ObjEffect_SetLayer(mObj,8);

	let width = (|nRight|) - (|nLeft|);
	let length = (|nBottom|) - (|nTop|);

	let width2 = ceil(width /  2);
	let length2 = ceil(length / 2);

	let width3 = width - width2;
	let length3 = length - length2;

	//lp`Ɋe_̍Wݒ
	ObjEffect_SetVertexXY(mObj, 0, -width3, -length3);
	ObjEffect_SetVertexXY(mObj, 1, -width3,  length2);
	ObjEffect_SetVertexXY(mObj, 2,  width2, -length3);
	ObjEffect_SetVertexXY(mObj, 3,  width2,  length2);
		
	//lp`Ɋe_UVlݒB
	ObjEffect_SetVertexUV(mObj, 0,  nLeft,  nTop);
	ObjEffect_SetVertexUV(mObj, 1,  nLeft, nBottom);
	ObjEffect_SetVertexUV(mObj, 2, nRight,  nTop);
	ObjEffect_SetVertexUV(mObj, 3, nRight, nBottom);
}

//CreateSquareEffectObject̃GCAX
task CSFO(let mObj,let nLeft,let nTop,let Right,let Bottom,let ConText){
	CreateSquareEffectObject(mObj,nLeft,nTop,Right,Bottom,ConText);
}

//{X`悷^XN
// @̃^XN͈Ӗ̖^XNł
//   @nAnm	: `悷摜
//
task BossDraw(let nAnm){
	SetTexture(imgBoss);
	SetGraphicScale(1,1);
	SetGraphicAngle(0,0,0);
	SetAlpha(mAlpha);
	SetGraphicRect(0, 0, 64, 64);
	DrawGraphic(GetX, GetY);
}


task BgDraw{

	SetTexture(bg3uzu);
	SetGraphicScale(1,1);
	SetGraphicAngle(0,0,bgframe/2);
	SetAlpha(255);
	SetGraphicRect(0, 0, 600, 600);
	DrawGraphic(GetCenterX, GetCenterY);

	bgframe += 1;
	
}

//@蔻`
task PlayerCol{
	
	LoadGraphic(setcol);

	yield;

	loop{
		let obj = Obj_Create(OBJ_EFFECT);

		if(GetPlayerMoveState == MOVE_SLOW){
			//obj = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);//v~eBu^Cvݒ
			ObjEffect_CreateVertex(obj, 4);//_4
			ObjEffect_SetTexture(obj,setcol);
			ObjEffect_SetLayer(obj,4);

			//lp`Ɋe_̍Wݒ
			ObjEffect_SetVertexXY(obj, 0, -5, -5);
			ObjEffect_SetVertexXY(obj, 1, -5,  5);
			ObjEffect_SetVertexXY(obj, 2,  5, -5);
			ObjEffect_SetVertexXY(obj, 3,  5,  5);
		
			//lp`Ɋe_UVlݒB
			ObjEffect_SetVertexUV(obj, 0,  0,  0);
			ObjEffect_SetVertexUV(obj, 1,  0, 10);
			ObjEffect_SetVertexUV(obj, 2, 10,  0);
			ObjEffect_SetVertexUV(obj, 3, 10, 10);

			Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
		}

		yield;
		
		Obj_Delete(obj);
		
		//yield;
	}
}


    // ړ
    // dist	:ړ͈
    function BossMoveEX(let dist){
	let dist2 = dist + rand(-dist/10, dist/10);	//ړ = ړɈړ10%̑O덷
	let theta = rand(0,360);
	
	let nX = cos(theta) * dist2;
	let nY = sin(theta) * dist2;
	
	BossMoveEXtoPlayer(absolute(nX), nY, GetClipMinX + 32, GetClipMinY + 32, GetClipMaxX - 32, GetClipMinY + 160);
    }

    // Aړ(g胋[v̈ꕔBossMoveEXgݍœƎv܂)
    // dist	:ړ͈
    // w	:ҋ@
    task BossMoveEXloop(let dist, let w){
	yield;
	
	loop{
		BossMoveEX(dist);
		loop(w){ yield; }
	}
    }

    // ړ֐
    // nX,nY	:ړ͈()
    // left,top,right,bottom	:̈
    function BossMoveEXtoPlayer(let nX, let nY, let left, let top, let right, let bottom) {
        let x = 0;
        let y = 0;
	
	//ɕsȂ炱̒lMĉ
	let MAXSPEED = 3;	//ő呬x
	let SLOW = 15;		//x

        if(GetPlayerX < GetX) {
        	x = GetX - nX;
        	if(x < left) {
        		x = GetX + nX;
        	}
        }else{
        	x = GetX + nX;
        	if(right < x) {
         		x = GetX - nX;
        	}
        }
        y = GetY + nY;
        if(y < top) {
        	y = top;
        }else if(bottom < y) {
        	y = bottom;
        }

        SetMovePosition03(x, y, SLOW, MAXSPEED);
    }


