//---------------------------------------------------------------------------------------------
//
//	Chromatic Wing Mod
//	
//	stage 2 file
//
//---------------------------------------------------------------------------------------------


//---------------------------------------------------------------------------------------------
// stage function - Play
function Stage02
{

//---------------------------------------------------------------------------------------------
// Data setting - set / clear require data from last play

	SetCommonData("ngc_playstage", 2);	// Mark as stage 2 once again -_,-
	SetCommonData("CD_BossFight", 0);	// No Boss Fighting Here

	ng_stageintro = 0;		// Reset stage intro

	ng_bg_scroll1 = 0;		// Set bg scrolling var1
	ng_bg_scroll2 = 0;		// Set bg scrolling var2
	ng_bg_scroll3 = 0;		// Set bg scrolling var3
	ng_bg_scroll4 = 0;		// Set bg scrolling var3

	ng_bg_angle1 = 0;		// Set bg angle var1
	ng_bg_angle2 = 0;		// Set bg angle var2

	ng_bg_fade1 = 0;		// Set bg fading var1
	ng_bg_fade2 = 0;		// Set bg fading var1

	ng_stagevar1 = 0;		// temp var for stage



//---------------------------------------------------------------------------------------------
// Loading - load everything here before start!

	LoadMusic(ng_bgms[GetCommonDataDefault("ngc_playstage",0)]);
	LoadMusic(ng_bgmb[GetCommonDataDefault("ngc_playstage",0)]);

	LoadGraphic(stagebg[4]);
	LoadGraphic(stagebg[5]);
	LoadGraphic(stagebg[6]);

	LoadGraphic(extraimage[GetCommonDataDefault("ngc_extraimage",0)]);
	LoadGraphic(stageintro[GetCommonDataDefault("ngc_playstage",0)]);
	LoadGraphic(stageclear[GetCommonDataDefault("ngc_playstage",0)]);

//---------------------------------------------------------------------------------------------
// Start! - Only after loading!

	PlayMusic(ng_bgms[GetCommonDataDefault("ngc_playstage",0)]);
	Wait(60);

	SetCommonData("ng_feverdecrease", 1);	// Fever score DECREASE!


//------------------------------------------
// Sorry, start here :p



	ascent (i in 0..5)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy03.txt", GetClipMinX-10, GetClipMinY-10, 0, 0, 0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy03.txt", GetClipMaxX+10, GetClipMinY-10, 0, 0, 1);
		Wait(30);
		}

	Wait(240);



//------------------------------------------
// Show stage intro
	ng_stageintro = 0;
		let ObjStageIntro = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(ObjStageIntro, stageintro[GetCommonDataDefault("ngc_playstage",0)]);
		ObjEffect_SetLayer(ObjStageIntro, 7);
		Obj_SetAlpha(ObjStageIntro, 0);
		ObjEffect_CreateVertex(ObjStageIntro, 4);
		ObjEffect_SetPrimitiveType(ObjStageIntro, PRIMITIVE_TRIANGLEFAN);

		ObjEffect_SetVertexUV(ObjStageIntro, 0, 0, 0);
		ObjEffect_SetVertexUV(ObjStageIntro, 1, 299, 0);
		ObjEffect_SetVertexUV(ObjStageIntro, 2, 299, 124);
		ObjEffect_SetVertexUV(ObjStageIntro, 3, 0, 124);

		ObjEffect_SetVertexXY(ObjStageIntro, 0, GetCenterX-150, GetCenterY-100-62.5);
		ObjEffect_SetVertexXY(ObjStageIntro, 1, GetCenterX+150, GetCenterY-100-62.5);
		ObjEffect_SetVertexXY(ObjStageIntro, 2, GetCenterX+150, GetCenterY-100+62.5);
		ObjEffect_SetVertexXY(ObjStageIntro, 3, GetCenterX-150, GetCenterY-100+62.5);

		while (ng_stageintro < 240)
		{
			if (ng_stageintro < 50)
			{
				ObjEffect_SetVertexColor(ObjStageIntro, 0, ng_stageintro*5, 255, 255, 255);	
				ObjEffect_SetVertexColor(ObjStageIntro, 1, ng_stageintro*5, 255, 255, 255);
				ObjEffect_SetVertexColor(ObjStageIntro, 2, ng_stageintro*5, 255, 255, 255);
				ObjEffect_SetVertexColor(ObjStageIntro, 3, ng_stageintro*5, 255, 255, 255);
			}
			else if (ng_stageintro > 190)
			{
				ObjEffect_SetVertexColor(ObjStageIntro, 0, 255-((ng_stageintro-190)*5), 255, 255, 255);	
				ObjEffect_SetVertexColor(ObjStageIntro, 1, 255-((ng_stageintro-190)*5), 255, 255, 255);
				ObjEffect_SetVertexColor(ObjStageIntro, 2, 255-((ng_stageintro-190)*5), 255, 255, 255);
				ObjEffect_SetVertexColor(ObjStageIntro, 3, 255-((ng_stageintro-190)*5), 255, 255, 255);
			}
			else
			{
				ObjEffect_SetVertexColor(ObjStageIntro, 0, 255, 255, 255, 255);	
				ObjEffect_SetVertexColor(ObjStageIntro, 1, 255, 255, 255, 255);
				ObjEffect_SetVertexColor(ObjStageIntro, 2, 255, 255, 255, 255);
				ObjEffect_SetVertexColor(ObjStageIntro, 3, 255, 255, 255, 255);
			}
			ng_stageintro++;
			yield;
		}
		Obj_Delete(ObjStageIntro);
	Wait(60);


//------------------------------------------------
// Real battle ahead


	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetCenterX, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+175, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-175, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+150, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-150, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+125, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-125, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+100, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-100, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+75, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-75, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+50, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-50, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+25, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-25, GetClipMinY-10, 0, 0, 0);
	Wait(20);

	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy05.txt", GetCenterX, GetClipMinY, 0, 0, 0);
	Wait(120);


	ascent (i in 0..5)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy01.txt", GetClipMinX+50, GetClipMinY-10, 0, 0, 0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy01.txt", GetClipMaxX-50, GetClipMinY-10, 0, 0, 0);
		Wait(20);
		}
	Wait(90);

	ascent (i in 0..10)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy04.txt", GetClipMinX+50, GetClipMinY-10, 0, 0, 0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy04.txt", GetClipMaxX-50, GetClipMinY-10, 0, 0, 0);
		Wait(10);
		}
	Wait(30);

	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy06.txt", GetCenterX, GetClipMinY, 0, 0, 0);
	Wait(120);

	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+25, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-25, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+50, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-50, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+75, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-75, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+100, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-100, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+125, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-125, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+150, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-150, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+175, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-175, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetCenterX, GetClipMinY-10, 0, 0, 0);
	Wait(220);



//	WaitForZeroEnemy;

//--------------------------------
// Mid Boss
//--------------------------------
	CreateEnemyBossFromFile(GetCurrentScriptDirectory~".\stage2\stage2_midboss.txt",GetCenterX,GetClipMinY,0,0,0);
	WaitForZeroEnemy;
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_DropItemMidBoss.txt", GetCenterX, GetClipMinY+100, 0, 0, 0);

	ascent (i in 0..5)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy01.txt", GetClipMinX+50, GetClipMinY-10, 0, 0, 0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy01.txt", GetClipMaxX-50, GetClipMinY-10, 0, 0, 0);
		Wait(20);
		}
	Wait(60);

	ascent (i in 0..10)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy04.txt", GetClipMinX+50, GetClipMinY-10, 0, 0, 0);
		Wait(10);
		}
	Wait(30);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy05.txt", GetCenterX, GetClipMinY, 0, 0, 0);
	Wait(30);

	ascent (i in 0..10)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy04.txt", GetClipMaxX-50, GetClipMinY-10, 0, 0, 0);
		Wait(10);
		}
	Wait(120);

	ascent (i in 0..5)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy03.txt", GetClipMinX-10, GetClipMinY-10, 0, 0, 0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy03.txt", GetClipMaxX+10, GetClipMinY-10, 0, 0, 1);
		Wait(20);
		}
	Wait(30);

	ascent (i in 0..10)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy04.txt", GetClipMinX-10, GetClipMinY+30, 0, 0, 1);
		Wait(10);
		}
	Wait(30);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy06.txt", GetCenterX, GetClipMinY, 0, 0, 0);
	Wait(60);

	ascent (i in 0..10)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy04.txt", GetClipMaxX-10, GetClipMinY+60, 0, 0, 2);
		Wait(10);
		}
	Wait(90);

	ascent (i in 0..5)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy01.txt", GetClipMinX+50, GetClipMinY-10, 0, 0, 0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy01.txt", GetClipMaxX-50, GetClipMinY-10, 0, 0, 0);
		Wait(20);
		}
	Wait(30);

	ascent (i in 0..10)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy04.txt", GetClipMinX+50, GetClipMinY-10, 0, 0, 0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy04.txt", GetClipMaxX-50, GetClipMinY-10, 0, 0, 0);
		Wait(10);
		}
	Wait(30);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy05.txt", GetClipMinX+75, GetClipMinY, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy05.txt", GetClipMaxX-75, GetClipMinY, 0, 0, 0);
	Wait(240);
	ascent (i in 0..5)
		{
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy03.txt", GetClipMinX-10, GetClipMinY-10, 0, 0, 0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy03.txt", GetClipMaxX+10, GetClipMinY-10, 0, 0, 1);
		Wait(20);
		}
	Wait(60);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy06.txt", GetCenterX, GetClipMinY, 0, 0, 0);
	Wait(120);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetCenterX, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+175, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-175, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+150, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-150, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+125, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-125, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+100, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-100, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+75, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-75, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+50, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-50, GetClipMinY-10, 0, 0, 0);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMinX+25, GetClipMinY-10, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_enemy02.txt", GetClipMaxX-25, GetClipMinY-10, 0, 0, 0);
	Wait(300);




	WaitForZeroEnemy;

//--------------------------------
// Boss
//--------------------------------

	Wait(60);


	CreateEnemyBossFromFile(GetCurrentScriptDirectory~".\stage2\stage2_boss.txt",GetCenterX,GetClipMinY,0,0,0);
	WaitForZeroEnemy;
	CreateEnemyFromFile(GetCurrentScriptDirectory~"stage2\stage2_DropItemBossSpell3.txt", GetCenterX, GetClipMinY+100, 0, 0, 0);

	Wait(60);

	EndofStage;
	WaitForClear;
	Stage2DeleteFile;
	
	Wait(60);
}


//---------------------------------------------------------------------------------------------
// stage function - BG

function Stage2BG
{
	SetTexture(stagebg[4]);
	SetGraphicScale(1.8, 1.8);
	SetGraphicRect(0, ng_bg_scroll1, 256, ng_bg_scroll1 + 256);
	SetAlpha(255);
	DrawGraphic(GetCenterX, GetCenterY);
	ng_bg_scroll1 -= 0.50;

	SetTexture(stagebg[5]);
	SetGraphicScale(1, 1);
	SetGraphicRect(0, ng_bg_scroll2, 400, ng_bg_scroll2 + 480);
	SetAlpha(255);
	DrawGraphic(GetCenterX, GetCenterY);
	ng_bg_scroll2 -= 0.75;

	SetTexture(stagebg[6]);
	SetGraphicScale(1, 1);
	SetGraphicRect(0, ng_bg_scroll3, 400, ng_bg_scroll3 + 480);
	SetAlpha(100);
	DrawGraphic(GetCenterX, GetCenterY);
	ng_bg_scroll3 -= 1;

}



//---------------------------------------------------------------------------------------------
// Delete - I forgot it oTL~

function Stage2DeleteFile
{
	DeleteMusic(ng_bgms[GetCommonDataDefault("ngc_playstage",0)]);
	DeleteMusic(ng_bgmb[GetCommonDataDefault("ngc_playstage",0)]);

	DeleteGraphic(stagebg[4]);
	DeleteGraphic(stagebg[5]);
	DeleteGraphic(stagebg[6]);

	DeleteGraphic(extraimage[GetCommonDataDefault("ngc_extraimage",0)]);
	DeleteGraphic(stageintro[GetCommonDataDefault("ngc_playstage",0)]);
	DeleteGraphic(stageclear[GetCommonDataDefault("ngc_playstage",0)]);
}

