#TouhouDanmakufu[Player]
#ScriptVersion[3]	
#ID["SKN_SANAE"]
#Title["SKN Sanae Kochiya"]
#Image["./Cutin.png"]
#ReplayName["Sanae"]

let objPlayer = GetPlayerObjectID();
let objSlowShot = ID_INVALID;
let current = GetCurrentScriptDirectory();
let enemy;
let focus = false;
let type = 0;
let vx = 5;
let vy = 2.25;
let spelltime = false;
let arr1 = [];
let arr2 = [];
let arr3 = [];
let arr4 = [];
let lwidth = 0;
let s = ObjSound_Create;
@Initialize
{
	SetPlayerSpeed(vx, vy);
	SetPlayerClip(12,12,GetStgFrameWidth-12,GetStgFrameHeight-12);
	SetPlayerDownStateFrame(60);
	SetPlayerRebirthFrame(20);
	let path = current ~ "MarisaShotData.txt";
	LoadPlayerShotData(path); //???????

	ObjPlayer_AddIntersectionCircleA1(objPlayer, 0, 0, 2, 25);
	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~"Weird1.wav");
	LoadSound(GetCurrentScriptDirectory~"Weird2.wav");
	LoadSound(GetCurrentScriptDirectory~"Weird3.wav");
	LoadSound(GetCurrentScriptDirectory~"ShotM.wav");
	LoadSound(GetCurrentScriptDirectory~"SpellCard.wav");
	LoadSound(current~"se_pldead.wav");
	TImage();
	TShot();
	TMagicCircle();
	HitBox;
	Orb;
}

@MainLoop
{
	enemy = GetAllEnemyID;
	yield;
}

@FinalizeShot
{
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_SPELL)
	{
		//????????
		let spell = GetPlayerSpell();
		if(spell >= 1)
		{
			SetScriptResult(true);
			SetPlayerSpell(spell-1);
			alternative(type)
			case(0){TSpell1;}
			case(1){TSpell2;}
			
		}
		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);
	}
	
}

task TImage
{
	let f = 0;
	let f2 = 0;
	let px = 32;
	let py = 48;
	let path = GetCurrentScriptDirectory() ~ "pl02.png";
	ObjPrim_SetTexture(objPlayer, path);
	Obj_SetRenderPriorityI(objPlayer,30);
	loop
	{
		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, 2, 1, px, 48);}
			if(f>=6&& f<=12){ObjSprite2D_SetSourceRect(objPlayer, px+2, 1, px*2, 48);}
			if(f>=12 && f<=18){ObjSprite2D_SetSourceRect(objPlayer, px*2+2, 1, px*3, 48);}
			if(f>=18 && f<=24){ObjSprite2D_SetSourceRect(objPlayer, px*3+2, 1, px*4, 48);}
			if(f>=24 && f<=30){ObjSprite2D_SetSourceRect(objPlayer, px*4+2, 1, px*5, 48);}
			if(f>=30 && f<=36){ObjSprite2D_SetSourceRect(objPlayer, px*5+2, 1, px*6, 48);}
			if(f>=36 && f<=42){ObjSprite2D_SetSourceRect(objPlayer, px*6+2, 1, px*7, 48);}
			if(f>=42){ObjSprite2D_SetSourceRect(objPlayer, px*7+2, 1, px*8, 48);}
			if(f>=48){f=0;}
			f++;
			f2 = 0;
		}
		ObjSprite2D_SetDestCenter(objPlayer);
		yield;
	}

}

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

	/*
	1.U:Blue missle / F:Green missle / Bomb: The sun thing
	2.U:Illution Laser [spead] / F:Flame / Bomb:master spark
	3.U:Spread Shot / F:Green Stars (Reisen) / Bomb: Marisa B 11
	4.U:Cold Inferno / F:Alice 11 / Bomb:Cold star
	*/
	ascent(i in 0..4)
	{
		Orb1(arr1[i],i);
		Orb2(arr2[i],i);
		Orb3(arr3[i],i);
		Orb4(arr4[i],i);
	}

		task Orb1(obj,num)
		{
			let ufco = [[-25,5],[-25,25],[25,5],[25,25]];
			let fco = [[18,-15],[7,-25],[-7,-25],[-18,-15]];
			let count = 0;
			let dif = [[0,-5],[15,0],[0,-5],[-15,0]];
			let way = [1,1,-1,-1];
			let time = 10;
			let fcount = 0;
			let dn0 = 0;
			let dn1 = 0;
			let dr0 = dif[num][0]/time;
			let dr1 = dif[num][1]/time;
			ObjRender_SetAlpha(obj,192);
			ObjSprite2D_SetDestRect(obj,-6,-6,7,7);
			ObjSprite2D_SetSourceRect(obj,64,144,80,160);
			AfterOrb(obj,64,144,80,160,0);
			while(!Obj_IsDeleted(obj))
			{
				if(GetPlayerState==STATE_DOWN || type!=0){Obj_SetVisible(obj,false);}
				else{Obj_SetVisible(obj,true);}
				ObjRender_SetPosition(obj,GetPlayerX+ufco[num][0]+dn0,GetPlayerY+ufco[num][1]+dn1,0);
				//ObjRender_SetAngleXYZ(obj,0,0,count*way[num]*10);
				ObjRender_SetScaleXYZ(obj,1.2+0.2*sin(count*5),1.2+0.2*sin(count*5),0);
				count++;
				if(focus==true && fcount<10)
				{
					ObjSprite2D_SetSourceRect(obj,64,144,80,160);
					dn0 += dr0;
					dn1 += dr1;
					fcount++; 
				}
				if(focus==false && fcount>0)
				{
					ObjSprite2D_SetSourceRect(obj,64,144,80,160);
					dn0 -= dr0;
					dn1 -= dr1;
					fcount--;
				}
				yield;
			}
		}
		
		task Orb2(obj,num)
		{
			let ufco = [[-30,20],[-15,-30],[15,-30],[30,20]];
			let fco = [[0,-30],[0,-30],[0,-30],[0,-30]];
			let count = 0;
			let dif = [[30,-50],[15,0],[-15,0],[-30,-50]];
			let way = [1,1,-1,-1];
			let time = 10;
			let fcount = 0;
			let dn0 = 0;
			let dn1 = 0;
			let dr0 = dif[num][0]/time;
			let dr1 = dif[num][1]/time;
			ObjRender_SetAlpha(obj,192);
			ObjSprite2D_SetDestRect(obj,-6,-6,7,7);
			ObjSprite2D_SetSourceRect(obj,114,161,128,175);
			LaserGraphic;
			LaserEffect;
			AfterOrb(obj,114,161,128,175,1);
			while(!Obj_IsDeleted(obj))
			{
				if(GetPlayerState==STATE_DOWN || type!=1){Obj_SetVisible(obj,false);}
				else{Obj_SetVisible(obj,true);}
				ObjRender_SetPosition(obj,GetPlayerX+ufco[num][0]+dn0,GetPlayerY+ufco[num][1]+dn1,0);
				//ObjRender_SetAngleXYZ(obj,0,0,count*way[num]*10);
				ObjRender_SetScaleXYZ(obj,0.8+0.1*sin(count*25),0.8+0.1*sin(count*25),0);
				count++;
				if(focus==true && fcount<10)
				{
					dn0 += dr0;
					dn1 += dr1;
					fcount++;
				}
				if(focus==false && fcount>0)
				{
					dn0 -= dr0;
					dn1 -= dr1;
					fcount--;
				}
				yield;
			}
			//GetVirtualKeyState(VK_SHOT)==KEY_HOLD
			task LaserEffect
			{
				let ball = ObjPrim_Create(OBJ_SPRITE_2D); // graphic
				let img = GetCurrentScriptDirectory~"Sprite.png";
				ObjPrim_SetTexture(ball,img);
				ObjSprite2D_SetSourceRect(ball,0,192,32,224);
				ObjSprite2D_SetDestCenter(ball);
				ObjRender_SetBlendType(ball,BLEND_ADD_ARGB);
				Obj_SetRenderPriorityI(ball,23);
				ObjRender_SetColor(ball,192,192,192);
				while(!Obj_IsDeleted(ball))
				{
					if(GetVirtualKeyState(VK_SHOT)==KEY_HOLD && type==1 && GetPlayerState==STATE_NORMAL){Obj_SetVisible(ball,true);}
					else{Obj_SetVisible(ball,false);}
					ObjRender_SetPosition(ball,ObjRender_GetX(obj),ObjRender_GetY(obj),0);
					ObjRender_SetScaleXYZ(ball,0.8+0.1*sin(count*25),0.8+0.1*sin(count*25),0);
					yield;
				}
			}
			task LaserGraphic
			{
				let laser = ObjPrim_Create(OBJ_SPRITE_2D); // graphic
				let img = GetCurrentScriptDirectory~"Sprite.png";
				let angle = [255,265,275,285];
				ObjPrim_SetTexture(laser,img);
				ObjSprite2D_SetSourceRect(laser,0,176,512,192);
				ObjSprite2D_SetDestCenter(laser);
				ObjRender_SetBlendType(laser,BLEND_ADD_ARGB);
				ObjRender_SetColor(laser,192,192,192);
				ObjRender_SetAngleXYZ(laser,0,0,angle[num]-180);
				while(!Obj_IsDeleted(obj))
				{
					ObjRender_SetPosition(laser,ObjRender_GetX(obj)+256*cos(angle[num]),ObjRender_GetY(obj)+256*sin(angle[num]),0);
					ObjSprite2D_SetSourceRect(laser,count*7.5,176,512+count*7.5,192);
					ObjRender_SetScaleY(laser,lwidth/4);
					if(GetPlayerState==STATE_DOWN || lwidth<=0 || type!=1 || IsPlayerSpellActive){Obj_SetVisible(laser,false);}
					else{Obj_SetVisible(laser,true);}
					let eneid = GetIntersectionRegistedEnemyID;
					ascent(i in 0..length(eneid))
					{
						let lx = ObjRender_GetX(obj);
						let ly = ObjRender_GetY(obj);
						if(IsIntersected_Line_Circle(lx,ly,lx+600*cos(angle[num]),ly+600*sin(angle[num]),24,ObjMove_GetX(eneid[i]),ObjMove_GetY(eneid[i]),10)
						&& count%4==0 && GetVirtualKeyState(VK_SHOT)==KEY_HOLD && type==1 && focus==false && !IsPlayerSpellActive && GetPlayerState!=STATE_DOWN)
						{
							let dis = GetObjectDistance(obj,eneid[i]);
							LaserDamage(eneid[i],ObjRender_GetX(obj)+dis*cos(angle[num]),ObjRender_GetY(obj)+dis*sin(angle[num]),angle[num]);
						}
					}
					yield;
				}
			}
		}
		
		task Orb3(obj,num)
		{
			let ufco = [[-15,35],[-30,-25],[30,-25],[15,35]];
			let fco = [[-45,0],[0,-45],[45,0],[0,45]];
			let count = 0;
			let dif = [[-30,-35],[30,-20],[15,25],[-15,10]];
			let way = [1,1,-1,-1];
			let time = 10;
			let fcount = 0;
			let orbcount = 0;
			let dn0 = 0;
			let dn1 = 0;
			let dr0 = dif[num][0]/time;
			let dr1 = dif[num][1]/time;
			ObjRender_SetAlpha(obj,192);
			ObjSprite2D_SetDestRect(obj,-6,-6,7,7);
			ObjSprite2D_SetSourceRect(obj,162,161,176,175);
			AfterOrb(obj,162,161,176,175,2);
			while(!Obj_IsDeleted(obj))
			{
				if(GetPlayerState==STATE_DOWN || type!=2){Obj_SetVisible(obj,false);}
				else{Obj_SetVisible(obj,true);}
				if(fcount<10){ObjRender_SetPosition(obj,GetPlayerX+ufco[num][0]+dn0,GetPlayerY+ufco[num][1]+dn1,0);}
				else{ObjRender_SetPosition(obj,GetPlayerX+45*cos(num*90+orbcount-40),GetPlayerY+45*sin(num*90+orbcount-40),0);}
				ObjRender_SetAngleXYZ(obj,0,0,count*way[num]*10);
				count++;
				if(focus==true && fcount<10)
				{
					dn0 += dr0;
					dn1 += dr1;
					fcount++;
				}
				if(focus==true){orbcount+=4;}
				
				if(focus==false && fcount>0)
				{
					dn0 -= dr0;
					dn1 -= dr1;
					fcount--;
					orbcount=0;
				}
				yield;
			}
		}
		task Orb4(obj,num)
		{
			let fco = [[-40,-20],[-15,-25],[15,-25],[40,-20]];
			let ufco = [[45,0],[20,30],[-20,30],[-45,0]];
			let count = 0;
			let dif = [[-85,-20],[-35,-55],[35,-55],[85,-20]];
			let way = [1,1,-1,-1];
			let time = 10;
			let fcount = 0;
			let dn0 = 0;
			let dn1 = 0;
			let dr0 = dif[num][0]/time;
			let dr1 = dif[num][1]/time;
			ObjRender_SetAlpha(obj,192);
			ObjSprite2D_SetDestRect(obj,-6,-6,7,7);
			ObjSprite2D_SetSourceRect(obj,240,204,256,226);
			AfterOrb(obj,178,161,192,175,3);
			while(!Obj_IsDeleted(obj))
			{
				if(GetPlayerState==STATE_DOWN || type!=3){Obj_SetVisible(obj,false);}
				else{Obj_SetVisible(obj,true);}
				if(focus==true){ObjRender_SetPosition(obj,GetPlayerX+ufco[num][0]+dn0,GetPlayerY+ufco[num][1]+dn1,0);}
				if(focus==false){ObjRender_SetPosition(obj,GetPlayerX+ufco[num][0],GetPlayerY+ufco[num][1]+dn1,0);}
				if(focus==true){ObjRender_SetAngleXYZ(obj,0,0,count*way[num]*10);ObjRender_SetScaleXYZ(obj,1,1,0);}
				if(focus==false){ObjRender_SetAngleXYZ(obj,0,0,20*sin(count*6));ObjRender_SetScaleXYZ(obj,1.5,2,0);}
				count++;
				if(focus==true && fcount<10)
				{
					ObjSprite2D_SetSourceRect(obj,178,161,192,175);
					dn0 += dr0;
					dn1 += dr1;
					fcount++;
				}
				if(focus==false && fcount>0)
				{
					ObjSprite2D_SetSourceRect(obj,240,204,256,226);
					dn0 -= dr0;
					dn1 -= dr1;
					fcount--;
				}
				yield;
			}
		}
		task AfterOrb(mobj,r1,r2,r3,r4,ftype)
		{
			let obj= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
			let img = GetCurrentScriptDirectory~"pl02.png";
			let scale = 1.55;
			let fcolor = [0,0,0];
			ObjPrim_SetTexture(obj,img);
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
			ObjSprite2D_SetSourceRect(obj,r1,r2,r3,r4);
			ObjSprite2D_SetDestCenter(obj);
			while(!Obj_IsDeleted(mobj))
			{
				if(ftype==0){fcolor = [128,128,128];}
				if(ftype==1){fcolor = [128,0,0];}
				if(ftype==2){fcolor = [128,128,0];}
				if(ftype==3){fcolor = [58,58,128];}
				if(ftype==3 && focus==false){fcolor = [128,0,0];}
				ObjRender_SetPosition(obj,ObjRender_GetX(mobj),ObjRender_GetY(mobj),0);
				if(type==ftype && GetPlayerState!=STATE_DOWN)
				{
					if(ftype!=3 || (ftype==3 && focus==true)) // type 3+1 is exclusive
					{
						Obj_SetVisible(obj,true);
					}
					else {Obj_SetVisible(obj,false);}
				}
				else {Obj_SetVisible(obj,false);}
				ObjRender_SetColor(obj,fcolor[0],fcolor[1],fcolor[2]);
				yield;
			}
		}
	}
	
function CreateTool
{
		let obj=ObjPrim_Create(OBJ_SPRITE_2D); 
		let img = GetCurrentScriptDirectory~"pl02.png";
		ObjPrim_SetTexture(obj,img);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		Obj_SetRenderPriorityI(obj,23);
		return obj;
}

task TShot
{
	let shotCount = -1;
	let bNextShot = false;
	let objShot = ID_INVALID;
	let shotnum = 0;
	AddVirtualKey(VK_USER1,KEY_C,KEY_INVALID);
	LoadSound(GetCurrentScriptDirectory~"Shot9.wav");
	loop
	{
		if(GetVirtualKeyState(VK_USER1)==KEY_PUSH && spelltime == false)
		{
			PlaySE(GetCurrentScriptDirectory~"Shot9.wav");
			type = (type+1)%1;
		}
		if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD || bNextShot==true) && shotCount==-1)
		{
			shotCount = 0;
			bNextShot = false;
		}
		if(GetVirtualKeyState(VK_SHOT)==KEY_FREE)
		{
			if(lwidth>0){lwidth--;}
		}
		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("se_shot",98,0);
					let dir = [270,270,270,270];;
					if(focus == true) {dir = [270,270,270,270];}
					VanillaBullet(GetPlayerX-10,GetPlayerY,20,270,3,1);
					VanillaBullet(GetPlayerX+10,GetPlayerY,20,270,3,1);
					if(focus==false)
					{
						if(shotnum%8==0)
						{
							Frog(ObjRender_GetX(arr1[0]),ObjRender_GetY(arr1[0]),2,270,8,1.5);
							Frog(ObjRender_GetX(arr1[2]),ObjRender_GetY(arr1[2]),2,270,8,1.5);
							Frog(ObjRender_GetX(arr1[1]),ObjRender_GetY(arr1[1]),2,230,8,1.5);
							Frog(ObjRender_GetX(arr1[3]),ObjRender_GetY(arr1[3]),2,310,8,1.5);
						}
						if(shotnum%8==4)
						{
							Frog(ObjRender_GetX(arr1[0]),ObjRender_GetY(arr1[0]),2,290,8,1.5);
							Frog(ObjRender_GetX(arr1[2]),ObjRender_GetY(arr1[2]),2,250,8,1.5);
							Frog(ObjRender_GetX(arr1[1]),ObjRender_GetY(arr1[1]),2,245,8,1.5);
							Frog(ObjRender_GetX(arr1[3]),ObjRender_GetY(arr1[3]),2,295,8,1.5);
						}
					}
					if(focus==true)
					{
					if(shotnum%1==0)
						{
							snake(ObjRender_GetX(arr1[0])+6,ObjRender_GetY(arr1[0]),7.5,0.5);
							snake(ObjRender_GetX(arr1[1])+6,ObjRender_GetY(arr1[1]),7.5,0.5);
							snake(ObjRender_GetX(arr1[2])+6,ObjRender_GetY(arr1[2]),7.5,0.5);
							snake(ObjRender_GetX(arr1[3])+6,ObjRender_GetY(arr1[3]),7.5,0.5);
							snake(ObjRender_GetX(arr1[0])-6,ObjRender_GetY(arr1[0]),7.5,0.5);
							snake(ObjRender_GetX(arr1[1])-6,ObjRender_GetY(arr1[1]),7.5,0.5);
							snake(ObjRender_GetX(arr1[2])-6,ObjRender_GetY(arr1[2]),7.5,0.5);
							snake(ObjRender_GetX(arr1[3])-6,ObjRender_GetY(arr1[3]),7.5,0.5);
							}

					}
					shotnum++;
				}
				if(type==1 && !IsPlayerSpellActive)
				{
					PlaySound("se_shot",98,0);
					VanillaBullet(GetPlayerX-10,GetPlayerY,20,270,3,1);
					VanillaBullet(GetPlayerX+10,GetPlayerY,20,270,3,1);
					if(lwidth<4 && GetVirtualKeyState(VK_SHOT)==KEY_HOLD)
					{
						if(focus==false){lwidth++;}
					}
					if(focus==true)
					{
						if(lwidth>0){lwidth--;}
						FlameBullet(ObjRender_GetX(arr2[1]),ObjRender_GetY(arr2[1]),9,270+rand(-10,10),3.6,2,0);
						FlameBullet(ObjRender_GetX(arr2[2]),ObjRender_GetY(arr2[2]),9,270+rand(-10,10),3.6,2,0);
						if(shotnum%2==0)
						{
							FlameBullet(ObjRender_GetX(arr2[1]),ObjRender_GetY(arr2[1]),4,135+rand(-5,5),3.6,1,1);
							FlameBullet(ObjRender_GetX(arr2[2]),ObjRender_GetY(arr2[2]),4,45+rand(-5,5),3.6,1,1);
						}
					}
					shotnum++;
				}
				if(type==2)
				{
					PlaySound("se_shot",98,0);
					let dir = [250,262.5,272.5,267.5,277.5,290];
					let dir2 = [70,85,95,110];
					VanillaBullet(GetPlayerX-10,GetPlayerY,20,270,3,1);
					VanillaBullet(GetPlayerX+10,GetPlayerY,20,270,3,1);
					if(focus==false)
					{
						SpreadBullet(ObjRender_GetX(arr3[1]),ObjRender_GetY(arr3[1]),20,dir[0],3.75,1);
						SpreadBullet(ObjRender_GetX(arr3[1]),ObjRender_GetY(arr3[1]),20,dir[1],3.75,1);
						SpreadBullet(ObjRender_GetX(arr3[1]),ObjRender_GetY(arr3[1]),20,dir[2],3.75,1);
						SpreadBullet(ObjRender_GetX(arr3[2]),ObjRender_GetY(arr3[2]),20,dir[3],3.75,1);
						SpreadBullet(ObjRender_GetX(arr3[2]),ObjRender_GetY(arr3[2]),20,dir[4],3.75,1);
						SpreadBullet(ObjRender_GetX(arr3[2]),ObjRender_GetY(arr3[2]),20,dir[5],3.75,1);
						SpreadBullet(ObjRender_GetX(arr3[3]),ObjRender_GetY(arr3[3]),20,dir2[0],3.75,1);
						SpreadBullet(ObjRender_GetX(arr3[3]),ObjRender_GetY(arr3[3]),20,dir2[1],3.75,1);
						SpreadBullet(ObjRender_GetX(arr3[0]),ObjRender_GetY(arr3[0]),20,dir2[2],3.75,1);
						SpreadBullet(ObjRender_GetX(arr3[0]),ObjRender_GetY(arr3[0]),20,dir2[3],3.75,1);
					}
					if(focus==true)
					{
						StarBullet(ObjRender_GetX(arr3[0]),ObjRender_GetY(arr3[0]),18,90,4,1);
						StarBullet(ObjRender_GetX(arr3[1]),ObjRender_GetY(arr3[1]),18,90,4,1);
						StarBullet(ObjRender_GetX(arr3[2]),ObjRender_GetY(arr3[2]),18,90,4,1);
						StarBullet(ObjRender_GetX(arr3[3]),ObjRender_GetY(arr3[3]),18,90,4,1);
						StarBullet(ObjRender_GetX(arr3[0]),ObjRender_GetY(arr3[0]),18,270,4,1);
						StarBullet(ObjRender_GetX(arr3[1]),ObjRender_GetY(arr3[1]),18,270,4,1);
						StarBullet(ObjRender_GetX(arr3[2]),ObjRender_GetY(arr3[2]),18,270,4,1);
						StarBullet(ObjRender_GetX(arr3[3]),ObjRender_GetY(arr3[3]),18,270,4,1);
					}
					shotnum++;
				}
				if(type==3)
				{
					PlaySound("se_shot",98,0);
					let dir = [210,240,300,330];
					if(focus == true) {dir = [270,270,270,270];}
					VanillaBullet(GetPlayerX-10,GetPlayerY,20,270,3,1);
					VanillaBullet(GetPlayerX+10,GetPlayerY,20,270,3,1);
					if(focus==false)
					{
						AliceShot(ObjRender_GetX(arr4[0]),ObjRender_GetY(arr4[0]),15,270,1.9,2,shotnum%8);
						AliceShot(ObjRender_GetX(arr4[0]),ObjRender_GetY(arr4[0]),15,260,1.9,2,shotnum%8);
						AliceShot(ObjRender_GetX(arr4[1]),ObjRender_GetY(arr4[1]),15,270,1.9,2,shotnum%8);
						AliceShot(ObjRender_GetX(arr4[1]),ObjRender_GetY(arr4[1]),15,250,1.9,2,shotnum%8);
						AliceShot(ObjRender_GetX(arr4[2]),ObjRender_GetY(arr4[2]),15,270,1.9,2,shotnum%8);
						AliceShot(ObjRender_GetX(arr4[2]),ObjRender_GetY(arr4[2]),15,290,1.9,2,shotnum%8);
						AliceShot(ObjRender_GetX(arr4[3]),ObjRender_GetY(arr4[3]),15,270,1.9,2,shotnum%8);	
						AliceShot(ObjRender_GetX(arr4[3]),ObjRender_GetY(arr4[3]),15,280,1.9,2,shotnum%8);						
					}
					if(focus==true)
					{
						ColdBullet(ObjRender_GetX(arr4[0]),ObjRender_GetY(arr4[0]),8,270,1.7,2);
						ColdBullet(ObjRender_GetX(arr4[1]),ObjRender_GetY(arr4[1]),8,270,1.7,2);
						ColdBullet(ObjRender_GetX(arr4[2]),ObjRender_GetY(arr4[2]),8,270,1.7,2);
						ColdBullet(ObjRender_GetX(arr4[3]),ObjRender_GetY(arr4[3]),8,270,1.7,2);
						if(shotnum%5==0)
						{
							ColdShot(ObjRender_GetX(arr4[0]),ObjRender_GetY(arr4[0]),6,270,3.7,2);
							ColdShot(ObjRender_GetX(arr4[1]),ObjRender_GetY(arr4[1]),6,270,3.7,2);
							ColdShot(ObjRender_GetX(arr4[2]),ObjRender_GetY(arr4[2]),6,270,3.7,2);
							ColdShot(ObjRender_GetX(arr4[3]),ObjRender_GetY(arr4[3]),6,270,3.7,2);
						}
					}
					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,64,80);
		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 shotcolor = 2;
	let mx;
	let my;
	let mangle;
	let sc = 1;
	let finalpos = 0;
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,shotcolor);
	ObjRender_SetAngleZ(mainobj, -90);
	let count = 0;
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		yield;
	}
	let obj= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
	let img = GetCurrentScriptDirectory~"pl02.png";
	let dx = 0;
	ObjPrim_SetTexture(obj,img);
	if(shotcolor==2){dx = 192;}
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,mx,my,0);
	ObjRender_SetAlpha(obj,128);
	ascent(i in 0..4)
	{
	loop(2)
		{
			ObjRender_SetPosition(obj,mx+finalpos*cos(mangle),my-8+finalpos*sin(mangle),0);
			finalpos+=10;
			yield;
		}
		ObjSprite2D_SetSourceRect(obj,dx+i*16,192,dx+16+i*16,208);
		ObjRender_SetScaleXYZ(obj,sc,sc,sc);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetAngleXYZ(obj,0,0,mangle);
		sc+=0.6;
		wait(3);
		
	}
	Obj_Delete(obj);
}

task Frog(x,y,spd,dir,dmg,pdmg)
{
	let shotcolor = 3;
	let mx;
	let my;
	let mangle;
	let langle;
	let scale = 0;
	let mainobj = CreatePlayerShotA1(x,y,0,dir,dmg,pdmg,shotcolor);
	ObjRender_SetAngleZ(mainobj, -90);
	ObjMove_AddPatternA2(mainobj,0,NO_CHANGE,NO_CHANGE,0.2,0,10);
	let count = 0;
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		langle = ObjMove_GetAngle(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		ObjRender_SetScaleXYZ(mainobj,1+0.2*sin(count*45),1+0.2*sin(count*45),0);
		count++;
		yield;
	}
	if(mx>0 && mx<GetStgFrameWidth && my>0 && my<GetStgFrameHeight)
	{
		if(shotcolor==3){PlaySound("Shot8",80,0);}
	}
	let obj= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
	let img = GetCurrentScriptDirectory~"Sprite.png";
	ObjPrim_SetTexture(obj,img);
	ObjRender_SetPosition(obj,mx,my,0);
	if(shotcolor==3){MissileExplode(mx,my,1);}
	ascent(i in 0..10)
	{
		if(shotcolor==3){ObjSprite2D_SetSourceRect(obj,18,160,50,176);}
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetAngleXYZ(obj,0,0,mangle);
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		ObjRender_SetAlpha(obj,192-i*19);
		scale+= 0.1;
		yield;
	}
	Obj_Delete(obj);
	task MissileExplode(mx,my,num)
	{
		if(num==1)
		{
			MExplode(mx,my,40,0.75);
		}
		else if(num>1)
		{
			ascent(i in 0..3)
			{
				let rx = rand(-50,50);
				let ry = rand(-50,50);
				let mr = rand(0,30);
				let ma = rand(0,360);
				if(my+ry>0)
				{
					MExplode(mx+mr*cos(ma),my+mr*sin(ma),0,0.75);
					mr = rand(0,60);
					wait(3);
					MExplode(mx+mr*cos(ma),my+mr*sin(ma),0,0.75);
				}
				wait(3);
			}
		}
		task MExplode(mx2,my2,sy,scale)
		{
			let obj= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
			let img = GetCurrentScriptDirectory~"missle2.png";
			ObjPrim_SetTexture(obj,img);
			ObjRender_SetPosition(obj,mx2,my2,0);
			ObjRender_SetScaleXYZ(obj,3,3,0);
			ObjRender_SetAlpha(obj,188);
			//ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
			ascent(i in 0..16)
			{
				ObjSprite2D_SetSourceRect(obj,truncate(i/2)*32,sy,truncate(i/2)*32+32,32+sy);
				ObjSprite2D_SetDestCenter(obj);
				if(num==1){ObjRender_SetPosition(obj,mx+1.5*i*cos(langle),my+1.5*i*sin(langle),0)};
				yield;
			}
			Obj_Delete(obj);
		}
	}
}

task snake(x, y, v, dmg){
		let obj = ObjShot_Create(OBJ_SHOT);
		ObjMove_SetPosition(obj, x, y);
		ObjShot_Regist(obj);
		ObjShot_SetDamage(obj, dmg);
		ObjShot_SetPenetration(obj, 4);
		ObjMove_SetAngle(obj, 270);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjMove_SetSpeed(obj, v);
		let frame = 0;
		let count = 0;
		ObjShot_SetGraphic(obj, 4);
		if(frame==16){frame=0;}
		frame++;
		count++;
		ObjRender_SetAngleZ(obj, -90);
		let hasChanged = false;
		while(!hasChanged){
			let ar = GetIntersectionRegistedEnemyID;
			ascent(i in 0..(length(ar))){
				if((|ObjMove_GetY(obj) - 30 - ObjMove_GetY(ar[i])|)<10){
					if(ObjMove_GetX(obj) - ObjMove_GetX(ar[i])<0){
						ObjMove_SetAngle(obj, 0);
					}else{
						ObjMove_SetAngle(obj, 180);
					}
					ObjShot_SetGraphic(obj, 4);
					ObjShot_SetPenetration(obj, 2);
					ObjShot_SetDamage(obj, dmg/2);
					ObjMove_SetSpeed(obj, 20);
					orb(ObjMove_GetX(obj) - 6, ObjMove_GetY(obj) - 30);
					orb(ObjMove_GetX(obj) + 6, ObjMove_GetY(obj) - 30);
					ObjMove_SetPosition(obj, ObjMove_GetX(obj), ObjMove_GetY(obj) - 30);
					hasChanged = true;
				}

				if(Obj_IsDeleted(obj)){
				ascent(i in 0..10)
	{
		ObjRender_SetPosition(obj,ObjMove_GetX(obj), ObjMove_GetY(obj),0);
		ObjRender_SetColor(obj,160-i*10,160-i*10,160-i*10);
		ObjRender_SetScaleXYZ(obj,1*i/10,1,0);
		//BulletBreakEffectA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 180, 255, 255, 255);
		yield;
	}
					hasChanged = true;
				}
			}
			yield;
		}
	}

/*if(frame<4){ObjSprite2D_SetSourceRect(graphic,0,162,64,172);}
		if(frame>=4 && frame<8){ObjSprite2D_SetSourceRect(graphic,64,162,128,172);}
		if(frame>=8 && frame<12){ObjSprite2D_SetSourceRect(graphic,128,162,192,172);}
		if(frame>=12 && frame<16){ObjSprite2D_SetSourceRect(graphic,192,162,256,172);}
		if(frame==16){frame=0;}*/

task orb(x, y){
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"sanasn.png");
		ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 64);
		Obj_SetRenderPriorityI(obj, 23);
		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetColor(obj,155,155,155);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		ObjSprite2D_SetDestCenter(obj);
		ascent(i in 0..2){
			ObjRender_SetScaleXYZ(obj, i*0.2, i*0.2, 1);
			yield;
		}
		descent(i in 0..2){
			ObjRender_SetScaleXYZ(obj, i*0.2, i*0.2, 1);
			yield;
		}
		Obj_Delete(obj);
	}
	
task LaserDamage(obj,x,y,dir)
{
	let mainobj = CreatePlayerShotA1(x,y,0,dir,6.5,0.1,5);
	
	let graphic= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
	let img = GetCurrentScriptDirectory~"Sprite.png";
	ObjPrim_SetTexture(graphic,img);
	ObjRender_SetPosition(graphic,x,y,0);
	ObjSprite2D_SetSourceRect(graphic,32,196,64,220);
	ObjSprite2D_SetDestCenter(graphic);
	ObjRender_SetAngleXYZ(graphic,0,0,dir);
	ascent(i in 0..10)
	{
		ObjRender_SetAlpha(graphic,256-i*20);
		ObjRender_SetScaleXYZ(graphic,0.5+i/10,0.5+i/10,0);
		yield;
	}
	Obj_Delete(graphic);
	Obj_Delete(mainobj);
}

task FlameBullet(x,y,spd,dir,dmg,pdmg,type)
{
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,2);
	let acc = rand(-spd/50,-spd/70);
	let maxv = rand(spd/5,spd/6);
	let v = 0;
	let mx = 0;
	let my = 0;
	let count = 0;
	let frame = 0;
	let maxcount = 90;
	let startcolor = 192;
	let degree = 6;
	let pspd = 2;
	if(type==1)
	{
		maxcount = 20;
		startcolor = 92;
		degree = 6;
		pspd = 2;
	}
	Obj_SetVisible(mainobj,false);
	ObjMove_AddPatternA2(mainobj,0,NO_CHANGE,NO_CHANGE,acc,0,maxv);
	
	let graphic= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
	let img = GetCurrentScriptDirectory~"pl02.png";
	ObjPrim_SetTexture(graphic,img);
	ObjRender_SetPosition(graphic,x,y,0);
	ObjSprite2D_SetSourceRect(graphic,192,160,208,176);
	ObjSprite2D_SetDestCenter(graphic);
	ObjRender_SetScaleXYZ(graphic,2.25,2.25,0);
	ObjRender_SetBlendType(graphic,BLEND_ADD_ARGB);
	ObjRender_SetAngleZ(graphic,dir+90);
	Obj_SetRenderPriorityI(graphic,22);
	ObjRender_SetColor(graphic,startcolor,startcolor,startcolor);
	while(!Obj_IsDeleted(mainobj) && count<maxcount)
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		v = ObjMove_GetSpeed(mainobj);
		ObjRender_SetPosition(graphic,ObjMove_GetX(mainobj),ObjMove_GetY(mainobj),0);
		if(frame<8){ObjSprite2D_SetSourceRect(graphic,193,160,208,176);}
		if(frame>=8 && frame<16){ObjSprite2D_SetSourceRect(graphic,209,160,224,176);}
		if(frame==16){frame=0;}
		count++;
		frame++;
		yield;
	}
	Obj_Delete(mainobj);
	ascent(i in 0..30)
	{
		ObjRender_SetColor(graphic,startcolor-i*degree,startcolor-i*degree,startcolor-i*degree);
		ObjRender_SetPosition(graphic,mx+pspd*i*cos(dir),my+pspd*i*sin(dir),0);
		yield;
	}
	Obj_Delete(graphic);
}

task SpreadBullet(x,y,spd,dir,dmg,pdmg)
{
	let mx;
	let my;
	let mangle;
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,7);
	let count = 0;
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		yield;
	}
	let obj= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
	let img = GetCurrentScriptDirectory~"Sprite.png";
	let dx = 0;
	ObjPrim_SetTexture(obj,img);
	ObjRender_SetPosition(obj,mx,my,0);
	ObjRender_SetAngleZ(obj,dir+90);
	ObjSprite2D_SetSourceRect(obj,76,160,108,176);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ascent(i in 0..10)
	{
		ObjRender_SetPosition(obj,mx+2*i*cos(dir),my+2*i*sin(dir),0);
		ObjRender_SetColor(obj,160-i*10,160-i*10,160-i*10);
		ObjRender_SetScaleXYZ(obj,1-i/10,1,0);
		yield;
	}
	Obj_Delete(obj);
}

task StarBullet(x,y,spd,dir,dmg,pdmg)
{
        let shotcolor = 8;
	let mx;
	let my;
	let mangle;
	let scale = 0;
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,8);
	let count = 0;
	Obj_SetVisible(mainobj,false);
	let obj= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
	let img = GetCurrentScriptDirectory~"Sprite.png";
	let dx = 0;
	let rdir = rand(0,360);
	ObjPrim_SetTexture(obj,img);
	ObjRender_SetAngleZ(obj,rdir);
	ObjSprite2D_SetSourceRect(obj,2,160,17,176);
	ObjSprite2D_SetDestRect(obj,-7,-8,8,8);
	ObjRender_SetAlpha(obj,192);
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		ObjRender_SetPosition(obj,mx,my,0);
		ObjRender_SetAngleXYZ(obj,0,0,rdir);
		count++;
		yield;
	}
	if(mx>0 && mx<GetStgFrameWidth && my>0 && my<GetStgFrameHeight)
	{
		if(shotcolor==8){PlaySound("ShotM",40,0);}
	}
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	if(shotcolor==8){TExpanS(mx,my,-2,31,150,250,150);}
	ascent(i in 0..10)
	{
		if(shotcolor==8){ObjSprite2D_SetSourceRect(obj,68,190,95,232);}
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetAngleXYZ(obj,0,0,mangle);
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		ObjRender_SetAlpha(obj,25-i*19);
		scale+= 0.8;
		yield;
	}
	Obj_Delete(obj);
}

task ColdBullet(x,y,spd,dir,dmg,pdmg)
{
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,9);
	let acc = rand(-spd/60,-spd/60);
	let maxv = spd/3;
	let v = 0;
	let mx = 0;
	let my = 0;
	let count = 0;
	let frame = 0;
	let scale = 1;
	let maxcount = 45;
	let alpha = 192;
	Obj_SetVisible(mainobj,false);
	ObjMove_AddPatternA2(mainobj,0,NO_CHANGE,NO_CHANGE,acc,0,maxv);
	let graphic= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
	let img = GetCurrentScriptDirectory~"Sprite.png";
	ObjPrim_SetTexture(graphic,img);
	ObjRender_SetPosition(graphic,x,y,0);
	ObjSprite2D_SetSourceRect(graphic,230,145,246,161);
	ObjSprite2D_SetDestCenter(graphic);
	ObjRender_SetScaleXYZ(graphic,scale,scale,0);
	ObjRender_SetBlendType(graphic,BLEND_ADD_ARGB);
	ObjRender_SetAngleZ(graphic,rand(0,360));
	Obj_SetRenderPriorityI(graphic,22);
	while(!Obj_IsDeleted(mainobj) && count<maxcount)
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		v = ObjMove_GetSpeed(mainobj);
		ObjRender_SetPosition(graphic,ObjMove_GetX(mainobj),ObjMove_GetY(mainobj),0);
		ObjRender_SetScaleXYZ(graphic,scale,scale,0);
		ObjRender_SetColor(graphic,alpha,alpha,alpha);
		count++;
		frame++;
		scale += 0.04;
		alpha-=4;
		yield;
	}
	Obj_Delete(mainobj);
	let ratio = alpha/30;
	ascent(i in 0..30)
	{
		ObjRender_SetColor(graphic,alpha,alpha,alpha);
		ObjRender_SetPosition(graphic,mx+2*i*cos(dir),my+2*i*sin(dir),0);
		ObjRender_SetScaleXYZ(graphic,scale,scale,0);
		scale += 0.02;
		if(alpha>0){alpha-=ratio;}
		yield;
	}
	Obj_Delete(graphic);
}

task ColdShot(x,y,spd,dir,dmg,pdmg)
{
	let shotcolor = 1;
	let mx;
	let my;
	let mangle;
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,shotcolor);
	ObjRender_SetAngleZ(mainobj, -90);
	let count = 0;
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		yield;
	}
	let obj= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
	let img = GetCurrentScriptDirectory~"Sprite.png";
	let dx = 0;
	ObjPrim_SetTexture(obj,img);
	if(shotcolor==1){dx = 112;}
	ObjRender_SetPosition(obj,mx,my,0);
	ObjRender_SetAlpha(obj,128);
	ascent(i in 0..3)
	{
		ObjSprite2D_SetSourceRect(obj,dx+i*32,144,dx+32+i*32,160);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetAngleXYZ(obj,0,0,mangle);
		wait(3);
	}
	Obj_Delete(obj);
}

task AliceShot(x,y,spd,dir,dmg,pdmg,num)
{
	let mx;
	let my;
	let mangle;
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,11+num);
	ObjRender_SetAngleZ(mainobj, -90);
	let count = 0;
	while(!Obj_IsDeleted(mainobj))
	{
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		yield;
	}
	let obj= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
	let img = GetCurrentScriptDirectory~"Sprite.png";
	let dx = 0;
	let sourceX = [[0,34],[34,66],[66,97],[97,128],[130,161],[161,192],[192,223],[223,255]];
	ObjPrim_SetTexture(obj,img);
	ObjRender_SetPosition(obj,mx,my,0);
	ObjSprite2D_SetSourceRect(obj,sourceX[num][0],232,sourceX[num][1],248);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetAngleZ(obj,dir);
	ascent(i in 0..10)
	{
		ObjRender_SetPosition(obj,mx+3*i*cos(dir),my+3*i*sin(dir),0);
		ObjRender_SetAlpha(obj,160-i*10);
		ObjRender_SetScaleXYZ(obj,1,1-i/10,0);
		yield;
	}
	Obj_Delete(obj);
}

task TSpell1
{
	PlaySound("Weird1",100,0);
	PlaySound("Laser7",100,0);
	ScreenShake(300);
	spelltime = true;
	SetPlayerInvincibilityFrame(210);
	let objManage = GetSpellManageObject();
	let spell = ObjSpell_Create;
	ObjSpell_Regist(spell);
	ObjSpell_SetDamage(spell,10);
	//---------------------Graphic Part---------------------//
	let img = GetCurrentScriptDirectory~"Cold.png";
	let px = GetPlayerX;
	let py = GetPlayerY;
	Graphic1;
	Graphic2;
	Graphic3;
	Graphic4;
	wait(300);
	spelltime = false;
	PlaySound("Weird2",100,0);
	Obj_Delete(objManage);
	task Graphic1
	{
		let spellgraphic= ObjPrim_Create(OBJ_SPRITE_2D);
		let scale = 0;
		let speed = 0.3;
		let acc = 0.01;
		let imgb = GetCurrentScriptDirectory~"bright.png";
		ObjPrim_SetTexture(spellgraphic,imgb);
		ObjRender_SetPosition(spellgraphic,px,py,0);
		ObjSprite2D_SetSourceRect(spellgraphic,0,0,64,64);
		ObjSprite2D_SetDestCenter(spellgraphic);
		Obj_SetRenderPriorityI(spellgraphic,54);
		ObjRender_SetBlendType(spellgraphic,BLEND_INV_DESTRGB);
		ascent(i in 0..300)
		{
			ObjSpell_SetIntersectionCircle(spell,px,py-speed,125);
			ObjRender_SetPosition(spellgraphic,px,py-speed,0);
			ObjRender_SetScaleXYZ(spellgraphic,scale+0.15*sin((i*3)%90),scale+0.15*sin((i*3)%90),0);
			if(scale<10.8){scale+=0.085;}
			speed += acc;
			acc+=0.005;
			yield;
		}
		let scaleratio = scale/30;
		let i = 0;
		while(scale>0)
		{
			scale-=scaleratio;
			ObjRender_SetScaleXYZ(spellgraphic,scale,scale,0);
			yield;
		}
		Obj_Delete(spellgraphic);
	}
	task Graphic2
	{
		let spellgraphic= ObjPrim_Create(OBJ_SPRITE_2D);
		let scale = 0;
		let speed = 0.3;
		let acc = 0.01;
		ObjPrim_SetTexture(spellgraphic,img);
		ObjRender_SetPosition(spellgraphic,px,py,0);
		ObjSprite2D_SetSourceRect(spellgraphic,0,0,256,256);
		ObjSprite2D_SetDestCenter(spellgraphic);
		Obj_SetRenderPriorityI(spellgraphic,23);
		ObjRender_SetBlendType(spellgraphic,BLEND_ALPHA);
		ascent(i in 0..300)
		{
			ObjRender_SetPosition(spellgraphic,px,py-speed,0);
			ObjRender_SetScaleXYZ(spellgraphic,scale,scale,0);
			ObjRender_SetAngleZ(spellgraphic,-i*20);
			if(scale<1){scale+=0.05;}
			speed += acc;
			acc+=0.005;
			yield;
		}
		let scaleratio = scale/30;
		let i = 0;
		while(scale>0)
		{
			i++;
			scale-=scaleratio;
			ObjRender_SetScaleXYZ(spellgraphic,scale,scale,0);
			ObjRender_SetAngleZ(spellgraphic,-i*20);
			yield;
		}
		Obj_Delete(spellgraphic);
	}
	task Graphic3
	{
		let spellgraphic= ObjPrim_Create(OBJ_SPRITE_2D);
		let scale = 0;
		let speed = 0.3;
		let acc = 0.01;
		ObjPrim_SetTexture(spellgraphic,img);
		ObjRender_SetPosition(spellgraphic,px,py,0);
		ObjSprite2D_SetSourceRect(spellgraphic,0,0,256,256);
		ObjSprite2D_SetDestCenter(spellgraphic);
		ObjRender_SetBlendType(spellgraphic,BLEND_ADD_ARGB);
		ObjRender_SetColor(spellgraphic,155,155,255);
		Obj_SetRenderPriorityI(spellgraphic,22);
		ascent(i in 0..300)
		{
			ObjRender_SetPosition(spellgraphic,px,py-speed,0);
			ObjRender_SetScaleXYZ(spellgraphic,scale,scale,0);
			ObjRender_SetAngleZ(spellgraphic,i*17);
			if(scale<1.35){scale+=0.075;}
			speed += acc;
			acc+=0.005;
			yield;
		}
		let scaleratio = scale/30;
		let i = 0;
		while(scale>0)
		{
			i++;
			scale-=scaleratio;
			ObjRender_SetScaleXYZ(spellgraphic,scale,scale,0);
			ObjRender_SetAngleZ(spellgraphic,i*17);
			yield;
		}
		Obj_Delete(spellgraphic);
	}
	task Graphic4
	{
		let spellgraphic= ObjPrim_Create(OBJ_SPRITE_2D);
		let scale = 0;
		let speed = 0.3;
		let acc = 0.01;
		img = GetCurrentScriptDirectory~"Cold.png";
		ObjPrim_SetTexture(spellgraphic,img);
		ObjRender_SetPosition(spellgraphic,px,py,0);
		ObjSprite2D_SetSourceRect(spellgraphic,0,0,256,256);
		ObjSprite2D_SetDestCenter(spellgraphic);
		ObjRender_SetBlendType(spellgraphic,BLEND_ADD_ARGB);
		//ObjRender_SetColor(spellgraphic,80,80,80);
		Obj_SetRenderPriorityI(spellgraphic,22);
		ascent(i in 0..300)
		{
			ObjRender_SetPosition(spellgraphic,px,py-speed,0);
			ObjRender_SetScaleXYZ(spellgraphic,scale,scale,0);
			ObjRender_SetAngleZ(spellgraphic,i*-7);
			if(scale<2){scale+=0.4;}
			speed += acc;
			acc+=0.005;
			yield;
		}
		let scaleratio = scale/30;
		while(scale>0)
		{
			scale-=scaleratio;
			ObjRender_SetScaleXYZ(spellgraphic,scale,scale,0);
			yield;
		}
		Obj_Delete(spellgraphic);
	}
}

task TSpell2
{
	PlaySound("Slash",100,0);
	PlaySound("Laser7",100,0);
	spelltime = true;
	SetPlayerInvincibilityFrame(300);
	let objManage = GetSpellManageObject();
	let spell = ObjSpell_Create;
	ObjSpell_Regist(spell);
	ObjSpell_SetDamage(spell,13);
	//---------------------Graphic Part---------------------//
	let img = GetCurrentScriptDirectory~"Bomb.png";
	let playerpose = 0;
	Graphic(0);
	Graphic(1); // spell
	ScreenShake(240);
	ascent(i in 0..240)
	{
		if(GetVirtualKeyState(VK_LEFT)==KEY_HOLD){playerpose-=0.15;}
		if(GetVirtualKeyState(VK_RIGHT)==KEY_HOLD){playerpose+=0.15;}
		if(i%10==9 && i>10)
		{
			SparkRing(0);
		}
		yield;
	}
	task SparkRing(dir)
	{
		let spellgraphic= ObjPrim_Create(OBJ_SPRITE_2D);
		let scalex = 1;
		let px = GetPlayerX;
		let py = GetPlayerY;
		let acc = 0.2;
		dir = 270+playerpose;
		ObjPrim_SetTexture(spellgraphic,img);
		ObjRender_SetBlendType(spellgraphic,BLEND_ADD_ARGB);
		Obj_SetRenderPriorityI(spellgraphic,24);
		ObjRender_SetColor(spellgraphic,255,255,255);		
		ObjSprite2D_SetSourceRect(spellgraphic,0,128,56,256);
		ObjSprite2D_SetDestCenter(spellgraphic);
		ObjRender_SetAngleZ(spellgraphic,-90+playerpose);
		ascent(i in 0..30)
		{
			dir = 270+playerpose;
			ObjRender_SetAngleZ(spellgraphic,-90+playerpose);
			ObjRender_SetPosition(spellgraphic,px+i*25*cos(dir),py+i*25*sin(dir),0);
			ObjRender_SetScaleXYZ(spellgraphic,2,scalex,0);
			if(scalex<3){scalex+=acc;acc-=0.01;}
			yield;
		}
		Obj_Delete(spellgraphic);
	}
	task Graphic(type)
	{
		let spellgraphic= ObjPrim_Create(OBJ_SPRITE_2D);
		let scalex = 0;
		let ratio = (1.75+type*0.75)/(30);
		ObjPrim_SetTexture(spellgraphic,img);
		ObjRender_SetBlendType(spellgraphic,BLEND_ADD_ARGB);
		Obj_SetRenderPriorityI(spellgraphic,24);
		ObjRender_SetColor(spellgraphic,255,255,255);
		if(type==1)
		{
			ObjRender_SetBlendType(spellgraphic,BLEND_ADD_ARGB);
			Obj_SetRenderPriorityI(spellgraphic,23);
			ObjRender_SetColor(spellgraphic,255,255,255);
		}
		ObjSprite2D_SetSourceRect(spellgraphic,1,1,256,128);
		ObjSprite2D_SetDestRect(spellgraphic,-128,-64,128,64);
		ObjRender_SetAngleZ(spellgraphic,-90);
		SetPlayerSpeed(vx/4, vy/4);
		ascent(i in 0..240)
		{
			let angle = 270+playerpose;
			let r = 244;
			ObjRender_SetPosition(spellgraphic,GetPlayerX+r*cos(angle),GetPlayerY+r*sin(angle),0);
			ObjRender_SetScaleXYZ(spellgraphic,2.1,scalex,0);
			ObjRender_SetAngleZ(spellgraphic,-90+playerpose);
			if(scalex<1.75+type*0.75){scalex+=ratio;}
			ObjSpell_SetIntersectionLine(spell,GetPlayerX,GetPlayerY,GetPlayerX+900*cos(angle),GetPlayerY+900*sin(angle),scalex*52.5);
			yield;
		}
		SetPlayerSpeed(vx, vy);
		while(scalex>-0.1)
		{
			let angle = 270+playerpose;
			let r = 244;
			ObjRender_SetPosition(spellgraphic,GetPlayerX+r*cos(angle),GetPlayerY+r*sin(angle),0);
			ObjRender_SetScaleXYZ(spellgraphic,2.1,scalex,0);
			ObjRender_SetAngleZ(spellgraphic,-90+playerpose);
			scalex-=ratio*2;
			yield;
		}
		Obj_Delete(spellgraphic);
		spelltime = false;
		Obj_Delete(objManage);
	}
}

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,25);
	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 TExpanS(px,py,maxv,t,r,g,b)
{
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./Sx.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,25);
	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(px,py,maxv,t,r,g,b) // Missile Explode
{
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./MissleExplode.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_ALPHA);
	ObjRender_SetPosition(obj,px,py,0);
	ObjRender_SetColor(obj,r,g,b);
	Obj_SetRenderPriorityI(obj,25);
	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);
		}
}


		
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);
		if(spelltime==false)
		{
			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) && Obj_GetValueD(h_obj,"HomingOrNot",1)==1 && FindTarget!=-1) {
        ObjMove_SetAngle(obj, angle);
		maxTraverse += 0.2;
		if(length(boss)>=1){
		dir = atan2(ObjMove_GetY(h_obj) - ObjMove_GetY(obj),
                        ObjMove_GetX(h_obj) - ObjMove_GetX(obj));
						if(ObjRender_GetX(h_obj)==0 && ObjRender_GetY(h_obj) ==0){
							if(FindTarget!=-1)
							{
								h_obj = FindTarget;
							}
							else
							{
								break;
							}
						}
						}
        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 PlaySound(str,v,w){
	if(str == "Laser7"){ObjSound_Load(s,GetCurrentScriptDirectory~"Laser7.wav");}
	if(str == "Shot7"){ObjSound_Load(s,GetCurrentScriptDirectory~"Shot7.wav");}
	if(str == "Shot8"){ObjSound_Load(s,GetCurrentScriptDirectory~"Shot8.wav");}
	if(str == "Shot9"){ObjSound_Load(s,GetCurrentScriptDirectory~"Shot9.wav");}
	if(str == "ShotM"){ObjSound_Load(s,GetCurrentScriptDirectory~"ShotM.wav");}
	if(str == "Charge1"){ObjSound_Load(s,GetCurrentScriptDirectory~"Charge1.wav");}
	if(str == "Charge2"){ObjSound_Load(s,GetCurrentScriptDirectory~"Charge2.wav");}
	if(str == "Charge3"){ObjSound_Load(s,GetCurrentScriptDirectory~"Charge3.wav");}
	if(str == "Charge4"){ObjSound_Load(s,GetCurrentScriptDirectory~"Charge4.wav");}
	if(str == "Eff2"){ObjSound_Load(s,GetCurrentScriptDirectory~"Eff2.wav");}
	if(str == "se_shot"){ObjSound_Load(s,GetCurrentScriptDirectory~"se_shot.wav");}
	if(str == "Slash"){ObjSound_Load(s,GetCurrentScriptDirectory~"Slash.wav");}
	if(str == "Weird1"){ObjSound_Load(s,GetCurrentScriptDirectory~"Weird1.wav");}
	if(str == "Weird2"){ObjSound_Load(s,GetCurrentScriptDirectory~"Weird2.wav");}
	if(str == "Weird3"){ObjSound_Load(s,GetCurrentScriptDirectory~"Weird3.wav");}
	loop(w){yield;}
	ObjSound_SetSoundDivision(s,SOUND_SE);
	ObjSound_SetVolumeRate(s,v);
	ObjSound_Play(s);
	/*loop(120){yield;}
	Obj_Delete(s);*/
	}

				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;}
	}
