if(time==100 && stagephase==1){ CreateEnemyFromFile("script\Functions\stagebars.txt",0,0,0,0,2); }

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=80; newviewy=20; viewmovetimexy=600; }
	if(frame%30==0){
		if(enemiescalled<5){ CreateEnemyFromFile("script\Enemies\Stage 2\201.txt",maxx+30-enemyx,miny-32,0,0,rand(4,5)); }
	enemyx+=35;
	enemiescalled++; }
	if(enemiescalled>=7){ nextphase=1; }
}
if(phase==2 && stagephase==1){
	if(frame%50==0){
		if(enemiescalled<4){ CreateEnemyFromFile("script\Enemies\Stage 2\202.txt",(cx-70)+70*cos(time+(rand(-70,70)*cos(time*5))),miny-32,0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=6){ nextphase=1; }
}
if(phase==3 && stagephase==1){
	if(frame%30==0){
		if(enemiescalled<5){ CreateEnemyFromFile("script\Enemies\Stage 2\201.txt",minx-30+enemyx,miny-32,0,0,rand(4,5)); }
	enemyx+=35;
	enemiescalled++; }
	if(enemiescalled>=7){ nextphase=1; }
}
if(phase==4 && stagephase==1){
	if(frame%50==0){
		if(enemiescalled<4){ CreateEnemyFromFile("script\Enemies\Stage 2\202.txt",(cx+70)-70*cos(time+(rand(-70,70)*cos(time*5))),miny-32,0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=8){ nextphase=1; }
}
if(phase==5 && stagephase==1){
	if(enemiescalled==0){ newviewx=40; newviewy=10; viewmovetimexy=300; }
	if(frame%10==0){
		if(enemiescalled<12){ CreateEnemyFromFile("script\Enemies\Stage 2\203.txt",minx-20,miny+rand(50,120),0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=25){ nextphase=1; }
}
if(phase==6 && stagephase==1){
	if(frame%30==0){
		if(enemiescalled<5){ CreateEnemyFromFile("script\Enemies\Stage 2\201.txt",maxx+30-enemyx,miny-32,0,0,rand(4,5)); }
	enemyx+=35;
	enemiescalled++; }
	if(enemiescalled>=7){ nextphase=1; }
}
if(phase==7 && stagephase==1){
	if(frame%50==0){
		if(enemiescalled<4){ CreateEnemyFromFile("script\Enemies\Stage 2\204.txt",minx,miny+50+enemyy,0,0,0); }
	enemyy+=20;
	enemiescalled++; }
	if(enemiescalled>=8){ nextphase=1; }
}
if(phase==8 && stagephase==1){
	if(enemiescalled==0){ newviewx=80; newviewy=-10; viewmovetimexy=600; }
	if(enemiescalled==0){ newviewh=50; newviewv=0; viewmovetimehv=300; }
	if(frame%30==0){
		if(enemiescalled<5){ CreateEnemyFromFile("script\Enemies\Stage 2\201.txt",minx-30+enemyx,miny-32,0,0,rand(4,5)); }
	enemyx+=35;
	enemiescalled++; }
	if(enemiescalled>=7){ nextphase=1; }
}
if(phase==9 && stagephase==1){
	if(frame%50==0){
		if(enemiescalled<4){ CreateEnemyFromFile("script\Enemies\Stage 2\204.txt",maxx,miny+50+enemyy,0,0,0); }
	enemyy+=20;
	enemiescalled++; }
	if(enemiescalled>=8){ nextphase=1; }
}
if(phase==10 && stagephase==1){
	if(frame%20==0){
		if(enemiescalled<12){
		if(enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 2\201.txt",minx-30+enemyx,miny-32,0,0,rand(5.5,6.5)); }
		if(enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 2\201.txt",maxx+30-enemyx,miny-32,0,0,rand(5.5,6.5)); }
		}
	enemyx+=20;
	enemiescalled++; }
	if(enemiescalled>=18){ nextphase=1; }
}
if(phase==11 && stagephase==1){
	if(frame%50==0){
		if(enemiescalled%2==0 && enemiescalled<6){ CreateEnemyFromFile("script\Enemies\Stage 2\204.txt",minx,miny+50+enemyy,0,0,0); }
		if(enemiescalled%2!=0 && enemiescalled<6){ CreateEnemyFromFile("script\Enemies\Stage 2\204.txt",maxx,miny+50+enemyy,0,0,0); }
	enemyy+=16;
	enemiescalled++; }
	if(enemiescalled>=8){ nextphase=1; }
}
if(phase==12 && stagephase==1){
	if(enemiescalled==0){ newviewx=40; newviewy=0; viewmovetimexy=300; }
	if(enemiescalled==0){ newviewh=0; newviewv=0; viewmovetimehv=300; }
	if(frame%10==0){
		if(enemiescalled==3){ CreateEnemyFromFile("script\Enemies\Stage 2\202.txt",(cx+70)-70*cos(time+(rand(-70,70)*cos(time*5))),miny-32,0,0,0); }
		if(enemiescalled==8){ CreateEnemyFromFile("script\Enemies\Stage 2\202.txt",(cx-70)+70*cos(time+(rand(-70,70)*cos(time*5))),miny-32,0,0,0); }
		if(enemiescalled<12){ CreateEnemyFromFile("script\Enemies\Stage 2\203.txt",maxx+20,miny+rand(50,120),0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=25){ nextphase=1; }
}
if(phase==13 && stagephase==1){
	if(frame%10==0){
		if(enemiescalled<24){
		CreateEnemyFromFile("script\Enemies\Stage 2\203.txt",minx-20,miny+rand(50,120),0,0,0);
		CreateEnemyFromFile("script\Enemies\Stage 2\203.txt",maxx+20,miny+rand(50,120),0,0,0);
		}
	enemiescalled++; }
	if(enemiescalled>=35){ nextphase=1; }
}
if(phase==14 && stagephase==1){
	if(enemiescalled==0){ newviewx=80; newviewy=10; viewmovetimexy=300; }
	if(frame%50==0){
		if(enemiescalled%2==0 && enemiescalled<6){ CreateEnemyFromFile("script\Enemies\Stage 2\202.txt",(cx+70)+70*cos(time+(rand(-70,70)*cos(time*5))),miny-32,0,0,0); }
		if(enemiescalled%2!=0 && enemiescalled<6){ CreateEnemyFromFile("script\Enemies\Stage 2\202.txt",(cx-70)-70*cos(time+(rand(-70,70)*cos(time*5))),miny-32,0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=14){ nextphase=1; }
}