#include "./MS_ShotFunctions.txt"
#include "./MS_DefaultFunctions.txt"

let kunai = [KUNAI_GREEN, KUNAI_BLUE, KUNAI_ORANGE, KUNAI_PURPLE];
let ball = [ORB_S_GREEN, ORB_S_BLUE, ORB_S_ORANGE, ORB_S_PURPLE];
let fireball = [FIREBALL_GREEN_ADD, FIREBALL_BLUE_ADD, FIREBALL_ORANGE_ADD, FIREBALL_PURPLE_ADD];
let ice = [ICE_GREEN, ICE_BLUE, ICE_ORANGE, ICE_PURPLE];
let scale = [SCALE_GREEN, SCALE_BLUE, SCALE_ORANGE, SCALE_PURPLE];
let pellet = [RICE_S_GREEN, RICE_S_BLUE, RICE_S_ORANGE, RICE_S_PURPLE];

		task Angular(obj, ang){
			while(!Obj_IsDeleted(obj)){
			ObjMove_SetAngle(obj, ObjMove_GetAngle(obj)+ang);
			yield;
			}
		}
		
function Door(X, Y){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjRender_SetPosition(obj,X,Y,0);
Render(obj);
DoorLeft(obj);
DoorRight(obj);
return(obj);

	task Render(obj){
		let path = GetCurrentScriptDirectory ~ "img/Ingame/BG/doorframe.mqo";
		let door = ObjMesh_Create();

		ObjRender_SetBlendType(door, BLEND_ALPHA);
		ObjMesh_SetCoordinate2D(door, true);
		ObjMesh_Load(door, path);
		Obj_SetRenderPriorityI(door, 45);
		ObjRender_SetPosition(door, X-32, Y-15, 0);
		ObjRender_SetAngleX(door, 180);
		ObjRender_SetScaleXYZ(door, 0.75, 0.75, 0.75);
		while(Obj_GetValueD(obj, "Open", 0) == 0){yield;}
		wait(90+140);
		ascent(i in 0..120){
		ObjMesh_SetAlpha(door, 255-i*10);
		yield;
		}
		Obj_Delete(door);
	}
	task DoorLeft(obj){
		let path = GetCurrentScriptDirectory ~ "img/Ingame/BG/doordoor.mqo";
		let door = ObjMesh_Create();

		ObjRender_SetBlendType(door, BLEND_ALPHA);
		ObjMesh_SetCoordinate2D(door, true);
		ObjMesh_Load(door, path);
		Obj_SetRenderPriorityI(door, 45);
		ObjRender_SetPosition(door, X-35+25, Y-15, 0);
		ObjRender_SetAngleX(door, 180);
		ObjRender_SetScaleXYZ(door, 0.75, 0.75, 0.75);
		
		while(Obj_GetValueD(obj, "Open", 0) == 0){yield;}
		ascent(i in 0..140){
		ObjRender_SetAngleY(door, 0+(i*1));
		ObjRender_SetPosition(door, X-35+25+i/4, Y-15, 0);
		yield;
		}
			wait(90);
		ascent(i in 0..120){
		ObjMesh_SetAlpha(door, 255-i*10);
		yield;
		}
		Obj_Delete(door);
	}
	task DoorRight(obj){
		let path = GetCurrentScriptDirectory ~ "img/Ingame/BG/doordoor.mqo";
		let door = ObjMesh_Create();

		ObjRender_SetBlendType(door, BLEND_ALPHA);
		ObjMesh_SetCoordinate2D(door, true);
		ObjMesh_Load(door, path);
		Obj_SetRenderPriorityI(door, 45);
		ObjRender_SetPosition(door, X-35-25, Y-15, 0);
		ObjRender_SetAngleX(door, 180);
		ObjRender_SetAngleY(door, 180);
		ObjRender_SetScaleXYZ(door, 0.75, 0.75, 0.75);
		
		while(Obj_GetValueD(obj, "Open", 0) == 0){yield;}
		ascent(i in 0..140){
		ObjRender_SetAngleY(door, 180+(i*-1));
		ObjRender_SetPosition(door,X-35-25-i/3.5, Y-15, 0);
		yield;
		}
			wait(90);
		ascent(i in 0..120){
		ObjMesh_SetAlpha(door, 255-i*10);
		yield;
		}
		Obj_Delete(door);
	}
}

function DoorTransition(X, Y){
let trans = 1000;
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjRender_SetPosition(obj,X,Y,0);
Render(obj);
DoorLeft(obj);
DoorRight(obj);
Transition;
return(obj);

task Transition{
ascent(i in 0..10000){
trans-=1+i/5;
yield;
}
}

	task Render(obj){
		let path = GetCurrentScriptDirectory ~ "img/Ingame/BG/doorframetrans.mqo";
		let door = ObjMesh_Create();

		ObjRender_SetBlendType(door, BLEND_ALPHA);
		ObjMesh_SetCoordinate2D(door, true);
		ObjMesh_Load(door, path);
		Obj_SetRenderPriorityI(door, 25);
		ObjRender_SetPosition(door, X-32, Y-15, trans);
		ObjRender_SetAngleX(door, 180);
		ObjRender_SetScaleXYZ(door, 0.75, 0.75, 0.75);
		ObjMesh_SetColor(door, 0, 0, 0);
		while(Obj_GetValueD(obj, "Open", 0) == 0){yield;}
		ascent(i in 0..120){
		ObjRender_SetPosition(door,  X-32, Y-15, trans);
		ObjRender_SetAngleX(door, 0+i/15);
		yield;
		}
		wait(90);
		ascent(i in 0..120){
		ObjRender_SetPosition(door, X-32, Y-15, trans);
		yield;
		}
		Obj_Delete(door);
	}
	task DoorLeft(obj){
		let path = GetCurrentScriptDirectory ~ "img/Ingame/BG/doordoor.mqo";
		let door = ObjMesh_Create();

		ObjRender_SetBlendType(door, BLEND_ALPHA);
		ObjMesh_SetCoordinate2D(door, true);
		ObjMesh_Load(door, path);
		Obj_SetRenderPriorityI(door, 45);
		ObjRender_SetPosition(door, X-35+25, Y-15, trans);
		ObjRender_SetAngleX(door, 180);
		ObjRender_SetScaleXYZ(door, 0.75, 0.75, 0.75);
		ObjMesh_SetColor(door, 0, 0, 0);
		
		while(Obj_GetValueD(obj, "Open", 0) == 0){yield;}
		ascent(i in 0..120){
		ObjRender_SetAngleY(door, 0+(i*1));
		ObjRender_SetPosition(door, X-35+25+i/4, Y-15, trans);
		ObjRender_SetAngleZ(door, i/15);
		yield;
		}
		wait(90);
		ascent(i in 0..120){
		ObjMesh_SetAlpha(door, 255-i*10);
		yield;
		}
		Obj_Delete(door);
	}
	task DoorRight(obj){
		let path = GetCurrentScriptDirectory ~ "img/Ingame/BG/doordoor.mqo";
		let door = ObjMesh_Create();

		ObjRender_SetBlendType(door, BLEND_ALPHA);
		ObjMesh_SetCoordinate2D(door, true);
		ObjMesh_Load(door, path);
		Obj_SetRenderPriorityI(door, 45);
		ObjRender_SetPosition(door, X-35-25, Y-15, trans);
		ObjRender_SetAngleX(door, 180);
		ObjRender_SetAngleY(door, 180);
		ObjRender_SetScaleXYZ(door, 0.75, 0.75, 0.75);
		ObjMesh_SetColor(door, 0, 0, 0);
		
		while(Obj_GetValueD(obj, "Open", 0) == 0){yield;}
		ascent(i in 0..120){
		ObjRender_SetAngleY(door, 180+(i*-1));
		ObjRender_SetPosition(door,X-35-25-i/3.5, Y-15, trans);
		ObjRender_SetAngleZ(door, i/15);
		yield;
		}
		wait(90);
		ascent(i in 0..120){
		ObjMesh_SetAlpha(door, 255-i*10);
		yield;
		}
		Obj_Delete(door);
	}
}

function DoorCena(X, Y){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjRender_SetPosition(obj,X,Y,0);
Render(obj);
DoorLeft(obj);
DoorRight(obj);
return(obj);

	task Render(obj){
		let path = GetCurrentScriptDirectory ~ "img/Ingame/BG/doorcena.mqo";
		let door = ObjMesh_Create();

		ObjRender_SetBlendType(door, BLEND_ALPHA);
		ObjMesh_SetCoordinate2D(door, true);
		ObjMesh_Load(door, path);
		Obj_SetRenderPriorityI(door, 45);
		ObjRender_SetPosition(door, X-32, Y-15, 0);
		ObjRender_SetAngleX(door, 180);
		ObjRender_SetScaleXYZ(door, 0.75, 0.75, 0.75);
		while(Obj_GetValueD(obj, "Open", 0) == 0){yield;}
		wait(90+140);
	}
	task DoorLeft(obj){
		let path = GetCurrentScriptDirectory ~ "img/Ingame/BG/doordoor.mqo";
		let door = ObjMesh_Create();

		ObjRender_SetBlendType(door, BLEND_ALPHA);
		ObjMesh_SetCoordinate2D(door, true);
		ObjMesh_Load(door, path);
		Obj_SetRenderPriorityI(door, 45);
		ObjRender_SetPosition(door, X-33+25, Y-15, 0);
		ObjRender_SetAngleX(door, 180);
		ObjRender_SetScaleXYZ(door, 0.80, 0.75, 0.75);
		
		while(Obj_GetValueD(obj, "Open", 0) == 0){yield;}
		ascent(i in 0..140){
		ObjRender_SetAngleY(door, 0+(i*1));
		ObjRender_SetPosition(door, X-33+25+i/4, Y-15, 0);
		yield;
		}
	}
	task DoorRight(obj){
		let path = GetCurrentScriptDirectory ~ "img/Ingame/BG/doordoor.mqo";
		let door = ObjMesh_Create();

		ObjRender_SetBlendType(door, BLEND_ALPHA);
		ObjMesh_SetCoordinate2D(door, true);
		ObjMesh_Load(door, path);
		Obj_SetRenderPriorityI(door, 45);
		ObjRender_SetPosition(door, X-35-25, Y-15, 0);
		ObjRender_SetAngleX(door, 180);
		ObjRender_SetAngleY(door, 180);
		ObjRender_SetScaleXYZ(door, 0.75, 0.75, 0.75);
		
		while(Obj_GetValueD(obj, "Open", 0) == 0){yield;}
		ascent(i in 0..140){
		ObjRender_SetAngleY(door, 180+(i*-1));
		ObjRender_SetPosition(door,X-35-25-i/3.5, Y-15, 0);
		yield;
		}
	}
}