
let objStar = ObjPrim_Create(OBJ_SPRITE_2D);
let MainSTG = GetMainStgScriptDirectory;
let img_effect = MainSTG~"cirno_system/img/effect.png"; // Effect Sheet

//ObjPrim_Create(OBJ_SPRITE_3D)

function PlayMusic(str){
	let objSound = ObjSound_Create;
	ObjSound_SetSoundDivision(objSound, SOUND_BGM);
	ObjSound_SetLoopEnable(objSound, true);
	ObjSound_SetVolumeRate(objSound, 100);
	if(str=="magusnight"){
		LoadSound(MainSTG~"source/marisabgm.ogg");
		ObjSound_Load(objSound, MainSTG~"source/marisabgm.ogg");
		ObjSound_SetLoopTime(objSound, 0, 126);  //206 ?
		ObjSound_Play(objSound);
	}
	return objSound;
}

task LoadSoundEffects{
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/selectok.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/selectinvalid.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/select.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/timeout.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/timeout2.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/spellfail.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/spellget.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/laser1.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/laser2.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/master.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/final.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/barrage.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/chargelong.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/charge.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/spirit.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/spell.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/smbullet.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/labullet.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/death.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/death2.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/damage1.wav");
	LoadSound(GetMainStgScriptDirectory~"source/Sounds/damage2.wav");
}

function DrawText(txtStr, txtX, txtY, txtSize, txtWidth, presetTxtColor, txtPriority){
	let SnowDrawText = ObjText_Create;
	ObjText_SetText(SnowDrawText,txtStr);
	SetTextColor;
	ObjText_SetFontSize(SnowDrawText,txtSize);
	ObjText_SetHorizontalAlignment(SnowDrawText, ALIGNMENT_LEFT);
	ObjText_SetFontBorderWidth(SnowDrawText,1);
	ObjText_SetFontBorderType(SnowDrawText,BORDER_FULL);
	ObjText_SetMaxWidth(SnowDrawText, txtWidth);
	Obj_SetRenderPriority(SnowDrawText, txtPriority);
	ObjRender_SetPosition(SnowDrawText, txtX, txtY, 0);
	
	SetTextColor;
	
	task SetTextColor{
		if(presetTxtColor=="black"){
			ObjText_SetFontColorTop(SnowDrawText,42,42,42);
			ObjText_SetFontColorBottom(SnowDrawText,42,42,42);
			ObjText_SetFontBorderColor(SnowDrawText,142,142,142);
		}
		if(presetTxtColor=="red"){
			ObjText_SetFontColorTop(SnowDrawText,175,20,111);
			ObjText_SetFontColorBottom(SnowDrawText,190,10,123);
			ObjText_SetFontBorderColor(SnowDrawText,142,142,142);
		}
		if(presetTxtColor=="blue"){
			ObjText_SetFontColorTop(SnowDrawText,20,80,175);
			ObjText_SetFontColorBottom(SnowDrawText,80,50,175);
			ObjText_SetFontBorderColor(SnowDrawText,142,142,142);
		}
	}
	
	return SnowDrawText;
}

function CreateEnemyA1(enemytype, x, y, enmspd, enmang, life, fcolor, argument, argument2){
	let enemyscript;
	if(enemytype == "Enemy1"){enemyscript = LoadScript(dir ~ "Enemy01.txt");}
	if(enemytype == "Boss1"){enemyscript = LoadScript(dir ~ "SnowPlural.txt");}
	SetScriptArgument(enemyscript, 1, fcolor);
	SetScriptArgument(enemyscript, 2, x);
	SetScriptArgument(enemyscript, 3, y);
	SetScriptArgument(enemyscript, 4, enmspd);
	SetScriptArgument(enemyscript, 5, enmang);
	SetScriptArgument(enemyscript, 6, argument);
	SetScriptArgument(enemyscript, 7, argument2);
	SetScriptArgument(enemyscript, 8, life);
	StartScript(enemyscript);
	return enemyscript;
}

function Wait(waitframes){
	loop(waitframes){yield}
}

task LoadStageSounds{
	LoadSound(MainSTG~"source/Sounds/selectok.wav");
	LoadSound(MainSTG~"source/Sounds/selectinvalid.wav");
	LoadSound(MainSTG~"source/Sounds/select.wav");
}

task PlaySound(str){
	if(str == "selectok"){
		PlaySE(MainSTG~"source/Sounds/selectok.wav");
	}
	if(str == "selectinvalid"){
		PlaySE(MainSTG~"source/Sounds/selectinvalid.wav");
	}
	if(str == "select"){
		PlaySE(MainSTG~"source/Sounds/select.wav");
	}
}

task SelectionScreen{
	let menuscreen = ObjPrim_Create(OBJ_SPRITE_2D);
	let finalalpha = 255;
	ObjRender_SetBlendType(menuscreen, BLEND_ALPHA);
	Obj_SetRenderPriorityI(menuscreen, 74);
	
	while(SelectionSet!=2){
		yield;
	}
	
	SetCommonData("SelectionSet", 2);
	ObjPrim_SetTexture(menuscreen, MainSTG~"source/img_select2.png");
	ObjSprite2D_SetSourceRect(menuscreen, 0, 0, 12, 12);
	ObjSprite2D_SetDestRect(menuscreen, 0, 0, 416, 464);
	while(finalalpha>0){
		finalalpha-=5;
		ObjRender_SetAlpha(menuscreen, finalalpha);
		yield;
	}
	
	Obj_Delete(menuscreen);
	
}

task FallingLeafA1(deX, deY, colorR, colorG, colorB, deScale){
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let obj_time = 0;
	let angX = rand(-360, 360);
	let angY = rand(-360, 360);
	let angZ = rand(-360, 360);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.75);
	ObjPrim_SetTexture(obj, img_effect);
	ObjSprite2D_SetSourceRect(obj, 0, 228, 33, 251);
	ObjSprite2D_SetDestRect(obj, -16, -12, 16, 12);
	ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
	ObjRender_SetPosition(obj, deX, deY, 0);
	ObjRender_SetColor(obj, colorR, colorG, colorB);
	ObjRender_SetAlpha(obj, 0);
	
	let alpha = 0;
	let scale = deScale;
	let randX = rand(50, 500);
	let randY = rand(50, 500);
	let RandZ = rand(17,170);
	//atan2(randY - deX, randX - deY);
	while(Obj_IsDeleted(obj)==false){
		obj_time++;
		
		if(obj_time<180 && alpha<105){alpha+=3}
		if(obj_time>180){alpha += -1;}
		alpha += 0.1;
		deX += randX/250;
		deY += randY/250;
		angX += randX/255;
		angY += randY/255;
		angZ += randX/295+randY/295;
		
		ObjRender_SetPosition(obj, deX, deY, 0);
		ObjRender_SetAngleXYZ(obj, angX, angY, angZ);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		
		if(alpha<0){Obj_Delete(obj)}
		if(SelectionSet==2){Obj_Delete(obj)}
		yield;
	}
	Obj_Delete(obj);
}









