if(time==100){ CreateEnemyFromFile("script\Functions\stagebars.txt",0,0,0,0,5); }

if(time==500 && stagephase==1){ phase+=1; frame=0; enemyx=0; enemyy=0; enemiescalled=0; }

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

if(phase==1 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=-20; viewmovetimexy=120; }
	if(frame%60==0){
		if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 5\506.txt",cx,miny-32,0,0,[4,0]); }
	enemiescalled++; }
	if(enemiescalled>=7){ nextphase=1; }
}
if(phase==2 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=-20; viewmovetimexy=120; }
	if(frame%60==0){
		if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 5\506.txt",cx-rand(110,130),miny-32,0,0,[4,1]); }
		if(enemiescalled==3){ CreateEnemyFromFile("script\Enemies\Stage 5\506.txt",cx+rand(110,130),miny-32,0,0,[4,0]); }
	enemiescalled++; }
	if(enemiescalled>=10){ nextphase=1; }
}
if(phase==3 && stagephase==1){
	if(enemiescalled==0){ newviewx=20; newviewy=-10; viewmovetimexy=60; }
	if(enemiescalled==7){ newviewx=-20; newviewy=-10; viewmovetimexy=60; }
	if(frame%45==0){
		if(enemiescalled<4){ CreateEnemyFromFile("script\Enemies\Stage 5\501.txt",maxx+32,miny-32,0,0,0); }
		if(enemiescalled>=7 && enemiescalled<11){ CreateEnemyFromFile("script\Enemies\Stage 5\501.txt",minx-32,miny-32,0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=16){ nextphase=1; }
}
if(phase==4 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=120; }
	if(frame%30==0){
		if(enemiescalled<12 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\503.txt",minx-32,miny+rand(120,150),0,0,[6,enemyx,1]); }
		if(enemiescalled<12 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\503.txt",maxx+32,miny+rand(120,150),0,0,[6,enemyx,1]); }
	enemiescalled++; enemyx+=rand_int(10,20); }
	if(enemiescalled>=22){ nextphase=1; }
}
if(phase==5 && stagephase==1){
	if(enemiescalled==0){ newviewx=20; newviewy=-10; viewmovetimexy=60; }
	if(enemiescalled==20){ newviewx=-20; newviewy=-10; viewmovetimexy=60; }
	if(frame%15==0){
		if(enemiescalled<8){ CreateEnemyFromFile("script\Enemies\Stage 5\501.txt",maxx+32,miny-32,0,0,0); }
		if(enemiescalled>=20 && enemiescalled<28){ CreateEnemyFromFile("script\Enemies\Stage 5\501.txt",minx-32,miny-32,0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=44){ nextphase=1; }
}
if(phase==6 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=120; }
	if(frame%30==0){
		if(enemiescalled<12 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\503.txt",minx-32,miny+rand(320,370),0,0,[9,enemyx,2]); }
		if(enemiescalled<12 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\503.txt",maxx+32,miny+rand(320,370),0,0,[9,enemyx,2]); }
	enemiescalled++; enemyx+=rand_int(10,20); }
	if(enemiescalled>=22){ nextphase=1; }
}
if(phase==7 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=60; }
	if(frame%25==0){
		if(enemiescalled<14 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\501.txt",minx-32,miny-32,0,0,0); }
		if(enemiescalled<14 && enemiescalled%2==1){ CreateEnemyFromFile("script\Enemies\Stage 5\501.txt",maxx+32,miny-32,0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=24){ nextphase=1; }
}
if(phase==8 && stagephase==1){
	if(frame%25==0){
		if(enemiescalled>=9 && enemiescalled<15 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\503.txt",minx-32,miny+rand(320,370),0,0,[1,enemyx,2]); }
		if(enemiescalled>=9 && enemiescalled<15 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\503.txt",maxx+32,miny+rand(320,370),0,0,[1,enemyx,2]); }
		if(enemiescalled<6 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 5\503.txt",minx-32,miny+rand(100,150),0,0,[3,enemyx,1]); }
		if(enemiescalled<6 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 5\503.txt",maxx+32,miny+rand(100,150),0,0,[3,enemyx,1]); }
		enemiescalled++; enemyx+=rand_int(10,20); }
	if(enemiescalled>=28){ nextphase=1; }
}
if(phase==9 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=120; }
	if(frame%60==0){
		if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 5\502.txt",cx,miny-32,0,0,[6,0]); }
	enemiescalled++; }
	if(enemiescalled>=10){ nextphase=1; }
}
if(phase==10 && stagephase==1){
	if(frame%60==0){
		if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 5\506.txt",cx,miny-32,0,0,[7,0]); }
		if(enemiescalled==3){ CreateEnemyFromFile("script\Enemies\Stage 5\509.txt",minx-32,miny+100,0,0,1); }
	enemiescalled++; }
	if(enemiescalled>=10){ nextphase=1; }
}
if(phase==11 && stagephase==1){
	if(frame%30==0){
	if(enemiescalled==0){ newviewx=-20; newviewy=-10; viewmovetimexy=60; }
	if(enemiescalled==8){ newviewx=20; newviewy=-10; viewmovetimexy=60; }
		if(enemiescalled<6){ CreateEnemyFromFile("script\Enemies\Stage 5\501.txt",minx-32,miny-32,0,0,0); }
		if(enemiescalled>=9 && enemiescalled<14){ CreateEnemyFromFile("script\Enemies\Stage 5\501.txt",maxx+32,miny-32,0,0,0); }
		if(enemiescalled==4){ CreateEnemyFromFile("script\Enemies\Stage 5\509.txt",maxx+32,miny+70,0,0,2); }
		if(enemiescalled==12){ CreateEnemyFromFile("script\Enemies\Stage 5\509.txt",minx-32,miny+70,0,0,3); }
	enemiescalled++; }
	if(enemiescalled>=18){ nextphase=1; }
}
if(phase==12 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=120; }
	if(frame%60==0){
		if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 5\502.txt",cx,miny-32,0,0,[4,0]); }
		if(enemiescalled==2){ CreateEnemyFromFile("script\Enemies\Stage 5\509.txt",maxx+32,miny+10,0,0,4); }
		if(enemiescalled==6){ CreateEnemyFromFile("script\Enemies\Stage 5\509.txt",minx-32,miny+10,0,0,5); }
	enemiescalled++; }
	if(enemiescalled>=10){ nextphase=1; }
}
if(phase==13 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=120; }
	if(frame%60==0){
		if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 5\502.txt",cx+100,miny-32,0,0,[4,1]); }
		if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 5\502.txt",cx-100,miny-32,0,0,[4,1]); }
	enemiescalled++; }
	if(enemiescalled>=14){ nextphase=1; }
}