#TouhouDanmakufu[Stage]
#ScriptVersion[3]
#System["./../tricky_system/TrickySystem.dnh"]
#Title["Stage 3 - Snowy Forest of Magic"]
#Player["./../lib/Okina_player_by_Python/Okina Matara/Okina.dnh"]

let CSD = GetCurrentScriptDirectory;
let MD = GetModuleDirectory;

let EndStateCalled = false;

let eventhappening = false;

let objmidboss = ObjEnemyBossScene_Create();
let objmidboss2 = ObjEnemyBossScene_Create();
let objboss = ObjEnemyBossScene_Create();

let scriptEnemy;
let scriptBackground;

#include "../lib/includes/dialogueconsts.dnh"
#include "../lib/stage.eventdialogue.dnh"
#include "../lib/includes/Function_Audio.dnh"
#include "../tricky_system/Event_Const.dnh"
#include "../lib/includes/EffectFunctions.dnh"
#include "../lib/includes/EnemyFunctions.dnh"
#include "../lib/UNL_Shot/lib_ShotConstants.dnh"
	
function LoadAllImagesInFolder(path){
	yield;
	let plist = GetFilePathList(path);
	let dlist = GetDirectoryList(path);
	ascent(i in 0..length(plist)){
		let cFile = plist[i];
		let fExt = cFile[length(cFile)-3..length(cFile)];
		if(fExt == "png" || fExt == "jpg" || fExt == "bmp"){
			LoadTextureInLoadThread(cFile);
		}
	}
	
	ascent(i in 0..length(dlist)){
		LoadAllImagesInFolder(dlist[i]);
	}
}
	
@Loading{
	
	if(GetCommonData("Main Game", false)==false){
		SetPlayerLife(9);
		InstallFont(CSD ~ "../BNKGOTHM.TTF");
		LoadAllImagesInFolder(CSD~"../");
	}
	
	ObjEnemyBossScene_Add(objmidboss, 0, CSD ~ "KotohimeMN1_H.dnh");
	ObjEnemyBossScene_Add(objmidboss2, 0, CSD ~ "Kotohime0.dnh");
	ObjEnemyBossScene_Add(objmidboss2, 0, CSD ~ "KotohimeMS1_H.dnh");
	//ObjEnemyBossScene_Add(objmidboss2, 1, CSD ~ "KotohimeMS2_H.dnh");

	ObjEnemyBossScene_Add(objboss, 0, CSD ~ "Tricky0.dnh");
	ObjEnemyBossScene_Add(objboss, 0, CSD ~ "TrickyN1_H.dnh");
	ObjEnemyBossScene_Add(objboss, 0, CSD ~ "TrickyS1_H.dnh");
	ObjEnemyBossScene_Add(objboss, 1, CSD ~ "TrickyN2_H.dnh");
	ObjEnemyBossScene_Add(objboss, 1, CSD ~ "TrickyS2_H.dnh");
	ObjEnemyBossScene_Add(objboss, 2, CSD ~ "TrickyN3_H.dnh");
	ObjEnemyBossScene_Add(objboss, 2, CSD ~ "TrickyS3_H.dnh");
	ObjEnemyBossScene_Add(objboss, 3, CSD ~ "TrickyN4_H.dnh");
	ObjEnemyBossScene_Add(objboss, 3, CSD ~ "TrickyS4_H.dnh");
	ObjEnemyBossScene_Add(objboss, 4, CSD ~ "TrickyS5_H.dnh");
	
	ObjEnemyBossScene_LoadInThread(objmidboss);
	ObjEnemyBossScene_LoadInThread(objmidboss2);
	ObjEnemyBossScene_LoadInThread(objboss);	
}
	
@Initialize{

	scriptEnemy = LoadScript(GetCurrentScriptDirectory ~ "Enemy.dnh");
	StartScript(scriptEnemy);
	
	scriptBackground = LoadScript(GetCurrentScriptDirectory ~ "./NamelessPath.dnh");
	StartScript(scriptBackground);

	TStage();
}

@MainLoop{

	//if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD ||GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH) { CollectItemsInCircle(GetPlayerX, GetPlayerY, 55); }
		if(GetPlayerState() == STATE_END && EndStateCalled==false){ EndStateCalled = true; StartCloseStgScene(); }
	
	yield;	
}

task StartCloseStgScene{
	wait(180);
	CloseStgScene();
}

@Event{
	alternative(GetEventType())	
	case(EV_PAUSE_ENTER){
		NotifyEventAll(EV_MUSIC_PAUSE, true);
	}
	case(EV_PAUSE_LEAVE){
		NotifyEventAll(EV_MUSIC_RESUME, true);
	}
	case(EV_DIALOGUE){
		let eventParam = GetEventArgument(0);
		let type = eventParam;
		
		alternative(type)
		case(0) { Event0; }
		case(1) { Event1; }
	}
}

task FairySwarm(time, amount, switch, color){
	loop(amount){
		CreateFairy_SmallA1(192+135*switch, -20, 0, color);
		wait(time);
	}
}

task FairySwarm2(time, amount){
	let count = 0;
	loop(amount){
		CreateFairy_SmallA1(-10, 50, 0, 1);
		if(count%10==0){ CreateFairy_SmallA3(384+10, 110, 0, 1); }
		wait(time);
		CreateFairy_SmallA1(384+10, 50, 0, 0);
		if(count%10==0){ CreateFairy_SmallA3(-10, 110, 0, 0); }
		wait(time);
		count++;
	}
}	

task TStage{
	let CSD = -1;
	SetCommonData("MidbossDead", false);
	wait(90);
	PlayMusic(3.1);

	let dir = 90;
	let switch = 1;
	let color = 0;
	if(GetPlayerX>GetCenterX){ switch = -1; }
	SetShotAutoDeleteClip(100, 100, 100, 40);
	CreateFairy_MediumA3(192+207*switch, 175, dir, 2);
	wait(65);
	dir+=360/18/3.85;
	switch*=-1;
	CreateFairy_MediumA3(192+207*switch, 175, dir, 1);
	wait(65);
	dir+=360/18/3.85;
	switch*=-1;
	CreateFairy_MediumA3(192+207*switch, 175, dir, 2);
	wait(65*2);
	dir+=360/18/3.85;
	switch*=-1;
	dir = 90;
	CreateFairy_MediumA3(192+207*switch, 175, dir, 1);
	wait(65);
	switch*=-1;
	dir-=360/18/3.85;
	CreateFairy_MediumA3(192+207*switch, 175, dir, 2);
	wait(65);
	switch*=-1;
	dir-=360/18/3.85;
	CreateFairy_MediumA3(192+207*switch, 175, dir, 1);
	wait((65*2));
	dir = 90;
	switch*=-1;
	CreateFairy_MediumA3(192+207*switch, 165, dir, 2);
	CreateFairy_MediumA2(192+96*switch, -10, 90, 1); 
	switch*=-1;
	wait(65);
	dir+=360/18/3.85;
	CreateFairy_MediumA3(192+207*switch, 165, dir, 1);
	wait(65);
	switch*=-1;
	dir+=360/18/3.85;
	CreateFairy_MediumA3(192+207*switch, 165, dir, 2);
	wait(2);
	switch*=-1;
	CreateFairy_MediumA2(192+96*switch, -10, 90, 1); 
	switch*=-1;
	wait(65*2 + 2);
	dir+=360/18/3.85;
	dir = 90;
	CreateFairy_MediumA2(192, -10, 90, 1); 
	CreateFairy_MediumA3(192+207*switch, 165, dir, 1);
	switch*=-1;
	wait(65);
	dir-=360/18/3.85;
	CreateFairy_MediumA3(192+207*switch, 165, dir, 2);
	wait(65);
	dir-=360/18/3.85;
	switch*=-1;
	CreateFairy_MediumA3(192+207*switch, 165, dir, 1);
	wait(2);
	CreateFairy_MediumA2(192+96*switch, -10, 90, 1); 
	switch*=-1;
	CreateFairy_MediumA2(192+96*switch, -10, 90, 1); 
	switch*=-1;
	switch*=-1;
	wait(30);
	SetShotAutoDeleteClip(32, 40, 32, 32);
	//SetCommonData("BGSpeed", 4);
	wait(30);
	Title;
	wait(245);
	if(GetPlayerX>GetStgFrameWidth/2){ switch = -1; } else { switch = 1; }

	loop(2){
		FairySwarm(24, 17, switch, color);
		wait(105);
		switch*=-1;
		CreateFairy_MediumA1(192+90*switch, -10, 90, color);
		color++;
		wait(340);
	}
	wait(60);
	//SetEnemyLifeToZero;
	wait(30);

	ObjEnemyBossScene_Regist(objmidboss);
	BossShadow;
	while(GetCommonData("MidbossDead", false)==false){
		yield;
	}
	
	wait(90);
	CreateFairy_MediumA4(192+90*switch, -10, 90, color);
	CreateFairy_MediumA4(192+(90*switch*-1), -10, 90, color);
	wait(360);
	FairySwarm(24, 17, switch, color);
	FairySwarm(24, 17, switch*-1, color);
	wait(400);
	WaitIfEnemiesOnScreen(800);
	wait(60);
	dir = rand(0, 360);
	loop(6){
		CreateFairy_MediumA5(192+60*cos(dir), -90+60*sin(dir), 90, color%3);
		dir+=360/6;
		color++;
	}
	wait(180);
	SetShotAutoDeleteClip(64, 64, 64, 64);
	CreateBomb;
	wait(180);
	SetShotAutoDeleteClip(32, 40, 32, 32);
	Event0;
	while(!Obj_IsDeleted(objmidboss2)){
		yield;
	}
	
	wait(150);
	CollectAllItems;
	Event1;
	while(!Obj_IsDeleted(objboss)){
		yield;
	}
	wait(90);
	Event2;
	eventhappening = true;
	while(eventhappening){ yield; }
	wait(120);
	if(GetCommonData("Main Game", false)==false){ CloseStgScene(); }
	else{
	CloseStgScene();
	CloseScript(scriptBackground);
	CloseScript(GetOwnScriptID());
	}
}
	
task CreateBomb{
	let obj = CreateShotA1(-30, 120, 0, 90, BUBBLE[RED], 0);
	PlaySoundEffect("shot3", 100, -30);
	let dir = 90;
	ObjMove_SetDestAtFrame(obj, GetStgFrameWidth/2, 120, 60);
	wait(60);
	PlaySoundEffect("se_enep02", 100, GetStgFrameWidth/2);
	ScreenShake(45, 30);
	ascent(i in 0..8){
		loop(30){
			let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 5-(i/2), dir, -0.125, 0, CIRCLE_S[RED], 0);
			ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
			dir+=360/30;
			ObjShot_SetDeleteFrame(obj2, 40);
		}
	}
	ObjShot_FadeDelete(obj);
	wait(25);
	SetEnemyLifeToZero;
	
}
	
task Event0{
	InitializeEvent(1, 1);
	HandleEventLogic();
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);
	SetCharStatusPresent(0, 0, true);
	SetCutinGraphic(1, 0, kotohime, 0, 50, true);
	SetCharStatusPresent(1, 0, false);
	Talking(0);
	SetEventText(0, 1, "What the fridge?", 0);
	Talking(1);
	SetEventText(1, 1, "Stop right there, criminal scum!", 0);
	ObjEnemyBossScene_Regist(objmidboss2);
	BossShadow;	
	wait(120);
	SetCharStatusPresent(1, 0, true);
	SetEventText(1, 1, "Where's your permit to solve incidents?", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);
	SetEventText(0, 4, "Since when did that require a permit?[r]And why do you look so...", 0);
	Talking(1);
	SetEventText(1, 1, "Since 8 o'clock this morning!", 0);
	BossName("Kotohime", 100, 0, 100);
	BossCircle;
	SetEventText(1, 5, "No permit means no passage![r]You are BLOCKED!!!", 0);
	SetCharStatusPresent(0, 0, false); SetCharStatusPresent(1, 0, false);
	NotifyEventAll(EV_KILLBOSS, 1);
	FinalizeEvent;
}

task Event1{
	let dispX_Player = 0;
	let dispX_Enem = 0;

	InitializeEvent(1, 1);
	HandleEventLogic();
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);
	SetCharStatusPresent(0, 0, true);
	SetCutinGraphic(1, 0, tricky, -0, 50, true);
	Talking(0);
	SetEventText(0, 0, "That was absurd.", 0);
	SetCutinGraphic(0, 0, okinaclosed, -70, 45, false);
	SetEventText(0, 4, "No matter. I still need to[r]find this mysterious 'he'.", 0);
	Talking(1);
	SetEventText(1, 4, "Excuse me? Are you[r]looking for someone?", 0);
	ObjEnemyBossScene_Regist(objboss); 
	wait(120);
	SetCharStatusPresent(1, 0, true);
	SetEventText(1, 0, "Do you need anything?", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);	
	SetEventText(0, 4, "I need to find the culprit of[r]this incident. Who're you?", 0);
	Talking(1);
	SetEventText(1, 0, "I am Rowan Gardner.", 0);
	BossName("Tricky", 136, 69, 19);
	SetEventText(1, 4, "Most call me Tricky.[r]It is a pseudonym.", 0);
	SetEventText(1, 4, "I'd ask for your name,[r]but I know about you.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);	
	SetEventText(0, 0, "You do?", 0);
	Talking(1);
	SetEventText(1, 0, "You're Okina Matara.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinahappy, -70, 45, false);
	SetEventText(0, 0, "Yes. Yes I am. It's nice to be known.", 0);
	Talking(1);
	SetEventText(1, 4, "You're the moron who ruined the[r]ecosystem by changing the seasons.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);	
	SetEventText(0, 0, "...What.", 0);
	Talking(1);
	SetEventText(1, 4, "Were you expecting me to revere you?[r]Frankly, you're extremely annoying.", 0);
	SetEventText(1, 4, "Your Four Seasons Incident was[r]quite the major inconvenience.", 0);
	SetEventText(1, 4, "The Forest of Magic's animals were[r]not prepared for a sudden winter.", 0);
	SetEventText(1, 4, "Luckily, my colleagues and I had solutions.[r]That doesn't make your antics any better.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);	
	SetEventText(0, 4, "What do you mean, antics?[r]It was a display of power!", 0);
	SetEventText(0, 0, "Everyone does that sort of thing here!", 0);
	Talking(1);
	SetEventText(1, 4, "Everyone does it, but no one[r]considers the consequences.", 0);
	SetEventText(1, 4, "It falls on people like me[r]to pick up the pieces.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinasmug, -70, 45, false);	
	SetEventText(0, 4, "People like you? You look[r]like another scrawny human.", 0);
	Talking(1);
	SetEventText(1, 4, "I take it upon myself to[r]guard the Forest of Magic.", 0);
	SetEventText(1, 4, "I avert disasters when I can.[r]Other times, I clean up after them.", 0);
	SetEventText(1, 4, "I'm pretty well-liked by my[r]fellow 'scrawny humans', too.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinaclosed, -70, 45, false);	
	SetEventText(0, 4, "Whatever, whatever.[r]Is this winter your fault?", 0);
	Talking(1);
	SetEventText(1, 0, "What if it is?", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinahappy, -70, 45, false);
	SetEventText(0, 0, "Then I've reached my goal.", 0);
	Talking(1);
	SetEventText(1, 0, "...Hmm.", 0);
	SetEventText(1, 4, "Let's go with yes.[r]It's absolutely my fault.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinasmug, -70, 45, false);
	SetEventText(0, 4, "Great! I hope you don't[r]mind a little beatdown.", 0);
	Talking(1);
	SetEventText(1, 4, "Very well. Let us[r] see how this goes.", 0);
	SetEventText(1, 4, "If you can best me, you're[r]a worthy opponent.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinasmugdark, -70, 45, false);
	SetEventText(0, 0, "Oh, please. This should be easy.", 0);
	Talking(1);
	SetEventText(1, 4, "I fight with the faith of[r]others at my back.", 0);
	PlayMusic(3.2);
	BossCircle;
	BossShadow;
	SetCommonData("BGSpeed", 4);
	SetEventText(1, 4, "I wonder how you'll fare[r]against a living god?", 0);
	SetCharStatusPresent(0, 0, false); SetCharStatusPresent(1, 0, false);
	NotifyEventAll(EV_KILLBOSS, 1);
	FinalizeEvent;
}

task Event2{
	let dispX_Player = 0;
	let dispX_Enem = 0;

	InitializeEvent(1, 1);
	HandleEventLogic();
	SetCutinGraphic(0, 0, okinahappy, -70, 45, false);
	SetCharStatusPresent(0, 0, true); SetCharStatusPresent(1, 0, true);
	SetCutinGraphic(1, 0, trickydefeated, -0, 50, true);
	Talking(1);
	SetEventText(1, 0, "Hmm. Well then.", 0);
	Talking(0);
	SetEventText(0, 1, "Aha! I win!", 0);
	Talking(1);
	SetEventText(1, 0, "You did indeed win. Congratulations.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinaclosed, -70, 45, false);	
	SetEventText(0, 4, "That last attack was tough,[r]but I made it through!", 0);
	Talking(1);
	SetEventText(1, 0, "That is correct.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinahappy, -70, 45, false);	
	SetEventText(0, 4, "So now is when the incident causer[r]usually stops the incident, right?", 0);
	Talking(1);
	SetEventText(1, 0, "Mhm.", 0);
	Talking(0);
	SetEventText(0, 0, "Great! Do the thing!", 0);
	Talking(1);
	SetEventText(1, 0, "I would love to.", 0);
	SetEventText(1, 0, "However, I did not cause the incident.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);	
	SetEventText(0, 0, "...What.", 0);
	Talking(1);
	SetEventText(1, 0, "I said, I didn't cause the incident.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinaclosed, -70, 45, false);	
	SetEventText(0, 0, "I heard you.", 0);
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);	
	SetEventText(0, 4, "But if it's not your fault,[r]why would you lie about it?", 0);
	Talking(1);
	SetEventText(1, 4, "I'm here to act as a filter for any[r]prospective incident resolvers.", 0);
	SetEventText(1, 4, "The real culprit does not want his[r]time wasted by weak opponents.", 0);
	SetEventText(1, 4, "Since you beat me, perhaps[r]you're worth giving a chance.", 0);
	SetEventText(1, 4, "As a comparison, Reimu is currently[r]on her tenth attempt at defeating me.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);	
	SetEventText(0, 0, "...So that means...", 0);
	Talking(1);
	SetEventText(1, 4, "You'll have to solve this during[r] a sort of extra stage, I believe.", 0);
	SetEventText(1, 4, "Come back tomorrow.[r]You can go right to him.", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinawhat, -70, 45, false);	
	SetEventText(0, 0, "Then what do I do now?", 0);
	Talking(1);
	SetEventText(1, 0, "I don't know. Go home?", 0);
	Talking(0);
	SetCutinGraphic(0, 0, okinaclosed, -70, 45, false);	
	SetEventText(0, 0, "...", 0);
	SetCutinGraphic(0, 0, okinahappy, -70, 45, false);	
	SetEventText(0, 0, "Good idea. I'm tired!", 0);
	SetCharStatusPresent(0, 0, false);
	Talking(1);
	SetEventText(1, 0, "...Fascinating.", 0);
	SetEventText(1, 0, "She might make a worthy opponent.", 0);
	SetEventText(1, 0, "...Even if she's an idiot.", 0);
	SetEventText(1, 0, "Now, for more pressing matters.", 0);
	SetEventText(1, 0, "I must return to work...", 0);
	SetEventText(1, 0, "...and I must put out my hair. How annoying.", 0);
	SetCharStatusPresent(1, 0, false);
	wait(60);
	FinalizeEvent;
	eventhappening = false;
}

function CreateFairy_SmallA1(x,y,CSD,color) {
	NotifyEventAll(EV_SPAWN_ENEMY,[1.1,x,y,CSD,color]);
}

function CreateFairy_SmallA2(x,y,CSD,color) {
	NotifyEventAll(EV_SPAWN_ENEMY,[1.2,x,y,CSD,color]);
}

function CreateFairy_SmallA3(x,y,CSD,color) {
	NotifyEventAll(EV_SPAWN_ENEMY,[1.3,x,y,CSD,color]);
}

function CreateFairy_MediumA1(x,y,CSD,color) {
	NotifyEventAll(EV_SPAWN_ENEMY,[2.1,x,y,CSD,color]);
}

function CreateFairy_MediumA2(x,y,CSD,color) {
	NotifyEventAll(EV_SPAWN_ENEMY,[2.2,x,y,CSD,color]);
}

function CreateFairy_MediumA3(x,y,CSD,color) {
	NotifyEventAll(EV_SPAWN_ENEMY,[2.3,x,y,CSD,color]);
}

function CreateFairy_MediumA4(x,y,CSD,color) {
	NotifyEventAll(EV_SPAWN_ENEMY,[2.4,x,y,CSD,color]);
}

function CreateFairy_MediumA5(x,y,CSD,color) {
	NotifyEventAll(EV_SPAWN_ENEMY,[2.5,x,y,CSD,color]);
}


function SetEnemyLifeToZero{
	let enm = GetAllEnemyID;
	ascent(i in 0..length(enm)) {
		Obj_SetValue(enm[i],"Item",false);
		ObjEnemy_SetLife(enm[i],0);
	}
}

function WaitIfEnemiesOnScreen(w){
	loop(w){ if(length(GetAllEnemyID)>0){ yield; } }
}

task Title {
    let objStar = ObjPrim_Create(OBJ_SPRITE_2D);
	let logotexture = CSD ~ "sprites/Logo_Tricky3.png";
	
    ObjRender_SetBlendType(objStar,BLEND_ALPHA);
    Obj_SetRenderPriorityI(objStar,90);
    ObjPrim_SetTexture(objStar, logotexture);
    ObjSprite2D_SetSourceRect(objStar,0,0,192,192);
    ObjSprite2D_SetDestCenter(objStar);
   
    let objStage = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(objStage,BLEND_ALPHA);
    Obj_SetRenderPriorityI(objStage,90);
    ObjPrim_SetTexture(objStage, logotexture);
    ObjSprite2D_SetSourceRect(objStage,192,0,512,128);
    ObjSprite2D_SetDestCenter(objStage);
   
    let objTitle = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(objTitle,BLEND_ALPHA);
    Obj_SetRenderPriorityI(objTitle,90);
    ObjPrim_SetTexture(objTitle, logotexture);
    ObjSprite2D_SetSourceRect(objTitle,0,192,512,256);
    ObjSprite2D_SetDestCenter(objTitle);
   
    let objText = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(objText,BLEND_ALPHA);
    Obj_SetRenderPriorityI(objText,90);
    ObjPrim_SetTexture(objText, logotexture);
    ObjSprite2D_SetSourceRect(objText,192,128,512,192);
    ObjSprite2D_SetDestCenter(objText);
   
    let x = GetCenterX-15;
    let y = 140;
    let alphaStar = 0;
    let alphaText = 0;
    let spin = 0;
   
    ObjRender_SetScaleXYZ(objStar,0.6,0.6,0.6);
    ObjRender_SetScaleXYZ(objStage,0.5,0.5,0.5);
    ObjRender_SetScaleXYZ(objTitle,0.7,0.7,0.7);
    ObjRender_SetScaleXYZ(objText,0.8,0.8,0.8);
   
    loop(270) {
        if(x>GetCenterX-95) { x-=1; spin-=180/80; alphaStar+=255/80; }
        else if(alphaText<255){ alphaText+=255/90; }
        ObjRender_SetAlpha(objStar,alphaStar);
        ObjRender_SetAlpha(objStage,alphaText);
        ObjRender_SetAlpha(objTitle,alphaText);
        ObjRender_SetAlpha(objText,alphaText);
        ObjRender_SetPosition(objStar,x,y,0);
        ObjRender_SetPosition(objStage,x,y-3,0);
        ObjRender_SetPosition(objTitle,GetCenterX+90,120,0);
        ObjRender_SetPosition(objText,GetCenterX+90,155,0);
        ObjRender_SetAngleZ(objStar,spin);
        yield;
    }
    loop(90) {
        ObjRender_SetAlpha(objStar,alphaStar);
        ObjRender_SetAlpha(objStage,alphaText);
        ObjRender_SetAlpha(objTitle,alphaText);
        ObjRender_SetAlpha(objText,alphaText);
        alphaStar-=255/90;
        alphaText-=255/90;
        yield;
    }
    Obj_Delete(objStar);
    Obj_Delete(objStage);
    Obj_Delete(objTitle);
    Obj_Delete(objText);
}

task BossName(name, r, g, b) {
	let objtext = ObjText_Create;
	
	ObjText_SetFontSize(objtext,12);
	ObjText_SetFontType(objtext, "Bank Gothic MD");
	// ObjText_SetFontBold(objtext, true);
	ObjText_SetFontColorTop(objtext,255,255,255);
	ObjText_SetFontColorBottom(objtext,r,g,b);
	ObjText_SetFontBorderType(objtext,BORDER_FULL);
	ObjText_SetFontBorderWidth(objtext,1);
	ObjText_SetFontBorderColor(objtext,0,0,0);
	ObjText_SetHorizontalAlignment(objtext,ALIGNMENT_LEFT);
	ObjText_SetMaxWidth(objtext,400);
	Obj_SetRenderPriorityI(objtext,65);
	
	let objEnemy = ID_INVALID;
	let objScene = GetEnemyBossSceneObjectID;
	let alpha = 0;
	
	while(!Obj_IsDeleted(objScene)) {
		if(length(GetEnemyBossObjectID)>0) { objEnemy = GetEnemyBossObjectID[0]; }
		ObjRender_SetAlpha(objtext,alpha);
		ObjText_SetText(objtext,name);
		ObjRender_SetPosition(objtext,5,18,0);
		if(alpha<255 && GetPlayerY>=115) { alpha+=255/30; }
		if(alpha>150 && GetPlayerY<115) { alpha-=255/30; }
		yield;
	}
	Obj_Delete(objtext);
}