#TouhouDanmakufu[Plural]
	#ScriptVersion[3]
	#System["./tricky_system/Default_System.txt"]
	#Title["Trickysticks' Contest Entry - Dreams of Ice"]
	#Text["lolololol"]
	#Image[""]
	#Background["./tricky_system/Default_Background_IceMountain.txt"]
	#Player["./Sagume_Player_Script_by_Python/Not Sagume/Not Sagume A.dnh"]

	let omgexplosions = false;	
	let IsSoundScript = false;
	let soundset = false;
	let moo2 = false;
	let moo3 = false;
	let xcoord = 0;
	let sound3set = false;
	let moo7 = false;
	let playx = GetStgFrameWidth/2;
	let playy = GetStgFrameHeight-32;
	let initx = 0;
	let inity = 0;
	let objSound;
	let obj2 = ObjEnemyBossScene_Create();
	let obj3;
	let thunder = GetCurrentScriptDirectory~"sfx/thunder.wav";
	let vol = 95;
	let sound2set = false;
	let bossx = 0;
	let dir = GetCurrentScriptDirectory();
	let bossy = 0;
	let ycoord = 0;
	let moo = false;
	let maxlife = 0;
	
	let objmid = ObjEnemyBossScene_Create();
	let objboss = ObjEnemyBossScene_Create();
	
	#include"./includes/dialogueconsts.txt"
	#include"./stage.eventdialogue.dnh"
	#include"./Function_Audio.dnh"
	
	@Loading{
	LoadTexture(sagume0);
	LoadTexture(sagumeclosed);
	LoadTexture(sagumesweat);
	
	LoadTexture(cirno0);
	LoadTexture(cirnojake);
	LoadTexture(cirnosmug);
	LoadTexture(cirnotear);
	LoadTexture(cirnotearsmug);
	
	LoadTexture(letty0);
	LoadTexture(lettymad);
	LoadTexture(lettyclosed);
	LoadTexture(lettysmug);
	
	
	ObjEnemyBossScene_Add(objmid, 0, dir ~ "Stage1/Cirno0.txt");
	ObjEnemyBossScene_Add(objmid, 0, dir ~ "Stage1/CirnoN1_H.txt");
	ObjEnemyBossScene_Add(objmid, 0, dir ~ "Stage1/CirnoS1_H.txt");
	ObjEnemyBossScene_Add(objmid, 0, dir ~ "Stage1/CirnoRun.txt");
	ObjEnemyBossScene_LoadInThread(objmid);
	
	ObjEnemyBossScene_Add(objboss, 0, dir ~ "Stage1/Letty0.txt");	
	ObjEnemyBossScene_Add(objboss, 0, dir ~ "Stage1/LettyN1_H.txt");
	ObjEnemyBossScene_Add(objboss, 0, dir ~ "Stage1/LettyS1_H.txt");
	ObjEnemyBossScene_Add(objboss, 1, dir ~ "Stage1/LettyN2_H.txt");
	ObjEnemyBossScene_Add(objboss, 1, dir ~ "Stage1/LettyS2_H.txt");
	ObjEnemyBossScene_Add(objboss, 2, dir ~ "Stage1/LettyN3_H.txt");
	ObjEnemyBossScene_Add(objboss, 2, dir ~ "Stage1/LettyS3_H.txt");
	ObjEnemyBossScene_Add(objboss, 3, dir ~ "Stage1/LettyN4_H.txt");
	ObjEnemyBossScene_Add(objboss, 3, dir ~ "Stage1/LettyS4_H.txt");
	ObjEnemyBossScene_Add(objboss, 4, dir ~ "Stage1/LettyS5_H.txt");
	
	ObjEnemyBossScene_Add(objboss, 5, dir ~ "Stage1/LettyS6_H.txt");

	ObjEnemyBossScene_LoadInThread(objboss);
	
	
	}
	
	@Initialize
	{
	
	SetPlayerLife(98);
	TPlural();
	
	}

	@MainLoop
	{
	  xcoord = GetCommonData("sakuyax", GetStgFrameWidth/2)+32;
	   ycoord = GetCommonData("sakuyay", 120);
	   if(xcoord>32){ bossx = xcoord; }
	   if(ycoord>0){ bossy = ycoord; }
		yield;
	}

	@Finalize
	{
	}

		

	@Event{
alternative(GetEventType())	
case(EV_PAUSE_ENTER)
{
NotifyEventAll(EV_MUSIC_PAUSE, true);
}

case(EV_PAUSE_LEAVE)
{
NotifyEventAll(EV_MUSIC_RESUME, true);
}

}





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

	task TPlural
	{
		
		PlayMusic(1.1);		
		wait(240);
		ObjEnemyBossScene_Regist(objmid);
		Event0A;
		BottomEnemyMarker;
		
		while(!Obj_IsDeleted(objmid))
		{
		if(GetCommonData("makaiboom", false)==true){
			Event0B;
			SetCommonData("makaiboom", false);
			}
			yield;
		}
		
		wait(60);
		
		//PlayMusic(1.2);
		//ObjEnemyBossScene_Regist(objboss);
		BottomEnemyMarker;
		wait(90);
		
		while(!Obj_IsDeleted(objboss))
		{
			if(GetCommonData("makaiboom", false)==true){
			//Event1B;
			SetCommonData("makaiboom", false);
			}
			yield;
		}
		
		wait(270);
		CloseStgScene;
		CloseScript(GetOwnScriptID());
		
	}

function Event0A {
	let dispX_Player = 0;
	let dispX_Enem = 0;
	InitializeEvent(1, 1);
	HandleEventLogic();
	SetCutinGraphic(0, 0, sagumeclosed, 0, 0, false);
	SetCharStatusPresent(0, 0, true);
	SetCutinGraphic(1, 0, cirno0, 20, -20, false);
	SetCharStatusPresent(1, 0, false);
	
	Talking(0); 
	SetEventText(0, 0, "...", 0);
	SetEventText(0, 2, "Earth is full of strange creatures...", 0);
	SetEventText(0, 6, "And why is this path so...endless?[r]Does it even have a name?", 0);
	SetEventText(0, 2, "This is the type of nonsense we'd pull...", 0);
	
	Talking(1);
	
	SetEventText(1, 0, "I'll play over here!", 75);
	
	Talking(0);
	
	SetCutinGraphic(0, 0, sagume0, 0, 0, false);	
	SetEventText(0, 2, "Eh? A commotion...?", 0);
	
	
	
	Talking(1);
	SetEventText(1, 0, "I know, I know. I won't go too far.", 0);
	wait(90);
	SetEventText(1, 0, "Okay, see ya soon!", 0);
	
	Talking(0);

	SetEventText(0, 2, "Hmm?", 0);
	
	
	
	SetCommonData("moveintoplace", true);
	yield;
	SetCommonData("moveintoplace", false);
	
	wait(180);
	SetCharStatusPresent(1, 0, true);
	
	Talking(1);
	SetEventText(1, 0, "Ah, someone else is here too?", 0);
	SetEventText(1, 4, "Nameless Path is popular, but it's[r]weird for someone to be here now.", 0);
	
	SetCutinGraphic(1, 0, cirnosmug, 20, -20, false);
	SetEventText(1, 0, "Well, whatever.", 0);
	
	
	SetCutinGraphic(1, 0, cirno0, 20, -20, false);
	SetEventText(1, 4, "Wanna play a game?[r]I learned it from Marisa.", 0);
	
	Talking(0);
	SetEventText(0, 0, "...?", 0);
	SetEventText(0, 6, "Marisa? That hyper-aggressive[r]loot addict of a witch?", 0);
	
	SetCutinGraphic(0, 0, sagumeclosed, 0, 0, false);
	SetEventText(0, 6, "Does this imply combat? [r]My mission can't wait much longer...", 0);
	
	Talking(1);
	SetCutinGraphic(1, 0, cirnojake, 20, -20, false);
	SetEventText(1, 0, "It's called 'Move, and I'll Shoot!'", 0);
	
	Talking(0);
	SetEventText(0, 0, "...?", 0);
	SetEventText(0, 6, "Ah, combat it is.[r]She's just a fairy, so...", 0);
	SetEventText(0, 0, "...This will be quick.", 0);
	
	SetCutinGraphic(0, 0, sagumesweat, 0, 0, false);
	SetEventText(0, 2, "Wait, did I say that aloud...?", 0);
	
	
	
	SetCharStatusPresent(0, 0, false); SetCharStatusPresent(1, 0, false); 
	wait(24);
	BottomEnemyMarker;
	SetCommonData("cirnodie", true);
	wait(1);
	SetCommonData("cirnodie", false);
	wait(19);
	FinalizeEvent;
	yield;
	
}

function Event0B {
	wait(120);
	let dispX_Player = 0;
	let dispX_Enem = 0;
	InitializeEvent(1, 1);
	HandleEventLogic();
	SetCutinGraphic(0, 0, sagumeclosed, 0, 0, false);
	SetCharStatusPresent(0, 0, true);
	SetCutinGraphic(1, 0, cirnotear, -20, -20, true);
	SetCharStatusPresent(1, 0, true);
	
	Talking(0); 
	SetEventText(0, 0, "...", 0);
	SetEventText(0, 0, "Effortless.", 0);
	
	Talking(1);
	
	SetEventText(1, 0, "Owowowowow....", 0);
	SetEventText(1, 0, "Geez, what're you, a goddess?", 0);
	
	
	SetEventText(1, 4, "What an unfair matchup.[r]You're totally overpowered!", 0);
	SetCutinGraphic(1, 0, cirnotearsmug, -20, -20, true);
	SetEventText(1, 0, "Two can play at that game. Be right back!", 0);
	SetCharStatusPresent(1, 0, false); 
	SetCommonData("moveintoplace", true);
	FadeOutMusic(180);
	wait(180);

	Talking(0);
	
	SetCutinGraphic(0, 0, sagumeclosed, 0, 0, false);	
	SetEventText(0, 2, "What?", 0);
	
	Talking(1);
	SetEventText(1, 0, "Letty! I got totally trashed!", 0);
	wait(90);
	SetEventText(1, 0, "Huh? No, I didn't provoke them this time!", 0);
	SetEventText(1, 4, "They actively hunted me [r]down and tried to kill me!", 0);
	
	Talking(0);
	
	SetCutinGraphic(0, 0, sagume0, 0, 0, false);	
	SetEventText(0, 2, "What.", 0);
	
	Talking(1);
	SetEventText(1, 0, "Huh? Yeah, it was SO scary.", 0);
	SetEventText(1, 4, "They even insulted winter and [r]called you &quot;Glorious and Huge!&quot;", 0);
	wait(90);
	SetEventText(1, 4, "You're going to go[r]mega-kill them? Sweet!", 0);
	
	Talking(0);
	SetCutinGraphic(0, 0, sagumesweat, 0, 0, false);	
	SetEventText(0, 2, "What?!", 0);
	
	Talking(1);
	ObjEnemyBossScene_Regist(objboss);
	
	wait(300);
	SetCharStatusPresent(1, 0, true);
	
	Talking(1);
	SetCutinGraphic(1, 0, lettymad, 70, -20, false);
	SetEventText(1, 0, "LEAVE CIRNO ALONE!!!", 0);
	
	Talking(0);
	SetEventText(0, 2, "...She just shot at me during the dialogue.", 0);
	SetEventText(0, 0, "...?", 0);
	
	Talking(1);
	SetCutinGraphic(1, 0, letty0, 70, -20, false);
	SetEventText(1, 4, "Oh, you don't look the type[r]to attack a fairy senselessly.", 0);
	SetEventText(1, 0, "I assume she started it. As usual.", 0);
	
	Talking(0);
	SetCutinGraphic(0, 0, sagumeclosed, 0, 0, false);
	SetEventText(0, 0, "She did.", 0);
	
	Talking(1);
	SetCutinGraphic(1, 0, lettysmug, 70, -20, false);
	SetEventText(1, 4, "Or perhaps you wouldn't attack her[r]because she's far beneath your notice.", 0);
	
	SetCutinGraphic(1, 0, letty0, 70, -20, false);
	SetEventText(1, 0, "Goddess Sagume. It's been a long time.", 0);
	
	Talking(0);
	
	SetEventText(0, 0, "Only a season.", 0);
	
	Talking(1);
	SetCutinGraphic(1, 0, letty0, 70, -20, false);
	SetEventText(1, 4, "It's practically always winter on the moon.[r]Seasons are a formality.", 0);
	
	Talking(0);
	SetEventText(0, 0, "...", 0);
	
	Talking(1);
	
	SetCutinGraphic(1, 0, lettyclosed, 70, -20, false);
	SetEventText(1, 0, "Still as quiet as ever. Rightfully so...", 0);
	
	SetCutinGraphic(1, 0, letty0, 70, -20, false);
	SetEventText(1, 4, "Why have you come to visit Gensokyo?[r]The incident is resolved, is it not?", 0);
	
	Talking(0);
	SetCutinGraphic(0, 0, sagume0, 0, 0, false);
	SetEventText(0, 0, "...Do you know where Reimu is?", 0);
	
	Talking(1);
	SetEventText(1, 0, "Maybe. Why?", 0);
	
	Talking(0);
	SetEventText(0, 0, "...", 0);
	
	Talking(1);
	SetCutinGraphic(1, 0, lettyclosed, 70, -20, false);
	SetEventText(1, 0, "...I won't get an answer from you.", 0);
	
	PlayMusic(1.2);
	SetCutinGraphic(1, 0, letty0, 70, -20, false);
	SetEventText(1, 0, "I'll tell you what, let's play a game.", 0);
	
	Talking(0);
	SetCutinGraphic(0, 0, sagumesweat, 0, 0, false);
	SetEventText(0, 2, "...are we really doing this?", 0);
	
	Talking(1);
	SetEventText(1, 4, "It's known that actions[r]speak louder than words.", 0);
	
	SetCutinGraphic(1, 0, lettysmug, 70, -20, false);
	
	Talking(0);
	SetEventText(0, 0, "...therefore?", 0);
	
	
	Talking(1);
	magiccircle2(0.7, true);
	SetEventText(1, 0, "Let's duel.", 0);
	
	Talking(0);
	SetEventText(0, 2, "...ah, it always comes to this.", 120);
	
	Talking(1);
	SetEventText(1, 4, "The defeat of pure winter[r]shows pure intentions.", 180);
	SetEventText(1, 4, "The cold is in full force today.[r]Prepare for a perfect freeze!", 180);
	

	Talking(0);
	SetCutinGraphic(0, 0, sagumeclosed, 0, 0, false);
	SetEventText(0, 2, "...always dramatic.", 90);

	SetCharStatusPresent(0, 0, false); SetCharStatusPresent(1, 0, false); 
	wait(24);
	BottomEnemyMarker;
	SetCommonData("lettydie", true);
	wait(1);
	SetCommonData("lettydie", false);
	wait(19);
	FinalizeEvent;
	yield;
	
}
		


task magiccircle2(size,type){ // draw magic circle
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let imgcircle=GetCurrentScriptDirectory~"sprites/MG.png";
	let spin = 0;
	let s = 0;
	LoadTexture(imgcircle);
	ObjPrim_SetTexture(obj,imgcircle);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetAlpha(obj,192);
	Obj_SetRenderPriorityI(obj, 28);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	while(!Obj_IsDeleted(GetEnemyBossSceneObjectID)){
	if(GetCommonData("timestop", false)==false){
	spin += 2;
	}
	ObjRender_SetAngleXYZ(obj,0,0,spin*2);
	ObjRender_SetPosition(obj,bossx-32,bossy,0);
	ObjRender_SetColor(obj,1*(192+42*sin(spin+180)),1*(192+42*sin(spin)),0);
	if(type==true){
	ObjRender_SetScaleXYZ(obj,size*1.1+0.1*sin(spin),size*1.1+0.1*sin(spin),0);
	}
	ObjMove_SetPosition(obj,bossx-32,bossy);
	yield;
	}
	Obj_Delete(obj);
	}


task BottomEnemyMarker{
  let imgnumber = GetCurrentScriptDirectory~"sprites/enemymarker.png";
  let objMarker = ObjPrim_Create(OBJ_SPRITE_2D);
  ObjRender_SetPosition(objMarker, GetStgFrameWidth/2, GetStgFrameHeight+32, 1); 
  ObjPrim_SetPrimitiveType(objMarker, PRIMITIVE_TRIANGLESTRIP);
  ObjRender_SetBlendType(objMarker, BLEND_ALPHA);
  Obj_SetRenderPriority(objMarker, 0.85);
  ObjPrim_SetTexture(objMarker, imgnumber);
  ObjRender_SetAlpha(objMarker, 255);
  ObjSprite2D_SetSourceRect(objMarker, 0, 0, 48, 16);
  ObjSprite2D_SetDestRect(objMarker, -25, -8, 25, 8);

 
  while(!Obj_IsDeleted(GetEnemyBossSceneObjectID)){
	
    ObjRender_SetPosition(objMarker, bossx, GetStgFrameHeight+24, 1);
	
    yield;
  }
  Obj_Delete(objMarker);
}
	

	task ManipulatePlayer{
	initx = ObjMove_GetX(GetPlayerObjectID);
	inity = ObjMove_GetY(GetPlayerObjectID);
	 let incx = ((GetStgFrameWidth/2-initx)/60);
	let incy = (playy-inity)/60;
	loop(60){
	ObjMove_SetPosition(GetPlayerObjectID, ObjMove_GetX(GetPlayerObjectID)+incx, ObjMove_GetY(GetPlayerObjectID)+incy);
	yield;
	}
	loop{
	ObjMove_SetPosition(GetPlayerObjectID, GetStgFrameWidth/2, playy);
	yield;
	}
	}


task fadeout{
let time = 0;
let objWhite = ObjPrim_Create(OBJ_SPRITE_2D);
let white = GetCurrentScriptDirectory~"sprites/white.png";

let alphavar = 0;

ObjPrim_SetTexture(objWhite, white);
	Obj_SetRenderPriorityI(objWhite, 100);
ObjSprite2D_SetSourceRect(objWhite, 0, 0, 691, 607);
ObjSprite2D_SetDestCenter(objWhite);
ObjRender_SetColor(objWhite, 0.1, 0.1, 0.1);
ObjRender_SetAlpha(objWhite, 127.5);
ObjMove_SetX(objWhite, GetStgFrameWidth/2);
ObjMove_SetY(objWhite, GetStgFrameHeight/2);
ObjRender_SetScaleXYZ(objWhite, 20, 20, 1);
loop(360){
	ObjRender_SetAlpha(objWhite, 0+alphavar);
	wait2(1);
	alphavar+=9;
	}
	
Obj_Delete(objWhite);
function wait2(w){ loop(w){ yield; } }
}	
	

task screenflash(r,g,b){
let time = 0;
let objWhite = ObjPrim_Create(OBJ_SPRITE_2D);
let white = GetCurrentScriptDirectory~"sprites/white.png";

let alphavar = 0;

ObjPrim_SetTexture(objWhite, white);
ObjSprite2D_SetSourceRect(objWhite, 0, 0, 691, 607);
ObjSprite2D_SetDestCenter(objWhite);
ObjRender_SetColor(objWhite, r, g, b);
ObjRender_SetAlpha(objWhite, 127.5);
ObjMove_SetX(objWhite, GetStgFrameWidth/2);
ObjMove_SetY(objWhite, GetStgFrameHeight/2);
ObjRender_SetScaleXYZ(objWhite, 2, 2, 1);
loop(60){
	ObjRender_SetAlpha(objWhite, 125+125*sin(alphavar));
	if(time<=10){
	alphavar+=9;
	}
	if(time>=30){
	alphavar+=180/30;
	}
	wait2(1);
	time++;
	}
Obj_Delete(objWhite);
function wait2(w){ loop(w){ yield; } }
}
	
	
	
	

/*
	task PlayMusic(arg){
	let rate = 100;
	sound2set = true;
	objSound = ObjSound_Create;
	if(arg==0.1){
	ObjSound_Load(objSound, GetCurrentScriptDirectory~"bgm/bgm2.ogg");
	ObjSound_SetLoopSampleCount(objSound, 1488, 6700040);
	}
	ObjSound_SetVolumeRate(objSound, rate);
	//ObjSound_SetVolumeRate(objSound, 0);
	ObjSound_SetLoopEnable(objSound, true);
	ObjSound_SetRestartEnable(objSound, true);
	
	ObjSound_SetSoundDivision(objSound, SOUND_BGM);
	ObjSound_Play(objSound);
	loop{
	if(moo3==true){
	ObjSound_SetFade(objSound, 2);
	loop(120){
	wait(1);
	ObjSound_SetVolumeRate(objSound, rate);
	rate-=100/140;
	}
	ObjSound_Stop(objSound);
	Obj_Delete(objSound);
	}
	
	yield;
	}
	}
*/	
	