#TouhouDanmakufu[Player]
#ScriptVersion[3]	
#ID["ReisenU"]
#Title["Reisen Udongein Inaba"]
#Text["Developed by[r]SKN SMR, Natashi, and Haru[r]Wide Shot: Lunatic Gun[r]Focused Shot: Mind Wave[r]Spell Card:[r]\"Stare of the Hazy Phantom Moon[r](Lunatic Red Eyes)\"[r]Flashbomb:[r]Illusion Bomb \"Myopic Firework[r](Mind Starmine)\"[r]Secret Spell Card: ???"]
#Image["./Cutin.png"]
#ReplayName["ReisenU"]

let objPlayer = GetPlayerObjectID();
let objSlowShot = ID_INVALID;
let current = GetCurrentScriptDirectory();
let enemy;
let focus = false;
let type = 0;
let vx = 5.5;
let vy = 2.75;
let spelltime = false;
let arr1 = [];
let arr2 = [];
let arr3 = [];
let lwidth = 0;
let lwidthC = 0;
let enemyCount;
let damage_rate_bomb = 1;
let fb_count = 0;

let Dx = 0;
let Dy = 0;
let flgSpellActive = false;
let isShieldActive = 0;
let shieldLeft = 0;
let isDead = 0;
let pOldPos = [0,0];

let FOCUS_OVERRIDE = 0;

let EV_FLASHBOMB 	= EV_USER + 1234;
let EV_OCCULT		= EV_USER + 1235;

let flgOccult = 0;
let spellDummy = 0;

task EnemyCount{
	loop{
		enemyCount = length(GetIntersectionRegistedEnemyID());
		yield;
	}
}
let s = ObjSound_Create;
@Initialize{
	AddVirtualKey(VK_USER1,KEY_C,KEY_INVALID);
	AddVirtualKey(VK_USER2,KEY_D,KEY_INVALID);

	SetPlayerSpeed(vx, vy);
	SetPlayerClip(12,12,GetStgFrameWidth-12,GetStgFrameHeight-12);
	SetPlayerDownStateFrame(0);
	SetPlayerRebirthFrame(20);
	ObjPlayer_AddIntersectionCircleA1(objPlayer, 0, 0, 2, 25);
	
	let path = current ~ "MarisaShotData.txt";
	LoadPlayerShotData(path);
	
	LoadSound(GetCurrentScriptDirectory~"graze.wav");
	LoadSound(GetCurrentScriptDirectory~"se_shot.wav");
	/*
	LoadSound(GetCurrentScriptDirectory~"Eff2.wav");
	LoadSound(GetCurrentScriptDirectory~"Shot6.wav");
	LoadSound(GetCurrentScriptDirectory~"Shot7.wav");
	LoadSound(GetCurrentScriptDirectory~"Shot8.wav");
	LoadSound(GetCurrentScriptDirectory~"Shot9.wav");
	LoadSound(GetCurrentScriptDirectory~"Laser7.wav");
	LoadSound(GetCurrentScriptDirectory~"Charge1.wav");
	LoadSound(GetCurrentScriptDirectory~"Charge2.wav");
	LoadSound(GetCurrentScriptDirectory~"SpellCard.wav");
	*/
	LoadSound(GetCurrentScriptDirectory~"1up.wav");
	LoadSound(GetCurrentScriptDirectory~"item_00.wav");
	LoadSound(current~"se_pldead.wav");
	
	//SetPlayerInvincibilityFrame(99999999999);
	TImage();
	TShot();
	TMagicCircle();
	TMagicCircle2();
	HitBox(1);
	HitBox(-1);
	Orb;
	InitFlashBomb;
}

@MainLoop{
	enemy = GetAllEnemyID;
	
	if(GetVirtualKeyState(VK_USER1)==KEY_PUSH){
		NotifyEvent(GetOwnScriptID,EV_FLASHBOMB,[0]);
	}
	if(GetVirtualKeyState(VK_USER2)==KEY_PUSH){
		NotifyEvent(GetOwnScriptID,EV_OCCULT,[0]);
	}
	
	if(shieldLeft<=0){isShieldActive=0;}
	else if(shieldLeft>0){isShieldActive=1;}
	if(shieldLeft>0){isDead=0;}
	if(isShieldActive){SetPlayerDownStateFrame(0);}
	else{SetPlayerDownStateFrame(90);}
	
	yield;
}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_SPELL){
		let spell = GetPlayerSpell();
		if(spell >= 1 && !flgOccult){
			SetScriptResult(true);
			SetPlayerSpell(spell-1);
			TSpellRH;
		}
		else if(spellDummy){
			SetScriptResult(true);
			WriteLog(0);
		}
		else{
			SetScriptResult(false);
		}
	}
	case(EV_HIT){
		let obj = GetEventArgument(0);
		
		pOldPos = [GetPlayerX,GetPlayerY];
		DIe();
		
		if(isShieldActive){
			BreakShield;
			SetPlayerLife(GetPlayerLife+1);
			TCharge01(GetPlayerX,GetPlayerY,5,10,0,255,255);
			PlaySound("hit",80,0);
			TExplosion(20);
			ascent(i in 0..10){
				LeafEffect(GetPlayerX,GetPlayerY, rand(2,10), rand(0,360), rand(5,40), 50, 255,255,255,0,20);
				LeafEffect(GetPlayerX,GetPlayerY, rand(2,10), rand(0,360), rand(5,30), 50, 255,255,255,1,20);
			}
		}
	}
	case(EV_PLAYER_REBIRTH){
		if(!isShieldActive){
			SetPlayerSpell(1);
			SetPlayerInvincibilityFrame(180);
			ObjMove_SetPosition(objPlayer,pOldPos[0],pOldPos[1]);
			BlinkEffect(180);
			rebirtheff(180);
		}
		else{
			SetPlayerInvincibilityFrame(60);
			ObjMove_SetPosition(objPlayer,pOldPos[0],pOldPos[1]);
			BlinkEffect(60);
			rebirtheff(60);
		}
	}
	case(EV_GRAZE){
		if(fb_count<=260){fb_count+=7;}
		PlaySE(GetCurrentScriptDirectory~"graze.wav");
		GrazeEff(objPlayer);
	}
	case(EV_GET_ITEM){
		let itemType = GetEventArgument(0);
		alternative(itemType)
		case(ITEM_1UP){
			PlaySE(current~"./1up.wav");
			SetPlayerLife(GetPlayerLife);
			//WriteLog("ITEM_1UP");
		}
		case(ITEM_1UP_S){
			PlaySE(current~"./1up.wav");
			SetPlayerLife(GetPlayerLife);
			//WriteLog("ITEM_1UP_S");
		}
		case(ITEM_SPELL){
			PlaySE(current~"./item_00.wav");
			SetPlayerSpell(GetPlayerSpell);
			//WriteLog("ITEM_SPELL");
		}
		case(ITEM_SPELL_S){
			PlaySE(current~"./item_00.wav");
			SetPlayerSpell(GetPlayerSpell);
			//WriteLog("ITEM_SPELL_S");
		}
		case(ITEM_POWER){
			PlaySE(current~"./item_00.wav");
			//WriteLog("ITEM_POWER");
		}
		case(ITEM_POWER_S){
			PlaySE(current~"./item_00.wav");
			//WriteLog("ITEM_POWER_S");
		}
		case(ITEM_POINT){
			PlaySE(current~"./item_00.wav");
			//WriteLog("ITEM_POWER");
		}
		case(ITEM_POINT_S){
			PlaySE(current~"./item_00.wav");
			//WriteLog("ITEM_POWER_S");
		}
	}
	case(EV_FLASHBOMB){
		if(fb_count>=260 && FOCUS_OVERRIDE==0 && IsPermitPlayerSpell){
			TSpellBlank;
			FlashBomb;
			fb_count = 0;
		}
	}
	case(EV_OCCULT){
		if(GetPlayerSpell >= 3){
			if(IsPermitPlayerSpell && !IsPlayerSpellActive){
				TSpellOccult;
				SetPlayerSpell(GetPlayerSpell-3);
			}
		}
	}
}
task SpellDummy{
	spellDummy = 1;
	
	/*
	SetVirtualKeyState(VK_BOMB,KEY_PUSH);
	yield;
	SetVirtualKeyState(VK_BOMB,KEY_PULL);
	*/
	CallSpell;
	
	wait(30);
	
	spellDummy = 0;
	SetForbidPlayerSpell(1);
}
task TSpellOccult{
	flgSpellActive = true;
	flgOccult = 1;
	
	SpellDummy;
	SetForbidPlayerShot(1);
	
	let objManage = GetSpellManageObject();
	_TSpellOccult;
	
	loop(30){
		yield;
	}
	
	SetForbidPlayerShot(0);
	SetForbidPlayerSpell(0);
	
	flgSpellActive = false;
	
	Obj_Delete(objManage);
}
function _TSpellOccult{
let pfPlayerCutInDpellNameDeleted = true;
let pfPlayerCutInSpellNameGhostDeleted = true;
let pfPlayerCuIinameEffectDeleted = true;
let pfPlayerCutInSpellName;
let pfPlayerCutInSpellNameGhost;
let pfPlayerCutInNameEffect;

	let SPELL_TIMER = 410;

SpellCard02(GetPlayerX,GetPlayerY);
PlaySound("cardcall",90,0);
SpellUseName("",255,255,255);
	SetPlayerInvincibilityFrame(SPELL_TIMER+100);
	rebirtheff(SPELL_TIMER+100);
	BlinkEffect(SPELL_TIMER+100);
	
	flgOccult = 0;
	
	
function SpellCard02(x,y){
	let texture = GetReservedRenderTargetName(2);
	let SPELL_TIMER = 360;
	let SPELL_SIZE = 0;
	let SIZE_OFFSET = 1;
	SetPlayerInvincibilityFrame(SPELL_TIMER+100);
	//shieldLeft = 4;
	DeleteShotInCircle(TYPE_SHOT,TYPE_ITEM,GetPlayerX,GetPlayerY,120);
	MainTask;
	loop(SPELL_TIMER-30){
		if(!IsPermitPlayerSpell){break;}
		yield;
	}
	loop(30){
		if(!IsPermitPlayerSpell){break;}
		yield;
	}
	flgSpellActive = false;
	
	task MainTask{
	//PlaySound("Slash",90,0);
		//let obj = ObjSpell_Create;
		//ObjSpell_Regist(obj);
		//ObjRender_SetPosition(obj,x,y,1);
		//ObjSpell_SetDamage(obj,3);
		let t = 0;
		loop(SPELL_TIMER){
			if(t<60){SPELL_SIZE+=1/60;}
			else if(t>SPELL_TIMER-30){SPELL_SIZE-=1/30;}
			if(t==90){MadnessTask;}
			if(t>=90 && t<SPELL_TIMER){RenderToTextureA1(texture,20,53,1);}
			//ObjSpell_SetIntersectionCircle(obj,x,y,SPELL_SIZE*256*SIZE_OFFSET);
			if(t%8==0){Spell_Sub;}
			t++;
			yield;
		}
		//Obj_Delete(obj);
	}
	task Spell_Sub{
	PlaySound("Shot4",90,0);
		let sobj = ObjSpell_Create;
		ObjSpell_Regist(sobj);
		ObjRender_SetPosition(sobj,x,y,1);
		ObjSpell_SetDamage(sobj,10);
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"reisen_wave.png");
		ObjSprite2D_SetSourceRect(obj,0,0,512,512);
		ObjSprite2D_SetDestCenter(obj);
		Obj_SetRenderPriorityI(obj,46);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetPosition(obj,x,y,1);
		let timer = 60;
		let t = 0;
		let alpha = 0;
		let sc = 0;
		let sc_max = SPELL_SIZE*8;
		TExplosion2;
		loop(20){
			alpha+=1/20;
			sc+=sc_max/60;
			Update;
		}
		//PlaySound("flash_01",90,0);
		loop(60-45){
			sc+=sc_max/60;
			Update;
			
		}
		loop(25){
			alpha-=1/25;
			sc+=sc_max/60*10;
			
			Update;
		}
		Obj_Delete(obj);
		Obj_Delete(sobj);
		function Update{
			ObjRender_SetAlpha(obj,alpha*255);
			ObjRender_SetScaleXYZ(obj,sc,sc,1);
			ObjRender_SetColor(obj,255,(sc_max-sc)*255,(sc_max-sc)*255);
			ObjSpell_SetIntersectionCircle(sobj,x,y,sc*256);
			
			t++;
			yield;
		}
	}
	task MadnessTask{
		PlaySound("Slash",90,0);
		SIZE_OFFSET = 5;
		SpellShade;
		
		EyeEffect;
		
		SplitScreen(1);
		SplitScreen(-1);
		SplitScreen(2);
		SplitScreen(-2);
		ScreenShake(210);
		loop(20)
		{
		TExplosion2;
		wait(10);
		}
		
	}
	task EyeEffect{
		let sobj = ObjSpell_Create;
		ObjSpell_Regist(sobj);
		ObjRender_SetPosition(sobj,GetStgFrameWidth/2,GetStgFrameHeight/2,1);
		ObjSpell_SetEraseShot(sobj,0);
		ObjSpell_SetDamage(sobj,6);
		
		ascent(i in 0..13*3){
			if(i%3==0){
				_EyeEffect(255-i*(128/13),(i/3)*3);
			}
			ObjSpell_SetIntersectionCircle(sobj,GetStgFrameWidth/2,GetStgFrameHeight/2,(GetStgFrameWidth^2+GetStgFrameHeight^2)^0.5);
			yield;
		}
		loop(210-13*3){ObjSpell_SetIntersectionCircle(sobj,GetStgFrameWidth/2,GetStgFrameHeight/2,(GetStgFrameWidth^2+GetStgFrameHeight^2)^0.5);yield;}
		Obj_Delete(sobj);
		
		task _EyeEffect(alpha,offset_timer){
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"stg5enm.png");
			ObjSprite2D_SetSourceRect(obj,0,192,256,256);
			ObjSprite2D_SetDestCenter(obj);
			Obj_SetRenderPriorityI(obj,60);
			ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
			//ObjRender_SetPosition(obj,GetStgFrameWidth/2,224-100,1);
			let an = 270+rand(-30,30);
			let x = GetStgFrameWidth/2;
			let y = 224-100;
			let sc = 1.6;
			let _alpha = 0;
			loop(300-90-offset_timer){
				if(_alpha<alpha){_alpha+=alpha/60;}
				if(sc>1.1){sc-=0.5/100;}
				Update;
			}
			loop(17){
				x += cos(an)*4;
				y += sin(an)*4;
				if(_alpha>0){_alpha-=alpha/17;}
				Update;
			}
			Obj_Delete(obj);
			function Update{
				ObjRender_SetPosition(obj,x,y,1);
				ObjRender_SetAlpha(obj,_alpha);
				ObjRender_SetScaleXYZ(obj,sc,sc,1);
				//ObjRender_SetColor(obj,255,(sc_max-sc)*255,(sc_max-sc)*255);
				yield;
			}
		}
	}
	task SplitScreen(muki){
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,texture);
		ObjSprite2D_SetSourceRect(obj,GetStgFrameLeft,GetStgFrameTop,GetStgFrameWidth+GetStgFrameLeft,GetStgFrameHeight+GetStgFrameTop);
		ObjSprite2D_SetDestRect(obj,0,0,GetStgFrameWidth,GetStgFrameHeight);
		Obj_SetRenderPriorityI(obj,55);
		//let x = GetStgFrameWidth/2;
		let x = 0;
		let y = GetStgFrameHeight/2;
		let maxdist = x + 90 * muki;
		let cx = x;
		let timer = 300-90;
		loop(210-5){
			cx += maxdist/(210-5);
			Update;
		}
		loop(5){
			cx -= maxdist/(5);
			Update;
		}
		Obj_Delete(obj);
		function Update{
			ObjRender_SetX(obj,cx);
			ObjRender_SetAlpha(obj,255+rand(-32,0));
			ObjRender_SetScaleXYZ(obj,1+rand(-1,1)*0.02,1+rand(-1,1)*0.02,1);
			ObjRender_SetColor(obj,rand(192,255),rand(192,255),rand(192,255));
			yield;
		}
	}
}
	
	task SpellUseName(n,r,g,b){
	
	pfPlayerCutInDpellNameDeleted = false;
	pfPlayerCutInSpellNameGhostDeleted = false;
	


	
	let tScale1 = 10;
	let tScale2 = 10;
	
	let tAlpha1 = 0;
	let tAlpha2 = 0;
	
	let yOff = 400;
	
	let tYOff1 = -yOff;
	let tYOff2 = -yOff;
	
	
	pfPlayerCutInDpellNameDeleted = false;
	
	pfPlayerCutInNameEffect = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(pfPlayerCutInNameEffect, BLEND_ALPHA);
	Obj_SetRenderPriority(pfPlayerCutInNameEffect, 0.60);
	ObjPrim_SetTexture(pfPlayerCutInNameEffect, GetCurrentScriptDirectory() ~ "./bom_waku_Wow.png");
	ObjSprite2D_SetDestRect(pfPlayerCutInNameEffect, -100, -15, 100, 15);
	ObjSprite2D_SetSourceRect(pfPlayerCutInNameEffect, 0, 0, 500, 60);
	
	let eScale = 10;
	
	let eAlpha = 0;
	
	let xOff = 100;
	yOff = 520;
	
	let eXOff = xOff;
	let eYOff = -yOff;
	
	loop(60){
		if(!pfPlayerCutInDpellNameDeleted){
			ObjRender_SetX(pfPlayerCutInNameEffect, 480 + eXOff);
			ObjRender_SetY(pfPlayerCutInNameEffect, 430 + eYOff);
			
			ObjRender_SetScaleXYZ(pfPlayerCutInNameEffect, eScale, eScale, eScale);
			ObjRender_SetAlpha(pfPlayerCutInNameEffect, eAlpha);
			
			eScale -= 8.5/60;
			eAlpha += 195/60;
			
			eXOff -= xOff/24;
			eYOff += yOff/61;
			yield;
		}
	}
	
	loop(60){yield;}
	
	let x = 14;
	let y = 218;
	
	while(x > 0 && !pfPlayerCutInDpellNameDeleted){
		//ObjRender_SetY(pfPlayerCutInNameEffect, 400);
		
		y -= x;
		
		if(y < 200){
			x -= 0.58;
		}
		yield;
	}
	

	
	loop(120){yield;}
	
	xOff = 0;
	
	loop(65){
		if(!pfPlayerCutInDpellNameDeleted){
			ObjRender_SetX(pfPlayerCutInNameEffect,400 - xOff);
			xOff -= 10;
			
			yield;
		}
	}
	
	if(!pfPlayerCutInDpellNameDeleted){
		Obj_Delete(pfPlayerCutInNameEffect);
		
		pfPlayerCutInDpellNameDeleted = true;
		pfPlayerCutInDpellNameDeleted = true;
	}
}

task DeleteSpellName{
	if(!pfPlayerCutInDpellNameDeleted){
		
		pfPlayerCutInDpellNameDeleted = true;
		
		Obj_Delete(pfPlayerCutInSpellName);
		if(!pfPlayerCutInSpellNameGhostDeleted){Obj_Delete(pfPlayerCutInSpellNameGhost);}
		if(!pfPlayerCutInDpellNameDeleted){Obj_Delete(pfPlayerCutInNameEffect);}
	}
}
}

task DIe()
{
TCharge01(GetPlayerX,GetPlayerY,5,10,0,255,255);
		PlaySound("hit",80,0);
		PlaySound("barrier",80,20);
		//PlaySound("DIE",80,20);
		TExplosion(20);
		ascent(i in 0..15){
			LeafEffect(GetPlayerX,GetPlayerY, rand(2,10), rand(0,360), rand(5,40), 50, 255,255,255,0,20);
			LeafEffect(GetPlayerX,GetPlayerY, rand(2,10), rand(0,360), rand(5,30), 50, 255,255,255,1,20);
		}
		ObjMove_SetPosition(objPlayer,pOldPos[0],pOldPos[1]);
		yield;
}

task rebirtheff(w){
	loop(w){yield;}
	TExpan2(GetPlayerX,GetPlayerY,20,20,255,255,255,0);
	PlaySound("barrier_on",100,0);
	yield;
}

task Homing(obj,h_obj,maxTraverse,mspeed,time){  // max. angle of traverse
	let angle = ObjMove_GetAngle(obj);
	let dir = 0;
	let count = 0;
	let boss = GetIntersectionRegistedEnemyID;
    while(! Obj_IsDeleted(obj) && Obj_GetValueD(h_obj,"HomingOrNot",1)==1 && FindTarget!=-1 && count<time){
        ObjMove_SetAngle(obj, angle);
		maxTraverse += mspeed;
		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;
        }
		count++;
		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];
			}
		}
		if(length(GetEnemyBossObjectID)>=1){
			return GetEnemyBossObjectID[0];
		}
		else{
			return h_obj;
		}
	}
	else{
		return -1;
	}
}

task PlaySound(str,v,w){
	if(str == "Laser7")		{ObjSound_Load(s,GetCurrentScriptDirectory~"Laser7.wav");}
	if(str == "Shot4")		{ObjSound_Load(s,GetCurrentScriptDirectory~"Shot4.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 == "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 == "cardcall")	{ObjSound_Load(s,GetCurrentScriptDirectory~"cardcall.wav");}
	if(str == "ShotM")		{ObjSound_Load(s,GetCurrentScriptDirectory~"ShotM.wav");}
	if(str == "ShotM2")		{ObjSound_Load(s,GetCurrentScriptDirectory~"ShotM2.wav");}
	if(str == "charge_up")	{ObjSound_Load(s,GetCurrentScriptDirectory~"charge_up.wav");}
	if(str == "flash_00")	{ObjSound_Load(s,GetCurrentScriptDirectory~"bom_flash_00.wav");}
	if(str == "flash_01")	{ObjSound_Load(s,GetCurrentScriptDirectory~"bom_flash_01.wav");}
	if(str == "warning")	{ObjSound_Load(s,GetCurrentScriptDirectory~"warning.wav");}
	if(str == "barrier")	{ObjSound_Load(s,GetCurrentScriptDirectory~"j_barrier.wav");}
	if(str == "barrier_on")	{ObjSound_Load(s,GetCurrentScriptDirectory~"j_barrier_on.wav");}
	if(str == "hit")		{ObjSound_Load(s,GetCurrentScriptDirectory~"j_hit.wav");}
	if(str == "DIE")		{ObjSound_Load(s,GetCurrentScriptDirectory~"se_pldead.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;}
}

task TMagicCircle{
	let countVertex = 48;
	let listRadius = [];
	loop(countVertex){
		listRadius = listRadius ~ [0];
	}
	let path = current ~ "spell_card_00.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(obj, countVertex);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	Obj_SetRenderPriority(obj, 0.60);
	ObjPrim_SetTexture(obj, path);
	ascent(iVert in 0..countVertex / 2){
		let left = iVert * 128 * 2;
		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 = 148;
	let alpha = 0;
	let frame = 0;
	let angleRender = 0;
	let frameInvOld = 0;
	ObjRender_SetAlpha(obj,192);
	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/1.3);
			frame++;
		}
		yield;
	}
}

task TMagicCircle2{
	let countVertex = 32;
	let listRadius = [];
	loop(countVertex){
		listRadius = listRadius ~ [0];
	}
	let path = current ~ "spell_eff_00.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(obj, countVertex);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	Obj_SetRenderPriority(obj, 0.60);
	ObjPrim_SetTexture(obj, path);
	ascent(iVert in 0..countVertex / 2){
		let left = iVert * 128 * 2;
		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;
	ObjRender_SetAlpha(obj,192);
	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, 255 * alpha, 170 * alpha, 255 * alpha);
			ObjRender_SetPosition(obj, px, py, 0);
			ObjRender_SetAngleZ(obj, -angleRender/1.3);
			frame++;
		}
		yield;
	}
}

task GrazeEff(obj){
	let x = ObjMove_GetX(obj);
	let y = ObjMove_GetY(obj);
	//GrazePoint(x,y,atan2(y-GetPlayerY,x-GetPlayerX)+rand(-30,30));
	GrazePoint(x,y,rand(0,360));
}

task GrazePoint(x,y,an){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./graze.png");
	Obj_SetRenderPriorityI(obj,48);
	ObjSprite2D_SetDestRect(obj,0,0,GetStgFrameWidth,GetStgFrameHeight);
	ObjSprite2D_SetSourceRect(obj,0,0,32,32);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,x,y,1);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	let defang = rand(0,360);
	ObjRender_SetAngleZ(obj,defang);
	ObjRender_SetColor(obj,255,255,64);
	let alpha = 0;
	let alphamax = 200;
	let f = 0;
	let t = 0;
	let mult = rand(-12,12);
	let spd = 3;
	let _spd = spd;
	loop(30){
		if(f<=5){
			alpha+=alphamax/5;
		}
		spd-=_spd/30;
		ObjRender_SetPosition(obj,x,y,1);
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetAngleZ(obj,t*mult+defang);
		x+=cos(an)*spd;
		y+=sin(an)*spd;
		f++;
		t++;
		yield;
	}
	f=0;
	loop(30){
		an = atan2(ObjRender_GetY(obj)-GetPlayerY,ObjRender_GetX(obj)-GetPlayerX);
		let dist = GetDistance(ObjRender_GetX(obj),ObjRender_GetY(obj),GetPlayerX,GetPlayerY)/5;
		if(f>10){
			alpha-=alphamax/20;
			x-=cos(an)*dist;
			y-=sin(an)*dist;
		}
		ObjRender_SetPosition(obj,x,y,1);
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetAngleZ(obj,t*mult+defang);
		f++;
		t++;
		yield;
	}
	Obj_Delete(obj);
}

task InitFlashBomb{
	let alpha = 1;

	CreateFillingBar;
	CreateEmptyBar;
	task CreateEmptyBar{
		let obj=ObjPrim_Create(OBJ_SPRITE_2D); 
		let img;
		img = GetCurrentScriptDirectory~"flash_gauge_00.png";
		ObjPrim_SetTexture(obj,img);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		Obj_SetRenderPriority(obj,2);
		//AlphaApproch( obj );
		
		ObjSprite2D_SetSourceRect(obj,0,0,260,15);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetColor(obj,255,255,255);
		ObjRender_SetAngleZ(obj,-90);
		ObjRender_SetPosition(obj,10,315,0);
		while(!Obj_IsDeleted(obj)){
			ObjRender_SetAlpha(obj,alpha*255);
			
			if(1){
				let px = GetPlayerX;
				let py = GetPlayerY;
				let rd = 30*2;
				let sp = [0,GetStgFrameHeight-260-50];
				let ep = [0,GetStgFrameHeight];
				if(IsIntersected_Line_Circle(sp[0],sp[1],ep[0],ep[1],15,px,py,rd)){
					if(alpha>0.4){alpha-=0.6/20;}
				}
				else{
					if(alpha<1){alpha+=0.6/20;}
				}
			}
			
			yield;
		}
	}
	task CreateFillingBar{
		let obj2=ObjPrim_Create(OBJ_SPRITE_2D); 
		let img2;
		let c = 0;
		img2 = GetCurrentScriptDirectory~"flash_gauge_00.png";
		ObjPrim_SetTexture(obj2,img2);
		ObjSprite2D_SetSourceRect(obj2,0,25,260,39);
		ObjSprite2D_SetDestCenter(obj2);
		ObjRender_SetBlendType(obj2,BLEND_ALPHA);
		Obj_SetRenderPriority(obj2,2);
		//AlphaApproch( obj2 );
		//ObjRender_SetAlpha(obj2,255);
		ObjRender_SetAngleZ(obj2,-90);
		while(!Obj_IsDeleted(obj2)){
			ObjSprite2D_SetSourceRect(obj2,0,25,fb_count,39);
		    ObjSprite2D_SetDestCenter(obj2);
			ObjRender_SetPosition(obj2,10,445-fb_count/2,0);
			if(fb_count>=260){
				ObjRender_SetColor(obj2,255,150+105*sin(c*3+180),155+105*sin(c*3+180));
				c++;
			}
			else{ObjRender_SetColor(obj2,255,255,255);}
			if(fb_count > 261){
				PlaySound("charge_up",100,0);
				fb_count-=1;
		    }
			ObjRender_SetAlpha(obj2,alpha*255);
			yield;
		}
	}
}

task AlphaApproch( obj ){
	let alpha_t = 255;
	while(!Obj_IsDeleted(obj)){
		if(GetPlayerY>100 && alpha_t<255){alpha_t+=10;}
		if(GetPlayerX<=80 && alpha_t>100){alpha_t-=10;}
		ObjRender_SetAlpha(obj,alpha_t);
		yield;
	}
}

task TSpellBlank{
	yield;
}

task FlashBomb{
	spelltime = true;
	//let objManage = GetSpellManageObject();
	let spell = ObjSpell_Create;
	ObjSpell_Regist(spell);
	ObjSpell_SetDamage(spell,5);
	let t = 0;
	let t2 = 1;
	let x = GetPlayerX;
	let y = GetPlayerY;
	let r = rand(0,360);
	SetPlayerInvincibilityFrame(120);
	let angle = rand(0, 360);
    SpellUseName(" ",255,255,255);
	//PlaySound("flash_01",60,0);
	wait(5);
	IsPermitPlayerShot;
	//ExCircle(x,y,0.07,60);
	loop(1)
	{
	boom(GetPlayerX,GetPlayerY,0,0,2,100);
	PlaySound("flash_01",70,0);
	ascent(i in 0..6)
	{
	boom(GetPlayerX,GetPlayerY,22,i*360/6,2,100);
	t++;
	}
	wait(1);
	}
	loop(2){yield;}
    //ExCircle(x,y,0.07,60-2);
	BlinkEffect(120);
	loop(10){
		SetPlayerSpeed(vx,vy);
		yield;
	}
	spelltime = false;
	//Obj_Delete(objManage);
	
	task boom(x,y,spd,dir,dmg,pdmg){
	let shotcolor = 6;
	let mx;
	let my;
	let mangle;
	let t = 0;
	let t2 = 1;
	let finalpos = 0;
	if(!IsPermitPlayerShot){return;}
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,shotcolor);
	ObjRender_SetAngleZ(mainobj, -90);
	ObjRender_SetAlpha(mainobj, 0);
    Obj_SetRenderPriorityI(mainobj,42);
	let count = 0;
	while(!Obj_IsDeleted(mainobj)){
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		//ObjMove_SetSpeed(mainobj,t*1);
		//ObjMove_SetPosition(objPlayer,GetPlayerX,GetPlayerY+t*0.05);
		//ObjSpell_SetIntersectionCircle(spell,mx,my,30);
		if(t>2){Obj_Delete(mainobj);}
		t++;
		
		yield;
	}
	TExpanSS(mx,my,0.5,46,255,255,255,BLEND_INV_DESTRGB);
}

function TExpanSS(px,py,maxv,t,r,g,b,BLEND){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./Effect03.png";
	let scale = 0;
	let v = 0;
	let sp = 0;
	let malpha = 255/t;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND);
	ObjRender_SetPosition(obj,px,py,0);
	ObjRender_SetColor(obj,r,g,b);
	Obj_SetRenderPriorityI(obj,65);
	Expan;
	fromnoo( obj );

	task fromnoo( obj ){
	ascent( i in 0..0.12*50 ){
	ObjRender_SetScaleXYZ(obj,i/50,i/50,0);
	yield;
	}
	wait( 32 );
	descent( i in 0..0.12*50 ){
	ObjRender_SetScaleXYZ(obj,i/50,i/50,0);
	yield;
	}
	//Obj_Delete( obj );
	}

	task Expan{
		descent(i in 0..t){
			ObjRender_SetAlpha(obj,malpha*i);
			ObjSpell_SetIntersectionCircle(spell,px,py,35);
			v = (i*maxv/2)/(t*t);
			scale += v;
			sp+=70;
			//ObjRender_SetScaleXYZ(obj,0.12,0.12,0);
			//ObjRender_SetAngleZ(obj,sp);
			yield;
		}
		//Obj_Delete(obj);
	}
}

	task SpellUseName(n,r,g,b){
		let tScale1 = 10;
		let tScale2 = 10;
		let tAlpha1 = 0;
		let tAlpha2 = 0;
		let yOff = 400;
		let tYOff1 = -yOff;
		let tYOff2 = -yOff;
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 60);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory() ~ "./flash_bom_name_05.png");
		//ObjSprite2D_SetDestRect(obj, -100, -14, 100, 14);
		ObjSprite2D_SetSourceRect(obj, 0, 0, 270,20);
		ObjSprite2D_SetDestCenter(obj);
		
		let eScale = 10;
		let eAlpha = 0;
		let xOff = 100;
		yOff = 500;
		
		let eXOff = xOff;
		let eYOff = -yOff;
		
		loop(20){
			ObjRender_SetX(obj, 440 + eXOff);
			ObjRender_SetY(obj, 445 + eYOff);
			ObjRender_SetScaleXYZ(obj, eScale, eScale, eScale);
			ObjRender_SetAlpha(obj, eAlpha);
			eScale -= 10/22;
			eAlpha += 195/20;
			eXOff -= xOff/20;
			eYOff += yOff/19.5;
			yield;
		}
		loop(5){yield;}
		let x = 14;
		let y = 438;
		while(x > 0){
			//ObjRender_SetY(obj, 430);
			y -= 14;
			if(y < 200){
				x -= 0.58;
			}
			yield;
		}
		loop(20){yield;}
		xOff = 0;
		loop(15){
			ObjRender_SetX(obj, 480 - xOff);
			xOff -= 20;
			yield;
		}
		Obj_Delete(obj);
	}
}

task TImage{
	let f = 0;
	let f2 = 0;
	let px = 32;
	let py = 48;
	let path = GetCurrentScriptDirectory() ~ "pl03.png";
	ObjPrim_SetTexture(objPlayer, path);
	Obj_SetRenderPriorityI(objPlayer,45);
	ObjRender_SetScaleXYZ(objPlayer,1,1,0);
	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, 0, 1, px, 48);}
			if(f>=6&& f<=12){ObjSprite2D_SetSourceRect(objPlayer, px, 1, px*2, 48);}
			if(f>=12 && f<=18){ObjSprite2D_SetSourceRect(objPlayer, px*2, 1, px*3, 48);}
			if(f>=18 && f<=24){ObjSprite2D_SetSourceRect(objPlayer, px*3, 1, px*4, 48);}
			if(f>=24 && f<=30){ObjSprite2D_SetSourceRect(objPlayer, px*4, 1, px*5, 48);}
			if(f>=30 && f<=36){ObjSprite2D_SetSourceRect(objPlayer, px*5, 1, px*6, 48);}
			if(f>=36 && f<=42){ObjSprite2D_SetSourceRect(objPlayer, px*6, 1, px*7, 48);}
			if(f>=42){ObjSprite2D_SetSourceRect(objPlayer, px*7, 1, px*8, 48);}
			if(f>=48){f=0;}
			f++;
			f2 = 0;
		}
		ObjSprite2D_SetDestCenter(objPlayer);
		yield;
	}
}
task BlinkEffect(time){
	ascent(i in 0..time){
		if(i % 2 == 0){
			ObjRender_SetColor(objPlayer, 255, 0, 0);
			if(i % 3 == 0){
				ObjRender_SetColor(objPlayer, 0, 0, 0);
			}
			if(i % 4 == 0){
				ObjRender_SetColor(objPlayer, 255, 255, 255);
			}
		}
		yield;
	}
	ObjRender_SetColor(objPlayer, 255, 255, 255);
}
task Orb{
	ascent(i in 0..4){
		arr1 = arr1 ~ [CreateTool];
		Orb1(arr1[i],i);
	}
	task Orb1(obj,num){
		let ufco = [[-50,0],[-0,-50],[50,0],[0,50]];
		let fco = [[-15,-20],[-35,10],[15,-20],[35,10]];
		let way = [1,1,1,1];
		let time = 3;
		let f = 0;
		let x;
		let y;
		let count = 0;
		ObjRender_SetAlpha(obj,192);
		ObjSprite2D_SetSourceRect(obj,0,0,18,16);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		AfterOrb(obj,33,0,47,15,0);
		let smoothspeed = 0.3;
		while(!Obj_IsDeleted(obj)){
			if(GetPlayerState==STATE_DOWN || type!=0){Obj_SetVisible(obj,false);}
			else{Obj_SetVisible(obj,true);}
			let posx = GetPlayerX;
			let posy = GetPlayerY;
			/*
			if(focus==false){
				x = ufco[num][0];
				y = ufco[num][1];	
			}
			else {
				x = fco[num][0];
				y = fco[num][1];	
			}
			let xc = (GetPlayerX+x-ox)/time;
			let yc = (GetPlayerY+y-oy)/time;
			if(GetPlayerState==STATE_DOWN){
				xc = (GetStgFrameWidth/2+x-ox)/time;
				yc = (478+y-oy)/time;
			}
			ox += xc;
			oy += yc;
			*/
			if(count>1){
				if(!focus){
					posx = (GetPlayerX+ufco[num][0])*smoothspeed + (ObjRender_GetX(obj))*(1-smoothspeed);
					posy = (GetPlayerY+ufco[num][1])*smoothspeed + (ObjRender_GetY(obj))*(1-smoothspeed);
				}
				else{
					posx = (GetPlayerX+ fco[num][0])*smoothspeed + (ObjRender_GetX(obj))*(1-smoothspeed);
					posy = (GetPlayerY+ fco[num][1])*smoothspeed + (ObjRender_GetY(obj))*(1-smoothspeed);
				}
			}
			else{
				posx = GetPlayerX;
				posy = GetPlayerY;
			}
			
			if(GetPlayerState==STATE_DOWN || GetPlayerState==STATE_END){
				Obj_SetVisible(obj,false);
				count = 0;
			}
			else{
				Obj_SetVisible(obj,true);
			}
			
			if(f<120){ObjSprite2D_SetSourceRect(obj, 0, 0, 16, 8);}
			if(f>=120&& f<=125){ObjSprite2D_SetSourceRect(obj, 16, 0, 32, 8);}
			if(f>=125 && f<=130){ObjSprite2D_SetSourceRect(obj, 32, 0, 48, 8);}
			if(f>=130){ObjSprite2D_SetSourceRect(obj, 48, 0, 64, 8);}
			if(f>=135){f=0;}
			f++;
			//ObjRender_SetPosition(obj,ox,oy,0);
			ObjRender_SetPosition(obj,posx,posy,0);
			ObjRender_SetAngleXYZ(obj,0,0,0);
			ObjRender_SetScaleXYZ(obj,1,0.65,0);
			count++;
			yield;
		}
	}
	task AfterOrb(mobj,r1,r2,r3,r4,ftype){
		let obj= ObjPrim_Create(OBJ_SPRITE_2D); // graphic
		let img = GetCurrentScriptDirectory~"Shitop.png";
		let scale = 1.5;
        let count = 0;
		let fcolor = [0,0,0];
		ObjPrim_SetTexture(obj,img);

		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjSprite2D_SetSourceRect(obj,r1,r2,r3,r4);
		ObjSprite2D_SetDestCenter(obj);
		let f = 0;
		Obj_SetRenderPriorityI(obj,42);
		while(!Obj_IsDeleted(mobj)){
			if(ftype==0){fcolor = [228,64,228];}
			if(ftype==1){fcolor = [228,64,64];}
			if(ftype==2){fcolor = [228,64,228];}
			ObjRender_SetPosition(obj,ObjRender_GetX(mobj),ObjRender_GetY(mobj),0);
            ObjRender_SetScaleXYZ(obj,1.6,1,0);
            ObjRender_SetAngleXYZ(obj,0,0,0);
	        ObjRender_SetAlpha(obj,192);
            count++;
			if(f<120){ObjSprite2D_SetSourceRect(obj, 0, 0, 16, 8);}
			if(f>=120&& f<=125){ObjSprite2D_SetSourceRect(obj, 16, 0, 32, 8);}
			if(f>=125 && f<=130){ObjSprite2D_SetSourceRect(obj, 32, 0, 48, 8);}
			if(f>=130){ObjSprite2D_SetSourceRect(obj, 48, 0, 64, 8);}
			if(f>=135){f=0;}
			f++;
			if(type==ftype && GetPlayerState!=STATE_DOWN){
				if(ftype!=3 || (ftype==3)){
					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~"Shitop.png";
	ObjPrim_SetTexture(obj,img);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj,43);
	return obj;
}

let bNextShot = false;

task TShot{
	let shotCount = -1;
	let objShot = ID_INVALID;
	let shotnum = 0;
	LoadSound(GetCurrentScriptDirectory~"Shot9.wav");
	loop{
		/*
		if(GetVirtualKeyState(VK_USER1)==KEY_PUSH && spelltime == false){
			type = (type+1)%1;
			PlaySound("Shot9",100,0);
			ExCircle(GetPlayerX,GetPlayerY,0.07,60);
			loop(2){yield;}
            ExCircle(GetPlayerX,GetPlayerY,0.07,60-2);
			if(type==0){TCharge01(GetPlayerX,GetPlayerY,2,30,0,0,256);}
			if(type==1){TCharge01(GetPlayerX,GetPlayerY,2,30,256,0,0);}
			if(type==2){TCharge01(GetPlayerX,GetPlayerY,2,30,256,0,256);}
		}
		*/
		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(lwidthC>0){lwidthC--;}
		}
		
		/*if(GetKeyState(KEY_X)==KEY_PUSH && GetVirtualKeyState(VK_SLOWMOVE)==KEY_FREE && GetPlayerState == STATE_NORMAL){
			if(fb_count>=260){
				NotifyEventAll(EV_FLASHBOMB,0);
			}
		}*/
		
		if(GetVirtualKeyState(VK_SHOT)==KEY_HOLD && shotCount>0){
			bNextShot = true;
		}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD && GetPlayerState == STATE_NORMAL){
			focus = true;
		}
		else if(GetPlayerState == STATE_NORMAL){
			focus = false;
			Obj_Delete(objSlowShot);
		}
		if(shotCount%3==0 && GetPlayerState==STATE_NORMAL && !IsPlayerSpellActive && IsPermitPlayerShot){
			if(type==0){
				PlaySound("se_shot",68,0);
				let dir = [270,270,270,270];;
				let t = 0;
				let xp = 0;
				if(focus == false){xp = 8;}
				if(focus == true){xp = 6;}
				ReisenVanillaBullet(GetPlayerX-10,GetPlayerY+20,30,270,4,1);
				ReisenVanillaBullet(GetPlayerX+10,GetPlayerY+20,30,270,4,1);
				if(focus == true){dir = [270,270,270,270];}
				
				if(focus == false )
				{
				RandBullet(ObjRender_GetX(arr1[0]),ObjRender_GetY(arr1[0]),25,270+rand(-1,1)*20,2.5,1);
				RandBullet(ObjRender_GetX(arr1[1]),ObjRender_GetY(arr1[1]),25,270+rand(-1,1)*20,2.5,1);
				RandBullet(ObjRender_GetX(arr1[2]),ObjRender_GetY(arr1[2]),25,270+rand(-1,1)*20,2.5,1);
				RandBullet(ObjRender_GetX(arr1[3]),ObjRender_GetY(arr1[3]),25,270+rand(-1,1)*20,2.5,1);
				}
				
				if(focus == true )
				{
					if(shotnum%1==0){
					mind(ObjRender_GetX(arr1[0]),ObjRender_GetY(arr1[0])+10,30,270,1.15,1000);
					mind(ObjRender_GetX(arr1[1]),ObjRender_GetY(arr1[1])+10,30,270,1.15,1000);
					mind(ObjRender_GetX(arr1[2]),ObjRender_GetY(arr1[2])+10,30,270,1.15,1000);
					mind(ObjRender_GetX(arr1[3]),ObjRender_GetY(arr1[3])+10,30,270,1.15,1000);
					}
				}
				t++;
				shotnum++;
			}	
		}
		if(shotCount >= 0){
			shotCount++;
		}
		if(shotCount == 15){
			shotCount=-1;
		}
		yield;
	}
}
task HitBox(type){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D); 
	let img = GetCurrentScriptDirectory~"eff2.png";
	let c = 0;
	let alpha = 0;
	let scale = 1.5;
	let scalepl = 1.1;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,15,63,80);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	while(!Obj_IsDeleted(obj)){
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetAngleZ(obj,c);
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		c+=3*type;
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD){
			if(scale>1){scale-=0.1;c+=3*type}
			if(alpha<250){alpha+=30;}
		}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_FREE){
			if(scale<2){scale+=0.1;c+=3*type}
			if(alpha>0){alpha-=30;}
		}
		if(GetPlayerState != STATE_NORMAL){alpha=0;}
		yield;
	}
}
	
task ReisenVanillaBullet(x,y,spd,dir,dmg,pdmg){
	let shotcolor = 1;
	let mx;
	let my;
	let mangle;
	let t = 0;
	let t2 = 1;
	let finalpos = 0;
	if(!IsPermitPlayerShot){return;}
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,shotcolor);
	ObjRender_SetAngleZ(mainobj, -90);
    Obj_SetRenderPriorityI(mainobj,42);
	let count = 0;
	while(!Obj_IsDeleted(mainobj)){
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		t++;
		yield;
	}
	if(!IsPermitPlayerShot){return;}
	let obj2 = CreatePlayerShotA1(mx,my-5,6,mangle,0,10^10,2);
	FUFAA(mx,my-25,mangle,200,150,150,195,1.75);
	ObjMove_SetAcceleration(obj2,-10/15);
	let alpha = 192;
	ObjMove_SetMaxSpeed(obj2,0);
	ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);
	let alphaM = 192;
	alpha = alphaM;	
	let angleZ = 0;
	let oa = rand(-(t%8-3.5)*5,(t%8-3.5)*5);
	let dirs = mangle;
	loop(15){
		alpha-=alphaM/15;
		angleZ+=20;
		ObjRender_SetAngleZ(obj2,-90);
		ObjRender_SetAlpha(obj2,alpha);
		ObjRender_SetScaleXYZ(obj2,1.1,1.1,0);
		t2+=0.08;
		yield;
	}
	Obj_Delete(obj2);
	Obj_Delete(mainobj);
}
	
task FUFAA(x,y,angle,sht,r,g,b,sc)
{
	if(!IsPermitPlayerShot){return;}
let obj2 = CreatePlayerShotA1(x,y,7,angle+rand(-1,1)*10,0,10^10,sht);
		ObjMove_SetAcceleration(obj2,-10/15);
		let alpha = 255;
		ObjMove_SetMaxSpeed(obj2,0);
		ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);
		let t = 0;
		let angleZ = rand(0,360);
		let oa = rand(-(t%8-3.5)*5,(t%8-3.5)*5);
		loop(18)
			{
			alpha-=7;
			angleZ+=14;
			ObjRender_SetAngleZ(obj2, -90);
			ObjRender_SetAlpha(obj2,alpha);
			ObjRender_SetColor(obj2, r,g,b);
			ObjRender_SetScaleXYZ(obj2,sc,sc,0);
			t+=2;
			yield;
			}
		Obj_Delete(obj2);
}
	
task RandBullet(x,y,spd,dir,dmg,pdmg){
	let shotcolor = 3;
	let mx;
	let my;
	let mangle;
	let t = 0;
	let t2 = 0.55;
	let t3 = 255;
	let finalpos = 0;
	if(!IsPermitPlayerShot){return;}
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,shotcolor);
	ObjRender_SetAngleZ(mainobj, -90);
    Obj_SetRenderPriorityI(mainobj,42);
	let count = 0;
	while(!Obj_IsDeleted(mainobj)){
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		if(t2<1){t2+=0.25;}
		ObjRender_SetScaleXYZ(mainobj,t2,t2,0);
		ObjRender_SetColor(mainobj,255,155,255);
		if(t3>155)
		{
		t3-=120;
		}
		t++;
		yield;
	}
	if(!IsPermitPlayerShot){return;}
	let obj2 = CreatePlayerShotA1(mx,my-5,6,mangle,0,10^10,4);
	FUFAA(mx,my-30,mangle,200,192,100,192,3);
	ObjMove_SetAcceleration(obj2,-10/15);
	let alpha = 192;
	ObjMove_SetMaxSpeed(obj2,0);
	ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);
	let alphaM = 192;
	alpha = alphaM;	
	let angleZ = 0;
	let oa = rand(-(t%8-3.5)*5,(t%8-3.5)*5);
	let dirs = mangle;
	loop(15){
		alpha-=alphaM/15;
		angleZ+=20;
		ObjRender_SetAngleZ(obj2,-90);
		ObjRender_SetAlpha(obj2,alpha);
		ObjRender_SetScaleXYZ(obj2,t2,t2,0);
		ObjRender_SetColor(obj2,255,155,255);
		t2+=0.0;
		yield;
	}
	Obj_Delete(obj2);
	Obj_Delete(mainobj);
}
	
task mind(x,y,spd,dir,dmg,pdmg){
	let shotcolor = 5;
	let mx;
	let my;
	let mangle;
	let t = 0;
	let t2 = 1;
	let finalpos = 0;
	if(!IsPermitPlayerShot){return;}
	let mainobj = CreatePlayerShotA1(x,y,spd,dir,dmg,pdmg,shotcolor);
	ObjRender_SetAngleZ(mainobj, -90);
    Obj_SetRenderPriorityI(mainobj,42);
	let count = 0;
	while(!Obj_IsDeleted(mainobj)){
		mx = ObjMove_GetX(mainobj);
		my = ObjMove_GetY(mainobj);
		mangle = ObjMove_GetAngle(mainobj);
		ObjRender_SetScaleXYZ(mainobj,1,1,0);
		t++;
		yield;
	}
	if(!IsPermitPlayerShot){return;}
	let obj2 = CreatePlayerShotA1(mx,my,5,mangle+rand(-1,1)*10,0,10^10,5);
	ObjMove_SetAcceleration(obj2,-10/15);
	let alpha = 132;
	ObjMove_SetMaxSpeed(obj2,0);
	ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);
	let alphaM = 132;
	alpha = alphaM;	
	let angleZ = 0;
	let oa = rand(-(t%8-3.5)*5,(t%8-3.5)*5);
	let dirs = mangle;
	loop(35){
		alpha-=alphaM/15;
		angleZ+=20;
		ObjRender_SetAngleZ(obj2,-90);
		ObjRender_SetAlpha(obj2,alpha);
		if(mx>0 && mx<GetStgFrameWidth && my>0 && my<GetStgFrameHeight){
			ObjRender_SetScaleXYZ(obj2,t2,1,0);
		}
		t2+=0.3;
		yield;
	}
	Obj_Delete(obj2);
	Obj_Delete(mainobj);
}
	
task TSpellRH{
	flgSpellActive = true;

	let bSlowMove = GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD;
	let objManage = GetSpellManageObject();
	
	PlaySound("Slash",90,0);
	//PlaySound("charge",70,0);
	rebirtheff(400);
	BlinkEffect(400);
	SpellUseName;
	SpellCard01(GetPlayerX,GetPlayerY);
	loop(30){
		yield;
	}
	flgSpellActive = false;
	Obj_Delete(objManage);
	
	task SpellUseName{
		let tScale1 = 10;
		let tScale2 = 10;
		let tAlpha1 = 0;
		let tAlpha2 = 0;
		let yOff = 400;
		let tYOff1 = -yOff;
		let tYOff2 = -yOff;
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		Obj_SetRenderPriority(obj, 60);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory() ~ "./bom_name_05.png");
		//ObjSprite2D_SetDestRect(obj, -100, -14, 100, 14);
		ObjSprite2D_SetSourceRect(obj, 0, 0, 350,40);
		ObjSprite2D_SetDestCenter(obj);
		
		let eScale = 10;
		let eAlpha = 0;
		let xOff = 100;
		yOff = 500;
		
		let eXOff = xOff;
		let eYOff = -yOff;
		
		loop(20){
			ObjRender_SetX(obj, 380 + eXOff);
			ObjRender_SetY(obj, 440 + eYOff);
			ObjRender_SetScaleXYZ(obj, eScale, eScale, eScale);
			ObjRender_SetAlpha(obj, eAlpha);
			eScale -= 10/22;
			eAlpha += 195/20;
			eXOff -= xOff/20;
			eYOff += yOff/19.5;
			yield;
		}
		loop(5){yield;}
		let x = 14;
		let y = 438;
		while(x > 0){
			//ObjRender_SetY(obj, 420);
			y -= x;
			if(y < 200){
				x -= 0.58;
			}
			yield;
		}
		loop(300-40){yield;}
		xOff = 0;
		loop(15){
			ObjRender_SetX(obj, 480 - xOff);
			xOff -= 20;
			yield;
		}
		Obj_Delete(obj);
	}
}
function SpellCard01(x,y){
	let texture = GetReservedRenderTargetName(2);
	let SPELL_TIMER = 300;
	let SPELL_SIZE = 0;
	let SIZE_OFFSET = 1;
	SetPlayerInvincibilityFrame(SPELL_TIMER+100);
	//shieldLeft = 4;
	DeleteShotInCircle(TYPE_SHOT,TYPE_ITEM,GetPlayerX,GetPlayerY,120);
	MainTask;
	loop(SPELL_TIMER-30){
		if(!IsPermitPlayerSpell){break;}
		yield;
	}
	loop(30){
		if(!IsPermitPlayerSpell){break;}
		yield;
	}
	flgSpellActive = false;
	
	task MainTask{
		//let obj = ObjSpell_Create;
		//ObjSpell_Regist(obj);
		//ObjRender_SetPosition(obj,x,y,1);
		//ObjSpell_SetDamage(obj,3);
		let t = 0;
		loop(SPELL_TIMER){
			if(t<60){SPELL_SIZE+=1/60;}
			else if(t>SPELL_TIMER-30){SPELL_SIZE-=1/30;}
			if(t==90){MadnessTask;}
			if(t>=90 && t<SPELL_TIMER){RenderToTextureA1(texture,20,53,1);}
			//ObjSpell_SetIntersectionCircle(obj,x,y,SPELL_SIZE*256*SIZE_OFFSET);
			if(t%8==0){Spell_Sub;}
			t++;
			yield;
		}
		//Obj_Delete(obj);
	}
	task Spell_Sub{
		let sobj = ObjSpell_Create;
		ObjSpell_Regist(sobj);
		ObjRender_SetPosition(sobj,x,y,1);
		ObjSpell_SetDamage(sobj,1);
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"reisen_wave.png");
		ObjSprite2D_SetSourceRect(obj,0,0,512,512);
		ObjSprite2D_SetDestCenter(obj);
		Obj_SetRenderPriorityI(obj,46);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetPosition(obj,x,y,1);
		let timer = 60;
		let t = 0;
		let alpha = 0;
		let sc = 0;
		let sc_max = SPELL_SIZE;
		loop(20){
			alpha+=1/20;
			sc+=sc_max/60;
			Update;
		}
		loop(60-45){
			sc+=sc_max/60;
			Update;
		}
		loop(25){
			alpha-=1/25;
			sc+=sc_max/60;
			Update;
		}
		Obj_Delete(obj);
		Obj_Delete(sobj);
		function Update{
			ObjRender_SetAlpha(obj,alpha*255);
			ObjRender_SetScaleXYZ(obj,sc,sc,1);
			ObjRender_SetColor(obj,255,(sc_max-sc)*255,(sc_max-sc)*255);
			ObjSpell_SetIntersectionCircle(sobj,x,y,sc*256);
			t++;
			yield;
		}
	}
	task MadnessTask{
		PlaySound("Slash",90,0);
		SIZE_OFFSET = 5;
		SpellShade;
		EyeEffect;
		SplitScreen(1);
		SplitScreen(-1);
		ScreenShake(210);
	}
	task EyeEffect{
		let sobj = ObjSpell_Create;
		ObjSpell_Regist(sobj);
		ObjRender_SetPosition(sobj,GetStgFrameWidth/2,GetStgFrameHeight/2,1);
		ObjSpell_SetEraseShot(sobj,0);
		ObjSpell_SetDamage(sobj,6);
		
		ascent(i in 0..13*3){
			if(i%3==0){
				_EyeEffect(255-i*(128/13),(i/3)*3);
			}
			ObjSpell_SetIntersectionCircle(sobj,GetStgFrameWidth/2,GetStgFrameHeight/2,(GetStgFrameWidth^2+GetStgFrameHeight^2)^0.5);
			yield;
		}
		loop(210-13*3){ObjSpell_SetIntersectionCircle(sobj,GetStgFrameWidth/2,GetStgFrameHeight/2,(GetStgFrameWidth^2+GetStgFrameHeight^2)^0.5);yield;}
		Obj_Delete(sobj);
		
		task _EyeEffect(alpha,offset_timer){
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"stg5enm.png");
			ObjSprite2D_SetSourceRect(obj,0,192,256,256);
			ObjSprite2D_SetDestCenter(obj);
			Obj_SetRenderPriorityI(obj,60);
			ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
			//ObjRender_SetPosition(obj,GetStgFrameWidth/2,224-100,1);
			let an = 270+rand(-30,30);
			let x = GetStgFrameWidth/2;
			let y = 224-100;
			let sc = 1.6;
			let _alpha = 0;
			loop(300-90-offset_timer){
				if(_alpha<alpha){_alpha+=alpha/60;}
				if(sc>1.1){sc-=0.5/100;}
				Update;
			}
			loop(17){
				x += cos(an)*4;
				y += sin(an)*4;
				if(_alpha>0){_alpha-=alpha/17;}
				Update;
			}
			Obj_Delete(obj);
			function Update{
				ObjRender_SetPosition(obj,x,y,1);
				ObjRender_SetAlpha(obj,_alpha);
				ObjRender_SetScaleXYZ(obj,sc,sc,1);
				//ObjRender_SetColor(obj,255,(sc_max-sc)*255,(sc_max-sc)*255);
				yield;
			}
		}
	}
	task SplitScreen(muki){
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,texture);
		ObjSprite2D_SetSourceRect(obj,GetStgFrameLeft,GetStgFrameTop,GetStgFrameWidth+GetStgFrameLeft,GetStgFrameHeight+GetStgFrameTop);
		ObjSprite2D_SetDestRect(obj,0,0,GetStgFrameWidth,GetStgFrameHeight);
		Obj_SetRenderPriorityI(obj,55);
		//let x = GetStgFrameWidth/2;
		let x = 0;
		let y = GetStgFrameHeight/2;
		let maxdist = x + 90 * muki;
		let cx = x;
		let timer = 300-90;
		loop(210-5){
			cx += maxdist/(210-5);
			Update;
		}
		loop(5){
			cx -= maxdist/(5);
			Update;
		}
		Obj_Delete(obj);
		function Update{
			ObjRender_SetX(obj,cx);
			ObjRender_SetAlpha(obj,255+rand(-32,0));
			ObjRender_SetScaleXYZ(obj,1+rand(-1,1)*0.02,1+rand(-1,1)*0.02,1);
			ObjRender_SetColor(obj,rand(192,255),rand(192,255),rand(192,255));
			yield;
		}
	}
}
task ManageShield{
	ManageBarrier;
	ManageHitbox;
}
task ManageBarrier{
	let obj = [
		ObjPrim_Create(OBJ_SPRITE_2D),
		ObjPrim_Create(OBJ_SPRITE_2D),
		ObjPrim_Create(OBJ_SPRITE_2D)
	];
	let x = GetPlayerX;
	let y = GetPlayerY;
	ascent(i in 0..3){
		ObjPrim_SetTexture(obj[i],current~"./pl03.png");
		Obj_SetRenderPriorityI(obj[i],46);
		ObjSprite2D_SetDestCenter(obj[i]);
		ObjRender_SetPosition(obj[i],x,y,1);
	}
	ObjSprite2D_SetSourceRect(obj[0],64,192,127,255);
	ObjSprite2D_SetSourceRect(obj[1],128,192,191,255);
	ObjSprite2D_SetSourceRect(obj[2],192,192,255,255);
	let len = length(obj);
	let muki = [1,-1,1];
	let count = 0;
	ascent(i in 0..len){Obj_SetVisible(obj[i],0);}
	loop{
		x = GetPlayerX;
		y = GetPlayerY;
		Obj_SetVisible(obj[0],shieldLeft==4);
		Obj_SetVisible(obj[1],shieldLeft>=3);
		Obj_SetVisible(obj[2],shieldLeft>=2);
		ascent(i in 0..3){
			ObjRender_SetPosition(obj[i],x,y,1);
			ObjSprite2D_SetDestCenter(obj[i]);
			ObjRender_SetAngleZ(obj[i],count*3*muki[i]);
		}
		count++;
		yield;
	}
}
task ManageHitbox{
	let obj = [
		ObjPrim_Create(OBJ_SPRITE_2D),
		ObjPrim_Create(OBJ_SPRITE_2D),
		ObjPrim_Create(OBJ_SPRITE_2D)
	];
	let x = GetPlayerX;
	let y = GetPlayerY;
	ascent(i in 0..3){
		ObjPrim_SetTexture(obj[i],current~"./pl03.png");
		Obj_SetRenderPriorityI(obj[i],46);
		ObjSprite2D_SetDestCenter(obj[i]);
		ObjRender_SetPosition(obj[i],x,y,1);
		ObjRender_SetScaleXYZ(obj[i],1.3,1.3,1);
	}
	ObjSprite2D_SetSourceRect(obj[0],192,144,207,159);
	ObjSprite2D_SetSourceRect(obj[1],208,144,223,159);
	ObjSprite2D_SetSourceRect(obj[2],224,144,239,159);
	let len = length(obj);
	ascent(i in 0..len){Obj_SetVisible(obj[i],0);}
	loop{
		x = GetPlayerX;
		y = GetPlayerY;
		Obj_SetVisible(obj[0],shieldLeft==4);
		Obj_SetVisible(obj[1],shieldLeft>=3);
		Obj_SetVisible(obj[2],shieldLeft>=2);
		ascent(i in 0..3){
			ObjRender_SetPosition(obj[i],x,y,1);
			ObjSprite2D_SetDestCenter(obj[i]);
		}
		yield;
	}
}
task BreakShield{
	flgSpellActive = true;
	let objManage = GetSpellManageObject();
	shieldLeft-=1;
	SetPlayerInvincibilityFrame(60);
	DeleteShotInCircle(TYPE_SHOT,TYPE_ITEM,GetPlayerX,GetPlayerY,120);
	wait(30);
	if(shieldLeft>=1){PlaySound("barrier",70,0);}
	wait(30);
	flgSpellActive = false;
	Obj_Delete(objManage);
}
task SpellShade{
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
	ObjRender_SetBlendType(obj,BLEND_SUBTRACT);
	Obj_SetRenderPriorityI(obj,47);
	let vc = 40;
	let tvc = vc/2-1;
	ObjPrim_SetVertexCount(obj,vc);
	let alpha = 128;
	let t = 0;
	let v1 = 800; 
	let x = GetPlayerX;
	let y = GetPlayerY;
	loop(300-90){
		ascent(i in 0..vc/2){
			ObjPrim_SetVertexPosition(obj,i*2,x+v1*cos((360/tvc)*i),y+v1*sin((360/tvc)*i),1);	//set vertex position for the outer edge
			ObjPrim_SetVertexPosition(obj,i*2+1,x+0*cos((360/tvc)*i),y+0*sin((360/tvc)*i),1);	//set vertex position for the inner edge
			ObjPrim_SetVertexColor(obj,i*2,255,255,0);
			ObjPrim_SetVertexColor(obj,i*2+1,0,128,255);
		}
		ObjRender_SetAlpha(obj,alpha);
		t++;
		yield;
	}
	Obj_Delete(obj);
}

function TExpan(px,py,maxv,t,r,g,b){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./grav_00.png";
	let scale = 0;
	let v = 0;
	let z = 0;
	let malpha = 255/t;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,55,55);
	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);
			ObjRender_SetAngleZ(obj,z*20);
			z++;
			yield;
		}
		Obj_Delete(obj);
	}
}

function TExpan2(px,py,maxv,t,r,g,b,w){
	loop(w){yield;}
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./barrier_01.png";
	let scale = 0;
	let v = 0;
	let z = 0;
	let malpha = 255/t;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,40,60);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,px,py,0);
	ObjRender_SetColor(obj,r,g,b);
	Obj_SetRenderPriorityI(obj,30);
	Expan;
	task Expan{
		descent(i in 0..t){
			ObjRender_SetAlpha(obj,malpha*i);
			v = (i*maxv/2)/(t*t);
			scale += v;
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			ObjRender_SetAngleZ(obj,z*25);
			z++;
			yield;
		}
		Obj_Delete(obj);
	}
}

function TExpan3(px,py,maxv,t,r,g,b){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./barrier_00.png";
	let scale = 0;
	let v = 0;
	let z = 0;
	let malpha = 255/t;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,50,51);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,px,py,0);
	ObjRender_SetColor(obj,r,g,b);
	Obj_SetRenderPriorityI(obj,30);
	Expan;
	task Expan{
		descent(i in 0..t){
			ObjRender_SetAlpha(obj,malpha*i);
			v = (i*maxv/2)/(t*t);
			scale += v;
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			ObjRender_SetAngleZ(obj,z*40);
			z++;
			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 TExpanS(px,py,maxv,t,r,g,b){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./seal.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 GetAtanAngle(obj,obj2){
	let angle=atan2(ObjMove_GetY(obj2)-ObjMove_GetY(obj),ObjMove_GetX(obj2)-ObjMove_GetX(obj));
	return angle;
}

function TCharge01(x,y,size,frame,r,g,b){
    let t = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"barrier_00.png";
	ObjPrim_SetTexture(obj,img);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(obj,0,0,50,51);
	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);
	TZ;
	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 TZ{
		loop(100){
			ObjRender_SetAngleZ(obj,t*10);
			t--;
			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 absolute(((x2-x1)^2+(y2-y1)^2)^(1/2));
}

task TExplosion(w){
	loop(w){yield;}
	let path = GetCurrentScriptDirectory() ~ "Explode.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	Obj_SetRenderPriority(obj, 0.60);
	ObjPrim_SetTexture(obj, path);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 64);
	ObjSprite2D_SetDestRect(obj, -100, -100, 100, 100);
	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.08;
			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 TExplosion2{
	let dtime = 60;
	let dis = 0;
	//ExCircle(GetPlayerX,GetPlayerY,0.05,dtime);
	//ExCircle(GetPlayerX-30,GetPlayerY,0.05,dtime);
	//ExCircle(GetPlayerX+30,GetPlayerY,0.05,dtime);
	//ExCircle(GetPlayerX,GetPlayerY-30,0.05,dtime);
	//ExCircle(GetPlayerX,GetPlayerY+30,0.05,dtime);
	//PlaySE(GetCurrentScriptDirectory~"se_pldead.wav");
	loop(10){yield;}
	//ExCircle(GetPlayerX,GetPlayerY,0.05,dtime-10);
	DeleteShotInCircle(TYPE_SHOT, TYPE_ITEM, GetPlayerX,GetPlayerY, dis);
	dis += 65;
}

task ExCircle(x,y,sc,dtime){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let timer = 0;
	let s = 0;
	let Target = current~"./reisen_wave.png";
	let mx = ObjRender_GetX(obj);
	let my = ObjRender_GetY(obj);

	Obj_SetRenderPriorityI(obj, 79);
	ObjPrim_SetTexture(obj, Target);
	ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 512, 512);
    ObjSprite2D_SetDestCenter(obj);
    ObjRender_SetScaleXYZ(obj, s, s, s);
	ObjRender_SetPosition(obj,x,y,0);
	loop{
		timer++;
        s+=sc;
        ObjRender_SetScaleXYZ(obj, s, s, s);
        if(timer == dtime){
			Obj_Delete(obj);
			break;
        }
        yield;
    }
}

task LeafEffect(x, y, speed, angle, size, timer, cr, cg, cb, type,w){
	loop(w){yield;}
	let gType = trunc(rand(0,4));
	let gx = (gType%4)*32 + 1;
	let gy = 97;
	let vx = cos(angle)*speed;
	let t = 0;
	let vy = sin(angle)*speed;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	if(type==0){
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory() ~ "barrier_02.png");
	}
	if(type==1){
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory() ~ "barrier_03.png");
	}
	ObjSprite2D_SetSourceRect(obj, 0, 0, 40, 60);
	ObjSprite2D_SetDestRect(obj, -size, -size, size, size);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	let nico = rand(0,360);
	ObjRender_SetAlpha(obj,255);
	descent(t in 0 .. timer){
		let tmp = (t+1)/timer;
		ObjRender_SetColor(obj, cr*tmp, cg*tmp, cb*tmp);
		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetAngleZ(obj, nico+t*10);
		t++;
		x += vx; y += vy;
		yield;
	}
	Obj_Delete(obj);
}
