#TouhouDanmakufu[Stage]
#Title[Youmu]
#Text[A boss fight against Youmu Konpaku!]
#Player[REIMU]
#ScriptVersion[2]

script_stage_main{
let D = GetCurrentScriptDirectory;
let selectbgm = D ~ "spells\bgm\Select.mp3";
let bgm = D ~ "spells\bgm\BGM2.mp3";
let bgm2 = D ~ "spells\bgm\Voyage 1970.mp3";
let bg = D ~ "spells\system\background3.png";
let ext = D ~ "spells\sfx\Extend.wav";
let s1 = D ~ "spells\sfx\Select00.wav";
let s2 = D ~ "spells\sfx\Ok00.wav";
let congrats = D ~ "spells\system\congrats.png";
let easy = D ~ "spells\system\Easy.png";
let normal = D ~ "spells\system\Normal.png";
let lunatic = D ~ "spells\system\Lunatic.png";
let wat = D ~ "spells\system\wat.png";
let spellpractice = D ~ "spells\system\Spell Practice.png";
let higanretour = D ~ "spells\system\higanretour.png";
let cherryimg = D ~ "spells\system\pcbcherry.png";
let menuon = 1;
let Selection = 1;
let alph0 = 150;
let alph1 = 150;
let alph2 = 70;
let alph3 = 150;
let alph4 = 150;
let move1 = GetCenterY;
let xpos = GetCenterX+340;
let bgmalph = 255;
let csize = rand(1,2);
let calph = 150;
let cypos = GetCenterY-rand(140,200);

 function Wait(let frames){loop(frames){yield;}}
 function WaitForZeroEnemy{while(GetEnemyNum != 0){yield;}}
task extendstate{
   let extendlist = [50, 100, 250, 500, 800, 1100, 1500, 2000];
   let indexq = 0;
   while(indexq<8){
      if(GetPoint > extendlist[indexq]){
        ExtendPlayer(1);
        PlaySE(ext);
        indexq++;
        SetNormPoint(extendlist);
      }
    yield;
  }
}
 task stagee{
  Wait(80);
  PlayMusic(bgm);
  Wait(40);
  CreateEnemyBossFromFile(GetCurrentScriptDirectory~"spells\eBoss.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;
  DeleteMusic(bgm);
  CollectItems;
  Wait(240);
  PlayMusic(bgm2);
  CreateEnemyBossFromFile(GetCurrentScriptDirectory~"spells\eSpell 3.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;
  Wait(45);
  CollectItems;
  congratulation;
  Wait(500);
  FadeOutMusic(bgm2,10);
  Wait(180);
  Clear;
 }
 task stagen{
  Wait(80);
  PlayMusic(bgm);
  Wait(40);
  CreateEnemyBossFromFile(GetCurrentScriptDirectory~"spells\Boss.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;
  DeleteMusic(bgm);
  CollectItems;
  Wait(240);
  PlayMusic(bgm2);
  CreateEnemyBossFromFile(GetCurrentScriptDirectory~"spells\Spell 3.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;
  Wait(45);
  CollectItems;
  congratulation;
  Wait(500);
  FadeOutMusic(bgm2,10);
  Wait(180);
  Clear;
 }
 task stagel{
  Wait(80);
  PlayMusic(bgm);
  Wait(40);
  CreateEnemyBossFromFile(GetCurrentScriptDirectory~"spells\lBoss.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;
  DeleteMusic(bgm);
  CollectItems;
  Wait(240);
  PlayMusic(bgm2);
  CreateEnemyBossFromFile(GetCurrentScriptDirectory~"spells\lSpell 3.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;
  Wait(45);
  CollectItems;
  congratulation;
  Wait(500);
  FadeOutMusic(bgm2,10);
  Wait(180);
  Clear;
 }
 task stagew{
  Wait(80);
  PlayMusic(bgm);
  Wait(40);
  CreateEnemyBossFromFile(GetCurrentScriptDirectory~"spells\wBoss.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;
  DeleteMusic(bgm);
  CollectItems;
  Wait(240);
  PlayMusic(bgm2);
  CreateEnemyBossFromFile(GetCurrentScriptDirectory~"spells\wSpell 3.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;
  Wait(45);
  CollectItems;
  congratulation;
  Wait(500);
  FadeOutMusic(bgm2,10);
  Wait(180);
  Clear;
 }
task background1{

yield;
  let obj=Obj_Create(OBJ_EFFECT);


  
let counter = 0;

    Obj_SetPosition(obj, GetCenterX, GetCenterY);


    
ObjEffect_SetRenderState(obj, ALPHA);

    ObjEffect_SetTexture(obj, bg);
    ObjEffect_SetScale(obj, 1, 1);

    ObjEffect_SetLayer(obj, 0);


    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);

    ObjEffect_CreateVertex(obj, 4);
    ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, 180, 255, 255, 255); }
    
ObjEffect_SetVertexXY(obj, 0, -256, -256);

    ObjEffect_SetVertexXY(obj, 1, 256, -256);

    ObjEffect_SetVertexXY(obj, 2, -256, 256);

    ObjEffect_SetVertexXY(obj, 3, 256, 256);


    ObjEffect_SetVertexUV(obj, 0, 0, 0);

    ObjEffect_SetVertexUV(obj, 1, 512, 0);

    ObjEffect_SetVertexUV(obj, 2, 0, 512);

    ObjEffect_SetVertexUV(obj, 3, 512, 512);


      while(!Obj_BeDeleted(obj)) {
	
      if(menuon==0){Obj_Delete(obj);}

      counter++;

    yield;

  }
}

task cherry{
yield;
let csize = rand(1,2);
let calph = 0;
let cypos = GetCenterY-rand(30,290);
let cxpos = rand(GetClipMaxX,GetClipMinX-100);
let cfall = rand(1,4);
let cangle = 0;
let cturn = rand(-2,2);
let cmove = rand(1,3);
loop(200){
  let obj=Obj_Create(OBJ_EFFECT);

  
let counter = 0;
    Obj_SetPosition(obj, cxpos, cypos);


    Obj_SetAlpha(obj, alph1);
    ObjEffect_SetAngle(obj,cangle,cangle,cangle);
    
ObjEffect_SetRenderState(obj, ALPHA);

    ObjEffect_SetTexture(obj, cherryimg);
    ObjEffect_SetScale(obj, csize, csize);

    ObjEffect_SetLayer(obj, 0);


    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);

    ObjEffect_CreateVertex(obj, 4);
    ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, calph, 255, 255, 255); }
    
ObjEffect_SetVertexXY(obj, 0, -11, -14);

    ObjEffect_SetVertexXY(obj, 1, 11, -14);

    ObjEffect_SetVertexXY(obj, 2, -11, 14);

    ObjEffect_SetVertexXY(obj, 3, 11, 14);


    ObjEffect_SetVertexUV(obj, 0, 0, 0);

    ObjEffect_SetVertexUV(obj, 1, 22, 0);

    ObjEffect_SetVertexUV(obj, 2, 0, 28);

    ObjEffect_SetVertexUV(obj, 3, 22, 28);


      while(!Obj_BeDeleted(obj)) {
	
	Obj_SetPosition(obj, cxpos, cypos);


	cypos+=cfall;
	cxpos+=cmove;

   	ObjEffect_SetAngle(obj,cangle,cangle,cangle);
	cangle+=cturn;

      if(int(counter)<25){
	ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, calph, 255, 255, 255); }
	calph+=4;
      }

      if(int(counter)>175 && int(counter)<200){
	ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, calph, 255, 255, 255); }
	calph-=4;
      }

      if(int(counter)>200){
	Obj_Delete(obj);
	}
      counter++;
    yield;

}
}
}
task cherry2{
	loop{
		if(menuon==1){
			cherry;
		}
	Wait(5);}
}
task bgmtext{
yield;
loop{
  let obj=Obj_Create(OBJ_EFFECT);
    Obj_SetPosition(obj, xpos, GetCenterY+205);


    Obj_SetAlpha(obj, alph1);
    
ObjEffect_SetRenderState(obj, ALPHA);

    ObjEffect_SetTexture(obj, higanretour);
    ObjEffect_SetScale(obj, 1.2, 1.2);

    ObjEffect_SetLayer(obj, 7);


    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);

    ObjEffect_CreateVertex(obj, 4);
    ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, bgmalph, 255, 255, 255); }
    
ObjEffect_SetVertexXY(obj, 0, -115, -11);

    ObjEffect_SetVertexXY(obj, 1, 115, -11);

    ObjEffect_SetVertexXY(obj, 2, -115, 11);

    ObjEffect_SetVertexXY(obj, 3, 115, 11);


    ObjEffect_SetVertexUV(obj, 0, 0, 0);

    ObjEffect_SetVertexUV(obj, 1, 230, 0);

    ObjEffect_SetVertexUV(obj, 2, 0, 22);

    ObjEffect_SetVertexUV(obj, 3, 230, 22);


      while(!Obj_BeDeleted(obj)) {

      yield;
	
      Obj_Delete(obj);
    }
}
}
task bgmtextsetup{
	loop(120){
		bgmtext;
	yield;
	}
}
	task movein{
		loop(140){
			xpos-=2;
		yield;
		}
		Wait(120);

		loop(51){
			bgmalph-=5;
		yield;
		}
	}
task congratulation{
  let obj=Obj_Create(OBJ_EFFECT);


  
let counter = 0;

    Obj_SetPosition(obj, GetCenterX, GetCenterY);


    
ObjEffect_SetRenderState(obj, ALPHA);

    ObjEffect_SetTexture(obj, congrats);
    ObjEffect_SetScale(obj, 0.6, 0.6);

    ObjEffect_SetLayer(obj, 5);


    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);

    ObjEffect_CreateVertex(obj, 4);
    ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, alph1, 255, 255, 255); }
    
ObjEffect_SetVertexXY(obj, 0, -300, -50);

    ObjEffect_SetVertexXY(obj, 1, 300, -50);

    ObjEffect_SetVertexXY(obj, 2, -300, 50);

    ObjEffect_SetVertexXY(obj, 3, 300, 50);


    ObjEffect_SetVertexUV(obj, 0, 0, 0);

    ObjEffect_SetVertexUV(obj, 1, 600, 0);

    ObjEffect_SetVertexUV(obj, 2, 0, 100);

    ObjEffect_SetVertexUV(obj, 3, 600, 100);


      while(!Obj_BeDeleted(obj)) {
	
      if(counter==180){Obj_Delete(obj);}

      counter++;

    yield;

  }
}
task easytext{

yield;
  let obj=Obj_Create(OBJ_EFFECT);

    Obj_SetPosition(obj, GetCenterX, move1-120);


    Obj_SetAlpha(obj, alph0);
    
ObjEffect_SetRenderState(obj, ALPHA);

    ObjEffect_SetTexture(obj, easy);
    ObjEffect_SetScale(obj, 1, 1);

    ObjEffect_SetLayer(obj, 5);


    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);

    ObjEffect_CreateVertex(obj, 4);
    ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, alph0, 255, 255, 255); }
    
ObjEffect_SetVertexXY(obj, 0, -75, -50);

    ObjEffect_SetVertexXY(obj, 1, 75, -50);

    ObjEffect_SetVertexXY(obj, 2, -75, 50);

    ObjEffect_SetVertexXY(obj, 3, 75, 50);


    ObjEffect_SetVertexUV(obj, 0, 0, 0);

    ObjEffect_SetVertexUV(obj, 1, 150, 0);

    ObjEffect_SetVertexUV(obj, 2, 0, 100);

    ObjEffect_SetVertexUV(obj, 3, 150, 100);


      while(!Obj_BeDeleted(obj)) {

    yield;
      Obj_Delete(obj);
  }
}

task normaltext{

yield;
  let obj=Obj_Create(OBJ_EFFECT);

    Obj_SetPosition(obj, GetCenterX, move1-40);


    Obj_SetAlpha(obj, alph1);
    
ObjEffect_SetRenderState(obj, ALPHA);

    ObjEffect_SetTexture(obj, normal);
    ObjEffect_SetScale(obj, 1, 1);

    ObjEffect_SetLayer(obj, 5);


    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);

    ObjEffect_CreateVertex(obj, 4);

    
ObjEffect_SetVertexXY(obj, 0, -126, -36);

    ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, alph1, 255, 255, 255); }
    ObjEffect_SetVertexXY(obj, 1, 126, -36);

    ObjEffect_SetVertexXY(obj, 2, -126, 36);

    ObjEffect_SetVertexXY(obj, 3, 126, 36);


    ObjEffect_SetVertexUV(obj, 0, 0, 0);

    ObjEffect_SetVertexUV(obj, 1, 252, 0);

    ObjEffect_SetVertexUV(obj, 2, 0, 72);

    ObjEffect_SetVertexUV(obj, 3, 252, 72);


      while(!Obj_BeDeleted(obj)) {

    yield;
      Obj_Delete(obj);
  }
}

task lunatictext{

yield;
  let obj=Obj_Create(OBJ_EFFECT);

    Obj_SetPosition(obj, GetCenterX, move1+40);


    Obj_SetAlpha(obj, alph2);
    
ObjEffect_SetRenderState(obj, ALPHA);

    ObjEffect_SetTexture(obj, lunatic);
    ObjEffect_SetScale(obj, 1, 1);

    ObjEffect_SetLayer(obj, 5);


    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);

    ObjEffect_CreateVertex(obj, 4);
    ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, alph2, 255, 255, 255); }
    
ObjEffect_SetVertexXY(obj, 0, -126, -36);

    ObjEffect_SetVertexXY(obj, 1, 126, -36);

    ObjEffect_SetVertexXY(obj, 2, -126, 36);

    ObjEffect_SetVertexXY(obj, 3, 126, 36);


    ObjEffect_SetVertexUV(obj, 0, 0, 0);

    ObjEffect_SetVertexUV(obj, 1, 252, 0);

    ObjEffect_SetVertexUV(obj, 2, 0, 72);

    ObjEffect_SetVertexUV(obj, 3, 252, 72);


      while(!Obj_BeDeleted(obj)) {

    yield;
      Obj_Delete(obj);
  }
}

task wattext{

yield;
  let obj=Obj_Create(OBJ_EFFECT);
    Obj_SetPosition(obj, GetCenterX, move1+120);


    Obj_SetAlpha(obj, alph3);
    
ObjEffect_SetRenderState(obj, ALPHA);

    ObjEffect_SetTexture(obj, wat);
    ObjEffect_SetScale(obj, 1.2, 1.2);

    ObjEffect_SetLayer(obj, 5);


    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);

    ObjEffect_CreateVertex(obj, 4);
    ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, alph3, 255, 255, 255); }
    
ObjEffect_SetVertexXY(obj, 0, -151, -36);

    ObjEffect_SetVertexXY(obj, 1, 151, -36);

    ObjEffect_SetVertexXY(obj, 2, -151, 36);

    ObjEffect_SetVertexXY(obj, 3, 151, 36);


    ObjEffect_SetVertexUV(obj, 0, 0, 0);

    ObjEffect_SetVertexUV(obj, 1, 302, 0);

    ObjEffect_SetVertexUV(obj, 2, 0, 72);

    ObjEffect_SetVertexUV(obj, 3, 302, 72);


      while(!Obj_BeDeleted(obj)) {

    yield;
      Obj_Delete(obj);
  }
}

task spelltext{

yield;
  let obj=Obj_Create(OBJ_EFFECT);

    Obj_SetPosition(obj, GetCenterX, move1+200);


    Obj_SetAlpha(obj, alph4);
    
ObjEffect_SetRenderState(obj, ALPHA);

    ObjEffect_SetTexture(obj, spellpractice);
    ObjEffect_SetScale(obj, 0.8, 0.8);

    ObjEffect_SetLayer(obj, 5);


    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);

    ObjEffect_CreateVertex(obj, 4);
    ascent(i in 0..4){ ObjEffect_SetVertexColor(obj, i, alph4, 255, 255, 255); }
    
ObjEffect_SetVertexXY(obj, 0, -220, -45);

    ObjEffect_SetVertexXY(obj, 1, 220, -45);

    ObjEffect_SetVertexXY(obj, 2, -220, 45);

    ObjEffect_SetVertexXY(obj, 3, 220, 45);


    ObjEffect_SetVertexUV(obj, 0, 0, 0);

    ObjEffect_SetVertexUV(obj, 1, 440, 0);

    ObjEffect_SetVertexUV(obj, 2, 0, 90);

    ObjEffect_SetVertexUV(obj, 3, 440, 90);


      while(!Obj_BeDeleted(obj)) {
	
    yield;
      Obj_Delete(obj);
  }
}

task menuthing{
Wait(30);
PlayMusic(selectbgm);
Wait(30);
	loop{
		if(menuon == 1){
			if(GetKeyState(VK_UP) == KEY_PUSH && Selection>=0){Selection-=1; PlaySE(s1); moveanimdown;}
 			if(GetKeyState(VK_DOWN) == KEY_PUSH && Selection<=4){Selection+=1; PlaySE(s1); moveanimup;}
			select;
		}
	yield;
	}
}
task menutext{
Wait(0);
	loop{
		if(menuon == 1){
			easytext;
			normaltext;
			lunatictext;
			wattext;
			//spelltext;
 			if(Selection==0){
				alph0=255; alph1=180; alph2=150; alph3=150; //alph4=170;
			}
 			if(Selection==1){
				alph0=180; alph1=255; alph2=150; alph3=150; //alph4=170;
			}
			if(Selection==2){
				alph0=180; alph1=180; alph2=255; alph3=150; //alph4=180;
			}
 			if(Selection==3){
				alph0=180; alph1=180; alph2=150; alph3=285; //alph4=180;
			}
 			//if(Selection==4){
				//alph0=180; alph1=180; alph2=150; alph3=150; //alph4=255;
			//}

 			if(Selection>3){Selection=0; restartdown;}
 			if(Selection<0){Selection=3; restartup;}
		}
	yield;}
}
task moveanimdown{
	loop(20){
		move1+=4;
	yield;}
}
task moveanimup{
	loop(20){
		move1-=4;
	yield;}
}
task restartdown{
	loop(20){
		move1+=16;
	yield;}
}
task restartup{
	loop(20){
		move1-=16;
	yield;}
}
task select{
	if(GetKeyState(VK_SHOT) == KEY_PUSH && Selection==0){
		PlaySE(s2);
		loop(3){ loop(3){alph0=0; yield;} loop(2){alph0=255; yield;} }
	yield;
	menuon = 0;
	DeleteMusic(selectbgm);
	stagee;}

	if(GetKeyState(VK_SHOT) == KEY_PUSH && Selection==1){
		PlaySE(s2);
		loop(3){ loop(3){alph1=0; yield;} loop(2){alph1=255; yield;} }
	yield;
	menuon = 0;
	DeleteMusic(selectbgm);
	stagen;}

	if(GetKeyState(VK_SHOT) == KEY_PUSH && Selection==2){
		PlaySE(s2);
		loop(3){loop(3){alph2=0; yield;} loop(2){alph2=255; yield;} }
	yield;
	menuon = 0;
	DeleteMusic(selectbgm);
	stagel;
	}

	if(GetKeyState(VK_SHOT) == KEY_PUSH && Selection==3){
		PlaySE(s2);
		loop(3){loop(3){alph3=0; yield;} loop(2){alph3=255; yield;} }
	yield;
	menuon = 0;
	DeleteMusic(selectbgm);
	stagew;
	}

	//if(GetKeyState(VK_SHOT) == KEY_PUSH && Selection==4){
		//PlaySE(s2);
		//loop(3){loop(3){alph4=0; yield;} loop(2){alph4=255; yield;} }
	//yield;
	//menuon = 0;
	//DeleteMusic(selectbgm);
	//spellpr;
	//}
}
 @Initialize{
  LoadMusic(selectbgm);
  LoadMusic(bgm);
  LoadMusic(bgm2);
  LoadGraphic(bg);
  LoadGraphic(congrats);
  LoadGraphic(easy);
  LoadGraphic(normal);
  LoadGraphic(lunatic);
  LoadGraphic(wat);
  LoadGraphic(spellpractice);
  LoadGraphic(higanretour);
  LoadGraphic(cherryimg);
  LoadSE(ext);
  bgmtextsetup;
  movein;
  menuthing;
  menutext;
  background1;
  cherry2;
  SetNormPoint(50);
  extendstate;
 }
 @MainLoop{
   yield;
  }
  @Background{
}
  @Finalize{
   DeleteGraphic(easy);
   DeleteGraphic(normal);
   DeleteGraphic(lunatic);
   DeleteGraphic(wat);
   DeleteGraphic(spellpractice);
   DeleteGraphic(cherryimg);
   DeleteSE(ext);
   DeleteGraphic(bg);
  }
}