#TouhouDanmakufu[Player]
#ScriptVersion[3]
#ID["gusano_contest4"]
#Title["Yukari-Nitori"]
#Text["For Contest 4[r]By Gusano2314"]
#Image["./img_Cutin.png"]
#ReplayName["gap-kappa"]

/* 
Original Player By gtbot
*/




let MaximumParticles = 24; // Maximum number of particles allowed
let AllowShotDecay = true; // Renders the shot degeneration effect when true
let AllowGrazePart = true; // Renders a particle when you graze when true
let GrazePartNum = 3; // Number of particles created when you graze a single bullet




/*
The following are common datas that this player uses. You may use
this data to further manipulate your scripts (or player) to your needs.

 --- Global Common Data --- 
	+ Common Data that is globally used
	
	- TimeSlow - Set to any value above 1 to slow down processes
					Change to 1 once you want normal time.
	
	- TimeStop - Set to any value above 0 to stop processes
					Change to 0 once you want normal time.
					
	
 --- Common Area Data --- 
	+ Area Common Data that use the area "c_Player_v1"
	
	GetRenderObject 	- Gets the object that renders the player's
							image + animation
	GetPlayerSpeed		- Returns the player's normal speed in an array
							[Unshift Speed, Shift Speed]
	ForceOptionsOff		- Set to true to hide options and other objects
							that may use this value
							
	GetTimerObject1		- Returns Reisen's bar gauge object
	GetTimerObject2		- Returns Tewi's bar gauge object
*/




let unshiftspd = 3.55;
let shiftspd = 2;
let playertype = 1;
let playerdead = false;
let playerchange = 0;
let TimeSpeed = 1;

let shotCount = 1;
let ShotDamage = 0;
let BombType = 0;
let ReisenMeter = 45;
let IsReisenActive = false;
let TewiMeter = 45;
let IsTewiActive = false;
let IsAnyActive = false;
let TotalParticleCount = 0;

let ActivateHitbox = false;
let RefreshOptions = false;
let ForceOptionsOff = false;
let CanShoot = true;
let IsTimeStopped = false;
let IsPlayerSpawning = false;


let AngulO = 0;


let BasePlayerObj = GetPlayerObjectID;
let objPlayer = ObjPrim_Create(OBJ_SPRITE_2D);
let current = GetCurrentScriptDirectory;

let imgPlayer = current ~ "img_Player.png";
let imgPlayer2 = current ~ "img_Player2.png";
let imgField = current ~ "img_Field.png";
let imgEffect = current ~ "img_Effect.png";
let imgAscii = current ~ "img_Ascii.png";


@Initialize{
	LoadPlayerShotData(current ~ "a_shotdata.txt"); 
	CreateCommonDataArea("c_Player_v1");
	SetCommonData("PlayerTimeSync", true);
	SetAreaCommonData("c_Player_v1", "GetRenderObject", objPlayer);
	SetAreaCommonData("c_Player_v1", "GetPlayerSpeed", [unshiftspd, shiftspd]);
	
	ObjPlayer_AddIntersectionCircleA1(BasePlayerObj, 0, 0, 2, 20); 
	
	SetPlayerRebirthFrame(24);
	SetPlayerRebirthLossFrame(6);
	
	SetPlayerSpeed(unshiftspd,shiftspd);
	SetPlayerAutoItemCollectLine(128);
	
	ShotType;

	LoadSound(current~"se_pldead.wav");
	LoadSound(current~"se_shot.wav");
	LoadSound(current~"se_spell.wav");
	LoadSound(current~"se_power.wav");
	LoadSound(current~"se_getlife.wav");
	LoadSound(current~"se_graze.wav");
	LoadSound(current~"se_item.wav");
	
	LoadSound(current~"se_ch1.wav");
	LoadSound(current~"se_ch1ready.wav");
	LoadSound(current~"se_ch1end.wav");
	LoadSound(current~"se_ch2ready.wav");
	LoadSound(current~"se_ch2end.wav");
	
	LoadSound(current~"se_spell1end.wav");
	LoadSound(current~"se_spell1normal.wav");
	LoadSound(current~"se_spell1phantasm.wav");
	LoadSound(current~"se_spell2normal.wav");
	LoadSound(current~"se_spell2phantasm.wav");
	LoadSound(current~"se_spell3.wav");
	
	
	LoadTexture(imgPlayer);
	LoadTexture(imgPlayer2);
	LoadTexture(imgEffect);
	LoadTexture(imgField);
	LoadTexture(imgAscii);
	
	Obj_SetValue(objPlayer, "dinv", -1);
	RenderPlayerImage(objPlayer);
	
	
	RenderHitboxImage(objPlayer,0,1);
	RenderHitboxImage(objPlayer,0,2);
	
		CreateOptionS1(objPlayer, 0, 12, 24, -12, 270, 1, -1, 1,0);
		CreateOptionS1(objPlayer, 0, 12, 24, -12, 270, 1, -1, 1,180);
CreateOptionS1(objPlayer, 0, 12, 24, -12, 270, 1, -1, 1,90);
CreateOptionS1(objPlayer, 0, 12, 24, -12, 270, 1, -1, 1,270);
	
	SetPlayerSpell(3);
	Spawn;
}


@MainLoop{
	if(GetPlayerState==STATE_DOWN){CanShoot = false;}
	if(GetPlayerState==STATE_NORMAL){CanShoot = true;}
	if(IsPermitPlayerShot==false && GetPlayerState==STATE_NORMAL){CanShoot = false;}
	if(IsPermitPlayerShot==true && GetPlayerState==STATE_NORMAL){CanShoot = true;}
	
	if(IsPlayerSpawning==false){
		SetPlayerClip(11,11,GetStgFrameWidth-11,GetStgFrameHeight-18);
		if(GetPlayerState==STATE_NORMAL){
			if(IsAnyActive==false&&CanShoot==true&&IsTimeStopped==false){
				AddToCharge(0.0475, 0);
			}
			if(IsAnyActive==false){
				if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH){RenderTeamChangeImage(2, false);}
				if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_PULL){RenderTeamChangeImage(1, false);}
			
				if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD && playerchange == 0 && playertype == 1){RenderTeamChangeImage(2, false);}
				if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_FREE && playerchange == 0 && playertype == 2){RenderTeamChangeImage(1, false);}
			}
		}
	}
	
	AngulO += 8;
	
	ForceOptionsOff = GetAreaCommonData("ForceOptionsOff", "c_Player_v1", false);
	
	
	if(IsReisenActive||IsTewiActive){IsAnyActive=true;}else{IsAnyActive=false;}
	
	if(GetVirtualKeyState(VK_USER1)!=KEY_FREE&&IsAnyActive == false
	&&ReisenMeter == 100&&playertype == 1){
		//ReisenTrio;
	}	
	if(GetVirtualKeyState(VK_USER1)!=KEY_FREE&&IsAnyActive == false
	&&TewiMeter == 100&&playertype == 2){
		//TewiPlayful;
	}
	
	if(GetCommonData("TimeStop", 0) != 0 && IsTimeStopped == false){TimeFrozen(-1);}
	TimeSpeed = GetCommonData("TimeSlow", 1);
	yield;
}

@Finalize{	
	RemoveTexture(imgPlayer);
	RemoveTexture(imgPlayer2);
	RemoveTexture(imgEffect);
	RemoveTexture(imgField);
	RemoveTexture(imgAscii);
	RemoveSound(current~"se_pldead.wav");
	RemoveSound(current~"se_shot.wav");
	RemoveSound(current~"se_spell.wav");
	RemoveSound(current~"se_power.wav");
	RemoveSound(current~"se_getlife.wav");
	RemoveSound(current~"se_graze.wav");
	RemoveSound(current~"se_item.wav");
	
	
	
	RemoveSound(current~"se_ch1.wav");
	RemoveSound(current~"se_ch1ready.wav");
	RemoveSound(current~"se_ch1end.wav");
	
	RemoveSound(current~"se_ch2ready.wav");
	RemoveSound(current~"se_ch2end.wav");
	
	RemoveSound(current~"se_spell1normal.wav");
	RemoveSound(current~"se_spell1phantasm.wav");
}

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_SPELL){
		if(GetPlayerSpell >= 1 && !IsTimeStopped){
			SetPlayerInvincibilityFrame(2);
			if(playerchange == 1 && GetPlayerState!=STATE_HIT){
				SetScriptResult(false);
				return;
			}
			SetScriptResult(true);
			PlaySE(current~"se_spell.wav");
			SetPlayerSpell(GetPlayerSpell-1);
			if(playertype == 1){
				if(GetPlayerState==STATE_HIT){
					SetPlayerSpell(max(0, GetPlayerSpell-1));
					//RenderTeamChangeImage(2, true);
					//TewiJeweledRabbits(1);
ReisenLunaticEyes(1);
//bomb1;
				}else{
ReisenLunaticEyes(1);
//bomb1;
					//ReisenGatlingGun(0);
				}
			}
			if(playertype == 2){
				if(GetPlayerState==STATE_HIT){
					SetPlayerSpell(max(0, GetPlayerSpell-1));
					RenderTeamChangeImage(1, true);
					ReisenLunaticEyes(1);
//TewiJeweledRabbits(1);
				}else{
//TewiJeweledRabbits(1);
RenderTeamChangeImage(1, true);
ReisenLunaticEyes(1);
					//TewiJeweledTewi(0);
				}
			}
		}
		else{
			SetScriptResult(false);
		}
	}
	case(EV_PLAYER_SHOOTDOWN){
		CanShoot = false;
		playerdead = true;
	}
	case(EV_HIT){
		PlaySE(current~"se_pldead.wav");
		loop(12){MapleLeaf(GetPlayerX, GetPlayerY, rand(0,360), rand(85, 185), 1.8);}
		DeathExplosion(0);
		ClearEnemyBullets(GetPlayerX, GetPlayerY, 10, 8, 900, GetPlayerRebirthFrame+31);
	}
	case(EV_PLAYER_REBIRTH){
		SetPlayerRebirthFrame(18);
		ClearEnemyBullets(GetPlayerX, GetPlayerY, 10, 15, 200, 0);
		SetPlayerInvincibilityFrame(135);
		AddToCharge(30, 1);
		AddToCharge(30, 2);
		playerdead = false;
		SetPlayerSpell(3);
		Spawn;
	}
	case(EV_GET_ITEM){
		let div = 1;
		if(IsReisenActive==true){div = 2;}
		alternative(GetEventArgument(0))
		case(ITEM_1UP){
			AddToCharge(85, 0);
			PlaySE(current~"se_getlife.wav");
			SetPlayerLife(GetPlayerLife+1);
		}
		case(ITEM_1UP_S){
			AddToCharge(85, 0);
			PlaySE(current~"se_getlife.wav");
			SetPlayerLife(GetPlayerLife+1);
		}
		case(ITEM_SPELL){
			AddToCharge(45, 0);
			PlaySE(current~"se_getlife.wav");
			SetPlayerSpell(GetPlayerSpell+1);
		}
		case(ITEM_SPELL_S){
			AddToCharge(45, 0);
			PlaySE(current~"se_getlife.wav");
			SetPlayerSpell(GetPlayerSpell+1);
		}
		case(ITEM_POWER){
			AddToCharge(20, 0);
			PlaySE(current~"se_item.wav");
		}
		case(ITEM_POWER_S){
			AddToCharge(0.575/div, 0);
			PlaySE(current~"se_item.wav");
		}
		others{
			AddToCharge(0.15/div, 0);
			PlaySE(current~"se_item.wav");
		}
	}
	case(EV_GRAZE){
		PlaySE(current~"se_graze.wav");
		loop(GrazePartNum){Particle(GetPlayerX, GetPlayerY, rand(0,360), rand(15, 85), 0.8);}
	}
}

task Spawn{
	let obj = GetPlayerObjectID;
	let y = 0;
	ObjRender_SetX(obj, GetStgFrameWidth/2);
	ObjRender_SetY(obj, GetStgFrameHeight-32);
	SetPlayerSpeed(0,0);
	IsPlayerSpawning = true;
	while(y<82){
		if(IsTimeStopped==false){
			SetPlayerClip(11,11,GetStgFrameWidth-11,GetStgFrameHeight+64);	
			SetPlayerSpeed(0,0);
			ObjRender_SetY(obj, GetStgFrameHeight+32-y);
			y+=2/TimeSpeed;
		}
		yield;
	}
	IsPlayerSpawning = false;
	SetPlayerSpeed(unshiftspd,shiftspd);
}

task TimeFrozen(num){
	let Uber = GetPlayerInvincibilityFrame;
	IsTimeStopped = true;
	SetPlayerSpeed(0, 0);
	ObjPlayer_ClearIntersection(BasePlayerObj);
	while(GetCommonData("TimeStop", 0) != 0 || num > 0){
		SetPlayerInvincibilityFrame(Uber);
		SetPlayerSpeed(0, 0);
		num--;
		if(IsReisenActive == true){break;}
		yield;
	}
	IsTimeStopped = false;
	SetPlayerSpeed(unshiftspd, shiftspd);
	ObjPlayer_AddIntersectionCircleA1(BasePlayerObj, 0, 0, 2, 20); 
}


task RenderPlayerImage(ObjectRender){	
	let anim_count = 0;
	let anim_type = 0;
	let Uber = 0;
	let Uberblink = 0;
	
	let x = 32;
	let y = 48;
	let ri = 6;
	let rm = 4;
	let bn = 0;
	
	ObjPrim_SetTexture(ObjectRender, imgPlayer);
	Obj_SetRenderPriority(ObjectRender, 0.45);
	
	
	while(!Obj_IsDeleted(ObjectRender)){
		if(GetPlayerState!=STATE_DOWN){
			ObjRender_SetAlpha(ObjectRender, 255);
		}
		
		if(GetPlayerState!=STATE_NORMAL || playerdead == true){ObjRender_SetAlpha(ObjectRender, 0);}
		ObjRender_SetPosition(ObjectRender, GetPlayerX, GetPlayerY, 0);
		
		
		if(IsPlayerSpawning==false){
			if(IsTimeStopped == false){
				Blink;
				if(GetVirtualKeyState(VK_RIGHT) == KEY_FREE && GetVirtualKeyState(VK_LEFT) == KEY_FREE){
					if(anim_type != 0){
						bn = 0;
						anim_count = 0;
						anim_type = 0;
					}
				}
				if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_LEFT) == KEY_HOLD){
					if(GetVirtualKeyState(VK_RIGHT) != KEY_HOLD && anim_type != 1){
						bn = 0.85;
						anim_count = 0;
						anim_type = 1;
					}
				}
				if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_RIGHT) == KEY_HOLD){
					if(anim_type != 2){
						bn = 0.85;
						anim_count = 0;
						anim_type = 2;
					}
				}
				anim_count+=(1+bn)/TimeSpeed;
				if(floor(anim_count) != anim_count && TimeSpeed == 1 && bn == 0){
					anim_count = floor(anim_count);
				}
			}
		}else{
			if(IsTimeStopped==false){
				Blink;
				anim_count+=1/TimeSpeed;
				if(anim_type != 0){
					anim_count = 0;
					anim_type = 0;
				}
			}
		}
		//0 - Idle; 1 - Left; 2 - Right;
		if(IsTimeStopped == false){
			if(round(anim_count) >= ri*3){anim_count = 0;}
			if(playertype == 1){
				ObjRender_SetScaleXYZ(ObjectRender, 1.25, 1.25, 1);
				x = 32;
				y = 32;
				if(anim_type==0){
					ObjSprite2D_SetSourceRect(ObjectRender, 0, 144+y*floor(anim_count/ri), x, 144+y*floor(anim_count/ri+1));
				}
				if(anim_type==1){
					ObjSprite2D_SetSourceRect(ObjectRender, x, 144+y*floor(anim_count/ri), x*2, 144+y*floor(anim_count/ri+1));
				}
				if(anim_type==2){
					ObjSprite2D_SetSourceRect(ObjectRender, x*2, 144+y*floor(anim_count/ri), x*3, 144+y*floor(anim_count/ri+1));
				}
			}else if(playertype == 2){
				ObjRender_SetScaleXYZ(ObjectRender, 1, 1, 1);
				x = 48;
				y = 48;
				if(anim_type==0){
					ObjSprite2D_SetSourceRect(ObjectRender, x*floor(anim_count/ri), 0, x*floor(anim_count/ri+1), y);
				}
				if(anim_type==1){
					ObjSprite2D_SetSourceRect(ObjectRender, x*floor(anim_count/ri), y, x*floor(anim_count/ri+1), y*2);
				}
				if(anim_type==2){
					ObjSprite2D_SetSourceRect(ObjectRender, x*floor(anim_count/ri), y*2, x*floor(anim_count/ri+1), y*3);
				}
			}
		}
		ObjSprite2D_SetDestCenter(ObjectRender);
		yield;
	}
	task Blink{
		if(GetPlayerInvincibilityFrame>0 || Obj_GetValue(ObjectRender, "dinv")>=0){
			if(Uber==0){ObjRender_SetColor(ObjectRender, 255, 255, 255);}
			if(Uber!=0){ObjRender_SetColor(ObjectRender, 0, 0, 200);}
			Uberblink+=1/TimeSpeed;
			if(Uberblink>1){Uberblink=0;Uber++;if(Uber>1){Uber=0}}
		}else{
			ObjRender_SetColor(ObjectRender, 255, 255, 255);
		}
	}
}

task RenderHitboxImage(plobj, offx, hitboxnum){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let ObjTime = 0;
	let offset = offx;
	
	let AlphaSet = 0;
	let ObjAlpha = 0;
	let ObjScale = 2.02;
	
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	if(hitboxnum==1){Obj_SetRenderPriority(obj, 0.69);}
	if(hitboxnum==2){Obj_SetRenderPriority(obj, 0.39);}
	ObjRender_SetAlpha(obj, 255);
	ObjPrim_SetTexture(obj, imgEffect);
	ObjSprite2D_SetSourceRect(obj, 63, 231, 127, 292);
	ObjSprite2D_SetDestCenter(obj);
	while(Obj_IsDeleted(plobj) == false){
		if(IsTimeStopped==false){
			ObjTime++;
			ObjRender_SetPosition(obj, GetPlayerX+offset, GetPlayerY+1, 0);
			if(IsPlayerSpellActive==true){
				if(BombType == 1 || BombType == 2){AlphaSet=0;}
				if(BombType == 3 || BombType == 4){AlphaSet=1;}
			}else{
				if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_FREE){AlphaSet=0;}
				if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD){AlphaSet=1;}
				if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH){ActivateHitbox = true;}
			}
			
			if(ActivateHitbox == true){ObjScale=2.02;ObjAlpha=0;ActivateHitbox = false;}
			if(ObjScale<0){ObjScale = 2.02}

			if(AlphaSet==0){
				if(ObjAlpha>0){
					ObjAlpha-=15;ObjScale-=0.07;
				}else{
					ObjScale = 0;
				}
			}
			if(AlphaSet==1){
				if(ObjAlpha<255){
					ObjAlpha+=15;ObjScale-=0.06;ObjTime+=6
				}else{
					ObjScale = 1;
				}
			}
			if(GetPlayerState == STATE_NORMAL){
				ObjRender_SetScaleXYZ(obj, ObjScale, ObjScale, 0);
				ObjRender_SetAlpha(obj, ObjAlpha);
				if(hitboxnum==1){ObjRender_SetAngleXYZ(obj, 0, 0, ObjTime*4);}
				if(hitboxnum==2){ObjRender_SetAngleXYZ(obj, 0, 0, ObjTime*-4);}
			}
			if(GetPlayerState==STATE_DOWN||GetPlayerState==STATE_END){ObjRender_SetAlpha(obj, 0);}
		}
		yield;
	}
	Obj_Delete(obj);
}

task RenderTeamChangeImage(num, exception){
	if(IsPlayerSpellActive == true && exception == false){return;}
	if(playerchange==1||RefreshOptions){return;}
	if(GetCommonData("TimeStop", 0) > 0){return;}
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let ObjTime = 0;
	
	let AlphaSet = 0;
	let ObjAlpha = 200;
	let ObjScale = 0;
	let ObjSclInc = 0.18;
	if(num == 1){
		let ObjScale = 3.6;
		let ObjSclInc = -0.18;
	}
	let HitX = GetPlayerX;
	let HitY = GetPlayerY;
	let Radio = 50;
                     let angulo = 0;
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	ObjPrim_SetTexture(obj, imgEffect);
	ObjSprite2D_SetSourceRect(obj, 1, 234, 62, 296);
	ObjSprite2D_SetDestRect(obj, -32, -32, 32, 32);
	
	Obj_SetRenderPriority(obj, 0.68);
	ObjRender_SetAlpha(obj, 200);
	ObjRender_SetPosition(obj, GetPlayerX, GetPlayerY, 0);
	ObjRender_SetColor(obj, 10, 12, 10);
	playerchange = 1;
	RefreshOptions=true;
	while(ObjAlpha>0){
		ObjAlpha-=10;
		ObjScale+=ObjSclInc;
		ObjRender_SetScaleXYZ(obj, ObjScale, ObjScale, 0);
		ObjRender_SetAlpha(obj, ObjAlpha);
		ObjRender_SetPosition(obj, GetPlayerX, GetPlayerY, 0);
		if(ObjAlpha==150){playertype = num;playerchange = 0;}
		yield;
	}
	RefreshOptions=false;
	
	
	if(playertype == 1){
		CreateOptionS1(objPlayer, 0, 12, 24, -12, 270, 1, -1, 1,0);
		CreateOptionS1(objPlayer, 0, 12, 24, -12, 270, 1, -1, 1,180);
CreateOptionS1(objPlayer, 0, 12, 24, -12, 270, 1, -1, 1,90);
CreateOptionS1(objPlayer, 0, 12, 24, -12, 270, 1, -1, 1,270);
	}else{
		CreateOptionS1(objPlayer, 24, 6, -24, -14, 280, 2, 1, 0.65,0);
		CreateOptionS1(objPlayer, -24, 6, 24, -14, 260, 2, -1, 0.65,0);
		CreateOptionS1(objPlayer, 48, 6, -60, -34, 290, 2, 1, 0.65,0);
		CreateOptionS1(objPlayer, -48, 6, 60, -34, 250, 2, -1, 0.65,0);
	}
	Obj_Delete(obj);
	
}


task DeathExplosion(offx){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ALPHA );
	Obj_SetRenderPriority(obj, 0.60);
	ObjPrim_SetTexture(obj, imgEffect);
	ObjSprite2D_SetSourceRect(obj, 198, 232, 262, 296);
	ObjSprite2D_SetDestRect(obj, -32, -32, 32, 32);

	let alpha = 200;
	let scale = 0;
	let expo = 0.4;
	while(alpha>0){
		scale += expo/TimeSpeed;
		alpha -= 5/TimeSpeed;
		if(expo>0){expo -=0.0085/TimeSpeed;}
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, GetPlayerX+offx, GetPlayerY, 0);
		ObjRender_SetScaleXYZ(obj, scale/2, scale/2, 1);
		yield;
	}
	yield;Obj_Delete(obj);
}

task ClearEnemyBullets(x, y, Tsize, Tspd, Tmaxrad, delay){
	let barray = GetShotIdInCircleA2(x, y, Tsize, TARGET_ENEMY);
	let stopclear = true;
	loop(delay){yield;}
	while(stopclear==true && GetPlayerState==STATE_DOWN){
		barray = GetShotIdInCircleA2(x, y, Tsize, TARGET_ENEMY);
		ascent(i in 0..length(barray)){
			let o = barray[i];
			if(ObjShot_IsSpellResist(o) == false){ObjShot_SetDeleteFrame(o, 0);}
		}
		Tsize += Tspd;
		if(Tsize>=Tmaxrad){
			stopclear = false;
		}
		yield;
	}
}

task ShadowA1(dumobj, incremental, alpha, colorR, colorG, colorB){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let xBend = 1;
	let BendInc = 0.22;
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.30);
	ObjRender_SetAlpha(obj, alpha);
	ObjPrim_SetTexture(obj, imgEffect);
	ObjSprite2D_SetSourceRect(obj, 0, 234, 62, 296);
	ObjSprite2D_SetDestRect(obj, -xBend, -xBend, xBend, xBend);
	ObjRender_SetPosition(obj, GetPlayerX, GetPlayerY, 0);
	ObjRender_SetColor(obj, colorR, colorG, colorB);
	while(!Obj_IsDeleted(dumobj)){
		ObjSprite2D_SetDestRect(obj, -xBend, -xBend, xBend, xBend);
		if(xBend<1500){
			xBend+=BendInc;
			BendInc+=incremental/TimeSpeed;
		}
		yield;
	}
	while(alpha>0){
		alpha -= 3/TimeSpeed;
		ObjRender_SetAlpha(obj, alpha);
		yield;
	}
	Obj_Delete(obj);
}

task ShadowA2(x, y, alpha, alphinc, colorR, colorG, colorB){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let ShadowTime = 0;
	let xBend = 1250;
	let BendInc = 0.22;
	let ShadSet = 0;
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.69);
	ObjRender_SetAlpha(obj, alpha);
	ObjPrim_SetTexture(obj, imgEffect);
	ObjSprite2D_SetSourceRect(obj, 0, 234, 62, 296);
	ObjSprite2D_SetDestRect(obj, -xBend, -xBend, xBend, xBend);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjRender_SetColor(obj, colorR, colorG, colorB);
	while(alpha>0){
		alpha += alphinc;
		ObjRender_SetAlpha(obj, alpha);
		yield;
	}
	Obj_Delete(obj);
}



task ShotType{
	let loopCount = 0;
	loop{
		FireShotData;
		PlayerShoot;
		yield;
	}
	
	task FireShotData{

		if(GetVirtualKeyState(VK_SHOT)!=KEY_FREE){loopCount = 1;}
		
		if(loopCount>0){
			if(IsTimeStopped==false){
				loopCount++;
				shotCount-=1/TimeSpeed;
			}
			if(loopCount>28||IsPlayerSpawning==true){
				loopCount = 0;
				shotCount = 1;
			}
		}
	}
	task PlayerShoot{		
		if(shotCount <= 0 && CanShoot == true){
			PlaySE(current~"se_shot.wav");
if(playertype ==1){
			CreatePlayerObjShotA1(GetPlayerX-9, GetPlayerY-16, 15, 265, 6, 1, 1, playertype+1);
CreatePlayerObjShotA1(GetPlayerX, GetPlayerY-16, 15, 270, 6, 1, 1, playertype+1);
			CreatePlayerObjShotA1(GetPlayerX+11, GetPlayerY-16, 15, 275, 6, 1, 1, playertype+1);
			yield;
}else{
CreatePlayerObjShotA1(GetPlayerX-9, GetPlayerY-16, 15, 270, 6, 1, 1, playertype+1);
CreatePlayerObjShotA1(GetPlayerX+11, GetPlayerY-16, 15, 270, 6, 1, 1, playertype+1);
yield;
}
			shotCount = 4;
		}
	}
}

task CreatePlayerObjShotA1(ShotX, ShotY, Shotspd, Shotangle, Shotdmg, pwr, Shotpenetration, Shotgraphic){
	let ShotObj = CreatePlayerShotA1(ShotX, ShotY, Shotspd, Shotangle, Shotdmg, Shotpenetration, Shotgraphic);
	let X = 0;
	let Y = 0;
	let A = 0;
	while(Obj_IsDeleted(ShotObj)==false){
		X = ObjRender_GetX(ShotObj);
		Y = ObjRender_GetY(ShotObj);
		A = ObjMove_GetAngle(ShotObj);
		ObjMove_SetSpeed(ShotObj, Shotspd/TimeSpeed);
		yield;
	}
	if(X>1 && Y >1){ShotHit(X, Y-8, A, Shotgraphic);loop(2){Particle(X, Y, A+rand(-70,70), 105, rand(0.25, 0.55))}}
}

task CreatePlayerObjShotA2(ShotX, ShotY, Shotspd, Shotangle, Shotdmg, pwr, Shotpenetration, Shotgraphic){
	let san = Shotangle-180;
	if(GetEnemyID==ID_INVALID){san = Shotangle}
	let ShotObj = CreatePlayerShotA1(ShotX, ShotY, Shotspd, san, Shotdmg, Shotpenetration, Shotgraphic);
	let X = ShotX;
	let Y = ShotY;
	let A = san;
	let S = 0;
	let mod = 2;
	while(Obj_IsDeleted(ShotObj)==false){
		if(!IsTimeStopped){
			X = ObjRender_GetX(ShotObj);
			Y = ObjRender_GetY(ShotObj);
			let eID = GetClosestEnemyID(ObjRender_GetX(ShotObj), ObjRender_GetY(ShotObj));
			let movea = atan2(ObjRender_GetY(eID)-ObjRender_GetY(ShotObj), ObjRender_GetX(eID)-ObjRender_GetX(ShotObj));
			if(eID!=ID_INVALID){
				let dir = atan2(ObjRender_GetY(eID) - Y, ObjRender_GetX(eID) - X);
				let diff = dir - A;
				while(diff >= 180) { diff -= 360; }
				while(diff < -180) { diff += 360; }
				let diffAbs = (|diff|);
				if(diffAbs <= 8*mod) {
					A = dir;
				}else{
					A += 8*mod * diff / diffAbs;
				}
			}else{
				let dir = Shotangle;
				let diff = dir - A;
				while(diff >= 180) { diff -= 360; }
				while(diff < -180) { diff += 360; }
				let diffAbs = (|diff|);
				if(diffAbs >= 8*mod) {
					A += 8*mod * diff / diffAbs;
				}else{
				}
			}
			//ObjMove_SetAngle(ShotObj, A);
			
			S+=1/TimeSpeed;
			mod = max(mod-0.025, 1);
			if(S>45){
				S+=4/TimeSpeed;
				ObjMove_SetSpeed(ShotObj, (Shotspd+S/100)/TimeSpeed);
			}else{
				ObjMove_SetAngle(ShotObj, A);
				ObjMove_SetSpeed(ShotObj, Shotspd/TimeSpeed);
			}
		}
		yield;
	}
	if(X>1 && Y >1){ShotHit(X, Y-8, A, Shotgraphic);loop(2){Particle(X, Y, A+rand(-70,70), 105, rand(0.25, 0.55))}}
}


task CreateOptionS1(robj, X1, Y1, X2, Y2, angle, type, s, dmg,EX){
	if(RefreshOptions){return;}
	let x = type;
	let y = 9;
	let oripla = playertype;
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D); 
	ObjPrim_SetTexture(obj, imgEffect);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.5);
	ObjSpriteList2D_SetSourceRect(obj, x*16, y*16, (x+1)*16+1, (y+1)*16);
	ObjSpriteList2D_SetDestCenter(obj);
	let rx = GetPlayerX;
	let ry = GetPlayerY;
let RadiO = 50;
	let alp = 0;
	let scaleset = 0;
	let scalespd = 1;
	let movea = 0;
	while(oripla == playertype && !Obj_IsDeleted(robj) && !RefreshOptions){
		if(IsTimeStopped == false){
			if(IsPlayerSpawning==true || ForceOptionsOff == true){
				rx = GetPlayerX;
				ry = GetPlayerY;
				alp = 245;
			}else{
				if(playerdead == true){
					alp = min(alp+20, 245);
				}else{
					alp = 0;
				}
			}
			posit;
			rend;
			if(scaleset==0){scalespd+=0.03/TimeSpeed}
			if(scaleset==1){scalespd-=0.03/TimeSpeed}
			if(scalespd<0.8){scaleset=0}
			if(scalespd>1.3){scaleset=1}
			
			if(shotCount <= 0 && CanShoot == true){
				if(type==1){
					CreatePlayerObjShotA1(ObjRender_GetX(obj)-6, ObjRender_GetY(obj), 15, 270, 2*dmg, 0.6, 1, 1);
					//CreatePlayerObjShotA1(ObjRender_GetX(obj)+6, ObjRender_GetY(obj), 15, 275, 2*dmg, 0.6, 1, 1);
				}else{
					CreatePlayerObjShotA1(ObjRender_GetX(obj), ObjRender_GetY(obj), 15, 270, 3*dmg, 0.6, 1, 3);
				}
			}
		}
		yield;
	}
	X1 = 0;
	Y1 = 0;
	X2 = 0;
	Y2 = 0;
	Obj_SetRenderPriority(obj, 0.39);
	let alpha = 0;
	while(alpha<255){
		if(IsTimeStopped==false){
			alp = alp+15;
			rend;
			posit;
			ObjRender_SetAlpha(obj, alp);
		}
		yield;
	}
	Obj_Delete(obj);
	
	task rend{
		ObjSpriteList2D_ClearVertexCount(obj);
		
		ObjRender_SetAlpha(obj, 122.5-alp/2);
		ObjRender_SetScaleXYZ(obj, 1.75, 1.75, 1);
		ObjRender_SetAngleZ(obj, movea*s-25);
		ObjSpriteList2D_AddVertex(obj);
		
		ObjRender_SetAlpha(obj, 245-alp);
		ObjRender_SetScaleXYZ(obj, scalespd, scalespd, 1);
		ObjRender_SetAngleZ(obj, -movea*s-25);
		ObjSpriteList2D_AddVertex(obj);
	}

	task posit{
if(type == 1){rx = GetPlayerX+X1+RadiO*cos(AngulO+EX);ry = GetPlayerY+RadiO*sin(AngulO+EX);}else{} 
		ObjRender_SetPosition(obj, rx, ry, 0);
		if(type == 1){
			let eID = GetClosestEnemyID(ObjRender_GetX(obj), ObjRender_GetY(obj));
			movea = atan2(ObjRender_GetY(eID)-ObjRender_GetY(obj), 
			ObjRender_GetX(eID)-ObjRender_GetX(obj));
			if(eID==ID_INVALID){movea = angle}
		}else{
			movea+=6/TimeSpeed;
		}
		let OptionShift = GetVirtualKeyState(VK_SLOWMOVE)!=KEY_FREE;
		if(IsPlayerSpellActive==true){
			if(BombType>2){
				OptionShift = true;
			}else{OptionShift = false}
		}
		if(OptionShift){
			let dist = GetDistance(rx, ry, (GetPlayerX+X2), (GetPlayerY+Y2));
			let oang = atan2((GetPlayerY+Y2)-ry, (GetPlayerX+X2)-rx);
			if(dist>0.8/TimeSpeed){
				rx = rx+((dist/4+0.75)/TimeSpeed)*cos(oang);
				ry = ry+((dist/4+0.75)/TimeSpeed)*sin(oang);
			}
		}else{
			let dist = GetDistance(rx, ry, (GetPlayerX+X1), (GetPlayerY+Y1));
			let oang = atan2((GetPlayerY+Y1)-ry, (GetPlayerX+X1)-rx);
			if(dist>0.55/TimeSpeed){
				rx = rx+((dist/2+0.5)/TimeSpeed)*cos(oang);
				ry = ry+((dist/2+0.5)/TimeSpeed)*sin(oang);
			}
		}
	}
}

task ShotHit(EffectX, EffectY, EffectA, type){
	if(AllowShotDecay==false){return;}
	let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
	let obj3_time = 0;
	ObjRender_SetBlendType(obj3, BLEND_ALPHA);
	ObjRender_SetAlpha(obj3, 200);
	Obj_SetRenderPriority(obj3, 0.59);
	ObjPrim_SetTexture(obj3, imgEffect);
	ObjSprite2D_SetSourceRect(obj3, 48+(type)*16, 64, 48+(type+1)*16, 96);
	ObjSprite2D_SetDestCenter(obj3);
	ObjRender_SetAngleZ(obj3, EffectA+90);
	ObjRender_SetX(obj3, EffectX);
	ObjRender_SetY(obj3, EffectY);
	let a = 125;
	if(type==3){a = 195;}
	while(Obj_IsDeleted(obj3)==false){
		obj3_time++;
		if(obj3_time==3){
			ObjSprite2D_SetSourceRect(obj3, 48+(type)*16, 32, 48+(type+1)*16, 64);
		}
		if(obj3_time==6){
			ObjSprite2D_SetSourceRect(obj3, 48+(type)*16, 0, 48+(type+1)*16, 32);
		}
		if(obj3_time==9){Obj_Delete(obj3);}
		ObjRender_SetAlpha(obj3, a-obj3_time*8);
		ObjRender_SetScaleXYZ(obj3, 1+obj3_time/10, 1+obj3_time/10, 1);
		ObjRender_SetPosition(obj3, ObjRender_GetX(obj3)+1*cos(EffectA), ObjRender_GetY(obj3)+1*sin(EffectA), 0);
		
		yield;
	}
}

task ReisenTrio{
	if(GetPlayerState!=STATE_NORMAL||!CanShoot||RefreshOptions){return;}
	let ReisenActive = true;
	IsReisenActive = true;
	let tempmet = ReisenMeter;
	LunaticEyes;
	ScreenShake(45, 8);
	SetPlayerInvincibilityFrame(60);
	Duplicate(-85);
	Duplicate(85);
	PlaySE(current~"se_ch1.wav");
	
	while(tempmet>0){
		if(IsTimeStopped==false&&CanShoot==true){
			if(shotCount<=0){
				ReisenMeter-=0.35; 
				CollectAllItems;
			}
			ReisenMeter-=0.027795; 
			tempmet = ReisenMeter;
			if(GetPlayerState!=STATE_NORMAL){tempmet = 0;}
		}
		yield;
	}
	IsReisenActive = false;
	

	task Duplicate(pos){
		let dummy = ObjPrim_Create(OBJ_SPRITE_2D);
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		RenderHitboxImage(dummy, pos, 1);
		RenderHitboxImage(dummy, pos, 2);
		let deex = 0;
		Obj_SetValue(obj, "dinv", 0);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		RenderPlayerImage(obj);
		let alpha = 0;
		let mod = 1;
		//CreateOptionS1(dummy, 32+pos, 12, -24+pos, -12, 270, 1, -1, 1,0);
		//CreateOptionS1(dummy, -32+pos, 12, 24+pos, -12, 270, 1, -1, 1,180);
		CreateOptionS1(dummy, pos, 12, 24+pos, -12, 270, 1, -1, 1,0);
		CreateOptionS1(dummy, pos, 12, 24+pos, -12, 270, 1, -1, 1,180);
		CreateOptionS1(dummy, pos, 12, 24+pos, -12, 270, 1, -1, 1,90);
		CreateOptionS1(dummy, pos, 12, 24+pos, -12, 270, 1, -1, 1,270);
		while(tempmet>0 && playerdead==false){
			if(IsTimeStopped==false){
				ObjRender_SetPosition(obj, GetPlayerX+pos, GetPlayerY, 0);
				ObjRender_SetAlpha(obj, alpha);
				if(GetPlayerInvincibilityFrame==0&&deex<0){ObjRender_SetColor(obj, 200, 200, 200)}
				if(ReisenActive == true){
					DupeHitbox;
					alpha = min(alpha+7+alpha/145, 255);		
					if(shotCount <= 0 && CanShoot == true){
						if(deex>0){mod = 1.45;}else{mod = 1}
						CreatePlayerObjShotA1(GetPlayerX-9+pos, GetPlayerY-16, 15, 270, 6/mod, 1, 1, 2);
						CreatePlayerObjShotA1(GetPlayerX+11+pos, GetPlayerY-16, 15, 270, 6/mod, 1, 1, 2);
					}
				}else{
					alpha = max(alpha-9, 0);
				}
			}
			yield;
		}
		Obj_Delete(dummy);
		
		if(GetPlayerState!=STATE_NORMAL){
			loop(6){MapleLeaf(GetPlayerX+pos, GetPlayerY, rand(0,360), rand(85, 185), 1.8);}
			DeathExplosion(pos);
		}
		loop(6){MapleLeaf(GetPlayerX+pos, GetPlayerY, rand(0,360), rand(85, 185), 1.2);}
		PlaySE(current~"se_ch1end.wav");
		
		while(alpha>0){
			ObjRender_SetPosition(obj, GetPlayerX+pos, GetPlayerY, 0);
			if(IsTimeStopped==false){
				alpha = max(alpha-20, 0);
				ObjRender_SetAlpha(obj, alpha);
			}
			yield;
		}
		Obj_Delete(obj);
		
		task DupeHitbox{
			Obj_SetValue(obj, "dinv", deex);
			let barray = GetShotIdInCircleA2(GetPlayerX+pos, GetPlayerY, 4, TARGET_ENEMY);
			let blength = length(barray);
			if(blength>0){
				if(GetPlayerInvincibilityFrame==0&&deex<=0){
					DeathExplosion(pos);
					loop(8){MapleLeaf(GetPlayerX+pos, GetPlayerY, rand(0,360), rand(85, 185), 1.2);}
					deex=45;
				}
			}
			barray = GetShotIdInCircleA2(GetPlayerX+pos, GetPlayerY, 20, TARGET_ENEMY);
			blength = length(barray);
			if(blength>0&&GetPlayerInvincibilityFrame==0){
				ascent(c in 0..blength){
					if(!Obj_IsValueExists(barray[c], "c_v1_DupeGrazed")){Obj_SetValue(barray[c], "c_v1_DupeGrazed", 1);}
					if(Obj_GetValue(barray[c], "c_v1_DupeGrazed")==1){
						loop(GrazePartNum){Particle(GetPlayerX+pos, GetPlayerY, rand(0,360), rand(15, 85), 0.9);}
						Obj_SetValue(barray[c], "c_v1_DupeGrazed", 2);
					}
				}
			}
			deex-=1/TimeSpeed;
		}
	
	}

}

task TewiPlayful{
	if(GetPlayerState!=STATE_NORMAL||CanShoot==false){return;}
	IsTewiActive = true;
	let tempmet = TewiMeter;
	let tamecount = 0;
	let tametotal = 14;
	
	ScreenShake(15, 8);
	SetPlayerInvincibilityFrame(30);
	PlaySE(current~"se_ch1.wav");
	
	let rads = 0;
	let setx = GetPlayerX;
	let sety = GetPlayerY;
	CreateCircle;
	while(tempmet>0){
		if(IsTimeStopped==false&&CanShoot==true){
			TameBullet(setx, sety, rads);
			TewiMeter-=0.65/TimeSpeed; 
			rads += 1.55/TimeSpeed;
			tempmet = TewiMeter;
			if(GetPlayerState!=STATE_NORMAL){tempmet = 0;}
		}
		yield;
	}
	
	IsTewiActive = false;

	task TameBullet(fbX, fbY, radius){
		let barray = GetShotIdInCircleA2(fbX, fbY, radius, TARGET_ENEMY);
		let blength = length(barray);
		if(blength>0){
			ascent (i in 0..blength){
				let buID = barray[i];
				if(ObjShot_IsSpellResist(buID) == false){
					Tame(ObjRender_GetX(buID),ObjRender_GetY(buID),ObjMove_GetAngle(buID),ObjMove_GetSpeed(buID));
					ObjShot_SetDeleteFrame(buID, 0);
				}
			}
		}
	}
	
	task Tame(x,y,a,s){
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetValue(obj, "FairyInv", true);
		let alpha = 205;
		let gra = 0;
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.39);
		ObjRender_SetPosition(obj, x, y, 0);
		ObjPrim_SetTexture(obj, imgEffect);
		ObjSprite2D_SetSourceRect(obj, 96, 34, 112, 52);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetScaleXYZ(obj, 1, 1, 1);
		ObjRender_SetAlpha(obj, alpha);

		let tatime = 0;
		let isfairy = false;
		let r = 3;
		while(tatime<100){
			if(!IsTimeStopped){
				if(tatime >= r && isfairy == false){
					ObjSprite2D_SetSourceRect(obj, 96, 2, 112, 20);
				}
				if(tatime >= r*2 && isfairy == false){
					if(tamecount>=tametotal){Obj_Delete(obj);tatime=111;}
					tamecount++;
					AnimateFairyA1(obj);
					isfairy = true;
				}
				ObjRender_SetPosition(obj, x, y-tatime/5, 0);
				tatime += 1/TimeSpeed;
			}
			yield;
		}
		if(Obj_IsDeleted(obj)){return;}
		Obj_SetValue(obj, "FairyInv", false);
		let deex = 0;
		let Fairylife = 2;
		let scount = 0;
		let sadd = rand(0.8, 1.2);
		while(Fairylife>0){
			if(!IsTimeStopped){
				FairyHitbox;
				if(gra>0){AddGraze(1); gra = 0;}
				if(shotCount<=0&&CanShoot == true&&!IsPlayerSpellActive){scount+=20*sadd;}
				if(scount>=60 && GetEnemyID != ID_INVALID){
					let eID = GetClosestEnemyID(ObjRender_GetX(obj), ObjRender_GetY(obj));
					let movea = atan2(ObjRender_GetY(eID)-ObjRender_GetY(obj), 
									ObjRender_GetX(eID)-ObjRender_GetX(obj));
					CreatePlayerObjShotA1(ObjRender_GetX(obj), ObjRender_GetY(obj), 6, movea, 3.5, 1, 1, 4);
					scount = 0;
				}
			}
			yield;
		}
		while(alpha>0){
			if(!IsTimeStopped){
				alpha -= 17.5/TimeSpeed;
				ObjRender_SetAlpha(obj, alpha);
			}
			yield;
		}
		PlaySE(current~"se_ch2end.wav");
		Obj_Delete(obj);
		
		task FairyHitbox{
			let barray = GetShotIdInCircleA2(ObjRender_GetX(obj), ObjRender_GetY(obj), 4, TARGET_ENEMY);
			let blength = length(barray);
			if(blength>0){
				if(Obj_GetValue(obj, "FairyInv")==false){
					loop(3){MapleLeaf(ObjRender_GetX(obj), ObjRender_GetY(obj), rand(0,360), rand(85, 185), 1.2);}
					deex=45;
					Fairylife--;
				}
			}
			barray = GetShotIdInCircleA2(ObjRender_GetX(obj), ObjRender_GetY(obj), 20, TARGET_ENEMY);
			blength = length(barray);
			if(blength>0&&Obj_GetValue(obj, "FairyInv")==false&&GrazePartNum>1){
				ascent(c in 0..blength){
					if(!Obj_IsValueExists(barray[c], "c_v1_"~IntToString(obj)~"Grazed")){Obj_SetValue(barray[c], "c_v1_"~IntToString(obj)~"Grazed", 1);}
					if(Obj_GetValue(barray[c], "c_v1_"~IntToString(obj)~"Grazed")==1){
						loop(GrazePartNum/2){Particle(ObjRender_GetX(obj), ObjRender_GetY(obj), rand(0,360), rand(15, 85), 0.7);}
						Obj_SetValue(barray[c], "c_v1_"~IntToString(obj)~"Grazed", 2);
						PlaySE(current~"se_graze.wav");
						gra += 0.01;
					}
				}
			}
			deex-=1/TimeSpeed;
			if(deex>0){Obj_SetValue(obj, "FairyInv", true);}
			else{Obj_SetValue(obj, "FairyInv", false);}
			
		}
		
	}

	task CreateCircle{
		let x = GetPlayerX;
		let y = GetPlayerY;
		let alpha = 0;
		let countVertex = 66;
		
		let circ = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetPrimitiveType(circ, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetTexture(circ, NULL);
		Obj_SetRenderPriority(circ, 0.60);
		ObjPrim_SetVertexCount(circ, countVertex);
		ObjRender_SetBlendType(circ, BLEND_ALPHA);
		
		
		ObjPrim_SetVertexUVT(circ, 0, 0, 0);	
		ObjPrim_SetVertexPosition(circ, 0, 0, 0, 0);
		ObjPrim_SetVertexColor(circ, 0, 255, 255, 255);
		ObjPrim_SetVertexAlpha(circ, 0, 0);
		
		ObjRender_SetPosition(circ, x, y, 0);
		
		let siz = 0;
		
		ascent(iVert in 1..countVertex){
			let angle = (360 / (countVertex - 2) * iVert);
			ObjPrim_SetVertexUVT(circ, iVert, 0, 0);	
			let x = siz*cos(angle);
			let y = siz*sin(angle);
			ObjPrim_SetVertexPosition(circ, iVert , x, y, 0);
			ObjPrim_SetVertexColor(circ, iVert, 128, 12, 128);
			ObjPrim_SetVertexAlpha(circ, iVert, alpha/1.35);
		}
		while(tempmet>12){
			if(IsTimeStopped==false){
				siz = rads;
				alpha = max(alpha+(6/TimeSpeed), 0);
				ascent(iVert in 1..countVertex){
					let angle = (360 / (countVertex - 2) * iVert);
					ObjPrim_SetVertexPosition(circ, iVert , (siz+8)*cos(angle), (siz+8)*sin(angle), 0);
					ObjPrim_SetVertexAlpha(circ, iVert, alpha/1.35);
				}
			}
			yield;
		}
		while(alpha>0){
			if(IsTimeStopped==false){
				siz = siz+1.55/TimeSpeed;
				alpha = max(alpha-(32/TimeSpeed), 0);
				ascent(iVert in 1..countVertex){
					let angle = (360 / (countVertex - 2) * iVert);
					ObjPrim_SetVertexPosition(circ, iVert , (siz+8)*cos(angle), (siz+8)*sin(angle), 0);
					ObjPrim_SetVertexAlpha(circ, iVert, alpha);
				}
			}
			yield;
		}
		Obj_Delete(circ);
	}

}

task ReisenGatlingGun(kdtype){
	//DEATHMACHINE
	yield;
	let objManage = GetSpellManageObject;
	let Master_Time=0;
	
	SetPlayerInvincibilityFrame(180);
	ShadowA1(objManage, 0.75, 60, 1, 1, 1);
	
	ScreenShake(115, 8);
	BombType = 1;
	
	let kdf = 0;
	while(Master_Time<120){
		if(!IsTimeStopped){
			SetPlayerSpeed(unshiftspd,unshiftspd);
			if(kdf>=3){
				let as = 0;
				PlaySE(current~"se_spell1normal.wav");
				loop(3){
					Shot(GetPlayerX, GetPlayerY, Master_Time*4+as, 1);
					as+=360/3;
				}
				if(IsReisenActive){
					loop(3){
						Shot(GetPlayerX+85, GetPlayerY, Master_Time*4+as, 1);
						Shot(GetPlayerX-85, GetPlayerY, Master_Time*4+as, 1);
						as+=360/3;
					}
				}
				kdf=0;
			}
			if(IsReisenActive){
				ReisenMeter-=0.45;
			}
			kdf+=1/TimeSpeed;
			Master_Time+=1/TimeSpeed;
		}
		yield;
	}
	PlaySE(current~"se_spell1phantasm.wav");
	
	while(Master_Time<145){
		if(IsTimeStopped==false){
			SetPlayerSpeed(unshiftspd,unshiftspd);
			Master_Time+=1/TimeSpeed;
		}
		yield;
	}
	
	SetPlayerSpeed(unshiftspd,shiftspd);
	Obj_Delete(objManage);
	BombType = 0;
	
	task Shot(x, y, angle, type){
		let origan = angle;
		let ktim = 0;
		angle+=90;
		let Hitbox = ObjSpell_Create;
		ObjSpell_Regist(Hitbox);
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.5);
		ObjRender_SetAlpha(obj, 235);
		ObjPrim_SetTexture(obj, imgEffect);
		ObjSprite2D_SetSourceRect(obj, 48+(type)*16, 96, 48+(type+1)*16, 128);
		ObjSprite2D_SetDestRect(obj, -8, -16, 8, 26);
		ObjRender_SetPosition(obj, x+45*cos(angle), y+42+12*sin(angle), 0);
		let move = 22.5;
		while(ktim<45){
			if(IsTimeStopped==false){
				if(!IsReisenActive){
					ObjSpell_SetDamage(Hitbox, 12);
				}else{ObjSpell_SetDamage(Hitbox, 8);}
				ktim+=1/TimeSpeed;
				ObjRender_SetPosition(obj, ObjRender_GetX(obj)+2*cos(angle), ObjRender_GetY(obj)-move, 0);
				ObjSpell_SetIntersectionLine(Hitbox, ObjRender_GetX(obj), ObjRender_GetY(obj)-16,
					ObjRender_GetX(obj), ObjRender_GetY(obj)-26, 16);
			}else{ObjSpell_SetDamage(Hitbox, 0);}
			yield;
		}
		Obj_Delete(obj);
		Obj_Delete(Hitbox);
	}
		

}

task ReisenLunaticEyes(kdtype){
	yield;
	let objManage = GetSpellManageObject;
	let Master_Time=0;
	let ori = ReisenMeter;
	ReisenMeter = 0;
	LunaticEyes;
	SetPlayerInvincibilityFrame(300);
	ShadowA1(objManage, 0.75, 60, 1, 1, 1);
	SetForbidPlayerShot(true);
	ScreenShake(115, 8);
	BombType = 3;
	
	PlaySE(current~"se_power.wav");
	PlaySE(current~"se_spell2normal.wav");
	let kdf = 0;
	while(Master_Time<215){
		if(IsTimeStopped==false){
			SetPlayerSpeed(shiftspd,shiftspd);
			if(kdf>=6){
				let as = 0;
				PlaySE(current~"se_spell2phantasm.wav");
				CreateCircle(85);
				kdf=0;
			}
			if(IsReisenActive){
				ReisenMeter-=0.45;
			}
			kdf+=1/TimeSpeed;
			Master_Time+=1/TimeSpeed;
		}
		yield;
	}
	PlaySE(current~"se_spell1phantasm.wav");
	
	while(Master_Time<235){
		if(IsTimeStopped==false){
			SetPlayerSpeed(shiftspd,shiftspd);
			Master_Time+=1/TimeSpeed;
		}
		yield;
	}
	SetForbidPlayerShot(false);
	SetPlayerSpeed(unshiftspd,shiftspd);
	Obj_Delete(objManage);
	BombType = 0;
	ascent(i in 0..ori/2){
		AddToCharge(2, 1);
		if(GetSpellManageObject==ID_INVALID){yield;}
	}
	
	task CreateCircle(destsiz){
		let x = GetPlayerX;
		let y = GetPlayerY;
		let alpha = 255;
		let countVertex = 6;
		
		let Hitbox = ObjSpell_Create;
		ObjSpell_Regist(Hitbox);
		
		let circ = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetPrimitiveType(circ, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetTexture(circ, NULL);
		Obj_SetRenderPriority(circ, 0.60);
		ObjPrim_SetVertexCount(circ, countVertex);
		ObjRender_SetBlendType(circ, BLEND_ALPHA);
		
		
		ObjPrim_SetVertexUVT(circ, 0, 0, 0);	
		ObjPrim_SetVertexPosition(circ, 0, 0, 0, 0);
		ObjPrim_SetVertexColor(circ, 0, 255, 255, 255);
		ObjPrim_SetVertexAlpha(circ, 0, 0);
		
		ObjRender_SetPosition(circ, x, y, 0);
		
		let siz = 0;	
		ascent(iVert in 1..countVertex){
			let angle = (360 / (countVertex - 2) * iVert);
			ObjPrim_SetVertexUVT(circ, iVert, 0, 0);	
			let x = siz*cos(angle);
			let y = siz*sin(angle);
			ObjPrim_SetVertexPosition(circ, iVert , x, y, 0);
			ObjPrim_SetVertexColor(circ, iVert, 212,1,212); //212,12,48
			ObjPrim_SetVertexAlpha(circ, iVert, alpha);
		}
		while(siz<destsiz){
			if(IsTimeStopped==false){
				siz += 10/TimeSpeed;
				alpha = max(alpha-(4/TimeSpeed), 0);
				ascent(iVert in 1..countVertex){
					let angle = (360 / (countVertex - 2) * iVert);
					ObjPrim_SetVertexPosition(circ, iVert , (siz+8)*cos(angle), (siz+8)*sin(angle), 0);
					ObjPrim_SetVertexAlpha(circ, iVert, alpha);
				}
				ObjSpell_SetIntersectionCircle(Hitbox, ObjRender_GetX(circ), ObjRender_GetY(circ), siz);
				ObjSpell_SetDamage(Hitbox, 6);
			}else{ObjSpell_SetDamage(Hitbox, 0);}
			yield;
		}		
		while(alpha>0){
			if(IsTimeStopped==false){
				siz += 10/TimeSpeed;
				alpha = max(alpha-(12/TimeSpeed), 0);
				ascent(iVert in 1..countVertex){
					let angle = (360 / (countVertex - 2) * iVert);
					ObjPrim_SetVertexPosition(circ, iVert , (siz+8)*cos(angle), (siz+8)*sin(angle), 0);
					ObjPrim_SetVertexAlpha(circ, iVert, alpha);
				}
				ObjSpell_SetIntersectionCircle(Hitbox, ObjRender_GetX(circ), ObjRender_GetY(circ), siz);
				ObjSpell_SetDamage(Hitbox, 3);
			}else{ObjSpell_SetDamage(Hitbox, 0);}
			yield;
		}	
		Obj_Delete(circ);
		Obj_Delete(Hitbox);
	}

		

}

task TewiJeweledTewi(kdtype){
	yield;
	let objManage = GetSpellManageObject;
	let Master_Time=0;
	let ori = TewiMeter;
	TewiMeter = 0;
	SetPlayerInvincibilityFrame(180);
	ShadowA1(objManage, 0.75, 60, 1, 1, 1);
	
	ScreenShake(265, 5);
	BombType = 4;
	
	
	PlaySE(current~"se_spell2normal.wav");
	
	ascent(i in 1..7){
		Jewel(GetPlayerX, GetPlayerY, 60*i, 1);
		Jewel(GetPlayerX, GetPlayerY, 60*i, -1);
	}
	
	while(Master_Time<275){
		if(IsTimeStopped==false){
			SetPlayerSpeed(shiftspd,shiftspd);
			Master_Time+=1/TimeSpeed;
		}
		yield;
	}
	
	SetPlayerSpeed(unshiftspd,shiftspd);
	Obj_Delete(objManage);
	BombType = 0;
	
	ascent(i in 0..ori/2){
		AddToCharge(2, 2);
		if(GetSpellManageObject==ID_INVALID){yield;}
	}
	
	task Jewel(x, y, angle, type){
		let origan = angle;
		let ktim = 0;
		angle+=90;
		let alpha = 0;
		let Hitbox = ObjSpell_Create;
		ObjSpell_Regist(Hitbox);
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.5);
		ObjRender_SetAlpha(obj, alpha);
		ObjPrim_SetTexture(obj, imgEffect);
		ObjSprite2D_SetSourceRect(obj, 144, 0, 192, 48);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj, x+45*cos(angle), y+45*sin(angle), 0);
		let move = 45;
		let ang = angle;
		while(ktim<rand(105, 195)){
			if(IsTimeStopped==false){
				alpha = min(alpha+6, 205);
				ObjRender_SetAlpha(obj, alpha);
				x = GetPlayerX; y = GetPlayerY;
				ang+=8*type/TimeSpeed;
				move+=0.75/TimeSpeed;
				ktim+=1/TimeSpeed;
				ObjRender_SetPosition(obj, x+(move)*cos(ang), y+(move)*sin(ang), 0);
				ObjRender_SetAngleZ(obj, -ang*type);
				ObjSpell_SetIntersectionCircle(Hitbox, ObjRender_GetX(obj), ObjRender_GetY(obj), 24);
				ObjSpell_SetDamage(Hitbox, 2);
			}else{ObjSpell_SetDamage(Hitbox, 0);}
			yield;
		}
		move = 12;
		ang+=45*type;
		let scl = 1;
		let rest = 0;
		let mvm = ang;
		while(scl>0){
			if(!IsTimeStopped){
				if(ktim>235){scl = max(scl-0.025, 0);}
				move-=0.025/TimeSpeed;
				ObjSpell_SetIntersectionCircle(Hitbox, ObjRender_GetX(obj), ObjRender_GetY(obj), 24*scl);
				ObjSpell_SetDamage(Hitbox, 12*scl);
				ktim+=1/TimeSpeed;
				x = ObjRender_GetX(obj);
				y = ObjRender_GetY(obj);
				if(x<=-1 || x>=GetStgFrameWidth+1){
					if(rest>0){x = max(0, min(GetStgFrameWidth, x));}
					PlaySE(current~"se_spell3.wav");
					ang = 180-ang;
					rest = 2;
				}
				if(y<=-1 || y>=GetStgFrameHeight+1){
					if(rest>0){y = max(0, min(GetStgFrameHeight, y));}
					PlaySE(current~"se_spell3.wav");
					ang = 360-ang;
					rest = 2;
				}
				ObjRender_SetPosition(obj, x+(move)*cos(ang), y+(move)*sin(ang), 0);
				ObjRender_SetScaleXYZ(obj, scl, scl, 1);
				mvm+=6/TimeSpeed;
				ObjRender_SetAngleZ(obj, -mvm*type);
			}
			yield;
		}
		Obj_Delete(obj);
		Obj_Delete(Hitbox);
	}
		

}

task TewiJeweledRabbits(kdtype){
	yield;
	let objManage = GetSpellManageObject;
	let Master_Time=0;
	let ori = TewiMeter;
	TewiMeter = 0;
	ShadowA1(objManage, 0.75, 60, 1, 1, 1);
	SetPlayerInvincibilityFrame(200);
	ScreenShake(30, 4);
	BombType = 2;
	
	
	PlaySE(current~"se_power.wav");
	
	ascent(i in 1..6){
		Jewel(GetPlayerX, GetPlayerY, 72*i, 1);
	}
	while(Master_Time<48){
		if(IsTimeStopped==false){
			SetPlayerSpeed(unshiftspd,unshiftspd);	
			Master_Time+=1/TimeSpeed;
		}
		yield;
	}
	
	ScreenShake(30, 5);
	PlaySE(current~"se_spell1phantasm.wav");
	ShadowA2(GetStgFrameWidth/2, GetStgFrameHeight/2, 255, -10, 200, 165, 185);
	
	while(Master_Time<75){
		if(IsTimeStopped==false){
			SetPlayerSpeed(unshiftspd,unshiftspd);
			Master_Time+=1/TimeSpeed;
		}
		yield;
	}
	
	SetPlayerSpeed(unshiftspd,shiftspd);
	Obj_Delete(objManage);
	BombType = 0;
	
	ascent(i in 0..ori/2){
		AddToCharge(2, 2);
		if(GetSpellManageObject==ID_INVALID){yield;}
	}
	
	task Jewel(x, y, angle, type){
		let origan = angle;
		angle+=90;
		let alpha = 0;
		let Hitbox = ObjSpell_Create;
		ObjSpell_Regist(Hitbox);
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.5);
		ObjRender_SetAlpha(obj, alpha);
		ObjPrim_SetTexture(obj, imgEffect);
		ObjSprite2D_SetSourceRect(obj, 144, 0, 192, 48);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj, x+45*cos(angle), y+45*sin(angle), 0);
		let move = 12;
		let ang = angle;
		let scl = 1;
		let rest = 0;
		while(move>0){
			alpha = min(alpha+6, 205);
			ObjRender_SetAlpha(obj, alpha);
			move = max(move-0.25, 0);
			ObjSpell_SetIntersectionCircle(Hitbox, ObjRender_GetX(obj), ObjRender_GetY(obj), 24*scl);
			ObjSpell_SetDamage(Hitbox, move*1.25+1.5);
			x = ObjRender_GetX(obj);
			y = ObjRender_GetY(obj);
			if(x<=-1 || x>=GetStgFrameWidth+1){
				if(rest>0){x = max(0, min(GetStgFrameWidth, x));}
				PlaySE(current~"se_spell3.wav");
				ang = 180-ang;
				rest = 2;
			}
			if(y<=-1 || y>=GetStgFrameHeight+1){
				if(rest>0){y = max(0, min(GetStgFrameHeight, y));}
				PlaySE(current~"se_spell3.wav");
				ang = 360-ang;
				rest = 2;
			}
			ObjRender_SetPosition(obj, x+(move)*cos(ang), y+(move)*sin(ang), 0);
			yield;
		}
		ObjSpell_SetIntersectionCircle(Hitbox, ObjRender_GetX(obj), ObjRender_GetY(obj), 9999);
		ObjSpell_SetDamage(Hitbox, 425);
		yield;
		loop(6){MapleLeaf(ObjRender_GetX(obj), ObjRender_GetY(obj), rand(0,360), rand(85, 185), 0.95);}
		let jran = rand(0,360);
		loop(5){
			JeweledRabbit(ObjRender_GetX(obj), ObjRender_GetY(obj), jran);
			jran+=360/5;
		}
		Obj_Delete(obj);
		Obj_Delete(Hitbox);
	}
	
	task JeweledRabbit(x, y, angle){
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetPosition(obj, x+45*cos(angle), y+45*sin(angle), 0);
		if(CheckOutsideScreen(obj, 0)){Obj_Delete(obj); return;}
		let alpha = 235;
		Obj_SetValue(obj, "FairyInv", true);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 0.39);
		ObjRender_SetAlpha(obj, alpha);
		ObjPrim_SetTexture(obj, imgEffect);
		AnimateFairyA1(obj);
		let deex = 135;
		let Fairylife = 4;
		let scount = 0;
		let sadd = rand(0.8, 1.2);
		let gra = 0;
		while(Fairylife>0){
			if(!IsTimeStopped){
				FairyHitbox;
				if(gra>0){AddGraze(1); gra = 0;}
				if(shotCount<=0&&CanShoot == true){scount+=30*sadd;}
				if(scount>=60 && GetEnemyID != ID_INVALID){
					let eID = GetClosestEnemyID(ObjRender_GetX(obj), ObjRender_GetY(obj));
					let movea = atan2(ObjRender_GetY(eID)-ObjRender_GetY(obj), 
									ObjRender_GetX(eID)-ObjRender_GetX(obj));
					CreatePlayerObjShotA1(ObjRender_GetX(obj), ObjRender_GetY(obj), 13, movea, 1.5, 1, 1, 4);
					scount = 0;
				}
			}
			yield;
		}
		while(alpha>0){
			if(!IsTimeStopped){
				alpha -= 17.5/TimeSpeed;
				ObjRender_SetAlpha(obj, alpha);
			}
			yield;
		}
		PlaySE(current~"se_ch2end.wav");
		Obj_Delete(obj);
		
		task FairyHitbox{
			let barray = GetShotIdInCircleA2(ObjRender_GetX(obj), ObjRender_GetY(obj), 4, TARGET_ENEMY);
			let blength = length(barray);
			if(blength>0){
				if(Obj_GetValue(obj, "FairyInv")==false){
					loop(3){MapleLeaf(ObjRender_GetX(obj), ObjRender_GetY(obj), rand(0,360), rand(85, 185), 1.2);}
					deex=55;
					Fairylife--;
					if(!ObjShot_IsSpellResist(barray[0])){ObjShot_SetDeleteFrame(barray[0], 0)}
				}
			}
			barray = GetShotIdInCircleA2(ObjRender_GetX(obj), ObjRender_GetY(obj), 20, TARGET_ENEMY);
			blength = length(barray);
			if(blength>0&&Obj_GetValue(obj, "FairyInv")==false&&GrazePartNum>1){
				ascent(c in 0..blength){
					if(!Obj_IsValueExists(barray[c], "c_v1_"~IntToString(obj)~"Grazed")){Obj_SetValue(barray[c], "c_v1_"~IntToString(obj)~"Grazed", 1);}
					if(Obj_GetValue(barray[c], "c_v1_"~IntToString(obj)~"Grazed")==1){
						loop(GrazePartNum/2){Particle(ObjRender_GetX(obj), ObjRender_GetY(obj), rand(0,360), rand(15, 85), 0.7);}
						Obj_SetValue(barray[c], "c_v1_"~IntToString(obj)~"Grazed", 2);
						PlaySE(current~"se_graze.wav");
						gra += 0.01;
					}
				}
			}
			deex-=1/TimeSpeed;
			if(deex>0){Obj_SetValue(obj, "FairyInv", true);}
			else{Obj_SetValue(obj, "FairyInv", false);}
		}
	}
}

task ScreenShake(shaketime, intensity){
	let x = Get2DCameraX;
	let y = Get2DCameraY;
	let ramp = 0;
	let fr = 0;
	while(shaketime>0){
		if(fr>=1){
			ramp = min(ramp+0.75, intensity);
			Set2DCameraFocusX(x + rand(-ramp, ramp));
			Set2DCameraFocusY(y + rand(-ramp, ramp));
			shaketime--;
		}else{
			
		}
		if(IsTimeStopped==false){fr+=1/TimeSpeed;}
		yield;
	}
	Set2DCameraFocusX(x);
	Set2DCameraFocusY(y);
	yield;
}


task Particle(deX, deY, angX, deAlpha, deScale){
	if(TotalParticleCount>=MaximumParticles){return;}
	if(AllowGrazePart != true){return;}
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.49);
	ObjPrim_SetTexture(obj, imgEffect);
	ObjSprite2D_SetSourceRect(obj, 0, 234, 62, 296);
	ObjSprite2D_SetDestRect(obj, -rand(1,4), -rand(1,7.5), rand(1, 4), rand(1, 7.5));
	ObjRender_SetAngleXYZ(obj, 0, 0, angX);
	ObjRender_SetPosition(obj, deX, deY, 0);
	ObjRender_SetAlpha(obj, deAlpha);
	ObjRender_SetColor(obj, 155, 155, 155);

	let scale = deScale;
	let randX = rand(75, 350);
	let randY = rand(75, 350);
	
	TotalParticleCount++;
	while(Obj_IsDeleted(obj)==false){
		scale += (-0.05)/TimeSpeed;
		deX = deX+(randX/100/TimeSpeed)*cos(angX);
		deY = deY+(randX/100/TimeSpeed)*sin(angX);
		ObjRender_SetPosition(obj, deX, deY, 0);	
		ObjRender_SetAngleXYZ(obj, 0, 0, angX+deX+deY+scale*45);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		ObjRender_SetAlpha(obj, deAlpha+scale*20);
		if(scale<0.01){Obj_Delete(obj)}
		yield;
	}
	TotalParticleCount--;
	Obj_Delete(obj);
}

task MapleLeaf(deX, deY, angX, deAlpha, deScale){
	deScale = deScale*1.25;
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D); 
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.49);
	ObjPrim_SetTexture(obj, imgEffect);
	ObjSpriteList2D_SetSourceRect(obj, 0, 48, 32, 80);
	ObjSpriteList2D_SetDestCenter(obj);
	ObjRender_SetAngleXYZ(obj, 0, 0, angX);
	ObjRender_SetPosition(obj, deX, deY, 0);
	ObjRender_SetAlpha(obj, deAlpha);

	let scale = deScale;
	let randX = rand(-350, 350);
	let randY = rand(-350, 350);
	let	ang2 = rand(0, 360);
	
	while(scale>0.01){
		scale += ((-0.05)/2)/TimeSpeed;
		deX += (randX/200)/TimeSpeed;
		deY += (randY/200)/TimeSpeed;
		angX += (randX/155)/TimeSpeed;
		ang2 += (randX/155)/TimeSpeed;
		ObjSpriteList2D_ClearVertexCount(obj);
		ObjSpriteList2D_SetSourceRect(obj, 0, 48, 32, 80);
		ObjSpriteList2D_SetDestCenter(obj);
		ObjSpriteList2D_AddVertex(obj);
		
		ObjRender_SetPosition(obj, deX, deY, 0);
		ObjRender_SetAngleXYZ(obj, ang2, angX, (ang2+angX)/2);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		ObjRender_SetAlpha(obj, deAlpha-scale*20);
		yield;
	}
	Obj_Delete(obj);
}

task LunaticEyes{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let deAlpha = 0;
	let scale = 1.95;
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.29);
	ObjPrim_SetTexture(obj, imgEffect);
	ObjSprite2D_SetSourceRect(obj, 0, 296, 255, 359);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, scale, scale, scale);
	ObjRender_SetAlpha(obj, 0);
	
	
	let bg = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(bg, BLEND_ALPHA);
	Obj_SetRenderPriority(bg, 0.28);
	ObjPrim_SetTexture(bg, NULL);
	ObjSprite2D_SetSourceRect(bg, 0, 296, 256, 360);
	ObjSprite2D_SetDestRect(bg, -48, -48, GetStgFrameWidth+48, GetStgFrameHeight+48);
	ObjRender_SetColor(bg, 165, 12, 12);
	ObjRender_SetAlpha(bg, 0);
	
	
	loop(4){yield;}
	let fe = 0;
	while(deAlpha<205){
		if(!IsTimeStopped){
			if(fe>=2){
				LunaticEyeFade;
				fe = 0;
			}
			deAlpha += 6.75/TimeSpeed;
			scale += -0.03/TimeSpeed;
			ObjRender_SetPosition(obj, GetStgFrameWidth/2, GetStgFrameHeight/2, 0);
			ObjRender_SetAlpha(obj, deAlpha);
			ObjRender_SetAlpha(bg, deAlpha/1.5);
			ObjRender_SetScaleXYZ(obj, scale, scale, scale);
			fe+=1/TimeSpeed;
		}
		yield;
	}
	let ttt = 0;
	while(ttt<35){
		if(!IsTimeStopped){ttt+=1/TimeSpeed;ObjRender_SetPosition(obj, GetStgFrameWidth/2, GetStgFrameHeight/2, 0);}
		yield;
	}
	while(deAlpha>0){
		if(!IsTimeStopped){
			deAlpha -= 8/TimeSpeed;
			ObjRender_SetAlpha(obj, deAlpha);
			ObjRender_SetAlpha(bg, deAlpha/1.5);
		}
		yield;
	}
	Obj_Delete(obj);
	Obj_Delete(bg);
	
	task LunaticEyeFade{
		let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj2, BLEND_ADD_RGB);
		Obj_SetRenderPriority(obj2, 0.28);
		ObjPrim_SetTexture(obj2, imgEffect);
		ObjSprite2D_SetSourceRect(obj2, 0, 296, 256, 359);
		ObjSprite2D_SetDestCenter(obj2);
		ObjRender_SetScaleXYZ(obj2, scale, scale, scale);
		ObjRender_SetColor(obj2, deAlpha/2, deAlpha/2, deAlpha/2);
			ObjRender_SetPosition(obj2, GetStgFrameWidth/2, GetStgFrameHeight/2, 0);
		let tttc = deAlpha/2;
		let tttt = 0;
		while(tttt<20){
			if(!IsTimeStopped){tttt+=1/TimeSpeed;}
			yield;
		}
		while(tttc>0){
			if(!IsTimeStopped){
				tttc -= 4/TimeSpeed;
				ObjRender_SetColor(obj2, tttc, tttc, tttc);
			}
			yield;
		}
		Obj_Delete(obj2);
	}
}

task AddToCharge(num, exc){
	if(exc == 0){exc = playertype;}
	if(exc==1){
		ReisenMeter = min(ReisenMeter+num, 100);
	}
	if(exc==2){
		TewiMeter = min(TewiMeter+num, 100);
	}
}

task Gauge(n){
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	SetAreaCommonData("c_Player_v1", "GetTimerObject"~IntToString(n), obj);
	ObjPrim_SetTexture(obj, imgEffect);
	Obj_SetRenderPriority(obj, 0.7);
	ObjRender_SetPosition(obj, 800, GetStgFrameHeight-16, 0);
	
	let fade = 255;
	let scale = 1/3;
	let Charged = false;
	let RenderMeter = 0;
	let flow = 0;
	let rend = 0;
	let m = 1;
	while(!Obj_IsDeleted(obj)){
		if(playertype == n){
			m = 1;
			let rx = 12;
			let ry = GetStgFrameHeight-16;
			let dist = GetDistance(rx, ry, ObjRender_GetX(obj), ObjRender_GetY(obj));
			let oang = atan2(ry-ObjRender_GetY(obj), rx-ObjRender_GetX(obj));	
			ObjRender_SetPosition(obj, 
				ObjRender_GetX(obj)+((dist/5)/TimeSpeed)*cos(oang),
				ObjRender_GetY(obj)+((dist/5)/TimeSpeed)*sin(oang), 0);
		}else{
			m = 2;
			let rx = 2;
			let ry = GetStgFrameHeight-24;
			let dist = GetDistance(rx, ry, ObjRender_GetX(obj), ObjRender_GetY(obj));
			let oang = atan2(ry-ObjRender_GetY(obj), rx-ObjRender_GetX(obj));	
			ObjRender_SetPosition(obj, 
				ObjRender_GetX(obj)+((dist/5)/TimeSpeed)*cos(oang),
				ObjRender_GetY(obj)+((dist/5)/TimeSpeed)*sin(oang), 0);
		}
				
		ObjSpriteList2D_ClearVertexCount(obj);
		ObjRender_SetAlpha(obj, fade);
		
		if(n==1){RenderMeter = ReisenMeter;}
		if(n==2){RenderMeter = TewiMeter;}
		
		
		if(GetPlayerX<264 && GetPlayerY > GetStgFrameHeight-32){
			fade = max(fade-10/TimeSpeed, 65);
		}else{fade = min(fade+10/TimeSpeed, 255);}
		if(Charged==false&&RenderMeter==100&&IsAnyActive==false){PlaySE(current~"se_ch"~IntToString(n)~"ready.wav");Charged = true;}
		if(Charged==true&&RenderMeter!=100){Charged = false;}
			
		
		if(ForceOptionsOff==true||playerdead==true){
			fade = max(fade-20/TimeSpeed, 0);
			if(fade==0){rend = 0;ObjRender_SetPosition(obj, 800, GetStgFrameHeight-16, 0);}
		}
		if(IsPlayerSpawning==true){
			fade = min(fade+20/TimeSpeed, 255);
		}
		
		if(n == 1){
			ObjRender_SetColor(obj, (rend*3+25)/m, (rend+45)/m, (rend/2+25)/m);
			if(Charged==true){ObjRender_SetColor(obj, (255)/m, (0)/m, (0)/m);}
			if(IsReisenActive==true){ObjRender_SetColor(obj, (255-rend*2.55)/m, (rend*2.55)/m, (32)/m);}
		}else{
			ObjRender_SetColor(obj, (rend*3.5+25)/m, (rend/2+45)/m, (rend*3+25)/m);
			if(Charged==true){ObjRender_SetColor(obj, (255)/m, 0, (255)/m);}
			if(IsTewiActive==true){ObjRender_SetColor(obj, (255-rend*2.55)/m, (rend*2.55)/m, (32)/m);}
		}
		
		ObjSpriteList2D_SetSourceRect(obj, flow, 176, 128*(rend/100)+flow, 185);
		ObjSpriteList2D_SetDestRect(obj, 1, 1, 256*(rend/100), 6);
		ObjSpriteList2D_AddVertex(obj);
		
		ObjRender_SetColor(obj, 255, 255, 255);
		ObjSpriteList2D_SetSourceRect(obj, 0, 184, 128, 195);
		ObjSpriteList2D_SetDestRect(obj, 0, 0, 256, 7);
		ObjSpriteList2D_AddVertex(obj);
		
		
		flow-=3/TimeSpeed;
		if(flow<0){flow = 256;}
		
		if(rend<RenderMeter){
			rend = min(rend+2.75/TimeSpeed, RenderMeter);
		}else{
			rend = max(rend-2.75/TimeSpeed, RenderMeter);
		}
		
		yield;
	}
}


task AnimateFairyA1(objID){
	let anim_count = 0;
	let Uber = 0;
	let Uberblink = 0;
	let yoffset = 60;
	while(!Obj_IsDeleted(objID)){
		if(!IsTimeStopped){
			if(anim_count >= 0){ObjSprite2D_SetSourceRect(objID, 128, yoffset, 160, yoffset+32);}
			if(anim_count >= 5){ObjSprite2D_SetSourceRect(objID, 160, yoffset, 192, yoffset+32);}
			if(anim_count >= 10){ObjSprite2D_SetSourceRect(objID, 192, yoffset, 224, yoffset+32);}
			if(anim_count >= 15){ObjSprite2D_SetSourceRect(objID, 224, yoffset, 256, yoffset+32);}
			if(anim_count >= 20){ObjSprite2D_SetSourceRect(objID, 192, yoffset, 224, yoffset+32);}
			if(anim_count >= 25){ObjSprite2D_SetSourceRect(objID, 160, yoffset, 192, yoffset+32);}
			if(anim_count >= 29){anim_count = 4;}
			Blink;
			ObjSprite2D_SetDestCenter(objID);
			anim_count+=1/TimeSpeed;
		}
		yield;
	}
	
	task Blink{
		if(Obj_GetValue(objID, "FairyInv")==true){
			if(Uber==0){ObjRender_SetColor(objID, 255, 255, 255);}
			if(Uber!=0){ObjRender_SetColor(objID, 0, 0, 200);}
			Uberblink+=1/TimeSpeed;
			if(Uberblink>1){Uberblink=0;Uber++;if(Uber>1){Uber=0}}
		}else{
			ObjRender_SetColor(objID, 255, 255, 255);
		}
	}
}




function DigitToArray(digit, count){
	let res = [];
	digit = truncate(digit);

	loop{
		let tnum = truncate(digit % 10);
		digit /= 10;
		res = [tnum] ~ res;
		if(truncate(digit) == 0){break;}
	}

	loop(max(0, count - length(res))){
		res = [0] ~ res;
	}

	return res;
}

function GetEnemyID{
	let earray = GetAllEnemyID;
	let objid = ID_INVALID;
	if(GetEnemyBossSceneObjectID != ID_INVALID){earray = GetEnemyBossObjectID~earray;}
	let size = max(-1, length(earray)-1);
	if(size>=0){objid = earray[0];}
	return objid;
}

function GetClosestEnemyID(x1, y1){
	let earray = GetAllEnemyID;
	if(GetEnemyBossSceneObjectID != ID_INVALID){earray = GetEnemyBossObjectID;}
	let objid = ID_INVALID;
	let dist = 99999;
	let size = max(-1, length(earray));
	if(size>=0){
		ascent(b in 0..size){
			let eID = earray[b];
			let edist = GetDistance(x1,y1,ObjRender_GetX(eID),ObjRender_GetY(eID));
			if(edist<dist){
				dist = edist;
				objid = eID
			}
		}
	}
	return objid;
}

function ArrayMin(array){
    let min = array[0];
    ascent(i in 1..length(array)){
        if(array[i] < min){ min = array[i]; }
	}
    return min;
}

function ArrayMax(array){
    let max = array[0];
    ascent(i in 1..length(array)){
        if(array[i] > max){ max = array[i]; }
    }
    return max;
}

function CheckOutsideScreen(objectID, distance){
	let COSvar = false;
	
	if(ObjRender_GetX(objectID)>GetStgFrameWidth+distance||ObjRender_GetX(objectID)<-distance||
	ObjRender_GetY(objectID)>GetStgFrameHeight+distance||ObjRender_GetY(objectID)<-distance){
		COSvar=true;
	}
	
	return COSvar;
}

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

function AnyKey(type){
	let skck = false;
	if(GetVirtualKeyState(VK_LEFT) == type){skck=true;}
	if(GetVirtualKeyState(VK_RIGHT) == type){skck=true;}
	if(GetVirtualKeyState(VK_UP) == type){skck=true;}
	if(GetVirtualKeyState(VK_DOWN) == type){skck=true;}
	return skck;
}
function AllKeysFree{
	let skck = false;
	if(GetVirtualKeyState(VK_LEFT) == KEY_FREE &&
	GetVirtualKeyState(VK_RIGHT) == KEY_FREE &&
	GetVirtualKeyState(VK_UP) == KEY_FREE &&
	GetVirtualKeyState(VK_DOWN) == KEY_FREE){skck=true;}
	return skck;
}

function DrawQuickText(txtStr, txtX, txtY){
	let SnowDrawText = ObjText_Create;
	let presetTxtColor = "black";
	//DrawText("", GetPlayerX-24, GetPlayerY, 11, 300, "black", 0.80);
	ObjText_SetText(SnowDrawText,txtStr);
	ObjText_SetFontColorTop(SnowDrawText,0,0,0);
	ObjText_SetFontColorBottom(SnowDrawText,0,0,0);
	ObjText_SetFontBorderColor(SnowDrawText,161,161,255);
	ObjText_SetFontSize(SnowDrawText,16);
	ObjText_SetHorizontalAlignment(SnowDrawText, ALIGNMENT_LEFT);
	ObjText_SetFontBorderWidth(SnowDrawText,1);
	ObjText_SetFontBorderType(SnowDrawText,BORDER_FULL);
	ObjText_SetMaxWidth(SnowDrawText, 300);
	Obj_SetRenderPriority(SnowDrawText, 0.6);
	ObjRender_SetPosition(SnowDrawText, txtX, txtY, 0);
	return SnowDrawText;
}


task bomb1{
let card =ObjSpell_Create;
ObjSpell_SetDamage(card,7);
ObjSpell_Regist(card);
ObjPrim_SetPrimitiveType(card, PRIMITIVE_TRIANGLEFAN);
ObjPrim_SetTexture(card, NULL);
Obj_SetRenderPriority(card, 0.60);
ObjPrim_SetVertexCount(card, 5);
ObjRender_SetBlendType(card, BLEND_ALPHA);
ObjPrim_SetVertexUVT(card, 0, 0, 0);	
ObjPrim_SetVertexPosition(card, 0, 0, 0, 0);
ObjPrim_SetVertexColor(card, 0, 255, 255, 255);
ObjPrim_SetVertexAlpha(card, 255, 0);
ObjRender_SetPosition(card, GetPlayerX, GetPlayerY, 0);
}