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

if(phase==1 && stagephase==2){
	if(enemiescalled==0){ newviewx=20; newviewy=-10; viewmovetimexy=60; }
	if(frame%40==0){
		if(enemiescalled<8 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+rand(100,140),0,0,[9,3,1,2]); }
		if(enemiescalled<8 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+rand(100,140),0,0,[9,3,1,2]); }
	enemiescalled++; enemyx+=17; enemyy+=200/15; }
	if(enemiescalled>=11){ nextphase=1; }
}
if(phase==2 && stagephase==2){
	if(enemiescalled==0){ newviewx=-20; newviewy=-10; viewmovetimexy=60; }
	if(frame%40==0){
		if(enemiescalled<8 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",cx+rand(100,120),miny-32,0,0,[7,3,1,2]); }
		if(enemiescalled<8 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",cx-rand(100,120),miny-32,0,0,[7,3,1,2]); }
	enemiescalled++; enemyx+=17; enemyy+=200/15; }
	if(enemiescalled>=11){ nextphase=1; }
}
if(phase==3 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=60; }
	if(frame%60==0){
		if(enemiescalled<8 && (enemiescalled+0)%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+rand(100,140),0,0,[8,3,1,2]); }
		if(enemiescalled<8 && (enemiescalled+1)%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",cx+100,miny-32,0,0,[9,3,1,2]); }
		if(enemiescalled<8 && (enemiescalled+2)%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+rand(100,140),0,0,[8,3,1,2]); }
		if(enemiescalled<8 && (enemiescalled+3)%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",cx-100,miny-32,0,0,[7,3,1,2]); }
	enemiescalled++; }
	if(enemiescalled>=13){ nextphase=1; }
}
if(phase==4 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=60; }
	if(frame%40==0){
		if(enemiescalled<10 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\504.txt",cx-rand(60,140),miny+rand(80,120),0,0,0); }
		if(enemiescalled<10 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\504.txt",cx+rand(60,140),miny+rand(80,120),0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=17){ nextphase=1; }
}
if(phase==5 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-20; viewmovetimexy=60; }
	if(frame%25==0){
		if(enemiescalled<18 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\505.txt",cx+rand(0,100),miny-32,0,0,0); }
		if(enemiescalled<18 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\505.txt",cx-rand(0,100),miny-32,0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=24){ nextphase=1; }
}
if(phase==6 && stagephase==2){
	if(enemiescalled==0){ newviewx=-20; newviewy=-10; viewmovetimexy=60; }
	if(frame%40==0){
		if(enemiescalled<8 && enemiescalled%2==0 && enemiescalled%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+rand(100,140),0,0,[3,3,1,1]); }
		if(enemiescalled<8 && enemiescalled%2==0 && enemiescalled%4!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+rand(100,140),0,0,[3,3,1,1]); }
	enemiescalled++; enemyx+=17; enemyy+=200/15; }
	if(enemiescalled>=11){ nextphase=1; }
}
if(phase==7 && stagephase==2){
	if(enemiescalled==0){ newviewx=20; newviewy=-10; viewmovetimexy=60; }
	if(frame%40==0){
		if(enemiescalled<8 && enemiescalled%2==0 && enemiescalled%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",cx+rand(100,120),miny-32,0,0,[1,3,1,1]); }
		if(enemiescalled<8 && enemiescalled%2==0 && enemiescalled%4!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",cx-rand(100,120),miny-32,0,0,[1,3,1,1]); }
	enemiescalled++; enemyx+=17; enemyy+=200/15; }
	if(enemiescalled>=11){ nextphase=1; }
}
if(phase==8 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=60; }
	if(frame%60==0){
		if(enemiescalled<8 && (enemiescalled+2)%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+rand(100,140),0,0,[2,3,1,1]); }
		if(enemiescalled<8 && (enemiescalled+3)%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",cx+100,miny-32,0,0,[3,3,1,1]); }
		if(enemiescalled<8 && (enemiescalled+0)%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+rand(100,140),0,0,[2,3,1,1]); }
		if(enemiescalled<8 && (enemiescalled+1)%4==0){ CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",cx-100,miny-32,0,0,[1,3,1,1]); }
	enemiescalled++; }
	if(enemiescalled>=13){ nextphase=1; }
}
if(phase==9 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=60; }
	if(frame%40==0){
		if(enemiescalled<12 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\504.txt",cx+rand(30,80),miny+60+enemyy,0,0,0); }
		if(enemiescalled<12 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\504.txt",cx-rand(30,80),miny+60+enemyy,0,0,0); }
	enemiescalled++; enemyy+=15; }
	if(enemiescalled>=20){ nextphase=1; }
}
if(phase==10 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-20; viewmovetimexy=60; }
	if(frame%50==0){
		if(enemiescalled<24 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\505.txt",cx+rand(0,100),miny-32,0,0,0); }
		if(enemiescalled<24 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\505.txt",cx-rand(0,100),miny-32,0,0,0); }
		if(enemiescalled==2){ CreateEnemyFromFile("script\Enemies\Stage 5\502.txt",cx-rand(100,60),miny-32,0,0,[5,1]); }
		if(enemiescalled==14){ CreateEnemyFromFile("script\Enemies\Stage 5\502.txt",cx+rand(100,60),miny-32,0,0,[5,1]); }
	enemiescalled++; }
	if(enemiescalled>=30){ nextphase=1; }
}
if(phase==11 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=60; }
	if(frame%90==0){
		if(enemiescalled==0){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+60,0,0,[9,5,1,2]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+60,0,0,[9,5,1,2]);
		}
		if(enemiescalled==1){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+120,0,0,[8,4,1,2]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+120,0,0,[8,4,1,2]);
		}
		if(enemiescalled==2){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+180,0,0,[7,3,1,2]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+180,0,0,[7,3,1,2]);
		}
		if(enemiescalled==4){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+60,0,0,[3,5,1,1]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+60,0,0,[3,5,1,1]);
		}
		if(enemiescalled==5){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+120,0,0,[2,4,1,1]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+120,0,0,[2,4,1,1]);
		}
		if(enemiescalled==6){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+180,0,0,[1,3,1,1]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+180,0,0,[1,3,1,1]);
		}
	enemiescalled++; }
	if(enemiescalled>=10){ nextphase=1; }
}
if(phase==12 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=60; }
	if(frame%90==0){
		if(enemiescalled==0){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny-32,0,0,[2,3,2,1]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny-32,0,0,[2,3,2,1]);
		}
		if(enemiescalled==2){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+40,0,0,[8,3,2,2]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+40,0,0,[8,3,2,2]);
		}
		if(enemiescalled==4){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny-32,0,0,[1,3,2,1]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny-32,0,0,[1,3,2,1]);
		}
		if(enemiescalled==6){
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",minx-32,miny+40,0,0,[7,3,2,2]);
		CreateEnemyFromFile("script\Enemies\Stage 5\507.txt",maxx+32,miny+40,0,0,[7,3,2,2]);
		}
	enemiescalled++; }
	if(enemiescalled>=12){ nextphase=1; }
}