#TouhouDanmakufu[Stage]
#Title[Worldwide War ~ Both Stages - Hard]
#Text[By Shockman2, Trickysticks, and Mewkyuu. Sprites by Tsalop.]
#Player[FREE]
#ScriptVersion[2]

script_stage_main{
	let NextExtend = 50;
let SP = GetCurrentScriptDirectory~"Stage1\Enemy\Hard\sp\sp.png";
   let m = -1400;
   let n = -700;
   let o = -1000;
   let acc1 = 10;
   let acc2 = 0;
   let acc3 = 0;
   let l = 0;
   let f2 = 0;
   let f3 = 0;
   let f4 = 0;
   let f5 = 0;
   let f6 = 0;
   let f7 = 0;
   let f = 0;
   let stageintro = GetCurrentScriptDirectory~"Stage1\intro\st01logo.png";
   let nbg = GetCurrentScriptDirectory ~ "Stage1\ef\nbg1.png";
   let nbg2 = GetCurrentScriptDirectory ~ "Stage1\ef\nbg2.png";
   let nbg3 = GetCurrentScriptDirectory ~ "Stage1\ef\nbg4.png";
   let title = GetCurrentScriptDirectory ~ "Stage1\ef\stg1txt.png";
   let ex = GetCurrentScriptDirectory ~ "Stage1\ef\EXTRA.png";
   let Frame = GetCurrentScriptDirectory ~ "Stage1\ef\Frame.png";
   let ST1 = GetCurrentScriptDirectory ~ "Stage1\mu\bgm.mp3";
   let BO1  = GetCurrentScriptDirectory ~ "Stage1\Boss\mu\bgm.ogg";
	 let ST2 = GetCurrentScriptDirectory ~ "Stage2\mu\bgm.mp3";
   let BO2  = GetCurrentScriptDirectory ~ "Stage2\Boss\mu\bgm.ogg";
   let depth_buffer_enable = false;

 function Wait(let frames){
   loop(frames*2){yield;}
 }
 function WaitForZeroEnemy{
  while(GetEnemyNum != 0){yield;}
 }
task CreateStageIntro(introimage) {
	LoadGraphic(introimage);
	let objs = [0, 0, 0, 0, 0];
	function objback { return objs[0]; }
	function objtext  { return objs[1]; }
	function objlocate  { return objs[2]; }
	function objdesc1  { return objs[3]; }
	function objdesc2  { return objs[4]; }
	iamthestageintroF; iamthestageintro;
	task iamthestageintroF { ascent(i in 0..5) {
		objs[i] = Obj_Create(OBJ_EFFECT);
		let obj = objs[i];
		let pos = [0, -16, 8, 32, 32];
		let rect = [
			 [0, 32, 384, 64]
			,[0, 0, 384, 32]
			,[0, 112, 128, 128]
			,[0, 64, 256, 96]
			,[256, 64, 512, 96]
		][i];
		let rectL = rect[2]-rect[0]; rectL/=2;
		let rectH = rect[3]-rect[1]; rectH/=2;
		Obj_SetPosition(obj, GetCenterX, GetCenterY-50+pos[i]);
		ObjEffect_SetTexture(obj, introimage);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexUV(obj, 0, rect[0], rect[1]);
		ObjEffect_SetVertexUV(obj, 1, rect[2], rect[1]);
		ObjEffect_SetVertexUV(obj, 2, rect[2], rect[3]);
		ObjEffect_SetVertexUV(obj, 3, rect[0], rect[3]);
		ObjEffect_SetVertexXY(obj, 0, -rectL, -rectH);
		ObjEffect_SetVertexXY(obj, 1, rectL, -rectH);
		ObjEffect_SetVertexXY(obj, 2, rectL, rectH);
		ObjEffect_SetVertexXY(obj, 3, -rectL, rectH);
		ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 0, 255, 255, 255); }
	} }

	
	task iamthestageintro {
		task back { ascent(i in 0..45) {
			ascent(j in 0..4) { ObjEffect_SetVertexColor(objback, j, 255/30*i, 255, 255, 255); }
		ObjEffect_SetScale(objback, 3/2-1/2*i/45, 1); Wait(1); } }
		task big { ascent(i in 0..30) { ascent(j in 0..4) {
			ObjEffect_SetVertexColor(objtext, j, 255/30*i, 255, 255, 255);
			ObjEffect_SetVertexColor(objlocate, j, 255/30*i, 255, 255, 255);
		} Wait(2); } }
		task small { ascent(i in 0..10) { ascent(j in 0..4) {
			ObjEffect_SetVertexColor(objdesc1, j, 255/10*i, 255, 255, 255);
			ObjEffect_SetVertexColor(objdesc2, j, 255/10*i, 255, 255, 255);
		} Wait(2); } }
		task move { descent(i in 0..3) { let s = 3;
			Obj_SetPosition(objdesc1, GetCenterX+rand(-i*s,i*s), GetCenterY-50+32+rand(-i*s,i*s));
			Obj_SetPosition(objdesc2, GetCenterX+rand(-i*s,i*s), GetCenterY-50+32+rand(-i*s,i*s));
		loop(5) { Wait(2); } } }
		back; loop(30) { Wait(1); } big; loop(75) { Wait(1); } small; move; loop(135-15-45) { Wait(1); }
		descent(i in 0..60) { ascent(j in 0..4) { ascent(k in 0..3) {
			ObjEffect_SetScale(objs[0], 1, i/60);
			ObjEffect_SetVertexColor(objs[k], j, 255/60*i, 255, 255, 255);
		} } Wait(2); } loop(15) { Wait(1); }
		ascent(i in 0..10) { let s = 2;
			Obj_SetPosition(objdesc1, GetCenterX+rand(-i*s,i*s), GetCenterY-50+32+rand(-i*s,i*s));
			Obj_SetPosition(objdesc2, GetCenterX+rand(-i*s,i*s), GetCenterY-50+32+rand(-i*s,i*s));
			ascent(j in 0..4) {
				ObjEffect_SetVertexColor(objdesc1, j, 255-255/10*i, 255, 255, 255);
				ObjEffect_SetVertexColor(objdesc2, j, 255-255/10*i, 255, 255, 255);
			}
		loop(2) { Wait(1); } } ascent(i in 0..5) { Obj_Delete(objs[i]); } Wait(1); 
		DeleteGraphic(introimage);
	}
}


 function stage1{
	DeleteSE("se\seEnemyExplode01.wav");
	DeleteSE("se\seUseSpellCard.wav");
  Wait(120);
loop(3){
  Wait(30);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\BF1.txt", GetClipMinX + rand(10,100), GetClipMinY - 30, 0, 0, 0);
}
  Wait(80);
loop(3){
  Wait(30);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\BF1.txt", GetClipMaxX - rand(10,100), GetClipMinY - 30, 0, 0, 0);
}
  Wait(120);
loop(5){
  Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\BF1.txt", GetClipMinX + rand(10,100), GetClipMinY - 30, 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\BF1.txt", GetClipMaxX - rand(10,100), GetClipMinY - 30, 0, 0, 0);
}
  Wait(100);
		CreateStageIntro(stageintro);

  Wait(200);
loop(5){
  Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\BYYE.txt", GetClipMinX - 10, GetClipMinY + 30, 0, 0, 0);
}
loop(5){
  Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RYYE.txt", GetClipMaxX + 10, GetClipMinY + 60, 0, 0, 0);
}
loop(5){
  Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\BYYE.txt", GetClipMinX - 12, GetClipMinY + 90, 0, 0, 0);
}
loop(5){
  Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RYYE.txt", GetClipMaxX + 12, GetClipMinY + 120, 0, 0, 0);
}
  WaitForZeroEnemy;
loop(10){
  Wait(30);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\BF2.txt", GetClipMinX - 10, GetClipMinY + rand(10,100), 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF2.txt", rand(GetClipMinX + 20,GetClipMaxX - 20), GetClipMinY - 10, 0, 0, 0);
}
Wait(60);
loop(1){
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\LF3.txt", GetClipMaxX - 80, GetClipMinY - 30, 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\LF3.txt", GetClipMinX + 80, GetClipMinY - 30, 0, 0, 0);
}
  Wait(40);
loop(3){
  Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF1.txt", GetClipMaxX - rand(100,200), GetClipMinY - 30, 0, 0, 0);
}
Wait(60);
loop(1){
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\LF3.txt", GetClipMaxX - 80, GetClipMinY - 30, 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\LF3.txt", GetClipMinX + 80, GetClipMinY - 30, 0, 0, 0);
}
  Wait(40);
loop(3){
  Wait(30);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF1.txt", GetClipMaxX - rand(100,200), GetClipMinY - 30, 0, 0, 0);
}
  Wait(80);
loop(3){
  Wait(30);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF1.txt", GetClipMaxX - rand(100,200), GetClipMinY - 30, 0, 0, 0);
}
  Wait(80);
loop(5){
  Wait(30);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF1.txt", GetClipMaxX - rand(100,200), GetClipMinY - 30, 0, 0, 0);
}
  Wait(80);
loop(10){
  Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\BF1.txt", GetCenterX+rand(-150,150), GetClipMinY - 30, 0, 0, 0);
}
  Wait(100);
loop(1){
  Wait(90);
}
  WaitForZeroEnemy; 
Wait(30);  
CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Stage1\SubBoss\PLURAL_H.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;  
  Wait(30);
loop(3){
  Wait(100);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\LF1.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(60);
loop(3){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(120);
loop(4){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(120);
loop(10){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(100);
loop(3){
Wait(5);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF1.txt", rand(GetClipMaxX - 100,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
loop(3){
Wait(5);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF1.txt", rand(GetClipMinX + 100,GetClipMinX + 10), GetClipMinY - 10, 0, 0, 0);
}
loop(3){
Wait(5);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF1.txt", rand(GetClipMaxX - 100,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
loop(3){
Wait(5);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF1.txt", rand(GetClipMinX + 100,GetClipMinX + 10), GetClipMinY - 10, 0, 0, 0);
}
loop(3){
  Wait(100);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\LF2.txt", rand(GetClipMaxX - 80,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(10);
loop(15){
  Wait(20);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage1\Enemy\Hard\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  WaitForZeroEnemy; 
  Wait(200);
CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Stage1\Boss\FutoH.txt", 0, 0, 0, 0, 0);
  Wait(100);
  WaitForZeroEnemy; 
  Wait(200);
 DeleteMusic(BO1);
 }

  function stage2{
	DeleteSE("se\seEnemyExplode01.wav");
	DeleteSE("se\seUseSpellCard.wav");
 PlayMusic(ST1);
  WaitForZeroEnemy; 
Wait(30);  
CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Stage2\SubBoss\PLURAL_H.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;  
  Wait(30);

loop(3){
Wait(5);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage2\Enemy\Hard\RF1.txt", rand(GetClipMaxX - 100,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
loop(3){
Wait(5);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage2\Enemy\Hard\RF1.txt", rand(GetClipMinX + 100,GetClipMinX + 10), GetClipMinY - 10, 0, 0, 0);
}
loop(3){
  Wait(100);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage2\Enemy\Hard\LF2.txt", rand(GetClipMaxX - 80,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(10);
loop(15){
  Wait(20);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Stage2\Enemy\Hard\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  WaitForZeroEnemy; 
  Wait(200);
  DeleteMusic(ST1);
  PlayMusic(BO2);
CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Stage2\Boss\PLURAL_H.txt", 0, 0, 0, 0, 0);

  WaitForZeroEnemy; 
  Wait(200);
  Clear;
 }

	task game{
		stage1;
		stage2;
	}
  @Initialize{
	
      LoadGraphic(nbg);
      LoadGraphic(nbg2);
      LoadGraphic(nbg3);
      LoadGraphic(ex);
      LoadGraphic(SP);
      LoadGraphic(title);
      LoadGraphic(Frame);
LoadMusic(ST1);
PlayMusic(ST1);
LoadMusic(BO1);
game;
  }
 @MainLoop{

if(GetPoint >= 50 && NextExtend == 50){ExtendPlayer(1); PlaySE("se\se_extend.wav"); NextExtend = 100;}

else if(GetPoint >= 100 && NextExtend == 100){ExtendPlayer(1); PlaySE("se\se_extend.wav");NextExtend = 300;}
else if(GetPoint >= 300 && NextExtend == 300){ExtendPlayer(1);PlaySE("se\se_extend.wav");NextExtend = 500;} 

else if(GetPoint >= 500 && NextExtend == 500){ExtendPlayer(1);PlaySE("se\se_extend.wav");NextExtend = 800;} 


SetNormPoint(NextExtend);

      m += 5;
      n += 5;
      o += 500;
f += 0.5;
yield;
  }
  @BackGround{
acc2 += acc1;
      WriteZBuffer(depth_buffer_enable);
      UseZBuffer(depth_buffer_enable);
   

      SetViewTo(0, -60, 80);
      SetViewFrom(10, -90, 35);  

      SetAlpha(255);
      SetTexture(nbg2);
      SetGraphicRect(0, 0, 512, 512);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(1,1);
      DrawGraphic(GetCenterX, GetCenterY);   

      SetAlpha(255);
      SetRenderState(ALPHA);
      SetTexture(nbg);
      SetGraphicRect(0, 0+f+acc2, 800, 1500+f+acc2);
      SetGraphicAngle(90, 0, 0);
      SetGraphicScale(1,1);
      DrawGraphic3D(0, -298, 600);

      SetAlpha(255);
      SetRenderState(ALPHA);
      SetTexture(nbg3);
      SetGraphicRect(0, 0+f+acc2, 512, 1200+f+acc2);
      SetGraphicAngle(90, 0, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(0, -298, 600);


if (acc1 > 0){
acc1 -= 0.01;
}
if (acc3 < 100){
acc3 += 0.1;
}
f2 += 4;
f3++;
f4++;
f5 += 0.4;
   yield;
}
  @Finalize{
      DeleteGraphic(nbg);
      DeleteGraphic(nbg2);
      DeleteGraphic(nbg3);
      DeleteGraphic(ex);
      DeleteGraphic(SP);
      DeleteGraphic(Frame);
DeleteMusic(ST1);
DeleteMusic(BO1);
DeleteMusic(ST2);
DeleteMusic(BO2);
}
}