#TouhouDanmakufu[Player]
#ScriptVersion[3]	
#ID["TM_Hecatia"]
#Title["Talos' Hecatia Player"]
#Text["3 Shot Types. Press C to switch"]
#Image["./Cutin2.png"]
#ReplayName["Hecatia"]

//---------------------------------------- Version 1.10 ----------------------------------------------//

//-------------------- Here is the basic things you can change ----------------------//
let shot_rate = 1; // Adjust the shot damage rate (Default value is 1)
let bomb_rate = 0.5; // Adjust the bomb damage rate (Default value is 0.5)
let bombpiece_rate = 0.05; // Adjust the bonus bomb damage which increase from bomb pieces (Default value is 0.05)
//-----------------------------------------------------------------------------------//

//------- Here is not (unless you're confident in your danmakufu skill xD) ----------//

let objPlayer = GetPlayerObjectID();
let objSlowShot = ID_INVALID;
let current = GetCurrentScriptDirectory();
let enemy;
let focus = false;
let type = 0; // Starting Form
let vx = 4.25; // Unfocused Speed
let vy = 2; // Focus Speed
let arr1 = [];
let arr2 = [];
let arr3 = [];
let arr4 = [];
let startangle = 0; // for Spell 3
let sound = [];
@Initialize
{
	SetPlayerSpeed(vx, vy);
	SetPlayerClip(12,12,GetStgFrameWidth-12,GetStgFrameHeight-12);
	SetPlayerDownStateFrame(60); // How much time it take to revive the player
	SetPlayerRebirthFrame(20); // Possible max time for death bombing
	let path = current ~ "HecatiaShotData.txt";
	LoadPlayerShotData(path); //???????

	ObjPlayer_AddIntersectionCircleA1(objPlayer, 0, 0, 1.5, 22.2); // 1.5 is player's hitbox, 22.2 is player's graze hitbox
	LoadSound(GetCurrentScriptDirectory~"graze.wav");
	LoadSound(GetCurrentScriptDirectory~"se_shot.wav");
	LoadSound(GetCurrentScriptDirectory~"Eff2.wav");
	LoadSound(GetCurrentScriptDirectory~"Shot6.wav");
	LoadSound(GetCurrentScriptDirectory~"Shot7.wav");
	LoadSound(GetCurrentScriptDirectory~"Shot8.wav");
	LoadSound(GetCurrentScriptDirectory~"Shot9.wav");
	LoadSound(GetCurrentScriptDirectory~"Laser7.wav");
	LoadSound(GetCurrentScriptDirectory~"Charge1.wav");
	LoadSound(GetCurrentScriptDirectory~"Charge2.wav");
	LoadSound(GetCurrentScriptDirectory~"SpellCard.wav");
	LoadSound(current~"se_pldead.wav");
	TImage();
	TShot();
	TMagicCircle();
	HitBox;
	Orb;
	SetUpSound();
}

@MainLoop
{
	enemy = GetAllEnemyID;
	yield;
}

@FinalizeShot
{
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_SPELL)
	{
		//????????
		let spell = GetPlayerSpell();
		alternative(type)
		case(0)
		{
			if(Obj_IsVisible(arr1[0]))
			{
				TSpell1;
				SetScriptResult(true);
			}
			else{SetScriptResult(false);}
		}
		case(1)
		{
			if(Obj_IsVisible(arr2[0]))
			{
				TSpell2;
				SetScriptResult(true);
			}
			else{SetScriptResult(false);}
		}
		case(2)
		{
			if(Obj_IsVisible(arr3[0]))
			{
				startangle = rand(0,60);
				TSpell3;
				SetScriptResult(true);
			}
			else{SetScriptResult(false);}
		}
	}
	case(EV_HIT)
	{
		PlaySE(GetCurrentScriptDirectory~"se_pldead.wav");
		TExplosion();
	}
	case(EV_PLAYER_REBIRTH)
	{
		//??
		SetPlayerSpell(3);
		SetPlayerInvincibilityFrame(180);
	}
		case(EV_GRAZE){
			PlaySE(GetCurrentScriptDirectory~"graze.wav");
		}
	case(EV_GET_ITEM)
	{
		let itemType = GetEventArgument(0);
	}
	
}

function SDF // spell damage factor
{
	return bomb_rate+GetPlayerSpell()*bombpiece_rate;
}

task TImage
{
	let f = 0;
	let f2 = 0;
	let px = 32;
	let py = 48;
	Obj_SetRenderPriorityI(objPlayer,30);
	loop
	{
		if(type==0)
		{
			let path = GetCurrentScriptDirectory() ~ "HecO.png";
			ObjPrim_SetTexture(objPlayer, path);
		}
		if(type==1)
		{
			let path = GetCurrentScriptDirectory() ~ "HecE.png";
			ObjPrim_SetTexture(objPlayer, path);
		}
		if(type==2)
		{
			let path = GetCurrentScriptDirectory() ~ "HecM.png";
			ObjPrim_SetTexture(objPlayer, path);
		}
		if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_LEFT) == KEY_HOLD)
		{
			if(f2<1){ObjSprite2D_SetSourceRect(objPlayer, 0, py, px, py*2);}
			if(f2>=1&& f2<=2){ObjSprite2D_SetSourceRect(objPlayer, px, py, px*2, py*2);}
			if(f2>=2 && f2<=3){ObjSprite2D_SetSourceRect(objPlayer, px*2, py, px*3, py*2);}
			if(f2>=3 && f2<=4){ObjSprite2D_SetSourceRect(objPlayer, px*3, py, px*4, py*2);}
			if(f2>=4 && f2<=10){ObjSprite2D_SetSourceRect(objPlayer, px*4, py, px*5, py*2);}
			if(f2>=10&& f2<=16){ObjSprite2D_SetSourceRect(objPlayer, px*5, py, px*6, py*2);}
			if(f2>=16 && f2<=22){ObjSprite2D_SetSourceRect(objPlayer, px*6, py, px*7, py*2);}
			if(f2>=22){ObjSprite2D_SetSourceRect(objPlayer, px*7,py, px*8, py*2);}
			if(f2>=28){f2=12;}
			f2++;
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_RIGHT) == KEY_HOLD)
		{
			if(f2<1){ObjSprite2D_SetSourceRect(objPlayer, 0, py*2, px, py*3);}
			if(f2>=1&& f2<=2){ObjSprite2D_SetSourceRect(objPlayer, px, py*2, px*2, py*3);}
			if(f2>=2 && f2<=3){ObjSprite2D_SetSourceRect(objPlayer, px*2, py*2, px*3, py*3);}
			if(f2>=3 && f2<=4){ObjSprite2D_SetSourceRect(objPlayer, px*3, py*2, px*4, py*3);}
			if(f2>=4 && f2<=10){ObjSprite2D_SetSourceRect(objPlayer, px*4, py*2, px*5, py*3);}
			if(f2>=10 && f2<=16){ObjSprite2D_SetSourceRect(objPlayer, px*5, py*2, px*6, py*3);}
			if(f2>=16 && f2<=22){ObjSprite2D_SetSourceRect(objPlayer, px*6, py*2, px*7, py*3);}
			if(f2>=22){ObjSprite2D_SetSourceRect(objPlayer, px*7, py*2, px*8, py*3);}
			if(f2>=28){f2=12;}
			f2++;
		}
		else
		{
			if(f<6){ObjSprite2D_SetSourceRect(objPlayer, 0, 1, px, 48);}
			if(f>=6&& f<=12){ObjSprite2D_SetSourceRect(objPlayer, px, 1, px*2, 48);}
			if(f>=12 && f<=18){ObjSprite2D_SetSourceRect(objPlayer, px*2, 1, px*3, 48);}
			if(f>=18 && f<=24){ObjSprite2D_SetSourceRect(objPlayer, px*3, 1, px*4, 48);}
			if(f>=24 && f<=30){ObjSprite2D_SetSourceRect(objPlayer, px*4, 1, px*5, 48);}
			if(f>=30 && f<=36){ObjSprite2D_SetSourceRect(objPlayer, px*5, 1, px*6, 48);}
			if(f>=36 && f<=42){ObjSprite2D_SetSourceRect(objPlayer, px*6, 1, px*7, 48);}
			if(f>=42){ObjSprite2D_SetSourceRect(objPlayer, px*7, 1, px*8, 48);}
			if(f>=48){f=0;}
			f++;
			f2 = 0;
		}
		ObjSprite2D_SetDestCenter(objPlayer);
		yield;
	}

}

task Orb
{
	ascent(i in 0..1) // Generate Orbs
	{
		let obj= CreateTool(0);
		arr1 = arr1 ~ [obj];
	}
	ascent(i in 0..1) // Generate Orbs
	{
		let obj= CreateTool(1);
		arr2 = arr2 ~ [obj];
	}
	ascent(i in 0..2) // Generate Orbs
	{
		let obj= CreateTool(2);
		arr3 = arr3 ~ [obj];
	}

		Orb1(arr1[0],0);
		Orb2(arr2[0],0);
		Orb3(arr3[0],0);
		Orb3(arr3[1],1);
		task Orb1(obj,num)
		{
			let count = 0;
			let r = 40;
			let angle = 0;
			while(!Obj_IsDeleted(obj))
			{
				if(GetPlayerState==STATE_DOWN || type!=0 || Obj_GetValueD(obj,"Alive",1)==0){Obj_SetVisible(obj,false);}
				else{Obj_SetVisible(obj,true);}
				ObjRender_SetPosition(obj,GetPlayerX+r*cos(angle),GetPlayerY+r*sin(angle),0);
				angle = count*3;
				Obj_SetValue(arr1[0],"B_Angle",angle);
				count++;
				yield;
			}
		}
		task Orb2(obj,num)
		{
			let count = 0;
			let r = 45;
			let angle = 0;
			while(!Obj_IsDeleted(obj))
			{
				if(GetPlayerState==STATE_DOWN || type!=1 || Obj_GetValueD(obj,"Alive",1)==0){Obj_SetVisible(obj,false);}
				else{Obj_SetVisible(obj,true);}
				ObjRender_SetPosition(obj,GetPlayerX+r*cos(angle),GetPlayerY+r*sin(angle),0);
				angle = count*3;
				count++;
				yield;
			}
		}
		task Orb3(obj,num)
		{
			let count = 0;
			let r = 40;
			let angle = 0;
			while(!Obj_IsDeleted(obj))
			{
				if(GetPlayerState==STATE_DOWN || type!=2 || Obj_GetValueD(obj,"Alive",1)==0){Obj_SetVisible(obj,false);}
				else{Obj_SetVisible(obj,true);}
				ObjRender_SetPosition(obj,GetPlayerX+r*cos(angle+num*180),GetPlayerY+r*sin(angle+num*180),0);
				angle = count*3;
				count++;
				yield;
			}
		}
	}
	
function CreateTool(cl)
{
		let obj=ObjPrim_Create(OBJ_SPRITE_2D); 
		let img;
		if(cl==0){img = GetCurrentScriptDirectory~"HecO.png";}
		if(cl==1){img = GetCurrentScriptDirectory~"HecE.png";}
		if(cl==2){img = GetCurrentScriptDirectory~"HecM.png";}
		ObjPrim_SetTexture(obj,img);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetAlpha(obj,160);
		ObjSprite2D_SetSourceRect(obj,222,144,222+34,144+38);
		ObjSprite2D_SetDestCenter(obj);
		return obj;
}

task TShot
{
	let shotCount = -1;
	let bNextShot = false;
	let objShot = ID_INVALID;
	let shotnum = 0;
	LoadSound(GetCurrentScriptDirectory~"Shot9.wav");
	loop
	{
		if(GetKeyState(KEY_C)==KEY_PUSH && GetPlayerState == STATE_NORMAL)
		{
			PlaySE(GetCurrentScriptDirectory~"Shot9.wav");
			type = (type+1)%3;
			if(type==0){TExpan2(GetPlayerObjectID,3,30,128,0,0);}
			if(type==1){TExpan2(GetPlayerObjectID,3,30,0,0,128);}
			if(type==2){TExpan2(GetPlayerObjectID,3,30,128,128,0);}
		}
		if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD || bNextShot==true) && shotCount==-1)
		{
			shotCount = 0;
			bNextShot = false;
		}
		if(GetVirtualKeyState(VK_SHOT)==KEY_HOLD && shotCount>0)
		{
			bNextShot = true;
		}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD && GetPlayerState == STATE_NORMAL && IsPermitPlayerShot)
		{
			focus = true;
		}
		else if(GetPlayerState == STATE_NORMAL && IsPermitPlayerShot)
		{
			focus = false;
			Obj_Delete(objSlowShot);
		}
		
		if(shotCount%4==0 && GetPlayerState==STATE_NORMAL && IsPermitPlayerShot)
		{
				if(type==0)
				{
					PlaySound(0,98,0);
					if(focus==false)
					{
						VanillaBullet(GetPlayerX-10,GetPlayerY,20,260,2,1);
						VanillaBullet(GetPlayerX-9,GetPlayerY,20,265,2,1);
						VanillaBullet(GetPlayerX-8,GetPlayerY,20,270,2,1);
						VanillaBullet(GetPlayerX+8,GetPlayerY,20,270,2,1);
						VanillaBullet(GetPlayerX+9,GetPlayerY,20,275,2,1);
						VanillaBullet(GetPlayerX+10,GetPlayerY,20,280,2,1);
					}
					if(focus==true)
					{
						VanillaBullet(GetPlayerX-10,GetPlayerY,20,262,2,1);
						VanillaBullet(GetPlayerX-9,GetPlayerY,20,266,2,1);
						VanillaBullet(GetPlayerX-8,GetPlayerY,20,270,2,1);
						VanillaBullet(GetPlayerX+8,GetPlayerY,20,270,2,1);
						VanillaBullet(GetPlayerX+9,GetPlayerY,20,274,2,1);
						VanillaBullet(GetPlayerX+10,GetPlayerY,20,278,2,1);
					}
					if(shotnum%2==0 && Obj_IsVisible(arr1[0]))
					{
						if(focus==false)
						{
							OBullet(ObjRender_GetX(arr1[0]),ObjRender_GetY(arr1[0]),7.5,270,12.5,2);
						}
						if(focus==true)
						{
							let p = Obj_GetValueD(arr1[0],"B_Angle",90); // so it still aim straight
							OBullet(ObjRender_GetX(arr1[0]),ObjRender_GetY(arr1[0]),7.5,270-3*cos(p),12.5,2);
						}
					}
					shotnum++;
				}
				if(type==1)
				{
					PlaySound(0,98,0);
					if(focus==false)
					{
						VanillaBullet(GetPlayerX-10,GetPlayerY,20,255,2,1);
						VanillaBullet(GetPlayerX-10,GetPlayerY,20,262.5,2,1);
						VanillaBullet(GetPlayerX-10,GetPlayerY,20,270,2,1);
						VanillaBullet(GetPlayerX+10,GetPlayerY,20,270,2,1);
						VanillaBullet(GetPlayerX+10,GetPlayerY,20,277.5,2,1);
						VanillaBullet(GetPlayerX+10,GetPlayerY,20,285,2,1);
					}
					if(focus==true)
					{
						VanillaBullet(GetPlayerX-10,GetPlayerY,20,258,2,1);
						VanillaBullet(GetPlayerX-9,GetPlayerY,20,264,2,1);
						VanillaBullet(GetPlayerX-8,GetPlayerY,20,270,2,1);
						VanillaBullet(GetPlayerX+8,GetPlayerY,20,270,2,1);
						VanillaBullet(GetPlayerX+9,GetPlayerY,20,276,2,1);
						VanillaBullet(GetPlayerX+10,GetPlayerY,20,282,2,1);
					}
						ascent(i in 0..5)
						{
							if(Obj_IsVisible(arr2[0]))
							{
								if(GetPlayerInvincibilityFrame==0)
								{
									EBullet(ObjRender_GetX(arr2[0])+10*cos(i*72+shotnum*11),ObjRender_GetY(arr2[0])+10*sin(i*72+shotnum*11),8,i*72+shotnum*11,7.5,2);
								}
								else
								{
									EBullet(ObjRender_GetX(arr2[0])+10*cos(i*72+shotnum*11),ObjRender_GetY(arr2[0])+10*sin(i*72+shotnum*11),8,i*72+shotnum*11,1,2);
								}
							}
						}
					shotnum++;
				}
				if(type==2)
				{
					PlaySound(0,98,0);
					if(focus==false)
					{
						VanillaBullet(GetPlayerX-10,GetPlayerY,20,266,2.1,1);
						VanillaBullet(GetPlayerX-10,GetPlayerY,20,271,2.1,1);
						VanillaBullet(GetPlayerX+10,GetPlayerY,20,269,2.1,1);
						VanillaBullet(GetPlayerX+10,GetPlayerY,20,274,2.1,1);
					}
					if(focus==true)
					{
						VanillaBullet(GetPlayerX-10,GetPlayerY,20,267,2.1,1);
						VanillaBullet(GetPlayerX-9,GetPlayerY,20,271.25,2.1,1);
						VanillaBullet(GetPlayerX+9,GetPlayerY,20,268.75,2.1,1);
						VanillaBullet(GetPlayerX+10,GetPlayerY,20,273,2.1,1);
					}
					if(Obj_IsVisible(arr3[0]))
					{
						MBullet(ObjRender_GetX(arr3[0]),ObjRender_GetY(arr3[0]),7.5,270,3.5,1);
						MBullet(ObjRender_GetX(arr3[1]),ObjRender_GetY(arr3[1]),7.5,270,3.5,1);
					}
					shotnum++;
				}
		}

		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 15)
		{
			shotCount=-1;
		}
		yield;
	}
}

task HitBox{
		let obj=ObjPrim_Create(OBJ_SPRITE_2D); 
		let img = GetCurrentScriptDirectory~"eff2.png";
		let c = 0;
		let alpha = 0;
		ObjPrim_SetTexture(obj,img);
		ObjSprite2D_SetSourceRect(obj,0,16,63,79);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		while(!Obj_IsDeleted(obj)){
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAngleXYZ(obj,0,0,c);
		ObjRender_SetAlpha(obj,alpha);
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD){
			if(alpha<250){alpha+=30;}
		}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_FREE){
		if(alpha>0){alpha-=30;}
		}
		if(GetPlayerState != STATE_NORMAL){alpha=0;}
		c+=3;
		yield;
		}
	}
	
task VanillaBullet(x,y,spd,dir,dmg,pdmg)
{
	let mainobj;
	if(GetPlayerInvincibilityFrame==0){mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg*shot_rate,pdmg,1);}
	else{mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg/2*shot_rate,pdmg,1);}
	Obj_SetVisible(mainobj,false);
	let obj= ObjPrim_Create(OBJ_SPRITE_2D);
	let img;
	let mx = ObjMove_GetX(mainobj);
	let my = ObjMove_GetY(mainobj);
	let finalpos = 0;
	if(type==0){img = GetCurrentScriptDirectory~"HecO.png";}
	if(type==1){img = GetCurrentScriptDirectory~"HecE.png";}
	if(type==2){img = GetCurrentScriptDirectory~"HecM.png";}
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,140,146,180,158);
	ObjSprite2D_SetDestCenter(obj);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetAngleZ(obj,dir);
	ObjRender_SetAlpha(obj,192);
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		ObjRender_SetPosition(obj,ObjMove_GetX(mainobj),ObjMove_GetY(mainobj),0);
		yield;
	}
	ascent(i in 0..5)
	{
		if(i==0){ObjSprite2D_SetSourceRect(obj,108,146,140,158);}
		if(i==1){ObjSprite2D_SetSourceRect(obj,80,146,108,158);}
		if(i==2){ObjSprite2D_SetSourceRect(obj,56,146,76,158);}
		if(i==3){ObjSprite2D_SetSourceRect(obj,16,146,30,158);}
		if(i==4){ObjSprite2D_SetSourceRect(obj,2,146,14,158);}
		loop(2)
		{
			ObjRender_SetPosition(obj,mx+finalpos*cos(dir),my+finalpos*sin(dir),0);
			finalpos+=2;
			yield;
		}
	}
	Obj_Delete(obj);
}

task OBullet(x,y,spd,dir,dmg,pdmg)
{
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg*shot_rate,pdmg,2); // placeholder
	Obj_SetVisible(mainobj,false);
	let obj= ObjPrim_Create(OBJ_SPRITE_2D);
	let img;
	let mx = ObjMove_GetX(mainobj);
	let my = ObjMove_GetY(mainobj);
	let count = 0;
	img = GetCurrentScriptDirectory~"HecO.png";
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,208,32,256);
	ObjSprite2D_SetDestCenter(obj);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetAngleZ(obj,dir+90);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetColor(obj,192,192,192);
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		ObjRender_SetPosition(obj,ObjMove_GetX(mainobj),ObjMove_GetY(mainobj),0);
		ObjSprite2D_SetSourceRect(obj,(truncate(count/4))*32,208,32+(truncate(count/4))*32,256);
		count++;
		count = count%32;
		yield;
	}
	ObjSprite2D_SetSourceRect(obj,0,208,32,256);
	ascent(i in 0..10)
	{
		ObjRender_SetScaleXYZ(obj,1-i/10,1,0);
		ObjRender_SetPosition(obj,mx+i*3*cos(dir),my+i*3*sin(dir),0);
		yield;
	}
	Obj_Delete(obj);
}

task EBullet(x,y,spd,dir,dmg,pdmg)
{
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg*0.625*shot_rate,pdmg,2); // placeholder
	Obj_SetVisible(mainobj,false);
	let obj= ObjPrim_Create(OBJ_SPRITE_2D);
	let img;
	let mx = ObjMove_GetX(mainobj);
	let my = ObjMove_GetY(mainobj);
	let count = 0;
	let rcount = 0;
	img = GetCurrentScriptDirectory~"HecE.png";
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,208,32,256);
	ObjSprite2D_SetDestCenter(obj);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetAngleZ(obj,dir+90);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetColor(obj,128,128,128);
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		ObjRender_SetPosition(obj,ObjMove_GetX(mainobj),ObjMove_GetY(mainobj),0);
		ObjSprite2D_SetSourceRect(obj,(truncate(count/4))*32,208,32+(truncate(count/4))*32,256);
		count++;
		if(rcount==20)
		{
			ObjRender_SetColor(obj,128,128,128);
			if(IsPermitPlayerShot)
			{
				let dummy = CreatePlayerShotA1(ObjMove_GetX(mainobj),ObjMove_GetY(mainobj),spd,dir,dmg*1.5*shot_rate,pdmg,2);
				Obj_SetVisible(dummy,false);
			}
		}
		count = count%16;
		rcount++;
		yield;
	}
	ascent(i in 0..10)
	{
		ObjRender_SetScaleXYZ(obj,1+i/10,1+i/10,0);
		ObjRender_SetColor(obj,160-i*16,160-i*16,160-i*16);
		yield;
	}
	Obj_Delete(obj);
}

task MBullet(x,y,spd,dir,dmg,pdmg)
{
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg*shot_rate,pdmg,1); // placeholder
	Obj_SetVisible(mainobj,false);
	let obj= ObjPrim_Create(OBJ_SPRITE_2D);
	let img;
	let mx = ObjMove_GetX(mainobj);
	let my = ObjMove_GetY(mainobj);
	let mangle = 0;
	let count = 0;
	img = GetCurrentScriptDirectory~"HecM.png";
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,28,162,46,177);
	ObjSprite2D_SetDestCenter(obj);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetAngleZ(obj,dir+90);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetColor(obj,160,160,160);
	if(FindTarget!=-1)
	{
		let h_obj = FindTarget;
		Homing(mainobj,h_obj,5);
	}
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		ObjRender_SetPosition(obj,ObjMove_GetX(mainobj),ObjMove_GetY(mainobj),0);
		yield;
	}
	ObjSprite2D_SetSourceRect(obj,28,162,46,177);
	ascent(i in 0..10)
	{
		ObjRender_SetScaleXYZ(obj,1-i/10,1-i/10,0);
		ObjRender_SetPosition(obj,mx+i*3*cos(mangle),my+i*3*sin(mangle),0);
		yield;
	}
	Obj_Delete(obj);
}

task TSpell1
{
	SetPlayerInvincibilityFrame(180);
	let objManage = GetSpellManageObject();
	let spell = ObjSpell_Create;
	ObjSpell_Regist(spell);
	ObjSpell_SetDamage(spell,10*SDF());
	CallGraphic;
	yield;
	Obj_Delete(objManage);
	task CallGraphic
	{
		//---------------------Graphic Part---------------------//
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		let img=GetCurrentScriptDirectory~"./HecO.png";
		let mx = 0;
		let my = 0;
		let dis = 45;
		let count = 0;
		ObjPrim_SetTexture(obj,img);
		ObjSprite2D_SetSourceRect(obj,222,144,222+34,144+38);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetPosition(obj,ObjRender_GetX(arr1[0]),ObjRender_GetY(arr1[0]),0);
		FadeAllOrb(900);
		PlaySound(3,100,0);
		while(!Obj_IsDeleted(obj) && ObjRender_GetY(obj)>0)
		{
			mx = ObjRender_GetX(obj);
			my = ObjRender_GetY(obj);
			ObjRender_SetY(obj,ObjRender_GetY(obj)-10);
			let enemyarr = GetIntersectionRegistedEnemyID;
			if(length(enemyarr)>0)
			{
				if(GetObjectDistance(enemyarr[0],obj)<dis){break;}
			}
			if(count%2==0){AfterOtherworld;}
			count++;
			yield;
		}
		PlaySound(2,100,0);
		NuclearExplode(0);
		NuclearExplode(1);
		TExpan(mx,my,20,90,255,0,0);
		Obj_Delete(obj);
		task AfterOtherworld
		{
			let obj=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory~"./HecO.png";
			ObjPrim_SetTexture(obj,img);
			ObjSprite2D_SetSourceRect(obj,222,144,222+34,144+38);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
			Obj_SetRenderPriorityI(obj,30);
			ObjRender_SetPosition(obj,mx,my,0);
			ascent(i in 0..20)
			{
				ObjRender_SetScaleXYZ(obj,1-i/20,1-i/20,0);
				ObjRender_SetColor(obj,255-i*255/20,128-i*128/20,128-i*128/20);
				yield;
			}
			Obj_Delete(obj);
		}
		task NuclearExplode(type)
		{
			let nuc=ObjPrim_Create(OBJ_SPRITE_2D);
			let img;
			if(type==0){img=GetCurrentScriptDirectory~"./nuclear1.png";}
			if(type==1){img=GetCurrentScriptDirectory~"./nuclear2.png";}
			let scale = 0;
			ObjPrim_SetTexture(nuc,img);
			ObjSprite2D_SetSourceRect(nuc,0,0,256,256);
			ObjSprite2D_SetDestCenter(nuc);
			if(type==1)
			{
				ObjRender_SetBlendType(nuc,BLEND_ADD_ARGB);
				ObjRender_SetColor(nuc,255,0,0);
			}
			Obj_SetRenderPriorityI(nuc,30);
			ObjRender_SetPosition(nuc,mx,my,0);
			ascent(i in 0..50)
			{
				scale = sin(i*1.5)+type/10;
				ObjRender_SetScaleXYZ(nuc,scale,scale,scale);
				ObjSpell_SetIntersectionCircle(spell,mx,my,128*scale);
				yield;
			}
			ascent(i in 0..60)
			{
				scale+=0.0025;
				ObjRender_SetScaleXYZ(nuc,scale,scale,scale);
				ObjSpell_SetIntersectionCircle(spell,mx,my,128*scale);
				yield;
			}
			ObjSpell_SetDamage(spell,5*SDF());
			ascent(i in 0..30)
			{
				scale+=0.0025;
				ObjRender_SetScaleXYZ(nuc,scale,scale,scale);
				ObjRender_SetAlpha(nuc,255-i*255/30);
				yield;
			}
			Obj_Delete(nuc);
			Obj_Delete(spell);
		}
	}
}

task TSpell2
{
	SetPlayerInvincibilityFrame(180);
	let objManage = GetSpellManageObject();
	CallGraphic;
	yield;
	Obj_Delete(objManage);
	task CallGraphic
	{
		//---------------------Graphic Part---------------------//
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		let img=GetCurrentScriptDirectory~"./HecE.png";
		let mx = 0;
		let my = 0;
		let sx = ObjRender_GetX(arr2[0]);
		let sy = ObjRender_GetY(arr2[0]);
		let difx = GetPlayerX-sx;
		let p = Obj_GetValueD(arr1[0],"B_Angle",0); // use same orb's position as otherworld
		let dify = GetPlayerY+45*sin(p)-150-sy;
		let dis = 45;
		let count = 0;
		ObjPrim_SetTexture(obj,img);
		ObjSprite2D_SetSourceRect(obj,222,144,222+34,144+38);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		Obj_SetRenderPriorityI(obj,30);
		FadeAllOrb(900);
		PlaySound(4,100,0);
		ascent(i in 0..60)
		{
			ObjRender_SetX(obj,sx+difx*sin(i*1.5));
			ObjRender_SetY(obj,sy+dify*sin(i*1.5));
			yield;
		}
		ascent(i in 0..3)
		{
			PlaySound(6,100,0);
			CallCold(sx+difx,sy+dify);
			CallCold2(sx+difx,sy+dify,(-1)^i);
			TExpan(sx+difx,sy+dify,20,90,0,64,128);
			wait(60);
		}
		ascent(i in 0..10)
		{
			ObjRender_SetScaleXYZ(obj,1+i/10,1+i/10,0);
			ObjRender_SetAlpha(obj,255-i*255/10);
			yield;
		}
		Obj_Delete(obj);
		task CallCold(cx,cy)
		{
			let obj=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory~"./nuclear2.png";
			let angular = 0;
			let angle = 0;
			let color = 0;
			let scale = 1;
			ObjPrim_SetTexture(obj,img);
			ObjSprite2D_SetSourceRect(obj,0,0,256,256);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
			ObjRender_SetPosition(obj,cx,cy,0);
			Obj_SetRenderPriorityI(obj,30);
			let spell = ObjSpell_Create;
			ObjSpell_Regist(spell);
			ObjSpell_SetDamage(spell,10*SDF);
			ascent(i in 0..90)
			{
				ObjRender_SetColor(obj,0,128-i*255/180,255-i*255/90);
				ObjRender_SetScaleXYZ(obj,i/50,i/50,0);
				ObjSpell_SetIntersectionCircle(spell,cx,cy,32+128*i/50);
				yield;
			}
			Obj_Delete(obj);
			Obj_Delete(spell);
		}
		task CallCold2(cx,cy,way)
		{
			let obj=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory~"./Cold.png";
			let angular = 0;
			let angle = 0;
			let color = 0;
			let scale = 1;
			ObjPrim_SetTexture(obj,img);
			ObjSprite2D_SetSourceRect(obj,0,0,256,256);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
			ObjRender_SetPosition(obj,cx,cy,0);
			Obj_SetRenderPriorityI(obj,30);
			ascent(i in 0..90)
			{
				ObjRender_SetColor(obj,0,255-i*255/90,255-i*255/90);
				ObjRender_SetScaleXYZ(obj,i/40,i/40,0);
				ObjRender_SetAngleZ(obj,i*10*way);
				yield;
			}
			Obj_Delete(obj);
		}
	}
}

task TSpell3
{
	SetPlayerInvincibilityFrame(210);
	let objManage = GetSpellManageObject();
	CallGraphic(0);
	CallGraphic(1);
	yield;
	Obj_Delete(objManage);
	task CallGraphic(num)
	{
		//---------------------Graphic Part---------------------//
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		let img=GetCurrentScriptDirectory~"./HecM.png";
		let mx = 0;
		let my = 0;
		let sx = ObjRender_GetX(arr3[num]);
		let sy = ObjRender_GetY(arr3[num]);
		let difx;
		let dify;
		ObjPrim_SetTexture(obj,img);
		ObjSprite2D_SetSourceRect(obj,222,144,222+34,144+38);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj,sx,sy,0);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		Obj_SetRenderPriorityI(obj,30);
		wait(num*45);
		let enemyarr = GetIntersectionRegistedEnemyID;
		if(length(enemyarr)==0)
		{
			difx = 0;
			dify = -sy;
		}
		else
		{
			difx = ObjMove_GetX(enemyarr[0])-sx;
			dify = ObjMove_GetY(enemyarr[0])-sy;
		}
		let dis = 45;
		let count = 0;
		if(num==0){FadeAllOrb(900);}
		PlaySound(7,100,0);
		ascent(i in 0..60)
		{
			ObjRender_SetX(obj,sx+difx*sin(i*1.5));
			ObjRender_SetY(obj,sy+dify*sin(i*1.5));
			let enemyarr = GetIntersectionRegistedEnemyID;
			if(length(enemyarr)>0)
			{
				if(GetObjectDistance(enemyarr[0],obj)<dis){break;}
			}
			count++;
			yield;
		}
		PlaySound(1,100,0);
		StarWave(sx+difx*sin(count*1.5),sy+dify*sin(count*1.5),startangle+num*30,num);
		TExpan(sx+difx*sin(count*1.5),sy+dify*sin(count*1.5),15,90,128,128,0);
		ascent(i in 0..10)
		{
			ObjRender_SetScaleXYZ(obj,1+i/10,1+i/10,0);
			ObjRender_SetAlpha(obj,255-i*255/10);
			yield;
		}
		Obj_Delete(obj);
	}
	task StarWave(px,py,startangle,num)
	{
		ImpactDamage;
		ascent(i in 0..6)
		{
			StarSpell(i*60+startangle,num);
		}
		task StarSpell(angle,num)
		{
			let obj=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory~"./StarOnly.png";
			let dx = 0;
			let r = 0;
			let anglez = 0;
			ObjPrim_SetTexture(obj,img);
			ObjRender_SetBlendType(obj,BLEND_ALPHA);
			ObjRender_SetPosition(obj,px,py,0);
			Obj_SetRenderPriorityI(obj,30);
			ObjSprite2D_SetSourceRect(obj,58,152,124,218);
			ObjSprite2D_SetDestCenter(obj);
			let spell = ObjSpell_Create;
			ObjSpell_Regist(spell);
			ObjSpell_SetDamage(spell,3*SDF);
			GlowObject(obj);
			ascent(i in 0..50)
			{
				r = (60)*sin(i*1.5);
				ObjRender_SetPosition(obj,px+r*cos(angle),py+r*sin(angle),0);
				ObjRender_SetScaleXYZ(obj,sin(i*1.5),sin(i*1.5),0);
				ObjSpell_SetIntersectionCircle(spell,px+r*cos(angle),py+r*sin(angle),50);
				ObjRender_SetAngleZ(obj,anglez);
				anglez += 4;
				yield;
			}
			ascent(i in 0..90)
			{
				r += 1.75-num/2;
				ObjRender_SetPosition(obj,px+r*cos(angle),py+r*sin(angle),0);
				ObjSpell_SetIntersectionCircle(spell,px+r*cos(angle),py+r*sin(angle),50);
				ObjRender_SetAngleZ(obj,anglez);
				anglez += 4;
				yield;
			}
			ascent(i in 0..60)
			{
				r += 0.75;
				ObjRender_SetPosition(obj,px+r*cos(angle),py+r*sin(angle),0);
				ObjSpell_SetIntersectionCircle(spell,px+r*cos(angle),py+r*sin(angle),33);
				ObjRender_SetAlpha(obj,255-i*255/60);
				ObjRender_SetAngleZ(obj,anglez);
				anglez += 4;
				yield;
			}
			Obj_Delete(obj);
			Obj_Delete(spell);
			task GlowObject(obj)
			{
				let sobj=ObjPrim_Create(OBJ_SPRITE_2D);
				let img=GetCurrentScriptDirectory~"./nuclear2.png";
				ObjPrim_SetTexture(sobj,img);
				ObjRender_SetBlendType(sobj,BLEND_ADD_ARGB);
				Obj_SetRenderPriorityI(sobj,30);
				ObjSprite2D_SetSourceRect(sobj,0,0,256,256);
				ObjSprite2D_SetDestCenter(sobj);
				ObjRender_SetColor(sobj,128,128,0);
				ascent(i in 0..50)
				{
					if(Obj_IsDeleted(obj)){break;}
					ObjRender_SetScaleXYZ(sobj,0.5*sin(i*1.5),0.5*sin(i*1.5),0);
					ObjRender_SetPosition(sobj,ObjRender_GetX(obj),ObjRender_GetY(obj),0);
					yield;
				}
				loop(90)
				{
					if(Obj_IsDeleted(obj)){break;}
					ObjRender_SetPosition(sobj,ObjRender_GetX(obj),ObjRender_GetY(obj),0);
					yield;
				}
				ascent(i in 0..60)
				{
					if(Obj_IsDeleted(obj)){break;}
					ObjRender_SetPosition(sobj,ObjRender_GetX(obj),ObjRender_GetY(obj),0);
					ObjRender_SetColor(sobj,128-i*128/60,128-i*128/60,0);
					yield;
				}
				Obj_Delete(sobj);
			}
		}
		task ImpactDamage
		{
			let spell = ObjSpell_Create;
			ObjSpell_Regist(spell);
			ObjSpell_SetDamage(spell,5*SDF);
			ascent(i in 0..10)
			{
				ObjSpell_SetIntersectionCircle(spell,px,py,30);
				yield;
			}
			Obj_Delete(spell);
		}
	}
}

task FadeAllOrb(time)
{
	DelayVisible(arr1[0],0);
	DelayVisible(arr2[0],1);
	DelayVisible(arr3[0],2);
	DelayVisible(arr3[1],2);
	CallLine(0);
	CallLine(1);
	task DelayVisible(obj,num)
	{
		loop(time)
		{
			Obj_SetValue(obj,"Alive",0);
			if(GetPlayerState==STATE_DOWN)
			{
				wait(60);
				break;
			}
			yield;
		}
		Obj_SetValue(obj,"Alive",1);
		SExpan(obj,4,45,num);
		PlaySound(8,100,0);
	}
	task CallLine(ltype)
	{
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		let img=GetCurrentScriptDirectory~"./lifeline.png";
		let dx = 0;
		ObjPrim_SetTexture(obj,img);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		ObjRender_SetPosition(obj,0,442,0);
		Obj_SetRenderPriorityI(obj,30);	
		if(ltype==0)
		{
			ObjSprite2D_SetSourceRect(obj,0,0,128,12);
			ObjSprite2D_SetDestCenter(obj);
			loop(time)
			{
				if(type==0){ObjRender_SetColor(obj,128,0,0);}
				if(type==1){ObjRender_SetColor(obj,0,64,128);}
				if(type==2){ObjRender_SetColor(obj,128,128,0);}
				if(GetPlayerState==STATE_DOWN)
				{
					wait(60);
					break;
				}
				yield;
			}
			Obj_Delete(obj);
		}
		else
		{
			loop(time)
			{
				dx += 128/time;
				ObjSprite2D_SetSourceRect(obj,0,0,dx,12);
				ObjSprite2D_SetDestCenter(obj);
				if(type==0){ObjRender_SetColor(obj,255,0,0);}
				if(type==1){ObjRender_SetColor(obj,0,128,255);}
				if(type==2){ObjRender_SetColor(obj,255,255,0);}
				if(GetPlayerState==STATE_DOWN)
				{
					wait(60);
					break;
				}
				yield;
			}
			Obj_Delete(obj);
		}
	}
}

function TExpan(px,py,maxv,t,r,g,b)
{
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./charge.png";
	let scale = 0;
	let v = 0;
	let malpha = 255/t;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,px,py,0);
	ObjRender_SetColor(obj,r,g,b);
	Obj_SetRenderPriorityI(obj,30);
	Expan;
		task Expan{
			descent(i in 0..t)
			{
			ObjRender_SetAlpha(obj,malpha*i);
			v = (i*maxv/2)/(t*t);
			scale += v;
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			yield;
			}
			Obj_Delete(obj);
		}
}

function TExpan2(fobj,maxv,t,r,g,b)
{
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./charge.png";
	let scale = 0;
	let v = 0;
	let malpha = 255/t;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetColor(obj,r,g,b);
	Obj_SetRenderPriorityI(obj,30);
	Expan;
	task Expan
	{
		descent(i in 0..t)
		{
			ObjRender_SetPosition(obj,ObjMove_GetX(fobj),ObjMove_GetY(fobj),0);
			ObjRender_SetAlpha(obj,malpha*i);
			v = (i*maxv/2)/(t*t);
			scale += v;
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			yield;
		}
		Obj_Delete(obj);
	}
}

function SExpan(fobj,maxv,t,num)
{
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./charge.png";
	let scale = 0;
	let v = 0;
	let malpha = 255/t;
	let r=0;
	let g=0;
	let b=0;
	if(num==0){r=128;}
	if(num==1){b=128;}
	if(num==2){r=128;g=128;}
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetColor(obj,r,g,b);
	Expan;
	task Expan
	{
		descent(i in 0..t)
		{
			if(type==num){Obj_SetVisible(obj,true);}
			else{Obj_SetVisible(obj,false);}
			ObjRender_SetPosition(obj,ObjRender_GetX(fobj),ObjRender_GetY(fobj),0);
			ObjRender_SetAlpha(obj,malpha*i);
			v = (i*maxv/2)/(t*t);
			scale += v;
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			yield;
		}
		Obj_Delete(obj);
	}
}


		
task etama(r,a,type){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"eff2.png";
	let dir = rand(0,359);
	let angle = rand(0,359);
	let size = 0.5+r/150;
	let s = size;
	let ra = r;
	let c = 0;
	let m = -10;
	let cp = rand(-7,7);
	let alpha = 0;
	let count = 0;
	let alphaplus = 255/ra;
	ObjPrim_SetTexture(obj,img);
	if(type==1){ObjSprite2D_SetSourceRect(obj,32,226,64,254);}
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,0);
	while(r>0){
	ObjRender_SetPosition(obj,GetPlayerX+r*cos(dir),GetPlayerY+r*sin(dir),0);
	ObjRender_SetAngleXYZ(obj,0,0,angle+c*20);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetAlpha(obj,alpha*5);
	if(r>ra/2){alpha += alphaplus+1;}
	else{
	alpha -= alphaplus;
	if(alpha<=0){Obj_Delete(obj);}
	}
	r -= 10+c;
	c -= 0.1;
	yield;
	}
	Obj_Delete(obj);
}

function TCharge01(x,y,size,frame,r,g,b){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"charge.png";
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,x,y,0);
	ObjRender_SetAlpha(obj,0);
	ObjRender_SetScaleXYZ(obj,size,size,0);
	ObjRender_SetColor(obj,r,g,b);
	TAlpha;
	TShrink;
	return obj;
	task TAlpha{
		let l=10;
		let alpha=255/l;
		loop(l){
			ObjRender_SetAlpha(obj,alpha);
			alpha+=255/(l*2);
			yield;
			}
		}
	task TShrink{
		let l=frame;
		let a = size*2/l/l;
		ascent(i in 0..l){
			ObjRender_SetScaleXYZ(obj,size,size,0);
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			size = size-i*a;
			if(Obj_IsDeleted(GetPlayerID)){Obj_Delete(obj);}
			yield;
			}
		Obj_Delete(obj);
		
	}
}

task fragment(shot,size,num){
		if(!Obj_IsDeleted(shot)){
		loop(num){
		realTask;
		}
		}
			task realTask{
			let obj=ObjPrim_Create(OBJ_SPRITE_2D);
			let img=GetCurrentScriptDirectory~"effbreak.png";
			let s = rand(0.8,1.2)+size;
			let pic = ObjShot_GetImageID(shot);
			let color = GetShotDataInfoA1(pic,TARGET_ENEMY,INFO_DELAY_COLOR);
			let rect = [0,0,32,32];
			ObjPrim_SetTexture(obj,img);
			ObjSprite2D_SetSourceRect(obj,rect[0],rect[1],rect[2],rect[3]);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetScaleXYZ(obj,s,s,0);
			ObjRender_SetAngleXYZ(obj,0,0,rand(0,359));
			ObjRender_SetBlendType(obj,BLEND_ALPHA);
			ObjRender_SetColor(obj,color[0],color[1],color[2]);
			Obj_SetRenderPriority(obj,0.21);
			ObjShot_SetIntersectionEnable(shot,false);
			let x = ObjMove_GetX(shot);
			let y = ObjMove_GetY(shot);
			if(x!=0 && y!=0){
			ascent(i in 0..7){
			ObjRender_SetPosition(obj,x,y,0);
			ObjSprite2D_SetSourceRect(obj,rect[0],rect[1],rect[2],rect[3]);
			rect[0] = rect[0]+32;
			rect[2] = rect[2]+32;
			wait(3);
			}
			}
			Obj_Delete(obj);
			}
		}
		
task spongy(shot,t){
		let cloud = ObjShot_GetImageID(shot);
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		if(!Obj_IsDeleted(shot)){
		let img=GetCurrentScriptDirectory()~"AllStarShot.png";
		let s = 1;
		let adc = false;
		let rect = GetShotDataInfoA1(cloud,TARGET_ENEMY,INFO_RECT);
		let dir = ObjMove_GetAngle(shot)+90;
		ObjPrim_SetTexture(obj,img);
		ObjSprite2D_SetSourceRect(obj,rect[0],rect[1],rect[2],rect[3]);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj,ObjMove_GetX(shot),ObjMove_GetY(shot),0);
		ObjRender_SetAngleXYZ(obj,0,0,dir);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
	 if( (cloud>=1 && cloud<=41) || (cloud>=58 && cloud<=73) || (cloud>=106 && cloud <=121)
	 || (cloud>=170 && cloud<=185) || (cloud>=233 && cloud<=239)
	 || (cloud>=248 && cloud <=252) || (cloud>=269 && cloud<=283)
	 || (cloud>=300 && cloud<=307) || (cloud>=340 && cloud<=346)
	 || (cloud>=355 && cloud<=362) || (cloud>=371 && cloud<=382)
	 || (cloud>=399 && cloud<=408)){
	 adc = true;
	 ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	 }
		if(cloud>=41){
		ascent(i in 0..t){
		ObjRender_SetScaleXYZ(obj,s,s,0);
		if(adc==false){ObjRender_SetAlpha(obj,255-i*255/t);}
		if(adc==true){ObjRender_SetColor(obj,255-i*255/t,255-i*255/t,255-i*255/t);}
		s += 0.1;
		yield;
		}
		}
		Obj_Delete(obj);
		}
		}

function GetDistance(x1,y1,x2,y2){
return((|((x2-x1)^2+(y2-y1)^2)^(1/2)|));
}

task TMagicCircle
{


	let countVertex = 64;
	let listRadius = [];
	loop(countVertex)
	{
		listRadius = listRadius ~ [0];
	}

	let path = current ~ "Default_Player_MagicCircle.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(obj, countVertex);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.60);
	ObjPrim_SetTexture(obj, path);
	ascent(iVert in 0..countVertex / 2)
	{
		let left = iVert * 128;
		let indexVert = iVert * 2;
		ObjPrim_SetVertexUVT(obj, indexVert + 0, left, 0);
		ObjPrim_SetVertexUVT(obj, indexVert + 1, left, 64);		
	}

	let cx = 0;
	let cy = 0;
	let maxRadius = 128;
	let alpha = 0;
	let frame = 0;
	let angleRender = 0;
	let frameInvOld = 0;

	while(true)
	{
		let frameInv = GetPlayerInvincibilityFrame();

		if(frameInv <= 0)
		{
			Obj_SetVisible(obj, false);
			frameInvOld = 0;
		}
		else
		{
			if(frameInvOld == 0)
			{
				//???
				ascent(iVert in 0..countVertex)
				{
					listRadius[iVert] = 0;
				}
				alpha = 0;
				frame = 0;
			}
			frameInvOld = frameInv;

			let px = GetPlayerX();
			let py = GetPlayerY();

			alpha += 1 / 120;
			alpha = min(alpha, 1);
			angleRender += 360 / countVertex / 2;
			Obj_SetVisible(obj, true);

			frameInv = min(100, frameInv);
			let rRate = frameInv / 100;

			ascent(iVert in 0..countVertex / 2)
			{
				let indexVert = iVert * 2;
				let angle = 360 / (countVertex / 2 - 1) * iVert;

				let vx1 = listRadius[indexVert] * cos(angle);
				let vy1 = listRadius[indexVert] * sin(angle);
				ObjPrim_SetVertexPosition(obj, indexVert + 0, vx1, vy1, 0);

				let vx2 = listRadius[indexVert+1] * cos(angle);
				let vy2 = listRadius[indexVert+1] * sin(angle);
				ObjPrim_SetVertexPosition(obj, indexVert + 1, vx2, vy2, 0);

				//?????
				if(frame >= 0)
				{//??
					let dr = (maxRadius * rRate - listRadius[indexVert]) / 8;
					listRadius[indexVert] = listRadius[indexVert] + dr;
				}
				if(frame > 10)
				{//??
					let rRateIn = rRate - 0.12;
					if(rRateIn < 0){rRateIn=0;}
					let dr= (maxRadius * rRateIn - listRadius[indexVert + 1]) / 16;
					listRadius[indexVert + 1] = listRadius[indexVert + 1] + dr;
				}

			}

			ObjRender_SetColor(obj, 192 * alpha, 192 * alpha, 255 * alpha);
			ObjRender_SetPosition(obj, px, py, 0);
			ObjRender_SetAngleZ(obj, angleRender);

			frame++;
		}

		yield;
	}
}

task TExplosion
{
	let path = GetCurrentScriptDirectory() ~ "eff2.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.60);
	ObjPrim_SetTexture(obj, path);
	ObjSprite2D_SetSourceRect(obj, 128, 16, 192, 79);
	ObjSprite2D_SetDestRect(obj, -32, -32, 32, 32);
	ObjRender_SetPosition(obj, GetPlayerX, GetPlayerY, 0);
	let alpha = 255;
	let scale = 0;
	let dis = 0;
	let px = GetPlayerX;
	let py = GetPlayerY;
	ExplosionCircle;
	DeleteCircle;
	task ExplosionCircle
	{
		loop(30)
		{
			scale += 0.2;
			alpha -= 9;
			ObjRender_SetColor(obj, alpha, alpha, alpha);
			ObjRender_SetPosition(obj, px, py, 0);
			ObjRender_SetScaleXYZ(obj, scale, scale, 1);
			yield;
		}
		Obj_Delete(obj);
	}
	task DeleteCircle
	{
		wait(GetPlayerRebirthFrame);
		loop(40)
		{
			let arr = GetShotIdInCircleA2(GetStgFrameWidth/2,GetStgFrameHeight/2,600,TARGET_ENEMY);
			DeleteShotInCircle(TYPE_SHOT, TYPE_ITEM, px, py, dis);
			dis += 25;
			yield;
		}
	}
}

task Homing(obj,h_obj,maxTraverse){  // max. angle of traverse
	let angle = ObjMove_GetAngle(obj);
	let dir = 0;
	let boss = GetIntersectionRegistedEnemyID;
    while(! Obj_IsDeleted(obj))
	{
        ObjMove_SetAngle(obj, angle);
		maxTraverse += 0.5;
		if(Obj_IsDeleted(h_obj)){break;}
		if(length(boss)>=1)
		{
			dir = atan2(ObjMove_GetY(h_obj) - ObjMove_GetY(obj),
			ObjMove_GetX(h_obj) - ObjMove_GetX(obj));
		}
        let diff = dir - angle;
        while(diff >= 180) { diff -= 360; }    // adjust the range
        while(diff < -180) { diff += 360; }

        let diffAbs = (|diff|);
        if(diffAbs < maxTraverse) {
            angle = dir;
        } else {
            angle += maxTraverse * diff / diffAbs;
        }
		yield;
    }
}	
	
function FindTarget{
	let enemy_id = GetIntersectionRegistedEnemyID;
	let mindis = 999;
	let h_obj;
	if(length(enemy_id)>0){
	h_obj = enemy_id[0];
	ascent(i in 0..length(enemy_id)){
	let dis = GetDistance(GetPlayerX,GetPlayerY,ObjMove_GetX(enemy_id[i]),ObjMove_GetY(enemy_id[i]));
		if(mindis>dis){
		mindis = dis;
		h_obj = enemy_id[i];
		}
	}
	return h_obj;
	}
	else
	{
	return -1;
	}
}

task SetUpSound()
{
	PutSound(GetCurrentScriptDirectory~"se_shot.wav"); // 0
	PutSound(GetCurrentScriptDirectory~"Eff1.wav"); // 1
	PutSound(GetCurrentScriptDirectory~"don.wav"); // 2
	PutSound(GetCurrentScriptDirectory~"Charge5.wav"); // 3
	PutSound(GetCurrentScriptDirectory~"Charge4.wav"); // 4
	PutSound(GetCurrentScriptDirectory~"Laser7.wav"); // 5
	PutSound(GetCurrentScriptDirectory~"Eff2.wav"); // 6
	PutSound(GetCurrentScriptDirectory~"Shot8.wav"); // 7
	PutSound(GetCurrentScriptDirectory~"Heal.wav"); // 8
	function PutSound(path)
	{
		let s = ObjSound_Create();
		ObjSound_Load(s,path);
		sound = sound ~ [s];
	}
}

task PlaySound(arg,v,w)
{
	loop(w){yield;}
	ObjSound_SetSoundDivision(sound[arg],SOUND_SE);
	ObjSound_SetVolumeRate(sound[arg],v);
	ObjSound_Play(sound[arg]);
}

				task ScreenShake(time){
				loop(time/2){
				Set2DCameraFocusX(Get2DCameraX + rand(-8, 8));
				Set2DCameraFocusY(Get2DCameraY + rand(-8, 8));
				yield;
				Reset2DCamera;
				yield;
				}
				Reset2DCamera;
			}	

function wait(t){
	loop(t){yield;}
	}
