#TouhouDanmakufu[Stage]
#Title[The Eternal Phantasmagoria -Momizi Revisited]
#Text[Our heroines ascend the mountain of faith for no reason at all on a boring day.
Then they meet...]
#Image[]
#Player[REIMU,MARISA]
#ScriptVersion[2]

script_stage_main{
let f = 1;
let c= 0;
let csd = GetCurrentScriptDirectory();
 let objHitbox = NULL;
   let objHitboxCopy = NULL;
   let objHitboxGraphic = GetCurrentScriptDirectory~"system\thHitbox.png";
   let objHitboxScale = 0;
   let objHitboxAngle = 0;
   let objHitboxAngleVel = 103;
   let objHitboxCopyScale = 1.45;
#include_function ".\powersystem.txt"
#include_function ".\ObjEffectFunctions.txt"
#include_function ".\DrawTextnew.txt"
#include_function ".\spellcardnum.txt"
   task CreateHitbox{
    LoadGraphic(objHitboxGraphic);
   yield;
   yield;
      objHitbox = Obj_Create(OBJ_EFFECT);
      ObjEffect_SetTexture(objHitbox, objHitboxGraphic);
      ObjEffect_SetRenderState(objHitbox, ALPHA);
      ObjEffect_SetLayer(objHitbox, 4);
      ObjEffect_SetPrimitiveType(objHitbox, PRIMITIVE_TRIANGLEFAN);
      ObjEffect_CreateVertex(objHitbox, 4);
      ObjEffect_SetVertexUV(objHitbox, 0, 0, 0);
      ObjEffect_SetVertexUV(objHitbox, 1, 63, 0);
      ObjEffect_SetVertexUV(objHitbox, 2, 63, 63);
      ObjEffect_SetVertexUV(objHitbox, 3, 0, 63);
      ObjEffect_SetVertexXY(objHitbox, 0, -32, -32);
      ObjEffect_SetVertexXY(objHitbox, 1, 32, -32);
      ObjEffect_SetVertexXY(objHitbox, 2, 32, 32);
      ObjEffect_SetVertexXY(objHitbox, 3, -32, 32);
      objHitboxCopy = Obj_Create(OBJ_EFFECT);
      ObjEffect_SetTexture(objHitboxCopy, objHitboxGraphic);
      ObjEffect_SetRenderState(objHitboxCopy, ALPHA);
      ObjEffect_SetLayer(objHitboxCopy, 4);
      ObjEffect_SetPrimitiveType(objHitboxCopy, PRIMITIVE_TRIANGLEFAN);
      ObjEffect_CreateVertex(objHitboxCopy, 4);
      ObjEffect_SetVertexUV(objHitboxCopy, 0, 0, 0);
      ObjEffect_SetVertexUV(objHitboxCopy, 1, 63, 0);
      ObjEffect_SetVertexUV(objHitboxCopy, 2, 63, 63);
      ObjEffect_SetVertexUV(objHitboxCopy, 3, 0, 63);
      ObjEffect_SetVertexXY(objHitboxCopy, 0, -32, -32);
      ObjEffect_SetVertexXY(objHitboxCopy, 1, 32, -32);
      ObjEffect_SetVertexXY(objHitboxCopy, 2, 32, 32);
      ObjEffect_SetVertexXY(objHitboxCopy, 3, -32, 32);
   }
   
   task DrawHitbox{
   yield;
   yield;
   yield;
      if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
         if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH){
            objHitboxCopyScale = 1.45;
         }
         if(objHitboxAngleVel>3){
            objHitboxAngleVel -= 5;
         }
         if(objHitboxScale<1){
            objHitboxScale += 0.2;
         }
         if(objHitboxCopyScale>1){
            objHitboxCopyScale-=0.05;
         }
         objHitboxAngle += objHitboxAngleVel;
         ObjEffect_SetAngle(objHitbox, 0, 0, objHitboxAngle);
         ObjEffect_SetScale(objHitbox, objHitboxScale, objHitboxScale);
         ObjEffect_SetAngle(objHitboxCopy, 0, 0, -objHitboxAngle);
         ObjEffect_SetScale(objHitboxCopy, objHitboxCopyScale, objHitboxCopyScale);
         Obj_SetPosition(objHitbox, GetPlayerX, GetPlayerY);
         Obj_SetPosition(objHitboxCopy, GetPlayerX, GetPlayerY);
      }else{
         if(objHitboxScale>0){
            objHitboxScale -= 0.2;
         }else{
            objHitboxScale = 0;
         }
         if(objHitboxCopyScale>0){
            objHitboxCopyScale -= 0.2;
         }else{
            objHitboxCopyScale = 0;
         }
            
         objHitboxAngleVel = 103;
         ObjEffect_SetAngle(objHitbox, 0, 0, objHitboxAngle);
         ObjEffect_SetScale(objHitbox, objHitboxScale, objHitboxScale);
         ObjEffect_SetAngle(objHitboxCopy, 0, 0, -objHitboxAngle);
         ObjEffect_SetScale(objHitboxCopy, objHitboxCopyScale, objHitboxCopyScale);
      }
   }
function WaitForNoEnemy { while(GetEnemyNum!=0) { yield; } }
function WaitToNumOfEnemy(num) { while(GetEnemyNum!=num) { yield; } }
function WaitForFrames(framestowait) { loop(framestowait) { yield; } }
function WaitForNoBomb { while(OnBomb) { yield; } }
function WaitForAlive { while(OnPlayerMissed) { yield; } }
function WaitForDead { while(!OnPlayerMissed) { yield; } }
function WaitForNoInvincibility { while(GetTimeOfSuperNaturalBorder != 0 && GetTimeOfPlayerInvincibility != 0) { yield; } }
function WaitForNoEvent { while(OnEvent) { yield; } }
	task stage{
		Wait(60);	

		CreateEnemyFromFile(csd~"momizi0.txt",GetCenterX,-64,0,0,0);
		WaitForNoEnemy;
		Wait(1);
		WaitForNoEnemy;
		Wait(1);
		WaitForNoEnemy;
		Wait(1);
		WaitForNoEnemy;
		Wait(1);
		WaitForNoEnemy;
		Wait(1);
		WaitForNoEnemy;
		Wait(1);
		WaitForNoEnemy;
		Wait(1);
		WaitForNoEnemy;
		Wait(1);
		WaitForNoEnemy;
		Wait(1);
		WaitForNoEnemy;
		Wait(1);
		Wait(50);
		AddScore(GetPlayerLife*23000000);
		DrawTextNew("Clear bonus! "~ToFormatz(GetPlayerLife*23000000,7),GetCenterX-60,GetCenterY-10,GetClipMaxX,255,255,255,255,1.3);
		Wait(320);
		
		Clear;
 	}

  	@Initialize{
 		extends;
 		hud;
 		stage;
		CreateHitbox;
  	}
 	@MainLoop{
	DrawHitbox;
  	
 		AddGraze(-GetGraze);
   		yield;
		waitItem;
  	}
  	
  	@Finalize{

  	}
  	task extends{
  		let f = 0;
  		let score = [2000000,4000000,6000000,10000000,13000000,16000000,20000000,30000000,50000000,999999999999999999999999999999];
  		loop{
  		if(GetScore>=score[f]){
  			ExtendPlayer(1);
  			PlaySE(csd~"se\se1up.wav");
  			f++;
  		}
  		yield;
  		}
  	}
  	task hud{
  		LoadCommonData;
		yield;
  		SetDefaultStatusVisible(false);
  		let imgLife = GetCurrentScriptDirectory~"system\life.png";
  		LoadGraphic(imgLife);
  		let imgFrame = GetCurrentScriptDirectory~"system\Phantasm.png";
  		LoadGraphic(imgFrame);
  		let truehighscore = GetCommonDataDefault("highscore",1000000);
  		let highscore = [];
  		let score = [];
  		let faith = [];
  		let frame = ObjEffect_InitializeRect(imgFrame,8);
  		let life = [];
  		let bomb = [];
  		ObjEffect_SetXYRect(frame,0,0,640,480);
   		ObjEffect_SetUVRect(frame,0,0,640,480);
  		
  		
		
		LoadCommonData;
		let prehs = 0;
		let pres = -10;
		let prelife = 0;
		let prebomb = 0;
		let frame = 0;
  		loop{
  			yield;
			frame++;
  			
			if(prehs!=truehighscore){
			resetNum(highscore);
  			highscore = DrawBonusNum(truehighscore,518,74,"ASDF",0.5);
			prehs = truehighscore;
			}
			if(pres!=GetScore){
			resetNum(score);
  			score = DrawBonusNum(GetScore,518,99,"ASDF",0.5);
			pres = GetScore;
			}
			if(prelife!=GetPlayerLife){
			resetNum(life);
  			life = DrawBonusNum(GetPlayerLife-1,518,149,"1Pc",0.5);
			prelife = GetPlayerLife;
			}
			if(prebomb!=GetPlayerBomb){
			resetNum(bomb);
  			bomb = DrawBonusNum(GetPlayerBomb,518,175,"1Pc",0.5);
			prebomb = GetPlayerBomb;
			}
			if(frame%60==0){
			ClearText(faith);
  			faith = DrawTextNew("Faith: "~ToFormatz(GetCommonDataDefaultEx("MOF","pointvalue",10000),7)~"   FPS:"~ToFormatz(GetFps,7),GetClipMinX,GetClipMaxY-10,GetClipMaxX,255,255,255,255,1);
			}
  			if(GetScore>truehighscore){
  				truehighscore=GetScore;
  			}
			yield;
  		}
  	
  	
  	}
	function Wait(w){loop(w){yield;}}
}
