#include "./MS_ShotFunctions.txt"
#include "./MS_Effects.txt"
#include "./MS_Rendering.txt"

function Sun3d(X, Y, scale, scalespeed, borderlimit){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjRender_SetPosition(obj,X,Y,0);
Boundary(obj, borderlimit);
Render(obj);
return(obj);

	task Render(obj){
	let scalecurrent = 0;
	let counter = 0;
	let counter2 = 0;
	let scroll = 0;
	let path2 = GetCurrentScriptDirectory ~ "img/Ingame/Effects/sun.mqo";
	let obj2 = ObjMesh_Create();

	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	ObjMesh_SetCoordinate2D(obj2, true);
	ObjMesh_Load(obj2, path2);
	Obj_SetRenderPriorityI(obj2, 45);
	ObjRender_SetPosition(obj2, X, Y, 0);
	ObjRender_SetAngleX(obj2, 0);
	ObjRender_SetScaleXYZ(obj2, scale, scale, scale);
	
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/sunglow.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	Obj_SetRenderPriorityI(obj, 46);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);	
	ObjRender_SetAlpha(obj, 25);
	ObjRender_SetScaleXYZ(obj, scale*4, scale*4, scale*4);
	ObjRender_SetColor(obj, 255, 255, 0);
	
	let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj3, GetCurrentScriptDirectory ~ "img/Ingame/Effects/nuclear2.png");
	ObjSprite2D_SetSourceRect(obj3,0,0,256,256);
	ObjRender_SetScaleXYZ(obj3,1,1,0);
	Obj_SetRenderPriorityI(obj3, 46);
	ObjSprite2D_SetDestCenter(obj3);	
	ObjRender_SetBlendType(obj3, BLEND_ADD_ARGB);	
	ObjRender_SetScaleXYZ(obj3, scale*1.1, scale*1.1, scale*1.1);
	ObjRender_SetColor(obj3, 255, 255, 255);
	
		while(!Obj_IsDeleted(obj)){
		scale = Obj_GetValueD(obj, "SunSize", scale);
		scalespeed = Obj_GetValueD(obj, "SunSizeSpeed", scalespeed);
		let ang = ObjMove_GetAngle(obj);
		let spd = ObjMove_GetSpeed(obj);
		ObjRender_SetPosition(obj2, ObjMove_GetX(obj)-30, ObjMove_GetY(obj)-13, 0);
		ObjRender_SetPosition(obj3, ObjMove_GetX(obj), ObjMove_GetY(obj), 0);
		ObjEnemy_SetIntersectionCircleToPlayer(obj, ObjRender_GetX(obj), ObjRender_GetY(obj), scalecurrent*95);
		ObjRender_SetAngleXYZ(obj2, counter*cos(ang+90), counter*sin(ang+90), 0);
		ObjRender_SetAngleXYZ(obj,0,0,counter2/4);
		ObjRender_SetScaleXYZ(obj, scalecurrent*4, scalecurrent*4, scalecurrent*4);
		ObjRender_SetAngleXYZ(obj3,0,0,-counter2);
		ObjRender_SetScaleXYZ(obj3, scalecurrent*1.1, scalecurrent*1.1, scalecurrent*1.1);
		ObjRender_SetScaleXYZ(obj2, scalecurrent, scalecurrent, scalecurrent);
		ObjRender_SetAlpha(obj3, 100*scalecurrent+Obj_GetValueD(obj, "SunIntensity", 0));
		ObjRender_SetAlpha(obj, 25+10*scalecurrent+Obj_GetValueD(obj, "SunIntensity", 0)/2);
		if(scalecurrent<scale){scalecurrent+=scalespeed;}
		if(scalecurrent>scale){scalecurrent-=scalespeed;}
		counter+=spd;
		counter2+=1;
		yield;
		}
		let scalefinal = scalecurrent;
		let scaledivide = scalecurrent/10;
		ascent(i in 0..10){
		ObjRender_SetScaleXYZ(obj, scalefinal*4, scalefinal*4, scalefinal*4);
		ObjRender_SetScaleXYZ(obj2, scalefinal, scalefinal, scalefinal);
		ObjRender_SetScaleXYZ(obj3, scalefinal*1.1, scalefinal*1.1, scalefinal*1.1);
		scalefinal-=scaledivide;
		yield;
		}
		Obj_Delete(obj2);
		Obj_Delete(obj3);
	}
	task Boundary(obj, sca){
		while(!Obj_IsDeleted(obj)){
		if(ObjMove_GetY(obj)<GetStageUp-sca){Obj_Delete(obj);}
		if(ObjMove_GetY(obj)>GetStageDown+sca){Obj_Delete(obj);}
		if(ObjMove_GetX(obj)<GetStageLeft-sca){Obj_Delete(obj);}
		if(ObjMove_GetX(obj)>GetStageRight+sca){Obj_Delete(obj);}
		yield;
		}
	}
}

function Sun3dZ(X, Y, Z, Zspd, scale, scalespeed, borderlimit){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjRender_SetPosition(obj,X,Y,Z);
Boundary(obj, borderlimit);
Render(obj);
return(obj);

	task Render(obj){
	let scalecurrent = 0;
	let counter = 0;
	let counter2 = 0;
	let scroll = 0;
	let switch = 0;
	let path2 = GetCurrentScriptDirectory ~ "img/Ingame/Effects/sun.mqo";
	let obj2 = ObjMesh_Create();

	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	ObjMesh_SetCoordinate2D(obj2, true);
	ObjMesh_Load(obj2, path2);
	Obj_SetRenderPriorityI(obj2, 30);
	ObjRender_SetPosition(obj2, X, Y, Z);
	ObjRender_SetAngleX(obj2, 0);
	ObjRender_SetScaleXYZ(obj2, scale, scale, scale);
	
		while(!Obj_IsDeleted(obj)){
		scale = Obj_GetValueD(obj, "SunSize", scale);
		scalespeed = Obj_GetValueD(obj, "SunSizeSpeed", scalespeed);
		let ang = ObjMove_GetAngle(obj);
		let spd = ObjMove_GetSpeed(obj);
		ObjRender_SetPosition(obj2, ObjMove_GetX(obj)-30, ObjMove_GetY(obj)-13, Z);
		if(Z<scalecurrent*95 && Z>-scalecurrent*95){ObjEnemy_SetIntersectionCircleToPlayer(obj, ObjRender_GetX(obj), ObjRender_GetY(obj), scalecurrent*95);}
		if(Z<scalecurrent*95 && switch == 0){PlaySound(GetCurrentScriptDirectory ~ "./se/woosh.wav", 80); switch++;}
		if(Z>0){Obj_SetRenderPriorityI(obj2, 30);}
		if(Z<0){Obj_SetRenderPriorityI(obj2, 60);}
		ObjRender_SetAngleXYZ(obj2, counter*cos(ang+90), counter*sin(ang+90), 0);
		ObjRender_SetScaleXYZ(obj2, scalecurrent, scalecurrent, scalecurrent);
		if(scalecurrent<scale){scalecurrent+=scalespeed;}
		if(scalecurrent>scale){scalecurrent-=scalespeed;}
		counter+=spd;
		counter2+=1;
		Z-=Zspd;
		yield;
		}
		let scalefinal = scalecurrent;
		let scaledivide = scalecurrent/10;
		ascent(i in 0..10){
		ObjRender_SetScaleXYZ(obj2, scalefinal, scalefinal, scalefinal);
		scalefinal-=scaledivide;
		yield;
		}
		Obj_Delete(obj2);
	}
	task Boundary(obj, sca){
		while(!Obj_IsDeleted(obj)){
		if(ObjMove_GetY(obj)<GetStageUp-sca){Obj_Delete(obj);}
		if(ObjMove_GetY(obj)>GetStageDown+sca){Obj_Delete(obj);}
		if(ObjMove_GetX(obj)<GetStageLeft-sca){Obj_Delete(obj);}
		if(ObjMove_GetX(obj)>GetStageRight+sca){Obj_Delete(obj);}
		yield;
		}
	}
}

function Sun3dExplode(X, Y, scale, scalespeed, borderlimit){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjRender_SetPosition(obj,X,Y,0);
Boundary(obj, borderlimit);
Render(obj);
return(obj);

	task Render(obj){
	let scalecurrent = 0;
	let counter = 0;
	let counter2 = 0;
	let scroll = 0;
	let path2 = GetCurrentScriptDirectory ~ "img/Ingame/Effects/sun.mqo";
	let obj2 = ObjMesh_Create();

	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	ObjMesh_SetCoordinate2D(obj2, true);
	ObjMesh_Load(obj2, path2);
	Obj_SetRenderPriorityI(obj2, 45);
	ObjRender_SetPosition(obj2, X, Y, 0);
	ObjRender_SetAngleX(obj2, 0);
	ObjRender_SetScaleXYZ(obj2, scale, scale, scale);
	
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/sunglow.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	Obj_SetRenderPriorityI(obj, 46);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);	
	ObjRender_SetAlpha(obj, 25);
	ObjRender_SetScaleXYZ(obj, scale*4, scale*4, scale*4);
	ObjRender_SetColor(obj, 255, 255, 0);
	
	let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj3, GetCurrentScriptDirectory ~ "img/Ingame/Effects/nuclear2.png");
	ObjSprite2D_SetSourceRect(obj3,0,0,256,256);
	ObjRender_SetScaleXYZ(obj3,1,1,0);
	Obj_SetRenderPriorityI(obj3, 46);
	ObjSprite2D_SetDestCenter(obj3);	
	ObjRender_SetBlendType(obj3, BLEND_ADD_ARGB);	
	ObjRender_SetScaleXYZ(obj3, scale*1.1, scale*1.1, scale*1.1);
	ObjRender_SetColor(obj3, 255, 255, 255);
	
		while(Obj_GetValueD(obj, "Nova", 0) == 0){
		scale = Obj_GetValueD(obj, "SunSize", scale);
		scalespeed = Obj_GetValueD(obj, "SunSizeSpeed", scalespeed);
		let ang = ObjMove_GetAngle(obj);
		let spd = ObjMove_GetSpeed(obj);
		ObjRender_SetPosition(obj2, ObjMove_GetX(obj)-30, ObjMove_GetY(obj)-13, 0);
		if(Obj_GetValueD(obj, "SunHitbox", true)==true){ObjEnemy_SetIntersectionCircleToPlayer(obj, ObjRender_GetX(obj), ObjRender_GetY(obj), scalecurrent*95);}
		ObjRender_SetPosition(obj3, ObjMove_GetX(obj), ObjMove_GetY(obj), 0);
		ObjRender_SetAngleXYZ(obj2, counter*cos(ang+90), counter*sin(ang+90), 0);
		ObjRender_SetAngleXYZ(obj,0,0,counter2/4);
		ObjRender_SetScaleXYZ(obj, scalecurrent*4, scalecurrent*4, scalecurrent*4);
		ObjRender_SetAngleXYZ(obj3,0,0,-counter2);
		ObjRender_SetScaleXYZ(obj3, scalecurrent*1.1, scalecurrent*1.1, scalecurrent*1.1);
		ObjRender_SetScaleXYZ(obj2, scalecurrent, scalecurrent, scalecurrent);
		ObjRender_SetAlpha(obj3, 100*scalecurrent+Obj_GetValueD(obj, "SunIntensity", 0));
		ObjRender_SetAlpha(obj, 25+10*scalecurrent+Obj_GetValueD(obj, "SunIntensity", 0)/2);
		if(scalecurrent<scale){scalecurrent+=scalespeed;}
		if(scalecurrent>scale){scalecurrent-=scalespeed;}
		counter+=spd;
		counter2+=1;
		yield;
		}
		let scalefinal = scalecurrent;
		let scaledivide = scalecurrent/10;
		ascent(i in 0..255){
		ObjRender_SetAlpha(obj3, 100*scalecurrent+Obj_GetValueD(obj, "SunIntensity", 0)-i*10);
		ObjRender_SetAlpha(obj2, 255-i*10);
		ObjRender_SetAlpha(obj, 25+10*scalecurrent+Obj_GetValueD(obj, "SunIntensity", 0)/2-i*10);
		scalefinal+=0.01;
		yield;
		}
		Obj_Delete(obj);
		Obj_Delete(obj2);
		Obj_Delete(obj3);

	}
	task Boundary(obj, sca){
		while(!Obj_IsDeleted(obj)){
		if(ObjMove_GetY(obj)<GetStageUp-sca){Obj_Delete(obj);}
		if(ObjMove_GetY(obj)>GetStageDown+sca){Obj_Delete(obj);}
		if(ObjMove_GetX(obj)<GetStageLeft-sca){Obj_Delete(obj);}
		if(ObjMove_GetX(obj)>GetStageRight+sca){Obj_Delete(obj);}
		yield;
		}
	}
}

task BreakSun(tar){
	let a = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/breaksun.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 128, 128);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	Obj_SetRenderPriorityI(obj, 69);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);	
	ObjRender_SetAlpha(obj, 0);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar)-28, 0);
	
	Shockwave(1);
	Shockwave(-1);
	
	while(attack){
	ObjRender_SetAlpha(obj, 0+a*7);
	ObjRender_SetAngleXYZ(obj, 0, 0, a/2);
	ObjRender_SetScaleXYZ(obj,GetCommonData("FlareIntensity", 1)+0.5*cos(a*90),GetCommonData("FlareIntensity", 1)+0.5*cos(a*90),0);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar)-28, 0);
	a++;
	yield;
	}
	ascent(i in 0..60){
	ObjRender_SetScaleXYZ(obj, GetCommonData("FlareIntensity", 1)/i,GetCommonData("FlareIntensity", 1)/i, 0);
	ObjRender_SetAlpha(obj, 255-i*7);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar)-28, 0);
	yield;
	}
	Obj_Delete(obj);
	
	task Shockwave(mult){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/breaksun.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 128, 128);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	Obj_SetRenderPriorityI(obj, 69);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);	
	ObjRender_SetAlpha(obj, 255);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar)-28, 0);
		ascent(i in 0..60){
		ObjRender_SetAngleXYZ(obj, 0, 0, i*mult);
		ObjRender_SetScaleXYZ(obj, 1+(i/3*GetCommonData("FlareIntensity", 1)/4), 1+(i/3*GetCommonData("FlareIntensity", 1)/4), 0);
		ObjRender_SetAlpha(obj, 255-i*7);
		ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar)-28, 0);
		yield;
		}
	Obj_Delete(obj);
	}
}

task NuclearCharge(tar){
	let a = 0;
	let b = 0;
	let c = 0;
	let alpha = 10;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/sunglow.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjRender_SetScaleXYZ(obj,2,2,0);
	Obj_SetRenderPriorityI(obj, 50);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);	
	ObjRender_SetAlpha(obj, 5);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);

	
	ascent(j in 0..75){
	ObjRender_SetScaleXYZ(obj,2-a/75,2-a/75,0);
	ObjRender_SetAngleXYZ(obj, 0, 0, a*2);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
	alpha+=10;
	b-=0.005;
	a+=1+b;
	yield;
	}
	alpha=255;
	ascent(i in 0..60){
	ObjRender_SetAngleXYZ(obj, 0, 0, a*2+c*10*c);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
	alpha-=5;
	c+=0.2;
	yield;
	}
	
}

task RocketBooster1(tar){
Booster(0);
Booster(180);
Chargebullet;
	task Booster(off){
		let a = 0;
		let b = 0;
		let x = 256;
		let y = 128;
		let alpha = 0;
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/booster.png");
		ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 128);
		ObjSprite2D_SetDestRect(obj, -64*3, -64, 256-64*3, 64);
		ObjRender_SetScaleXYZ(obj,1,1,0);
		Obj_SetRenderPriorityI(obj, 50);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);	
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
		loop{
		let ang = ObjMove_GetAngle(tar);
		let spd = ObjMove_GetSpeed(tar);
		if(a <= 8) {ObjSprite2D_SetSourceRect(obj,0,0,x,y);}
		if(a >= 8){ObjSprite2D_SetSourceRect(obj,x,0,x*2,y);}
		if(a >= 16){ObjSprite2D_SetSourceRect(obj,x*2,0,x*3,y);}
		if(a >= 24){ObjSprite2D_SetSourceRect(obj,x*3,0,x*4,y);}
		if(a==32){a=0;}
		ObjRender_SetAngleXYZ(obj, 0, 0, ang+64*sin(b*spd/2+off));
		ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
		
		ObjRender_SetAlpha(obj, alpha);
		alpha+=10;
		a++;
		b++;
		if(GetCommonData("BoosterDone", 0)==1){break;}
		yield;
		}
		Obj_Delete(obj);
	}
	
	task Chargebullet{
	let a = 0;
	let alpha = 0;
	let X = 256;
	let Y = 256;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/chargebullet2.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjRender_SetScaleXYZ(obj,0.75,0.75,0);
	Obj_SetRenderPriorityI(obj, 50);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);	
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
	
		loop{
			let ang = ObjMove_GetAngle(tar);
			ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
			ObjRender_SetAngleXYZ(obj, 0, 0, ang);
			ObjRender_SetAlpha(obj, alpha);
			if(a <= 3){ObjSprite2D_SetSourceRect(obj,0,0,X,Y);}
			if(a >= 3){ObjSprite2D_SetSourceRect(obj,X,0,X*2,Y);}
			if(a >= 6){ObjSprite2D_SetSourceRect(obj,X*2,0,X*3,Y);}
			if(a >= 9){ObjSprite2D_SetSourceRect(obj,X*3,0,X*4,Y);}
			if(a >= 12){ObjSprite2D_SetSourceRect(obj,X*4,0,X*5,Y);}
			alpha+=10;
			a++;
			if(a >=15){a=0;}
			if(GetCommonData("BoosterDone", 0)==1){break;}
			yield;
		}
		Obj_Delete(obj);
	}
}

function NuclearLaser(x, y, ang, len, wid, tim, scale, del){
let lasangle = 0;
let base = CreateStraightLaserA1(x, y, ang, len, wid*1.5, tim, BEAM_GRAY, del);
Obj_SetVisible(base, 0);
lasangle = ObjStLaser_GetAngle(base);
Beam(base);
Source;
AngleCheck;
return base;

task AngleCheck{
loop{
lasangle = ObjStLaser_GetAngle(base);
yield;
}
}

task Source{
	let frame = 0;
	let X = 256;
	let Y = 256;
	let scale2 = scale/2;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/source.png");
	Obj_SetRenderPriorityI(obj, 40);
	ObjSprite2D_SetSourceRect(obj,0,0,X,Y);
	ObjRender_SetScaleXYZ(obj, wid/scale, wid/scale, 0);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetAngleZ(obj, lasangle);
	ObjRender_SetPosition(obj, x, y, 0);
	ascent(i in 0..del){
	ObjRender_SetAngleZ(obj, lasangle+frame);
	frame++;
	yield;
	}
	ascent(i in 0..tim){
	ObjRender_SetScaleXYZ(obj, wid/scale, wid/scale, 0);
	ObjRender_SetAngleZ(obj, lasangle+frame);
	if(scale>scale2){scale-=5;}
	frame++;
	yield;
	}
	ascent(i in 0..30){
	ObjRender_SetAngleZ(obj, lasangle+frame);
	ObjRender_SetAlpha(obj, 255-i*20);
	frame++;	
	yield;
	}
	Obj_Delete(obj);
}

task Beam(obj){
	let X = 256;
	let Y = 256;
	let scale = 10;
	let frame = 0;
		
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
		
	ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory ~ "img/Ingame/Effects/beam.png");
	Obj_SetRenderPriorityI(obj2, 40);
	ObjSprite2D_SetSourceRect(obj2,0,0,len,Y);
	ObjRender_SetScaleXYZ(obj2, 1, 0.5, 0);
	ObjSprite2D_SetDestCenter(obj2);	
	ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
	ObjRender_SetAngleZ(obj2, lasangle);
	ObjRender_SetPosition(obj2, ObjMove_GetX(obj)+len/2*cos(lasangle), ObjMove_GetY(obj)+len/2*sin(lasangle), 0);
	ascent(i in 0..del){
	ObjSprite2D_SetSourceRect(obj2,0-frame*20,0,len*2-frame*20,Y);
	ObjRender_SetScaleXYZ(obj2, 1, wid/scale/35, 0);
	frame++;
	yield;
	}
	ascent(i in 0..tim){
	ObjRender_SetScaleXYZ(obj2, 1,  wid/scale/60, 0);
	ObjSprite2D_SetSourceRect(obj2,0-frame*20,0,len*2-frame*20,Y);
	if(scale>1){scale--;}
	frame++;
	yield;
	}
	ascent(i in 0..30){
	ObjSprite2D_SetSourceRect(obj2,0-frame*20,0,len*2-frame*20,Y);
	ObjRender_SetAlpha(obj2, 255-i*20);
	frame++;	
	yield;
	}
	Obj_Delete(obj2);
}
}

task Explosion(x, y, scale){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjRender_SetPosition(obj,x,y,0);
Render(obj);

	task Render(obj){
		let scalecurrent = 0;
			
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/explosion.png");
		Obj_SetRenderPriorityI(obj, 40);
		ObjSprite2D_SetSourceRect(obj,0,0,128,128);
		ObjRender_SetScaleXYZ(obj, 0, 0, 0);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		
		ascent(i in 0..scale*10){
		ObjRender_SetScaleXYZ(obj, scalecurrent, scalecurrent, 0);
		ObjEnemy_SetIntersectionCircleToPlayer(obj, ObjRender_GetX(obj), ObjRender_GetY(obj), scalecurrent*25);
		scalecurrent = i/10;
		}
		wait(40);
		ascent(i in 0..30){
		ObjRender_SetAlpha(obj, 255-i*20);
		yield;
		}
	}
}

task Circle(x, y){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);

	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/circle.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 128, 128);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	Obj_SetRenderPriorityI(obj, 69);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);	
	ObjRender_SetAlpha(obj, 255);
	ObjRender_SetPosition(obj, x, y, 0);
		ascent(i in 0..60){
		ObjRender_SetAngleXYZ(obj, 0, 0, i);
		ObjRender_SetScaleXYZ(obj, 1+i/10, 1+i/10, 0);
		ObjRender_SetAlpha(obj, 255-i*7);
		yield;
		}
	Obj_Delete(obj);
	}
	
function NuclearBall(x, y, scale){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjRender_SetPosition(obj,x,y,0);
Render(obj);
Orbit(obj, -1);
Orbit(obj, 1);
return obj;
	task Orbit(tar, mult){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		
		let angle = 0;
		if(mult == 1){angle = 180;}
		if(mult == -1){angle = 0;}
		
		let scalecurrent = 0;
		let rotate = 0;
			
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/ring.png");
		Obj_SetRenderPriorityI(obj, 60);
		ObjSprite2D_SetSourceRect(obj,0,0,128,128);
		ObjRender_SetScaleXYZ(obj, 0, 0, 0);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetAngleXYZ(obj, 0, 0, 0);
		
		ascent(i in 0..scale*10){
		ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
		ObjRender_SetScaleXYZ(obj, scalecurrent, scalecurrent, 0);
		scalecurrent = i/16;
		ObjRender_SetAngleXYZ(obj, angle+180*cos(rotate*mult), 180*sin(rotate*mult), -rotate);
		rotate++;
		yield;
		}
		while(!Obj_IsDeleted(tar)){
		ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
		ObjRender_SetAngleXYZ(obj, angle+180*cos(rotate*mult), 180*sin(rotate*mult), -rotate);
		rotate++;
		yield;
		}
		ascent(i in 0..scale*20){
		ObjRender_SetScaleXYZ(obj, scalecurrent, scalecurrent, 0);
		scalecurrent+=0.1;
		ObjRender_SetAlpha(obj, 255-i*20);
		rotate++;
		yield;
		}
		Obj_Delete(obj);
	}
	
	task Render(obj){
		let scalecurrent = 0;
		let rotate = 0;
			
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/smallsun.png");
		Obj_SetRenderPriorityI(obj, 60);
		ObjSprite2D_SetSourceRect(obj,0,0,128,128);
		ObjRender_SetScaleXYZ(obj, 0, 0, 0);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		
		ascent(i in 0..scale*10){
		ObjRender_SetScaleXYZ(obj, scalecurrent, scalecurrent, 0);
		scalecurrent = i/25;
		ObjRender_SetAngleXYZ(obj, 0, 0, rotate);
		rotate++;
		yield;
		}
		while(!Obj_IsDeleted(obj)){
		ObjRender_SetAngleXYZ(obj, 0, 0, rotate);
		rotate++;
		yield;
		}
	}
}
	
function NuclearSign(x, y, scale){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
ObjRender_SetPosition(obj,x,y,0);
Render(obj);
Orbit(obj, -1);
Orbit(obj, 1);
return obj;
	task Orbit(tar, mult){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		
		let angle = 0;
		if(mult == 1){angle = 180;}
		if(mult == -1){angle = 0;}
		
		let scalecurrent = 0;
		let rotate = 0;
			
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/orbit.png");
		Obj_SetRenderPriorityI(obj, 60);
		ObjSprite2D_SetSourceRect(obj,0,0,256,256);
		ObjRender_SetScaleXYZ(obj, 0, 0, 0);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetAngleXYZ(obj, 0, 0, 0);
		
		ascent(i in 0..scale*10){
		ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar),0);
		ObjRender_SetScaleXYZ(obj, scalecurrent, scalecurrent, 0);
		scalecurrent = i/16;
		ObjRender_SetAngleXYZ(obj, angle, 0, rotate+angle);
		rotate++;
		yield;
		}
		while(!Obj_IsDeleted(tar)){
		ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar),0);
		ObjRender_SetAngleXYZ(obj, angle+180*cos(rotate*mult), 180*sin(rotate*mult), -rotate);
		rotate++;
		yield;
		}
		Obj_Delete(obj);
	}
	
	task Render(obj){
		let scalecurrent = 0;
		let rotate = 0;
			
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/nuclear.png");
		Obj_SetRenderPriorityI(obj, 60);
		ObjSprite2D_SetSourceRect(obj,0,0,256,256);
		ObjRender_SetScaleXYZ(obj, 0, 0, 0);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		
		ascent(i in 0..scale*10){
		ObjRender_SetScaleXYZ(obj, scalecurrent, scalecurrent, 0);
		scalecurrent = i/25;
		ObjRender_SetAngleXYZ(obj, 0, 0, rotate);
		rotate++;
		yield;
		}
		while(!Obj_IsDeleted(obj)){
		ObjRender_SetAngleXYZ(obj, 0, 0, rotate);
		rotate++;
		yield;
		}
	}
}

task GravityAura(tar){
	loop{
	circ(tar);
	wait(10);
	}
task circ(tar){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);

	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/Effects/circle.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 128, 128);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	Obj_SetRenderPriorityI(obj, 69);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);	
	ObjRender_SetAlpha(obj, 45);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
		ascent(i in 0..30){
		if(Obj_IsDeleted(tar)){break;}
		ObjRender_SetAngleXYZ(obj, 0, 0, i);
		ObjRender_SetScaleXYZ(obj, 2-i/15, 2-i/15, 0);
		//ObjRender_SetAlpha(obj, 122-i*7);
		ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
		yield;
		}
	Obj_Delete(obj);
}
}