#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Minoriko End Scene"]
#include"./LoadGraphics.txt"
let bossObj;

let music = ObjSound_Create;
@Initialize{
	SetCommonData("FPS",1);
	SetCommonData("Timer",1);
	SetCommonData("ForceLifebar",1);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	scene;}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(100);}}

@MainLoop{yield;}

@Finalize{}

task scene{
	ObjSound_Load(music,GetCurrentScriptDirectory ~ "./../Music/ending.mp3");
	ObjSound_Play(music);
	SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,"");
	Obj_SetRenderPriorityI(obj, 100);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 640, 480);
	ObjSprite2D_SetDestRect(obj, 0, 0, 640, 480);
	loop(10){yield;}
	let u = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(u,scene_e);
	Obj_SetRenderPriorityI(u, 98);
	ObjSprite2D_SetSourceRect(u, 0, 0, 1280, 960);
	ObjSprite2D_SetDestRect(u, 0, 0, 640, 480);
	
	loop(120){yield;}
	let object = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(object,scene00);
	Obj_SetRenderPriorityI(object, 95);
	ObjSprite2D_SetSourceRect(object, 0, 0, 1280, 960);
	ObjSprite2D_SetDestRect(object, 0, 0, 640, 480);

	let alpha = 0;
	loop(85){
		ObjRender_SetAlpha(obj,255-alpha);
		alpha+=255/85;yield;}
	Obj_Delete(obj);
	loop(60){yield;}

	let a = text(35,380,"Minoriko: Come sister...",255,180,120);
	let b = text(35,400,"Minoriko: Nobody needs us...",255,180,120);
	let c = text(35,420,"Shizuha: ...",255,220,120);

	let object2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(object2,scene01);
	Obj_SetRenderPriorityI(object2, 96);
	ObjSprite2D_SetSourceRect(object2, 0, 0, 1280, 960);
	ObjSprite2D_SetDestRect(object2, 0, 0, 640, 480);
	let alpha2 = 0;
	loop(85){
		ObjRender_SetAlpha(object2,alpha2);
		ObjRender_SetAlpha(a,255-alpha2*2);
		ObjRender_SetAlpha(b,255-alpha2*2);
		ObjRender_SetAlpha(c,255-alpha2*2);
		alpha2+=255/85;yield;}
	Obj_Delete(a);
	Obj_Delete(b);
	Obj_Delete(c);
	let d = text(35,380,"Reimu: Wait!",255,120,120);
	let e = text(35,400,"Reimu: Don't go away please!",255,120,120);
	let f = text(35,420,"Reimu: Gensokyo needs you.",255,120,120);
	let g = text(35,440,"Minoriko: I don't think so...",255,180,120);
	let alpha3 = 0;
	loop(85){
		ObjRender_SetAlpha(d,255-alpha3*2);
		ObjRender_SetAlpha(e,255-alpha3*2);
		ObjRender_SetAlpha(f,255-alpha3*2);
		ObjRender_SetAlpha(g,255-alpha3*2);
		alpha3+=255/85;yield;}
	Obj_Delete(d);
	Obj_Delete(e);
	Obj_Delete(f);
	Obj_Delete(g);
	let h = text(35,380,"Reimu: How could people live without meal that you give us?",255,120,120);
	let j = text(35,400,"Minoriko: It makes no sense, if people are not praying.",255,180,120);
	let k = text(35,420,"Reimu: I think you have misunderstood...",255,120,120);

	let object3 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(object3,scene02);
	Obj_SetRenderPriorityI(object3, 97);
	ObjSprite2D_SetSourceRect(object3, 0, 0, 1280, 960);
	ObjSprite2D_SetDestRect(object3, 0, 0, 640, 480);
	let alpha4 = 0;
	loop(85){
		ObjRender_SetAlpha(object2,255-alpha4);
		ObjRender_SetAlpha(object3,alpha4);
		ObjRender_SetAlpha(h,255-alpha4*2);
		ObjRender_SetAlpha(j,255-alpha4*2);
		ObjRender_SetAlpha(k,255-alpha4*2);
		alpha4+=255/85;yield;}
	Obj_Delete(h);
	Obj_Delete(j);
	Obj_Delete(k);
	let l = text(35,380,"Reimu: Look, after many years of abundance, people were very thankful to [r]'      you.",255,120,120);
	let m = text(35,420,"Reimu: They even decide to build a SHRINE for YOU, where everybody could [r]'      honor you.",255,120,120);
	let n = text(35,460,"Minoriko: Really?",255,180,120);
	let alpha5 = 0;
	loop(85){
		ObjRender_SetAlpha(l,255-alpha5*2);
		ObjRender_SetAlpha(m,255-alpha5*2);
		ObjRender_SetAlpha(n,255-alpha5*2);
		alpha5+=255/85;yield;}
	Obj_Delete(l);
	Obj_Delete(m);
	Obj_Delete(n);
	let o = text(35,380,"Reimu: Yes. And people were waiting until shrine will be built to pray[r]'      and honor you in new place.",255,120,120);
	let p = text(35,420,"Reimu: But you have gone, and people became very weak without food. And [r]'      they couldn't even finish the building.",255,120,120);
	let q = text(35,460,"Minoriko: Oh...",255,180,120);
	
	let object4 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(object4,scene03);
	Obj_SetRenderPriorityI(object4, 97);
	ObjSprite2D_SetSourceRect(object4, 0, 0, 1280, 960);
	ObjSprite2D_SetDestRect(object4, 0, 0, 640, 480);
	let alpha6 = 0;
	loop(85){
		ObjRender_SetAlpha(object3,255-alpha6);
		ObjRender_SetAlpha(object4,alpha6);
		ObjRender_SetAlpha(o,255-alpha6*2);
		ObjRender_SetAlpha(p,255-alpha6*2);
		ObjRender_SetAlpha(q,255-alpha6*2);
		alpha6+=255/85;yield;}
	Obj_Delete(object3);
	Obj_Delete(o);
	Obj_Delete(p);
	Obj_Delete(q);
	let r = text(35,380,"Reimu: So, will you help them to build your shrine?",255,120,120);
	let s = text(35,400,"Minoriko: S-sure!",255,180,120);
	
	let object5 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(object5,"");
	Obj_SetRenderPriorityI(object5, 99);
	ObjSprite2D_SetSourceRect(object5, 0, 0, 1280, 960);
	ObjSprite2D_SetDestRect(object5, 0, 0, 640, 480);
	let alpha7 = 0;
	loop(85){
		ObjSound_SetVolumeRate(music,ObjSound_GetVolumeRate(music)-100/85);
		ObjRender_SetAlpha(r,255-alpha7);
		ObjRender_SetAlpha(s,255-alpha7);
		ObjRender_SetAlpha(object5,alpha7);
		alpha7+=255/85;yield;}
	Obj_Delete(u);
	Obj_Delete(object);
	Obj_Delete(object2);
	Obj_Delete(object4);
	Obj_Delete(object5);
	Obj_Delete(music);
	Obj_Delete(r);
	Obj_Delete(s);
	loop(1){yield;}
	ObjEnemy_SetLife(bossObj,0);
	Obj_Delete(bossObj);
	DeleteShotAll(TYPE_ALL,TYPE_ITEM);yield;
	CloseScript(GetOwnScriptID());}

function text(x,y,text,r,g,b){
	let obj = ObjText_Create;
	ObjText_SetText(obj, text);
	ObjText_SetFontSize(obj, 14);
	ObjText_SetFontBold(obj, true);
	ObjText_SetFontColorTop(obj, r, g, b);
	ObjText_SetFontColorBottom(obj, r-20, g-20, b-20);
	Obj_SetRenderPriorityI(obj, 100);
	ObjRender_SetX(obj, x);
	task ManageObj{
	let sc = 0;
	let pl = 0;
		loop(15){
			ObjRender_SetScaleXYZ(obj, 1, sc, 0);
			ObjRender_SetY(obj, y-10+pl);
			sc+=1/14;pl+=10/15;yield;}}
	ManageObj;
	waitpress;
	return obj;}

function waitpress{while(GetVirtualKeyState(VK_SHOT) != KEY_PUSH){yield;}yield;}