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(frame%60==0){ enemiescalled++; }
	if(enemiescalled>=1){ nextphase=1; }
}
if(phase==1 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; viewmovetimexy=120; }
	if(enemiescalled==0){ newviewh=0; viewmovetimehv=120; }
	if(enemiescalled==0 && enemyx==0){ CreateEnemyFromFile("script\Functions\fadeout-in.txt",0,0,0,0,255); enemyx++; }//whiteout
	if(enemiescalled==2){ bgphase=2; }
	if(enemiescalled>=3){ nextphase=1; }
	if(frame%60==0){ enemiescalled++; } //Wait
}


if(phase==2 && stagephase==2){
	if(enemiescalled==0){ newviewx=30; newviewy=0; viewmovetimexy=300; }
	if(frame%90==0){
		if(enemiescalled<4 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Extra\707.txt",minx+30,miny-32,0,0,0); }
		if(enemiescalled<4 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Extra\707.txt",maxx-30,miny-32,0,0,0); }
	enemiescalled++; }
	if(enemiescalled>=7){ nextphase=1; }
}
if(phase==3 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=300; }
	if(frame%40==0){
		if(enemiescalled<8 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx+rand(40,120),miny+rand(80,140),0,0,[18,3,20,5]); }
		if(enemiescalled<8 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx-rand(40,120),miny+rand(80,140),0,0,[18,3,-20,7]); }
	enemiescalled++; }
	if(enemiescalled>=12){ nextphase=1; }
}
if(phase==4 && stagephase==2){
	if(enemiescalled==0){ newviewx=60; newviewy=-10; viewmovetimexy=1200; }
	if(frame%10==0){
		if(enemiescalled<10 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Extra\702.txt",cx-180*cos((time*4)+(rand(-60,60))),miny-32,0,0,[4,1]); }
		if(enemiescalled<10 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Extra\702.txt",cx-100*cos((time*4)+(rand(-60,60))),miny-32,0,0,[4,1]); }
		if(enemiescalled>=16 && enemiescalled<26 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Extra\702.txt",cx-180*cos((time*4)+(rand(-60,60))),miny-32,0,0,[4,2]); }
		if(enemiescalled>=16 && enemiescalled<26 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Extra\702.txt",cx-100*cos((time*4)+(rand(-60,60))),miny-32,0,0,[4,2]); }
	enemiescalled++; }
	if(enemiescalled>=40){ nextphase=1; }
}
if(phase==5 && stagephase==2){
	if(enemiescalled==0){ newviewx=30; newviewy=-15; viewmovetimexy=300; }
	if(frame%30==0){
		if(enemiescalled<18 && enemiescalled%2!=0 && enemiescalled%3==0){ CreateEnemyFromFile("script\Enemies\Extra\707.txt",minx+30,miny-32,0,0,0); }
		if(enemiescalled<18 && enemiescalled%2==0 && enemiescalled%3==0){ CreateEnemyFromFile("script\Enemies\Extra\707.txt",maxx-30,miny-32,0,0,0); }
		if(enemiescalled>=6 && enemiescalled<22 && enemiescalled%2==0 && enemiescalled%4!=0){ CreateEnemyFromFile("script\Enemies\Extra\702.txt",cx-rand(120,80),miny-32,0,0,[3,1]); }
		if(enemiescalled>=6 && enemiescalled<22 && enemiescalled%2==0 && enemiescalled%4==0){ CreateEnemyFromFile("script\Enemies\Extra\702.txt",cx+rand(120,80),miny-32,0,0,[3,2]); }
	enemiescalled++; }
	if(enemiescalled>=28){ nextphase=1; }
}


if(phase==6 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=300; }
	if(frame%40==0){
		if(enemiescalled<10 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx+rand(40,120),miny+rand(80,140),0,0,[18,3,20,5]); }
		if(enemiescalled<10 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx-rand(40,120),miny+rand(80,140),0,0,[18,3,-20,7]); }
	enemiescalled++; }
	if(enemiescalled>=14){ nextphase=1; }
}
if(phase==7 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=60; }
	if(frame%20==0){
		if(enemiescalled<12){ CreateEnemyFromFile("script\Enemies\Extra\701.txt",cx-100*cos((time*4)+(rand(-60,60))),miny-32,0,0,rand(6,8)); }
	enemiescalled++; }
	if(enemiescalled>=16){ nextphase=1; }
}
if(phase==8 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=60; }
	if(frame%10==0){
		if(enemiescalled<12){ CreateEnemyFromFile("script\Enemies\Extra\701.txt",cx-100*cos((time*4)+(rand(-60,60))),miny-32,0,0,rand(8,10)); }
	enemiescalled++; }
	if(enemiescalled>=16){ nextphase=1; }
}
if(phase==9 && stagephase==2){
	if(enemiescalled==0){ newviewx=20; newviewy=0; viewmovetimexy=300; }
	if(frame%30==0){
		if(enemiescalled<27 && enemiescalled%2==0 && enemiescalled%3==0){ CreateEnemyFromFile("script\Enemies\Extra\707.txt",minx+30,miny-32,0,0,0); }
		if(enemiescalled<27 && enemiescalled%2!=0 && enemiescalled%3==0){ CreateEnemyFromFile("script\Enemies\Extra\707.txt",maxx-30,miny-32,0,0,0); }
		if(enemiescalled>=6 && enemiescalled<33 && enemiescalled%3==0 && enemiescalled%6==0){ CreateEnemyFromFile("script\Enemies\Extra\701.txt",cx-rand(120,80),miny-32,0,0,rand(4.5,6)); }
		if(enemiescalled>=6 && enemiescalled<33 && enemiescalled%3==0 && enemiescalled%6!=0){ CreateEnemyFromFile("script\Enemies\Extra\701.txt",cx+rand(120,80),miny-32,0,0,rand(4.5,6)); }
		enemiescalled++; }
	if(enemiescalled>=40){ nextphase=1; }
}


if(phase==10 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=300; }
	if(frame%32==0){
		if(enemiescalled<12 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx+rand(40,120),miny+rand(80,140),0,0,[18,3.75,27.5,5]); }
		if(enemiescalled<12 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx-rand(40,120),miny+rand(80,140),0,0,[18,3.75,-27.5,7]); }
		enemiescalled++; }
	if(enemiescalled>=16){ nextphase=1; }
}
if(phase==11 && stagephase==2){
	if(enemiescalled==0){ newviewx=45; newviewy=-20; viewmovetimexy=300; }
	if(frame%150==0){
		if(enemiescalled<4 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Extra\708.txt",minx-32,miny+100,0,0,rand(-10,10)); }
		if(enemiescalled<4 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Extra\708.txt",maxx+32,miny+100,0,0,rand(-10,10)); }
	enemiescalled++; }
	if(enemiescalled>=5){ nextphase=1; }
}
if(phase==12 && stagephase==2){
	if(enemiescalled==0){ newviewx=45; newviewy=0; viewmovetimexy=300; }
	if(frame%30==0){
if(enemiescalled<27 && enemiescalled%2!=0 && enemiescalled%3==0){ CreateEnemyFromFile("script\Enemies\Extra\707.txt",minx+30,miny-32,0,0,0); }
if(enemiescalled<27 && enemiescalled%2==0 && enemiescalled%3==0){ CreateEnemyFromFile("script\Enemies\Extra\707.txt",maxx-30,miny-32,0,0,0); }
if(enemiescalled>=6 && enemiescalled<30 && enemiescalled%2==0 && enemiescalled%4==0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx+rand(40,120),miny+rand(80,140),0,0,[18,3,rand(-30,30),5]); }
if(enemiescalled>=6 && enemiescalled<30 && enemiescalled%2==0 && enemiescalled%4!=0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx-rand(40,120),miny+rand(80,140),0,0,[18,3,rand(-30,30),7]); }
	enemiescalled++; }
	if(enemiescalled>=36){ nextphase=1; }
}
if(phase==13 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-5; viewmovetimexy=300; }
	if(frame%24==0){
		if(enemiescalled<14 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx+rand(40,120),miny+rand(80,140),0,0,[18,4.5,35,5]); }
		if(enemiescalled<14 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx-rand(40,120),miny+rand(80,140),0,0,[18,4.5,-35,7]); }
	enemiescalled++; }
	if(enemiescalled>=18){ nextphase=1; }
}
if(phase==14 && stagephase==2){
	if(enemiescalled==0){ newviewx=-45; newviewy=-20; viewmovetimexy=300; }
	if(frame%120==0){
		if(enemiescalled<4 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Extra\708.txt",minx-32,miny+30,0,0,20); }
		if(enemiescalled<4 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Extra\708.txt",maxx+32,miny+30,0,0,-20); }
	enemiescalled++; }
	if(enemiescalled>=9){ nextphase=1; }
}

if(phase==15 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-15; viewmovetimexy=300; }
	if(frame%10==0){
		if(enemiescalled>=0 && enemiescalled<6){
		CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx-120+enemyx,miny+140,0,0,[16,3,enemyx/2,9]);
		enemyx+=240/5;
		}
		if(enemiescalled>=5 && enemiescalled<11){
		CreateEnemyFromFile("script\Enemies\Extra\701.txt",cx+120-enemyy,miny-32,0,0,5);
		enemyy+=240/5;
		}
		if(enemiescalled==24){ enemyx=0; enemyy=0; }
		if(enemiescalled>=24 && enemiescalled<30){
		CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx+120-enemyx,miny+70,0,0,[16,3,-enemyx/2,10]);
		enemyx+=240/5;
		}
		if(enemiescalled>=29 && enemiescalled<35){
		CreateEnemyFromFile("script\Enemies\Extra\701.txt",cx-120+enemyy,miny-32,0,0,7);
		enemyy+=240/5;
		}
	enemiescalled++; }
	if(enemiescalled>=48){ nextphase=1; }
}
if(phase==16 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=1200; }
	if(frame%20==0){
		if(enemiescalled%2==0 && enemiescalled<10){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx-160+enemyx,miny+120,0,0,[18,4,35,7]); }
		if(enemiescalled%2!=0 && enemiescalled<10){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx+160-enemyx,miny+120,0,0,[18,4,55,8]); }
		if(enemiescalled%2!=0){ enemyx+=35; }
		if(enemiescalled>=12 && enemiescalled<22){
		CreateEnemyFromFile("script\Enemies\Extra\701.txt",cx+rand(-80,80),miny-32,0,0,5+enemyy);
		enemyy+=0.5;
		}
	enemiescalled++; }
	if(enemiescalled>=28){ nextphase=1; }
}
if(phase==17 && stagephase==2){
	if(frame%20==0){
		if(enemiescalled%2==0 && enemiescalled<10){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx-20-enemyx,miny+120,0,0,[18,4,35,5]); }
		if(enemiescalled%2!=0 && enemiescalled<10){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx+20+enemyx,miny+120,0,0,[18,4,55,6]); }
		if(enemiescalled%2!=0){ enemyx+=35; }
		if(enemiescalled>=12 && enemiescalled<22){
		CreateEnemyFromFile("script\Enemies\Extra\702.txt",cx+rand(-80,80),miny-32,0,0,[3+enemyy,1]);
		enemyy+=0.25;
		}
	enemiescalled++; }
	if(enemiescalled>=28){ nextphase=1; }
}
if(phase==18 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=-20; viewmovetimexy=120; }
	if(frame%30==0){
		if(enemiescalled==0){
		CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx-100,miny+120,0,0,[36,2,0,1]);
		CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx+100,miny+120,0,0,[36,2,0,1]);
		}
		if(enemiescalled==1){ CreateEnemyFromFile("script\Enemies\Extra\706.txt",cx,miny+70,0,0,[34,2,45,2]);  }
	enemiescalled++; }
	if(enemiescalled>=16){ nextphase=1; }
}
if(phase==19 && stagephase==2){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=60; }
	if(frame%60==0){
	if(enemiescalled==0 && enemyx==0){ CreateEnemyFromFile("script\Functions\fadeout-in.txt",0,0,0,0,255); enemyx++; }//whiteout
	if(enemiescalled==1){ bgphase=3; SetCommonData("InEvent",1); SetCommonData("BackgroundStop",1); }
	if(enemiescalled>=3){ nextphase=1; }
	enemiescalled++; } //Wait
}