#TouhouDanmakufu[Stage]
#Title[Shinki-Sakuya -Normal-]
#Text[Alice is testing you. Okay.]
#Image[./alicecut.png]
#Background[./stgbg.png]
#Player[FREE]
#ScriptVersion[2]
#PlayLevel[Normal]

script_stage_main{
let enemyx = 0;
let blah = 202020;
let BorderGraze = 1000;
let background = GetCurrentScriptDirectory~"stgbg.png";
let extend = GetCurrentScriptDirectory~"se_extend.wav";
let LifeScore = 5000000;
let end = GetCurrentScriptDirectory~"end.mp3";

 function Wait(let frames){
   loop(frames){yield;}
 }
 function WaitForZeroEnemy{
  while(GetEnemyNum != 0){yield;}
 }

	function wait(w){ loop(w){ yield; } }

 function WaitForEventEnd{
while(OnEvent){yield;}
}

task RunMyCrappyGame{stage1; }



 function stage1{
	blah=2;
	DeleteSE("se\seEnemyExplode01.wav");
	DeleteSE("se\seUseSpellCard.wav");
	CompileEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy1.txt");
	CompileEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy2.txt");
	CompileEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt");
	CompileEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy4.txt");
	PlayMusic(end);
	Wait(120);
	loop(11){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy1.txt", 0+enemyx, GetClipMinY-20, 0, 0, 0);
	enemyx+=40;
	wait(10);
	}
	wait(60);
	loop(11){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy1.txt", 0+enemyx, GetClipMinY-20, 0, 0, 1);
	enemyx-=40;
	wait(10);
	}
	wait(80);
	loop(11){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy2.txt", 0+enemyx, GetClipMinY-20, 0, 0, 0);
	enemyx+=40;
	wait(10);
	}
	wait(60);
	loop(11){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy2.txt", 0+enemyx, GetClipMinY-20, 0, 0, 1);
	enemyx-=40;
	wait(10);
	}
	wait(120);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt", GetCenterX+100, GetClipMinY-20, 0, 0, 1);
	wait(240);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt", GetCenterX-100, GetClipMinY-20, 0, 0, 1);
	wait(220);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt", GetCenterX, GetClipMinY-20, 0, 0, 1);
	wait(200);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt", GetCenterX+100, GetClipMinY-20, 0, 0, 1);
	wait(180);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt", GetCenterX-100, GetClipMinY-20, 0, 0, 1);
	wait(160);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt", GetCenterX, GetClipMinY-20, 0, 0, 1);
	wait(240);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt", GetCenterX+100, GetClipMinY-20, 0, 0, 1);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt", GetCenterX-100, GetClipMinY-20, 0, 0, 1);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy3.txt", GetCenterX, GetClipMinY-20, 0, 0, 1);
	wait(600);
	enemyx = 0;
	loop(20){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy4.txt", GetCenterX+enemyx, GetClipMinY-20, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"BlueFairy4.txt", GetCenterX-enemyx, GetClipMinY-20, 0, 0, 0);
	enemyx+=14;
	wait(12);
	}
	wait(60);
	WaitForZeroEnemy;
	wait(180);
	CreateEnemyBossFromFile(GetCurrentScriptDirectory~"shinkiplural.txt", 0, 0, 0, 0, rand(-10, 10));
	WaitForZeroEnemy;
	wait(300);
	CreateEnemyBossFromFile(GetCurrentScriptDirectory~"sakuyaplural.txt", 0, 0, 0, 0, rand(-10, 10));
	WaitForZeroEnemy;
	CreateEventFromScript("conversation");
	WaitForEventEnd;
	Wait(240);
 	Clear;
	
 }

  @Initialize{
RunMyCrappyGame;
LoadGraphic(background);
LoadMusic(end);

  }
 @MainLoop{


if(GetScore >= 2000000 && LifeScore==2000000){ExtendPlayer(1); PlaySE(extend); LifeScore=5000000; } 
	if(GetScore >= 5000000 && LifeScore==5000000){ExtendPlayer(1); PlaySE(extend); LifeScore=10000000; } 
	if(GetScore >= 10000000 && LifeScore==10000000){ExtendPlayer(1); PlaySE(extend); LifeScore=15000000; } 
	if(GetGraze >= 100 && BorderGraze==100){SuperNaturalBorder(600); BorderGraze=200; } else if(GetGraze >=200 && BorderGraze==200){ SuperNaturalBorder(600); BorderGraze=300; }
	else if(GetGraze >=300 && BorderGraze==300){ SuperNaturalBorder(600); BorderGraze=450; }else if(GetGraze >=450 && BorderGraze==450){ SuperNaturalBorder(600); BorderGraze=600; }
else if(GetGraze >=600 && BorderGraze==600){ SuperNaturalBorder(600); BorderGraze=1000; } else if(GetGraze >=1000 && BorderGraze==1000){ SuperNaturalBorder(600); BorderGraze=9999; }

   yield;
  }
  
@BackGround{
   SetTexture(background);
   SetGraphicRect(1, 2, 380, 256);
SetGraphicScale(1.5, 2);
  DrawGraphic(GetCenterX, GetCenterY);
	

   

}

  @Finalize{

  }
}


script_event conversation{
let reimu =GetCurrentScriptDirectory ~ ("\reimu.png");
let alice =GetCurrentScriptDirectory~ ("\sakuyacut.png");

@Initialize{
  LoadGraphic(reimu);
  LoadGraphic(alice);
	
 }

@MainLoop{
SetChar(LEFT, reimu);
SetChar(RIGHT, alice);                 
SetGraphicRect(LEFT, 0, 0, 128, 300);           
SetStep(15);
SetStep(16);
SetGraphicRect(RIGHT, 0, 0, 180, 256);
MoveChar(LEFT, BACK);
MoveChar(RIGHT, FRONT);                          
TextOutA("Okay, you know what?");    
MoveChar(RIGHT, BACK);                           
MoveChar(LEFT, FRONT);
SetGraphicRect(LEFT, 1, 1, 128, 270);                           
TextOutA("\c[RED] What?");   
DeleteName(LEFT);                 
MoveChar(RIGHT, FRONT);                           
MoveChar(LEFT, BACK); 
SetNameFromText(RIGHT,TEXT_BLUE,"Game Over","Come Back Later");                          
TextOutA("\c[BLUE] This script is imcomplete. \n So, go away.");
MoveChar(RIGHT, BACK);                           
MoveChar(LEFT, FRONT);
TextOutA("\c[RED] ..."); 
MoveChar(RIGHT, FRONT);                           
MoveChar(LEFT, BACK);
DeleteName(RIGHT);
SetGraphicRect(RIGHT, 0, 0, 180, 256);
MoveChar(LEFT, BACK);
MoveChar(RIGHT, FRONT);                          
TextOutA("BEGONE.");   


End;          

}

 @Finalize{
  
 }
}
