if(nextphase==1 && stagephase==2){ phase+=1; frame=0; enemyx=0; enemyy=0; enemiescalled=0; nextphase=0; SetCommonData("IncreasePhase",0); }

if(phase==0 && stagephase==2){
	if(enemiescalled==0){ SetCommonData("BackgroundStop",1); }
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=240; }
	if(enemiescalled==0){ newviewh=0; newviewv=0; viewmovetimehv=180; }
	if(frame%60==0){ enemiescalled++; }
	if(enemiescalled>=3){ nextphase=1; SetCommonData("BackgroundStop",0); }
}

if(phase==1 && stagephase==2){
	if(enemiescalled==3){ newviewx=15; newviewy=0; viewmovetimexy=60; }
	if(frame%15==0){
		if(enemiescalled<14){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",maxx+32,miny+50,0,0,[20+enemyx,3]); }
	enemiescalled++; enemyx+=5; }
	if(enemiescalled>=20){ nextphase=1; }
}
if(phase==2 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=90; }
	if(frame%60==0){
		if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 3\306.txt",cx,miny+rand(60,120),0,0,[1,1]); }
	enemiescalled++; }
	if(enemiescalled>=5){ nextphase=1; }
}
if(phase==3 && stagephase==2){
	if(enemiescalled==0){ newviewx=-15; newviewy=0; viewmovetimexy=60; }
	if(frame%15==0){
		if(enemiescalled<14){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",minx-32,miny+120,0,0,[20+enemyx,3]); }
	enemiescalled++; enemyx+=5; }
	if(enemiescalled>=20){ nextphase=1; }
}
if(phase==4 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=90; }
	if(frame%60==0){
		if(enemiescalled==0){
		CreateEnemyFromFile("script\Enemies\Stage 3\306.txt",cx-100,miny+rand(60,120),0,0,[6,1]);
		CreateEnemyFromFile("script\Enemies\Stage 3\306.txt",cx+100,miny+rand(60,120),0,0,[7,1]);
		}
	enemiescalled++; }
	if(enemiescalled>=6){ nextphase=1; }
}
if(phase==5 && stagephase==2){
	if(enemiescalled==0){ newviewx=15; newviewy=0; viewmovetimexy=60; }
	if(frame%8==0){
		if(enemiescalled<14){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",maxx+32,miny+70,0,0,[20+enemyx,4.5]); }
	enemiescalled++; enemyx+=5; }
	if(enemiescalled>=20){ nextphase=1; }
}
if(phase==6 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=120; }
	if(frame%50==0){
		if(enemiescalled<4 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx-rand(60,120),miny-32,0,0,3+rand(-0.5,0.5)); }
		if(enemiescalled<4 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx+rand(60,120),miny-32,0,0,3+rand(-0.5,0.5)); }
	enemiescalled++; }
	if(enemiescalled>=8){ nextphase=1; }
}
if(phase==7 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=60; }
	if(frame%15==0){
		if(enemiescalled<24 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",maxx+32,miny+70,0,0,[20+enemyx,1]); }
		if(enemiescalled<24 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",minx-32,miny+70,0,0,[20+enemyx,1]); }
	enemiescalled++; enemyx+=3; }
	if(enemiescalled>=30){ nextphase=1; }
}
if(phase==8 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=120; }
	if(frame%50==0){
		if(enemiescalled<6 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx+rand(60,120),miny-32,0,0,3+rand(-0.5,0.5)); }
		if(enemiescalled<6 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx-rand(60,120),miny-32,0,0,3+rand(-0.5,0.5)); }
	enemiescalled++; }
	if(enemiescalled>=7){ nextphase=1; }
}
if(phase==9 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=90; }
	if(frame%120==0){
		if(enemiescalled<3 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 3\306.txt",cx+rand(50,150),miny+rand(60,120),0,0,[4,1]); }
		if(enemiescalled<3 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 3\306.txt",cx-rand(50,150),miny+rand(60,120),0,0,[4,1]); }
	enemiescalled++; }
	if(enemiescalled>=5){ nextphase=1; }
}
if(phase==10 && stagephase==2){
	if(enemiescalled==0){ newviewh=-120; viewmovetimehv=240; newviewx=45; viewmovetimexy=90; }
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=120; }
	if(frame%40==0){
		if(enemiescalled<8 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx+rand(60,120),miny-32,0,0,4+rand(-0.5,0.5)); }
		if(enemiescalled<8 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx-rand(60,120),miny-32,0,0,4+rand(-0.5,0.5)); }
	enemiescalled++; }
	if(enemiescalled>=12){ nextphase=1; }
}
if(phase==11 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=90; }
	if(frame%8==0){
		if(enemiescalled<18 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 3\303.txt",minx-32,miny+150,0,0,[2,1]); }
		if(enemiescalled<18 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 3\303.txt",maxx+32,miny+150,0,0,[2,1]); }
	enemiescalled++; }
	if(enemiescalled>=30){ nextphase=1; }
}
if(phase==12 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=120; }
	if(frame%30==0){
		if(enemiescalled<8 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx+rand(60,120),miny-32,0,0,5+rand(-0.5,0.5)); }
		if(enemiescalled<8 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx-rand(60,120),miny-32,0,0,5+rand(-0.5,0.5)); }
	enemiescalled++; }
	if(enemiescalled>=14){ nextphase=1; }
}
if(phase==13 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=90; }
	if(frame%45==0){
		if(enemiescalled<5 && enemiescalled!=3){ CreateEnemyFromFile("script\Enemies\Stage 3\306.txt",cx-120+enemyx,miny+rand(60,120),0,0,[3,1]); }
		if(enemiescalled==3){ CreateEnemyFromFile("script\Enemies\Stage 3\306.txt",cx-120+enemyx,miny+rand(60,120),0,0,[3,2]); }
	enemiescalled++; enemyx+=60; }
	if(enemiescalled>=12){ nextphase=1; }
}
if(phase==14 && stagephase==2){
	if(enemiescalled==0){ newviewx=-15; newviewy=0; viewmovetimexy=60; }
	if(frame%8==0){
		if(enemiescalled<14){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",minx-32,miny+70,0,0,[20+enemyx,4.5]); }
	enemiescalled++; enemyx+=5; }
	if(enemiescalled>=26){ nextphase=1; }
}
if(phase==15 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=120; }
	if(frame%10==0){
		if(enemiescalled<12){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",maxx+32,miny+70,0,0,[20+enemyx,2.5]); }
		if(enemiescalled==24){ enemyx=0; }
		if(enemiescalled>=24 && enemiescalled<36){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",minx-32,miny+70,0,0,[20+enemyx,2.5]); }
		if(enemiescalled<36 && enemiescalled%12==0 && enemiescalled%6==0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx+rand(60,120),miny-32,0,0,3+rand(-0.5,0.5)); }
		if(enemiescalled<36 && enemiescalled%12!=0 && enemiescalled%6==0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx-rand(60,120),miny-32,0,0,3+rand(-0.5,0.5)); }
	enemiescalled++; enemyx+=5; }
	if(enemiescalled>=48){ nextphase=1; }
}
if(phase==16 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=120; }
	if(frame%10==0){
		if(enemiescalled<12){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",maxx+32,miny+70,0,0,[20+enemyx,4]); }
		if(enemiescalled==24){ enemyx=0; }
		if(enemiescalled>=24 && enemiescalled<36){ CreateEnemyFromFile("script\Enemies\Stage 3\305.txt",minx-32,miny+70,0,0,[20+enemyx,4]); }
		if(enemiescalled<36 && enemiescalled%12!=0 && enemiescalled%6==0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx+rand(60,120),miny-32,0,0,3+rand(-0.5,0.5)); }
		if(enemiescalled<36 && enemiescalled%12==0 && enemiescalled%6==0){ CreateEnemyFromFile("script\Enemies\Stage 3\304.txt",cx-rand(60,120),miny-32,0,0,3+rand(-0.5,0.5)); }
	enemiescalled++; enemyx+=5; }
	if(enemiescalled>=48){ nextphase=1; }
}
if(phase==17 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=90; }
	if(frame%30==0){
		if(enemiescalled<5){ CreateEnemyFromFile("script\Enemies\Stage 3\306.txt",cx+120-enemyx,miny+rand(60,120),0,0,[11,1]); }
	enemiescalled++; enemyx+=60; }
	if(enemiescalled>=18){ nextphase=1; }
}
if(phase==18 && stagephase==2){
	if(enemiescalled==0){ newviewx=90; newviewy=0; viewmovetimexy=210; }
	if(enemiescalled==2 && frame==1){ CreateEnemyFromFile("script\Functions\fadeout-in.txt",0,0,0,0,255); }//whiteout
	if(enemiescalled==3){ bgphase=2; SetCommonData("BackgroundStop",2); }
	if(frame==60){ enemiescalled++; frame=0; }
	if(enemiescalled>=5){ nextphase=1; }
}