#include"./../System/LIB/Event_Const.dnh"

function CreateShot01(xpos,ypos,speed,angle,graphic,delay) {
	let obj = CreateShotA1(xpos,ypos,speed,angle,graphic,delay);
	Stop;
	return obj;
	task Stop {
		let speed = 0;
		let angle = 0;
		while(!Obj_IsDeleted(obj)) {
			speed = ObjMove_GetSpeed(obj);
			angle = ObjMove_GetAngle(obj);
			if(GetCommonData("TimeStop",false)) {
				while(GetCommonData("TimeStop",false)) {
					ObjMove_SetSpeed(obj,0);
					ObjMove_SetAngle(obj,angle);
					yield;
				}
				ObjMove_SetSpeed(obj,speed);
			}
			yield;
		}
	}
}
function CreateShot02(xpos,ypos,speed,angle,acceleration,maxspeed,graphic,delay) {
	let obj = CreateShotA2(xpos,ypos,speed,angle,acceleration,maxspeed,graphic,delay);
	Stop;
	return obj;
	task Stop {
		let speed = 0;
		let angle = 0;
		while(!Obj_IsDeleted(obj)) {
			speed = ObjMove_GetSpeed(obj);
			angle = ObjMove_GetAngle(obj);
			if(GetCommonData("TimeStop",false)) {
				while(GetCommonData("TimeStop",false)) {
					ObjMove_SetSpeed(obj,0);
					ObjMove_SetAngle(obj,angle);
					yield;
				}
				ObjMove_SetSpeed(obj,speed);
			}
			yield;
		}
	}
}
function CreateShot12(xpos,ypos,xspeed,yxpeed,xacceleration,yacceleration,xmaxspeed,ymaxspeed,graphic,delay) {
	let obj = CreateShotB2(xpos,ypos,xspeed,yxpeed,xacceleration,yacceleration,xmaxspeed,ymaxspeed,graphic,delay);
	Stop;
	return obj;
	task Stop {
		let speed = 0;
		let angle = 0;
		while(!Obj_IsDeleted(obj)) {
			speed = ObjMove_GetSpeed(obj);
			angle = ObjMove_GetAngle(obj);
			if(GetCommonData("TimeStop",false)) {
				while(GetCommonData("TimeStop",false)) {
					ObjMove_SetSpeed(obj,0);
					ObjMove_SetAngle(obj,angle);
					yield;
				}
				ObjMove_SetSpeed(obj,speed);
			}
			yield;
		}
	}
}
function CreateShotRing01(num,xpos,ypos,speed,angle,graphic,delay) {
let BulletArray = [];
	loop(num) {
		let obj = CreateShot01(xpos,ypos,speed,angle,graphic,delay);
		BulletArray = BulletArray ~ [obj];
		angle+=360/num;
	}
	return BulletArray;
}
function CreateShotRing02(num,xpos,ypos,speed,angle,acceleration,maxspeed,graphic,delay) {
let BulletArray = [];
	loop(num) {
		let obj = CreateShot02(xpos,ypos,speed,angle,acceleration,maxspeed,graphic,delay);
		BulletArray = BulletArray ~ [obj];
		angle+=360/num;
	}
	return BulletArray;
}
function CreateLaser01(xpos,ypos,speed,angle,length,width,graphic,delay) {
	let obj = CreateLooseLaserA1(xpos,ypos,speed,angle,length,width,graphic,delay);
	let DelayColor = [];
	if(GetAreaCommonData("Options","BulletDelete",true)) { NotifyEventAll(EV_DELETE_LASER,[obj,width]); }
	Stop;
	return obj;
	task Stop {
		let speed = 0;
		let angle = 0;
		while(!Obj_IsDeleted(obj)) {
			speed = ObjMove_GetSpeed(obj);
			angle = ObjMove_GetAngle(obj);
			if(GetCommonData("TimeStop",false)) {
				while(GetCommonData("TimeStop",false)) {
					ObjMove_SetSpeed(obj,0);
					ObjMove_SetAngle(obj,angle);
					yield;
				}
				ObjMove_SetSpeed(obj,speed);
			}
			yield;
		}
	}
}
function CreateLaserRing01(num,xpos,ypos,speed,angle,length,width,graphic,delay) {
let LaserArray = [];
	loop(num) {
		let obj = CreateLaser01(xpos,ypos,speed,angle,length,width,graphic,delay);
		LaserArray = LaserArray ~ [obj];
		angle+=360/num;
	}
	return LaserArray;
}
function CreateStraightLaser01(xpos,ypos,angle,length,width,del,graphic,delay) {
	let obj = CreateStraightLaserA1(xpos,ypos,angle,length,width,del,graphic,delay);
	let DelayColor = [];
	if(GetAreaCommonData("Options","BulletDelete",true)) { NotifyEventAll(EV_DELETE_LASER,[obj,width]); }
	return obj;
}
function PagodaLaser(x,y,angle,maxwidth,color,delay,del) {
	let objHitbox = CreateStraightLaserA1(x,y,angle,500,maxwidth*(5/4),del+45,1,delay);
	PagodaBeam;
	return objHitbox;
	
	task PagodaBeam {
		let objLaser1 = ObjPrim_Create(OBJ_SPRITE_2D);
		let objLaser2 = ObjPrim_Create(OBJ_SPRITE_2D);
		let objDetail = ObjPrim_Create(OBJ_SPRITE_2D);
		let objFire = ObjPrim_Create(OBJ_SPRITE_2D);
		let objFire2 = ObjPrim_Create(OBJ_SPRITE_2D);
		
		let width = 2;
		let length = 0;
		let fire_scale = 1.2;
		let fire_scale2 = 0.8;
		let fire_count = 0;
		let detail_count = 0;
		
		Obj_SetVisible(objHitbox,false);
		
		ObjRender_SetBlendType(objLaser1, BLEND_ALPHA);
		Obj_SetRenderPriorityI(objLaser1, 48);
		ObjPrim_SetTexture(objLaser1, PSD ~ "IMG/Effect/PagodaLaser.png");
		ObjSprite2D_SetSourceRect(objLaser1, 0, 37, 256, 69);
		ObjSprite2D_SetDestRect(objLaser1, 0.5, -16, 256.5, 16);
		ObjRender_SetColor(objLaser1,color[0],color[1],color[2]);
		
		ObjRender_SetBlendType(objLaser2, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(objLaser2, 49);
		ObjPrim_SetTexture(objLaser2, PSD ~ "IMG/Effect/PagodaLaser.png");
		ObjSprite2D_SetSourceRect(objLaser2, 0, 77, 256, 109);
		ObjSprite2D_SetDestRect(objLaser2, 0.5, -16, 256.5, 16);
		
		ObjRender_SetBlendType(objDetail, BLEND_ALPHA);
		Obj_SetRenderPriorityI(objDetail, 49);
		ObjPrim_SetTexture(objDetail, PSD ~ "IMG/Effect/PagodaLaser.png");
		ObjSprite2D_SetSourceRect(objDetail, 0, 0, 256, 30);
		ObjSprite2D_SetDestRect(objDetail, 0.5, -18, 256.5, 18);
		
		ObjRender_SetBlendType(objFire, BLEND_ALPHA);
		Obj_SetRenderPriorityI(objFire, 47);
		ObjPrim_SetTexture(objFire, PSD ~ "IMG/Effect/PagodaLaser_Fire.png");
		ObjRender_SetColor(objFire,color[0],color[1],color[2]);
		ObjRender_SetScaleXYZ(objFire,fire_scale,fire_scale,1);
		
		ObjRender_SetBlendType(objFire2, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(objFire2, 50);
		ObjPrim_SetTexture(objFire2, PSD ~ "IMG/Effect/PagodaLaser_Fire.png");
		ObjRender_SetScaleXYZ(objFire2,fire_scale2,fire_scale2,1);
		
		loop(delay) {
			ObjRender_SetScaleXYZ(objLaser1,2,width/25,0);
			ObjRender_SetPosition(objLaser1,ObjMove_GetX(objHitbox),ObjRender_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objLaser1,ObjStLaser_GetAngle(objHitbox));
			
			ObjRender_SetScaleXYZ(objLaser2,2,width/32,0);
			ObjRender_SetPosition(objLaser2,ObjMove_GetX(objHitbox),ObjRender_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objLaser2,ObjStLaser_GetAngle(objHitbox));
			
			
			ObjRender_SetScaleXYZ(objDetail,2,width/32,0);
			ObjRender_SetPosition(objDetail,ObjMove_GetX(objHitbox),ObjRender_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objDetail,ObjStLaser_GetAngle(objHitbox));
			ObjSprite2D_SetSourceRect(objDetail, 0-detail_count, 0, 256-detail_count, 30);
			ObjSprite2D_SetDestRect(objDetail, 1.5, -18, 257.5, 18);
			
			
			ObjRender_SetPosition(objFire,ObjMove_GetX(objHitbox),ObjRender_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objFire,ObjStLaser_GetAngle(objHitbox));
			if(fire_count%2==0) { ObjSprite2D_SetSourceRect(objFire, 1, 1, 123, 127); }
			else if(fire_count%2==1) { ObjSprite2D_SetSourceRect(objFire, 129, 1, 255, 127); }
			ObjSprite2D_SetDestRect(objFire, 0.5, -61, 128.5, 61);
			
			ObjRender_SetPosition(objFire2,ObjMove_GetX(objHitbox),ObjRender_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objFire2,ObjStLaser_GetAngle(objHitbox));
			if(fire_count%2==0) { ObjSprite2D_SetSourceRect(objFire2, 1, 129, 123, 255); }
			else if(fire_count%2==1) { ObjSprite2D_SetSourceRect(objFire2, 129, 129, 255, 255); }
			ObjSprite2D_SetDestRect(objFire2, 0.5, -61, 128.5, 61);
			
			if(Obj_IsDeleted(objHitbox)) {
				Obj_Delete(objLaser1);
				Obj_Delete(objLaser2);
				Obj_Delete(objDetail);
				Obj_Delete(objFire);
				Obj_Delete(objFire2);
			}
			
			fire_count+=0.5;
			detail_count+=12;
			yield;
		}
		loop(20) {
			ObjRender_SetScaleXYZ(objLaser1,2*(length/500),width/25,1);
			ObjRender_SetPosition(objLaser1,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objLaser1,ObjStLaser_GetAngle(objHitbox));
			
			ObjRender_SetScaleXYZ(objLaser2,2*(length/500),width/32,0);
			ObjRender_SetPosition(objLaser2,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objLaser2,ObjStLaser_GetAngle(objHitbox));
			
			
			ObjRender_SetScaleXYZ(objDetail,2,width/32,0);
			ObjRender_SetPosition(objDetail,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objDetail,ObjStLaser_GetAngle(objHitbox));
			ObjSprite2D_SetSourceRect(objDetail, 0-detail_count, 0, 256-detail_count, 30);
			ObjSprite2D_SetDestRect(objDetail, 0.5, -18, 256.5, 18);
			
			
			ObjRender_SetPosition(objFire,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objFire,ObjStLaser_GetAngle(objHitbox));
			if(fire_count%2==0) { ObjSprite2D_SetSourceRect(objFire, 1, 1, 123, 127); }
			else if(fire_count%2==1) { ObjSprite2D_SetSourceRect(objFire, 129, 1, 255, 127); }
			ObjSprite2D_SetDestRect(objFire, 0.5, -61, 128.5, 61);
			
			ObjRender_SetPosition(objFire2,ObjMove_GetX(objHitbox),ObjRender_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objFire2,ObjStLaser_GetAngle(objHitbox));
			if(fire_count%2==0) { ObjSprite2D_SetSourceRect(objFire2, 1, 129, 123, 255); }
			else if(fire_count%2==1) { ObjSprite2D_SetSourceRect(objFire2, 129, 129, 255, 255); }
			ObjSprite2D_SetDestRect(objFire2, 0.5, -61, 128.5, 61);
			
			if(Obj_IsDeleted(objHitbox)) {
				Obj_Delete(objLaser1);
				Obj_Delete(objLaser2);
				Obj_Delete(objDetail);
				Obj_Delete(objFire);
				Obj_Delete(objFire2);
			}
			
			length+=500/20;
			width+=(maxwidth-2)/20;
			fire_count+=0.5;
			detail_count+=12;
			yield;
		}
		
		loop(del) {
			ObjRender_SetScaleXYZ(objLaser1,2*(length/500),width/25,1);
			ObjRender_SetPosition(objLaser1,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objLaser1,ObjStLaser_GetAngle(objHitbox));
			
			ObjRender_SetScaleXYZ(objLaser2,2*(length/500),width/32,0);
			ObjRender_SetPosition(objLaser2,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objLaser2,ObjStLaser_GetAngle(objHitbox));
			
			
			ObjRender_SetScaleXYZ(objDetail,2,width/32,0);
			ObjRender_SetPosition(objDetail,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objDetail,ObjStLaser_GetAngle(objHitbox));
			ObjSprite2D_SetSourceRect(objDetail, 0-detail_count, 0, 256-detail_count, 30);
			ObjSprite2D_SetDestRect(objDetail, 0.5, -18, 256.5, 18);
			
			
			ObjRender_SetPosition(objFire,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objFire,ObjStLaser_GetAngle(objHitbox));
			if(fire_count%2==0) { ObjSprite2D_SetSourceRect(objFire, 1, 1, 123, 127); }
			else if(fire_count%2==1) { ObjSprite2D_SetSourceRect(objFire, 129, 1, 255, 127); }
			ObjSprite2D_SetDestRect(objFire, 0.5, -61, 128.5, 61);
			
			ObjRender_SetPosition(objFire2,ObjMove_GetX(objHitbox),ObjRender_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objFire2,ObjStLaser_GetAngle(objHitbox));
			if(fire_count%2==0) { ObjSprite2D_SetSourceRect(objFire2, 1, 129, 123, 255); }
			else if(fire_count%2==1) { ObjSprite2D_SetSourceRect(objFire2, 129, 129, 255, 255); }
			ObjSprite2D_SetDestRect(objFire2, 0.5, -61, 128.5, 61);
			
			if(Obj_IsDeleted(objHitbox)) {
				Obj_Delete(objLaser1);
				Obj_Delete(objLaser2);
				Obj_Delete(objDetail);
				Obj_Delete(objFire);
				Obj_Delete(objFire2);
			}
			
			fire_count+=0.5;
			detail_count+=12;
			yield;
		}
		
		loop(30) {
			ObjShot_SetIntersectionEnable(objHitbox,false);
		
			ObjRender_SetScaleXYZ(objLaser1,2,width/25,1);
			ObjRender_SetPosition(objLaser1,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objLaser1,ObjStLaser_GetAngle(objHitbox));
			
			ObjRender_SetScaleXYZ(objLaser2,2,width/32,0);
			ObjRender_SetPosition(objLaser2,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objLaser2,ObjStLaser_GetAngle(objHitbox));
			
			
			ObjRender_SetScaleXYZ(objDetail,2,width/32,0);
			ObjRender_SetPosition(objDetail,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objDetail,ObjStLaser_GetAngle(objHitbox));
			ObjSprite2D_SetSourceRect(objDetail, 0-detail_count, 0, 256-detail_count, 30);
			ObjSprite2D_SetDestRect(objDetail, 0.5, -18, 256.5, 18);
			
			
			ObjRender_SetScaleY(objFire,fire_scale*(width/32));
			ObjRender_SetPosition(objFire,ObjMove_GetX(objHitbox),ObjMove_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objFire,ObjStLaser_GetAngle(objHitbox));
			if(fire_count%2==0) { ObjSprite2D_SetSourceRect(objFire, 1, 1, 123, 127); }
			else if(fire_count%2==1) { ObjSprite2D_SetSourceRect(objFire, 129, 1, 255, 127); }
			ObjSprite2D_SetDestRect(objFire, 0.5, -61, 128.5, 61);
			
			ObjRender_SetScaleY(objFire2,fire_scale2*(width/32));
			ObjRender_SetPosition(objFire2,ObjMove_GetX(objHitbox),ObjRender_GetY(objHitbox),0);
			ObjRender_SetAngleZ(objFire2,ObjStLaser_GetAngle(objHitbox));
			if(fire_count%2==0) { ObjSprite2D_SetSourceRect(objFire2, 1, 129, 123, 255); }
			else if(fire_count%2==1) { ObjSprite2D_SetSourceRect(objFire2, 129, 129, 255, 255); }
			ObjSprite2D_SetDestRect(objFire2, 0.5, -61, 128.5, 61);
			
			if(Obj_IsDeleted(objHitbox)) {
				Obj_Delete(objLaser1);
				Obj_Delete(objLaser2);
				Obj_Delete(objDetail);
				Obj_Delete(objFire);
				Obj_Delete(objFire2);
			}
			
			width-=(maxwidth+2)/30;
			fire_count+=0.5;
			detail_count+=12;
			yield;
		}
		Obj_Delete(objLaser1);
		Obj_Delete(objLaser2);
		Obj_Delete(objDetail);
		Obj_Delete(objFire);
		Obj_Delete(objFire2);
	}
}