let objScene = GetEnemyBossSceneObjectID;
#include".\Resources.txt"

let OnSpell = false;

@Initialize{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(800);
    SetCameraElevationAngle(+20);
	SetCameraAzimuthAngle(90);
	Background;
	Camera;
	SpellBG;
}

@MainLoop{
OnSpell = (GetEnemyBossSceneObjectID != ID_INVALID && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_IS_SPELL)); 
	yield;
}

task Camera{
let ele = 20;
	wait(20);
	while(GetVirtualKeyState(VK_OK) == KEY_FREE || GetVirtualKeyState(VK_OK) == KEY_HOLD){yield;}
	SetCommonData("Commander01",true);
loop(20){
ele-=1;
SetCameraElevationAngle(+ele);
yield;
}
}

task Background{

let obj = ObjPrim_Create(OBJ_SPRITE_3D);
ObjPrim_SetTexture(obj,CSD~"./img/stgbg1.png");
Obj_SetRenderPriorityI(obj,20);
ObjRender_SetAngleX(obj,-40);
ObjSprite3D_SetSourceDestRect(obj,0,0,512,128);
ObjRender_SetScaleXYZ(obj,1.5,1.5,1.5);
ObjRender_SetBlendType(obj,BLEND_ALPHA);

ObjRender_SetAlpha(obj,255);
        let alpha = 0;
	let frameInvisible = 0;
	let movel = 0;
	let movel2 = 0;
	loop
	{

    movel+=0;
    movel2+=1.5;
	if(GetCommonData("Commander01",false)==true){movel2+=3.5}
     ObjSprite3D_SetSourceDestRect(obj,0,0+movel2,(256*6)+movel,(256*6)+movel2);
               ascent(i in 0..length(obj)){
	//	ObjRender_SetAlpha(obj[i],alpha);
          //      ObjRender_SetAlpha(objg,alpha);
                }

    	if(alpha > 255){
        	alpha = 255;
        	}
        	if(alpha < 0){
        	alpha = 0;
        	}
                
		yield;
	}
}

task SpellBG{
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj1, 21);
	ObjPrim_SetTexture(obj1, GetCurrentScriptDirectory~"./img/splbg.png");
	ObjRender_SetScaleXYZ(obj1, 0.9, 0.9, 1);
	ObjSprite2D_SetSourceRect(obj1, 0, 0,412, 407);
	ObjRender_SetPosition(obj1, GetStgFrameWidth/2, GetStgFrameHeight/2, 0);
		
	let frame = 0;
	let ang = 0;
	let ang2 = 0;
	let slide = 0;
	let ang3 = rand(0,360);
	let x = 0;
	let y = 0;
	let alpha = 0;
	let alpha2 = 0;
	let alpha3 = 0;
	
	loop {
		frame++;
		if(OnSpell) {
			if(alpha < 255) { alpha += 4.25;}
		} else {if(alpha>0){alpha -= 8.25;}}
		
		ObjRender_SetAlpha(obj1, alpha);
		
		slide+=2;
		ObjSprite2D_SetSourceRect(obj1,0,0,512,20000+slide);
		ObjSprite2D_SetDestCenter(obj1);
		ObjRender_SetPosition(obj1,GetStgFrameWidth/2,GetStgFrameHeight/2-(slide*0.5),0);
		yield;}
}
