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

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=0; viewmovetimexy=450; }
	if(frame%60==0){
		if(enemiescalled<10 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",minx-32,miny+40,0,0,[1.5,10-enemyx]); }
		if(enemiescalled<10 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",maxx+32,miny+80,0,0,[1.5,10-enemyx]); }
	enemiescalled++; enemyx++; if(enemyx>=10){ enemyx=0; } }
	if(enemiescalled>=14){ nextphase=1; }
}
if(phase==2 && stagephase==1){
	if(enemiescalled==0){ newviewx=10; newviewy=0; viewmovetimexy=60; }
	if(enemiescalled==1){ newviewx=-10; newviewy=0; viewmovetimexy=300; }
	if(frame%60==0){
		if(enemiescalled<6){ CreateEnemyFromFile("script\Enemies\Stage 4\406.txt",cx+120-enemyx,miny-32,0,0,0); }
	enemiescalled++; enemyx+=240/5; }
	if(enemiescalled>=8){ nextphase=1; }
}
if(phase==3 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=120; }
	if(frame%60==0){
		if(enemiescalled<5){ CreateEnemyFromFile("script\Enemies\Stage 4\402.txt",cx+150-enemyx,miny-32,0,0,[cx+150-enemyx,cy,0,50,3]); }
	enemiescalled++; enemyx+=300/4; }
	if(enemiescalled>=10){ nextphase=1; }
}
if(phase==4 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=-20; viewmovetimexy=120; }
	if(enemiescalled==3){ newviewx=0; newviewy=0; viewmovetimexy=300; }
	if(frame%60==0){
		if(enemiescalled<10 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",minx-32,miny+40,0,0,[1.5,1+enemyx]); }
		if(enemiescalled<10 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",maxx+32,miny+80,0,0,[1.5,1+enemyx]); }
		if(enemiescalled>=4 && enemiescalled<10){ CreateEnemyFromFile("script\Enemies\Stage 4\406.txt",cx+100*cos((time+rand(-80,80))*3),miny-32,0,0,0); }
	enemiescalled++; enemyx++; }
	if(enemiescalled>=14){ nextphase=1; }
}
if(phase==5 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=120; }
	if(frame%60==0){
		if(enemiescalled<10 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 4\402.txt",cx-150+enemyx,miny-32,0,0,[cx-150+enemyx,cy,0,50,3]); enemyx+=300/4; }
		if(enemiescalled<10 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",minx-32,miny+40,0,0,[1.5,1+enemyy]); }
		if(enemiescalled<10 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",maxx+32,miny+80,0,0,[1.5,1+enemyy]); }
	enemiescalled++; enemyy++; }
	if(enemiescalled>=14){ nextphase=1; }
}
if(phase==6 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=60; }
	if(frame%100==0){
		if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 4\404.txt",minx-32,miny+100,0,0,2); }
		if(enemiescalled==1){ CreateEnemyFromFile("script\Enemies\Stage 4\404.txt",maxx+32,miny+100,0,0,1); }
	enemiescalled++; }
	if(enemiescalled>=3){ nextphase=1; }
}
if(phase==7 && stagephase==1){
	if(enemiescalled==0){ newviewx=-10; newviewy=0; viewmovetimexy=60; }
	if(enemiescalled==2){ newviewx=10; newviewy=0; viewmovetimexy=300; }
	if(frame%60==0){
		if(enemiescalled<5){ CreateEnemyFromFile("script\Enemies\Stage 4\405.txt",cx-120+enemyx,rand(50,150),0,0,0); }
	enemiescalled++; enemyx+=240/4; }
	if(enemiescalled>=10){ nextphase=1; }
}
if(phase==8 && stagephase==1){
	if(enemiescalled==1){ newviewx=0; newviewy=-15; viewmovetimexy=90; }
	if(frame%60==0){
		if(enemiescalled<9){ CreateEnemyFromFile("script\Enemies\Stage 4\406.txt",cx+rand(-100,100),miny-32,0,0,0); }
		if(enemiescalled>=2 && enemiescalled<8){ CreateEnemyFromFile("script\Enemies\Stage 4\405.txt",cx+120-enemyx,rand(50,150),0,0,0);  enemyx+=240/5; }
	enemiescalled++; }
	if(enemiescalled>=16){ nextphase=1; }
}
if(phase==9 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=120; }
	if(frame%60==0){
		if(enemiescalled<10 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",minx-32,miny+40,0,0,[1.5,10-enemyx]); }
		if(enemiescalled<10 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",maxx+32,miny+80,0,0,[1.5,10-enemyx]); }
		if(enemiescalled<10 && enemiescalled%2==0 && enemiescalled%4==0){ CreateEnemyFromFile("script\Enemies\Stage 4\404.txt",maxx+32,miny+100,0,0,1); }
		if(enemiescalled<10 && enemiescalled%2==0 && enemiescalled%4!=0){ CreateEnemyFromFile("script\Enemies\Stage 4\404.txt",minx-32,miny+100,0,0,2); }
	enemiescalled++; enemyx++; }
	if(enemiescalled>=13){ nextphase=1; }
}
if(phase==10 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=450; }
	if(frame%30==0){
		if(enemiescalled<20 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",minx-32,miny+40,0,0,[1.5,10-enemyx]); }
		if(enemiescalled<20 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 4\403.txt",maxx+32,miny+80,0,0,[1.5,10-enemyx]); }
	enemiescalled++; enemyx++; if(enemyx>=10){ enemyx=0; } }
	if(enemiescalled>=30){ nextphase=1; }
}