#include"./lib/lib_shot/shot_const.txt"
#include"./lib/lib_sound/_PathSound.txt"
#include"./lib/lib_img/_PathImage.txt"
#include"./function.txt"

let BossObj;
let BossObjX = 0;
let BossObjY = 0;

let BossAlpha = 255;
let hitbox = [64,54];
let imgBossObj 	= bossSprite;

let bossHitbox = true;
let damage = 0;
let life = 3500;
let alive = true;

let objScene = GetEnemyBossSceneObjectID();

@Initialize 
{
	SetAutoDeleteObject	(true);
	BossObj = ObjEnemy_Create	(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist				(BossObj);
	ObjRender_SetPosition		(BossObj,320,120,0);
	mainTask;
} 

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(life);
	}
}

@MainLoop 
{
	ObjEnemy_SetDamageRate	(BossObj,damage,damage);
	ObjRender_SetAlpha		(BossObj,BossAlpha);
	BossObjX = ObjMove_GetX	(BossObj);
	BossObjY = ObjMove_GetY	(BossObj);
	if(bossHitbox == true)
	{
		ObjEnemy_SetIntersectionCircleToShot(BossObj,BossObjX,BossObjY,hitbox[0]/2);
		ObjEnemy_SetIntersectionCircleToPlayer(BossObj,BossObjX,BossObjY,hitbox[1]/2);
	}
	if(ObjEnemy_GetInfo(BossObj, INFO_LIFE) > 0){alive = true;}
	if(ObjEnemy_GetInfo(BossObj, INFO_LIFE) <= 0){alive = false;}
	yield;
} 

@Finalize 
{ 
} 

task mainTask
{
	spriteIdle(BossObj,GetCommonData("bgModeTime",0),imgBossObj,1);
	SetCommonData("bgMode",2);
	loop(GetCommonData("bgModeTime",0)){yield;}
	enemyMarker(BossObj);
	ObjEnemyBossScene_SetSpellTimer(objScene,3600);
	spawnSpectre;
	TEnd;
}

task magicCircle
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture			(obj,sfxMagicCircle);
	ObjSprite2D_SetSourceRect	(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter	(obj);
	ObjRender_SetColor			(obj,255,120,60);
	ObjRender_SetBlendType		(obj,BLEND_ADD_ARGB);
	let c = 0.5;
	let ang = rand(0,360);
	visibility;
	task visibility
	{
		let alpha = 0;
		while(alive == true)
		{
			if(BossAlpha > 0 && alpha < 240){alpha += 4;}
			if(BossAlpha <= 0 && alpha > 0){alpha -= 4;}
			ObjRender_SetAlpha(obj,alpha);
			yield;
		}
		while(alpha > 0)
		{
			alpha -= 4;
			ObjRender_SetAlpha(obj,alpha);
		}
		Obj_Delete(obj);
	}
	let mm = 1;
	while(!Obj_IsDeleted(obj))
	{
		loop(60)
		{
			c += 1/60*mm;
			ObjRender_SetScaleXYZ	(obj,(128/512)*(0.8+c*0.2/0.5),128/512*(0.8+c*0.2/0.5),1);
			ObjRender_SetAngleZ		(obj,ang);
			ObjRender_SetPosition	(obj,BossObjX,BossObjY,0);
			ang += 6 *c;
			yield;
		}
		mm *= -1;
	}
}

task TEnd
{
	while(alive == true){yield;}
	SetCommonData("autoSnap",true);
	bossHitbox = false;
	damage = 0;
	let ang = -(atan2(BossObjY-120,BossObjX-320))-90;
	let spd = GetDistance(320,120,BossObjX,BossObjY)/60;
	let sp = spd;
	let r = sp * 120;
	spriteIdle(BossObj,120,imgBossObj,1);
	if(BossObjX + r * sin(ang) < BossObjX-16)	{spriteHold(BossObj,120,imgBossObj,0,1);} // Going Left
	if(BossObjX + r * sin(ang) > BossObjX+16)	{spriteHold(BossObj,120,imgBossObj,1,1);} // Going Right
	let c = 0;
	loop(120)
	{
		c += 1/180;
		if(BossAlpha < 255){BossAlpha += 255/60;}
		DeleteShotInCircle(TYPE_SHOT,TYPE_FADE,BossObjX,BossObjY,1280 * c);
		ObjMove_SetDestAtSpeed(BossObj,BossObjX+r*sin(ang),BossObjY+r*cos(ang),sp);
		sp -= spd/120;
		yield;
	}
	spriteIdle(BossObj,60,imgBossObj,1);
	loop(60)
	{
		c += 1/180;
		if(BossAlpha < 255){BossAlpha += 255/60;}
		DeleteShotInCircle(TYPE_SHOT,TYPE_FADE,BossObjX,BossObjY,1280 * c);
		yield;
	}
	Obj_Delete(BossObj);
	CloseScript(GetOwnScriptID());
}

task move(x,y,time)
{
	let ang = -(atan2(BossObjY-y,BossObjX-x))-90;
	let spd = GetDistance(x,y,BossObjX,BossObjY)/(time/2);
	let sp = spd;
	let r = sp * time;
	if(BossObjX + r * sin(ang) < BossObjX && alive == true)	{spriteHold(BossObj,time,imgBossObj,0,1);} // Going Left
	if(BossObjX + r * sin(ang) >= BossObjX && alive == true){spriteHold(BossObj,time,imgBossObj,1,1);} // Going Right
	loop(time)
	{
		if(alive == true){ObjMove_SetDestAtSpeed(BossObj,BossObjX+r*sin(ang),BossObjY+r*cos(ang),sp);}
		sp -= spd/time;
		yield;
	}
	ObjMove_SetSpeed(BossObj,0);
}

task swingMove(x,y)
{
	let r = [0,0];
	let ang = [0,0];
	if(BossObjX > 320)
	{
		if(alive == true){spriteHold(BossObj,180,imgBossObj,0,1);}
		ang[0] = -(atan2(y-BossObjY,x-BossObjX))-90;
		r[0] = GetDistance(x,y,BossObjX,BossObjY);
		ang[1] = -(atan2(y-90,x-200))-90;
		r[1] = GetDistance(x,y,200,150);
	}
	if(BossObjX < 320)
	{
		if(alive == true){spriteHold(BossObj,180,imgBossObj,1,1);}
		ang[0] = -(atan2(y-BossObjY,x-BossObjX))-90;
		r[0] = GetDistance(x,y,BossObjX,BossObjY);
		ang[1] = -(atan2(y-90,x-440))-90;
		r[1] = GetDistance(x,y,440,150);
	}
	let angDif = ang[1]-ang[0];
	let rDif = r[1]-r[0];
	loop(120)
	{
		ang[0] = ang[0] + angDif/120;
		r[0] = r[0] + rDif/120;
		if(alive == true){ObjRender_SetPosition(BossObj,x+r[0]*sin(ang[0]),y+r[0]*cos(ang[0]),0);}
		yield;
	}
}

task spawnSpectre
{
	let wave = 1;
	while(alive==true)
	{
		spriteIdle(BossObj,150,imgBossObj,1);loop(60){yield;}
		spectreFormation(-1);loop(45){yield;}
		loop(15){if(alive == true){BossAlpha -= 255/15};yield;}
		bossHitbox = false;
		move(140,60,120);loop(120){yield;}
		swingMove(440,0);
		spectreFormation2(1);loop(165){yield;}
		loop(15){if(alive == true){BossAlpha += 255/15};yield;}
		bossHitbox = true;
		spriteIdle(BossObj,150,imgBossObj,1);loop(60){yield;}
		move(320,120,60);
		if(wave > 1){spectreFormation3(-1);}loop(60){yield;}
		spriteIdle(BossObj,60,imgBossObj,1);loop(60){yield;}
		if(damage <= 0){damage = 65;magicCircle;}
		spriteIdle(BossObj,150,imgBossObj,1);loop(60){yield;}
		spectreFormation(1);loop(50){yield;}
		loop(15){if(alive == true){BossAlpha -= 255/15};yield;}
		bossHitbox = false;
		move(500,60,120);loop(120){yield;}
		swingMove(200,0);
		spectreFormation2(-1);loop(165){yield;}
		loop(15){if(alive == true){BossAlpha += 255/15};yield;}
		bossHitbox = true;
		spriteIdle(BossObj,150,imgBossObj,1);loop(60){yield;}
		move(320,120,60);
		if(wave > 1){spectreFormation3(1);}loop(60){yield;}
		spriteIdle(BossObj,60,imgBossObj,1);loop(60){yield;}
		wave ++;
	}
	
	task spectreFormation(m)
	{
		if(alive == true){playSE(seCharge0,80);}
		let ang = rand(0,360);
		let r = 0;
		let y = 32;
		loop(2)
		{
			let aa = 0;
			let sp = 0.9;
			loop(3)
			{
				y -= 64/30;
				r += 32/6;
				if(alive == true){spectre(BossObjX+r*1.2*sin(ang+aa),BossObjY+r*0.2*cos(ang+aa)+y,sp,ang,120);}
				ang += 12*m;
				ang = ang%360;
				aa += 120*m;
				sp += 0.3;
				loop(2){yield;}
			}
		}
		loop(3)
		{
			let aa = 0;
			let sp = 0.9;
			loop(3)
			{
				y -= 64/30;
				r -= 16/9;
				if(alive == true){spectre(BossObjX+r*1.2*sin(ang+aa),BossObjY+r*0.2*cos(ang+aa)+y,sp,ang,120);}
				ang += 30*m;
				ang = ang%360;
				aa += 120*m;
				sp += 0.3;
				loop(2){yield;}
			}
		}
		loop(3)
		{
			let aa = 0;
			let sp = 0.9;
			loop(3)
			{
				y -= 64/30;
				r += 16/9;
				if(alive == true){spectre(BossObjX+r*1.2*sin(ang+aa),BossObjY+r*0.2*cos(ang+aa)+y,sp,ang,120);}
				ang += 30*m;
				ang = ang%360;
				aa += 120*m;
				sp += 0.3;
				loop(2){yield;}
			}
		}
		loop(2)
		{
			let aa = 0;
			let sp = 0.9;
			loop(3)
			{
				y -= 64/30;
				r -= 32/6;
				if(alive == true){spectre(BossObjX+r*1.2*sin(ang+aa),BossObjY+r*0.2*cos(ang+aa)+y,sp,ang,120);}
				ang += 12*m;
				ang = ang%360;
				aa += 120*m;
				sp += 0.3;
				loop(2){yield;}
			}
		}
		ang = rand(0,360);
		if(alive == true){playSE(seShot2,80);}
		let d = 180;
		let pos = [BossObjX,BossObjY];
		loop(6)
		{
			if(alive == true)
			{
				createShotB2flower(pos[0],pos[1],1.2,ang,SMALL_YELLOW,d,m);
				createShotB2flower(pos[0],pos[1],0.9,ang+20,SMALL_YELLOW,d,m);
				createShotB2flower(pos[0],pos[1],0.9,ang-20,SMALL_YELLOW,d,m);
			}
			ang += 60*m;
			loop(5){yield;}
			d -= 5;
		}
	}

	task spectre(x,y,s,a,d)
	{
		a = (-a)%360;
		let obj = ObjEnemy_Create	(OBJ_ENEMY);
		ObjEnemy_Regist				(obj);
		ObjRender_SetPosition		(obj,x,y,0);
		ObjEnemy_SetLife			(obj,50);
		spriteIdle(obj,d,imgBossObj,0.5);
		let pos = [0,0,0];
		let alpha = 0;
		existence;
		while(alpha < 255 && alive == true)
		{
			alpha += 255/15;
			ObjRender_SetAlpha		(obj,alpha);
			yield;
		}
		loop(d-15){yield;}
		if(a > 90 && a < 270)	{spriteHold(obj,480,imgBossObj,0,0.5);}
		else					{spriteHold(obj,480,imgBossObj,1,0.5);}
		let objB2 = CreateShotB2(x,y,s*cos(a),s*sin(a),0,0.01,s*cos(a),s+2.4,0,0);
		ObjRender_SetAlpha				(objB2,0);
		ObjShot_SetIntersectionEnable	(objB2,false);
		task existence
		{
			while(ObjEnemy_GetInfo(obj,INFO_LIFE) > 0){if(alive == false){ObjEnemy_SetLife(obj,0);}yield;}
			if(pos[0] > 0 && pos[0] < 640 && pos[1] > 0 && pos[1] < 480)
			{
				charge(sfxGlow,BLEND_ADD_ARGB,180,120,60,128,pos[0],pos[1],60,120,0,pos[2]);
				if(alive == true)
				{
					playSE(seEnemyDeath0,35);
					createShotA2(pos[0],pos[1],0,90+rand(0,15),0.02,1.2,FIRE_ORANGE,60,BLEND_ADD_ARGB);
					createShotA2(pos[0],pos[1],0,90+rand(0,-15),0.02,1.2,FIRE_ORANGE,60,BLEND_ADD_ARGB);
				}
			}
			while(alpha > 0)
			{
				if(alive == false){alpha -= 255/30;}
				if(alive == true){alpha -= 255/5;}
				ObjRender_SetAlpha(obj,alpha);
				yield;
			}
			Obj_Delete(obj);
		}
		
		let c = 0;
		while(!Obj_IsDeleted(objB2))
		{
			c++;
			pos = [ObjMove_GetX(objB2),ObjMove_GetY(objB2),ObjMove_GetAngle(objB2)];
			if(c%30 == 0 && alive == true && pos[1] < 470 && pos [1] > 10)
			{
				playSE(seShot0,15);
				createShotA2(pos[0],pos[1],0,pos[2]-15,0.01,1.2,DOT_YELLOW,60,BLEND_ALPHA);
				createShotA2(pos[0],pos[1],0,pos[2]+15,0.01,1.2,DOT_YELLOW,60,BLEND_ALPHA);
			}
			let dis = GetDistance(pos[0],pos[1],GetPlayerX,GetPlayerY);
			if(dis <= 16)
			{
				ObjEnemy_SetIntersectionCircleToPlayer	(obj,pos[0],pos[1],8);
				ObjEnemy_SetIntersectionCircleToPlayer	(BossObj,pos[0],pos[1],8);
			}
			ObjEnemy_SetIntersectionCircleToShot	(obj,pos[0],pos[1],8);
			ObjEnemy_SetIntersectionCircleToShot	(BossObj,pos[0],pos[1],8);
			ObjRender_SetPosition					(obj,pos[0],pos[1],0);
			yield;
			if(Obj_IsDeleted(obj) || ObjEnemy_GetInfo(obj,INFO_LIFE) < 0){Obj_Delete(objB2);}
		}
	}
	
	task spectreFormation2(m)
	{
		let ang = rand(0,360);
		let r = 240;
		while(r > 60)
		{
			r -= 12;
			let aa = ang;
			loop(3)
			{
				if(alive == true)
				{
					spectre2(BossObjX+r*sin(aa+60),BossObjY+r*cos(aa+60),r/12*5,aa+60,30);
					spectre2(BossObjX+r*sin(aa),BossObjY+r*cos(aa),r/12*3,aa,30);
				}
				aa += 120;
			}
			loop(10){yield;}
			ang += 48*m;
		}
	}
	
	task spectre2(x,y,rr,a,time)
	{
		let obj = ObjEnemy_Create	(OBJ_ENEMY);
		ObjEnemy_Regist				(obj);
		ObjRender_SetPosition		(obj,x,y,0);
		ObjRender_SetColor			(obj,180,180,180);
		moveS(BossObjX+rr*sin(a),BossObjY+rr*cos(a),time);
		let alpha = 0;
		loop(time)
		{	
			alpha += 255/time;
			ObjRender_SetAlpha	(obj,alpha);
			yield;
			if(alive == false){break;}
		}
		task moveS(x,y,time)
		{
			let pos = [ObjMove_GetX(obj),ObjMove_GetY(obj)];
			let ang = -(atan2(pos[1]-y,pos[0]-x))-90;
			let spd = GetDistance(x,y,pos[0],pos[1])/(time/2);
			let sp = spd;
			let r = sp * time;
			if(pos[0] + r * sin(ang) < pos[0])	{spriteHold(obj,time,imgBossObj,0,0.5);} // Going Left
			if(pos[0] + r * sin(ang) >= pos[0])	{spriteHold(obj,time,imgBossObj,1,0.5);} // Going Right
			loop(time)
			{
				ObjMove_SetDestAtSpeed(obj,pos[0]+r*sin(ang),pos[1]+r*cos(ang),sp);
				sp -= spd/time;
				yield;
			}
			ObjMove_SetSpeed(obj,0);
		}
		spriteIdle(obj,30,imgBossObj,0.5);
		while(alpha > 0)
		{	
			alpha -= 255/30;
			ObjRender_SetAlpha	(obj,alpha);
			yield;
		}
		Obj_Delete(obj);
	}
	
	task spectreFormation3(m)
	{
		let ang = rand(0,360);
		if(alive == true)
		{
			loop(12)
			{
				spectre3(BossObjX+32*sin(ang),BossObjY+32*cos(ang),1.2,ang,60,240,-m);
				spectre3(BossObjX+16*sin(ang),BossObjY+16*cos(ang),0.9,ang+10,60,240,m);
				ang += 30;
			}
		}
	}
	
	task spectre3(x,y,s,a,d,time,m)
	{
		a = (-a)%360;
		let obj = ObjEnemy_Create	(OBJ_ENEMY);
		ObjEnemy_Regist				(obj);
		ObjRender_SetPosition		(obj,x,y,0);
		ObjEnemy_SetLife			(obj,50);
		spriteIdle(obj,d,imgBossObj,0.5);
		let pos = [x,y,a];
		let alpha = 0;
		existence;
		while(alpha < 255 && ObjEnemy_GetInfo(obj,INFO_LIFE) > 0)
		{
			alpha += 255/15;
			ObjRender_SetAlpha		(obj,alpha);
			yield;
		}
		loop(d-15){yield;}
		if(m == -1)
		{
			if(a > 90 && a < 270)	{spriteHold(obj,time,imgBossObj,0,0.5);}
			else					{spriteHold(obj,time,imgBossObj,1,0.5);}
		}
		if(m == 1)
		{
			if(a > 90 && a < 270)	{spriteHold(obj,time,imgBossObj,1,0.5);}
			else					{spriteHold(obj,time,imgBossObj,0,0.5);}
		}
		let objA2 = CreateShotA2(x,y,s,a,-s/time,0,0,0);
		ObjRender_SetAlpha				(objA2,0);
		ObjShot_SetIntersectionEnable	(objA2,false);
		
		task existence
		{
			while(ObjEnemy_GetInfo(obj,INFO_LIFE) > 0){if(alive == false){ObjEnemy_SetLife(obj,0);}yield;}
			if(pos[0] > 0 && pos[0] < 640 && pos[1] > 0 && pos[1] < 480)
			{
				charge(sfxGlow,BLEND_ADD_ARGB,180,120,60,128,pos[0],pos[1],60,120,0,pos[2]);
				if(alive == true)
				{
					playSE(seEnemyDeath0,35);
					createShotA2(pos[0],pos[1],0,90+rand(0,15),0.02,1.2,FIRE_ORANGE,60,BLEND_ADD_ARGB);
					createShotA2(pos[0],pos[1],0,90+rand(0,-15),0.02,1.2,FIRE_ORANGE,60,BLEND_ADD_ARGB);
				}
			}
			while(alpha > 0)
			{
				if(alive == false){alpha -= 255/30;}
				if(alive == true){alpha -= 255/5;}
				ObjRender_SetAlpha(obj,alpha);
				yield;
			}
			Obj_Delete(obj);
		}
		let c = 0;
		let cc = 1;
		
		
		while(!Obj_IsDeleted(objA2))
		{
			c++;
			cc -= 1/time;
			pos = [ObjMove_GetX(objA2),ObjMove_GetY(objA2),ObjMove_GetAngle(objA2)];
			if(c%60 == 0 && alive == true && pos[1] < 470 && pos [1] > 10)
			{
				playSE(seShot1,60);
				createShotA2(pos[0],pos[1],1.8,pos[2],-0.02,0.6,LARGE_ORANGE,60,BLEND_ALPHA);
			}
			let dis = GetDistance(pos[0],pos[1],GetPlayerX,GetPlayerY);
			if(dis <= 16)
			{
				ObjEnemy_SetIntersectionCircleToPlayer	(obj,pos[0],pos[1],8);
				ObjEnemy_SetIntersectionCircleToPlayer	(BossObj,pos[0],pos[1],8);
			}
			ObjEnemy_SetIntersectionCircleToShot	(obj,pos[0],pos[1],8);
			ObjEnemy_SetIntersectionCircleToShot	(BossObj,pos[0],pos[1],8);
			ObjRender_SetPosition					(obj,pos[0],pos[1],0);
			ObjMove_SetAngularVelocity				(objA2,m*cc*360/time);
			yield;
			if(Obj_IsDeleted(obj) || ObjEnemy_GetInfo(obj,INFO_LIFE) < 0 || c >= time){Obj_Delete(objA2);}
		}
		Obj_Delete(objA2);
		ObjEnemy_SetLife(obj,0);
	}
}

task createShotA2(x,y,s,ang,acc,maxs,st,d,blend)
{
	let obj = CreateShotA2(x,y,s,ang,acc,maxs,st,0);
	ObjRender_SetBlendType			(obj,blend);
	ObjRender_SetAlpha				(obj,0);
	ObjShot_SetIntersectionEnable	(obj,false);
	let alpha = 0;
	while (alpha < 255 && !Obj_IsDeleted(obj))
	{
		alpha += 255/d;
		ObjRender_SetAlpha(obj,alpha);
		yield;
	}
	ObjShot_SetIntersectionEnable	(obj,true);
}


task createShotB2flower(x,y,s,ang,st,d,m)
{
	let obj = CreateShotB2(x,y,s*cos(ang),s*sin(ang),0,-(s*sin(ang))/d,s*cos(ang),0,st,0);
	ObjRender_SetAlpha				(obj,0);
	ObjShot_SetIntersectionEnable	(obj,false);
	
	if(!Obj_IsDeleted(obj) && alive == true)
	{
		let ag = ang;
		loop(6)
		{
			createShotA1petal(x,y,1.2,ICE_YELLOW,d,ag,8);
			ag += 60;
			ag = ag%360;
		}
		loop(6)
		{
			createShotA1petal(x,y,0.6,ICE_ORANGE,d,ag+36,6);
			ag += 60;
			ag = ag%360;
		}
		Glow(64);
	}
	task Glow(xyz)
	{
		let objGlow = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture			(objGlow,sfxGlow);
		ObjSprite2D_SetSourceRect	(objGlow,0,0,512,512);
		ObjSprite2D_SetDestCenter	(objGlow);
		ObjRender_SetColor			(objGlow,180,120,60);
		ObjRender_SetBlendType		(objGlow,BLEND_ADD_ARGB);
		let alpha = 0;
		while(!Obj_IsDeleted(obj))
		{
			if(alpha < 60){alpha ++;}
			xyz += 128/d;
			ObjRender_SetAlpha(objGlow,alpha);
			ObjRender_SetScaleXYZ(objGlow,xyz/512,xyz/512,1);
			ObjRender_SetPosition(objGlow,ObjMove_GetX(obj),ObjMove_GetY(obj),0);
			yield;
		}
		while(alpha > 0)
		{
			alpha --;
			ObjRender_SetAlpha(objGlow,alpha);
			yield;
		}
	}
	loop(d){yield;}
	if(alive == true && !Obj_IsDeleted(obj)){playSE(seShiny0,60);}
	ObjShot_FadeDelete(obj);
	
	task createShotA1petal(x,y,s,st,d,aa,r)
	{
		let objAlp = CreateShotA1(x,y,s,0,st,0);
		ObjRender_SetAlpha				(objAlp,0);
		ObjShot_SetIntersectionEnable	(objAlp,false);
		let alpha = 0;
		let c = 0;
		loop(d)
		{
			if(c < 1){c += 1/(d-30);}
			if(alpha < 255){alpha += 255/(d-60);if(alpha >= 255){ObjShot_SetIntersectionEnable	(objAlp,true);}}
			ObjRender_SetAlpha(objAlp,alpha);
			let pos = [ObjMove_GetX(obj)+r*c*sin(ObjMove_GetAngle(obj)+aa),ObjMove_GetY(obj)+r*c*cos(ObjMove_GetAngle(obj)+aa)];
			ObjMove_SetPosition(objAlp,pos[0],pos[1]);
			let agg = atan2(ObjMove_GetY(obj)-ObjRender_GetY(objAlp),ObjMove_GetX(obj)-ObjRender_GetX(objAlp))+180;
			ObjMove_SetAngle(objAlp,agg);
			aa += m*(1-c)*10;
			yield;
		}
		if(!Obj_IsDeleted(objAlp) && alive == true)
		{
			let pos = [ObjMove_GetX(objAlp),ObjMove_GetY(objAlp),ObjMove_GetAngle(objAlp)];
			createShotB2(pos[0],pos[1],s*cos(pos[2]),s*sin(pos[2]),0.005*m,0.005,(s+1.2)*m,s+1.2,st,15);
		}
		Obj_Delete(objAlp);
	}
}

task createShotB2(x,y,sx,sy,xspd,yspd,xspdmax,yspdmax,st,d)
{
	let obj = CreateShotB2(x,y,sx,sy,xspd,yspd,xspdmax,yspdmax,st,0);
	ObjRender_SetAlpha				(obj,0);
	ObjShot_SetIntersectionEnable	(obj,false);
	let alpha = 0;
	while (alpha < 255 && !Obj_IsDeleted(obj))
	{
		alpha += 255/d;
		ObjRender_SetAlpha	(obj,alpha);
		yield;
	}
	ObjShot_SetIntersectionEnable	(obj,true);
}