
task ChargeFilmSE//高速巻き時のSEを出すタスク。Deleteして無理やり中断している
{
loop
{
if(IsForbidBomb==false)
{
	if(Charge<100)
	{
		if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD && GetKeyState(VK_SHOT)==KEY_HOLD)
		{
			PlaySE(SE[5]);
		}
		while(GetKeyState(VK_SLOWMOVE)==KEY_HOLD && GetKeyState(VK_SHOT)==KEY_HOLD && Charge<100){yield; }
	}
	DeleteSE(SE[5]);
	if(FinderMode==true)
	{
		while(FinderMode==true){yield;}
		wait(90);
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			wait(30);
		}
	}
}
yield;
}
}

task ChargeFilmFinishSE//100%になったときに鳴るSEのタスク
{
loop
{
if(IsForbidBomb==false)
{
	if(Charge==100)
	{
		PlaySE(SE[2]);
		while(Charge==100){yield;}
	}
}
yield;
}
}

task ChargeFilm//通常時と高速巻き時の装填速度。高速巻き時の装填速度は若干初めが遅い
{
loop
{
if(IsForbidBomb==false)
{
	if(Charge<100)
	{
		Charge+=0.2;
		if((GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && (GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD))
		{
			ChargeEffect;
			Charge+=PlusCharge;
			if(PlusCharge<0.3)
			{
				PlusCharge+=0.01;
			}
		}
		else
		{
			PlusCharge=0;
		}
	}
	else
	{
		Charge=100;
	}
	if(FinderMode==true)
	{
		while(FinderMode==true){yield;}
		wait(90);
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			wait(30);
		}
	}
}
yield;
}
}

task SetSpeedChange//自機のスピード制御。ファインダーモードではスピード０
{
loop
{
	if(FinderMode==true || GetCommonDataDefault("TimeStop",false)==true || GetCommonDataDefault("DefeatBoss",false)==true)
	{
		loop
		{
		SetSpeed(0, 0);
		if(FinderMode==false){yield;break;}
		yield;
		}
	}
	else if((GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && (GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD))
	{
		SetSpeed(5.5, 0.5);
	}
	else
	{
		SetSpeed(5.5, 2.5);
	}
yield;
}
}

task CameraDirChange//カメラを回転させる
{
loop
{
	if(GetKeyState(VK_USER)==KEY_PUSH)
	{
		PlaySE(SE[7]);
		CameraDir+=90;
	}
yield;
}
}

task EffectItemCreate//アイテム取得時のエフェクト
{
		let scax=1;
		let scay=1;
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBorder);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -4, -4);
		ObjEffect_SetVertexXY(obj, 1, 4,  -4);
		ObjEffect_SetVertexXY(obj, 2, 4, 4);
		ObjEffect_SetVertexXY(obj, 3,  -4,  4);
		
		ObjEffect_SetVertexUV(obj, 0,  173,  119);
		ObjEffect_SetVertexUV(obj, 1,  180, 119);
		ObjEffect_SetVertexUV(obj, 2, 180,  126);
		ObjEffect_SetVertexUV(obj, 3, 173, 126);
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,255,200,200,255);
			}	
		let speed=5;
		let angle=rand(0,360);
		loop(50)
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			speed-=0.1;
		yield;
		}

		loop(50)
		{
			let sangle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(sangle),Obj_GetY(obj)+speed*sin(sangle));
			speed+=0.3;
			ObjEffect_SetScale(obj, scax,scay);
			scax-=0.02;
			scay-=0.02;
			if(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<10)
			{
				Obj_Delete(obj);
			}
			yield;
		}
		Obj_Delete(obj);
}

task dummyshot(let enemyID,let dx,let dy)//写真内に敵がいた場合敵座標に弾を発生させる
{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,dx,dy);
		Obj_SetSpeed(obj,0);
		Obj_SetAngle(obj,0);
		ObjShot_SetDamage(obj,501);
		ObjShot_SetPenetration(obj,1);
		ObjShot_SetGraphic(obj,121);
		Obj_SetAlpha(obj,0);
	//	ObjShot_SetBombResist(obj,true);
		while(!Obj_BeDeleted(obj))
		{
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			if(Obj_IsIntersected(obj) && enemyID==1)
			{
				BossCapture=true;
			}
		}
		else
		{
			if(Obj_IsIntersected(obj) && enemyID==0)
			{
				BossCapture=true;
			}
		}
		yield;
		}
		Obj_Delete(obj);
}

function dxdy(i,j,dis2,finderangle,CAngle,size)//カメラの中心からカメラの端までのX座標
{
	let a=dis2*cos(finderangle+CAngle-270)+5*size*i*cos(CAngle+CameraDir)+5*size*j*sin(-CAngle-CameraDir);
	return(a);
}
function dxdy2(i,j,dis2,finderangle,CAngle,size)//カメラの中心からカメラの端までのY座標
{
	let a=dis2*sin(finderangle+CAngle-270)+5*size*i*sin(CAngle+CameraDir)+5*size*j*cos(-CAngle-CameraDir);
	return(a);
}

task ShootTimeOut//ファインダーモードをタイムアウトしたときに呼び出される
{
//	wait(5);
	yield;
	Charge=50;
	if(GetCommonDataDefault("BunSpell",false)==false)
	{
	TimeSlowEffect;
	}
	else
	{
		SetCommonData("PlayerPhotoTimeStop",true);
		wait(5);
		if(GetPlayerScriptName=="HATATE.txt")
		{
			Charge=50;
		}	
		wait(25);
	}
}

task TimeSlowEffect//写真を撮ったときやタイムアウトになったときに呼び出される。本家では時間停止するが、無理なのでスローに
{
wait(1);
if(GetCommonDataDefault("BunSpell",false)==false)
{
Slow(2);
}
wait(10);
Slow(0);
}


function PhotoSelect(obj,obj9,No,DX,DY, scax,scay)//変数（PhotoSelectCorsol）にしたがってスペル終了時拡大写真を選択する。Adjust使って見た目よくしてる
{
let CX=GetCenterX;
let CY=GetCenterY-55;
let AdJust=0;
let AdJustsize=0;
let MoveFrame=10;
let size=0.9;
	if(PhotoSelectCorsol==No)
	{
		loop
		{
			if(AdJust<MoveFrame)
			{
				AdJust+=1;
			}
			Obj_SetPosition(obj,DX+(CX-DX)*AdJust/MoveFrame,DY+(CY-DY)*AdJust/MoveFrame);
			ObjEffect_SetScale(obj, scax+(size-scax)*AdJust/MoveFrame,scay+(size-scay)*AdJust/MoveFrame);
			Obj_SetPosition(obj9,DX+(CX-DX)*AdJust/MoveFrame,DY+(CY-DY)*AdJust/MoveFrame);
			ObjEffect_SetScale(obj9, scax+(size-scax)*AdJust/MoveFrame,scay+(size-scay)*AdJust/MoveFrame);
			if(PhotoSelectCorsol!=No)
			{
				break;
			}
			if(GetCommonDataDefault("PhotoEraze",false)==true)
			{
				Obj_Delete(obj);
				Obj_Delete(obj9);
				break;
			}

			if(AdJust==MoveFrame)
			{
				SetCommonData("PhotoSaveReady",true);
			}
			else
			{
				SetCommonData("PhotoSaveReady",false);
			}
			
			yield;	
		}
	}
	if(PhotoSelectCorsol!=No)
	{
		loop
		{
			if(AdJust>0)
			{
				AdJust-=1;
			}
			Obj_SetPosition(obj,DX+(CX-DX)*AdJust/MoveFrame,DY+(CY-DY)*AdJust/MoveFrame);
			ObjEffect_SetScale(obj, scax+(1-scax)*AdJust/MoveFrame,scay+(1-scay)*AdJust/MoveFrame);
			Obj_SetPosition(obj9,DX+(CX-DX)*AdJust/MoveFrame,DY+(CY-DY)*AdJust/MoveFrame);
			ObjEffect_SetScale(obj9, scax+(1-scax)*AdJust/MoveFrame,scay+(1-scay)*AdJust/MoveFrame);
			if(PhotoSelectCorsol==No)
			{
				break;
			}
			if(GetCommonDataDefault("PhotoEraze",false)==true)
			{
				Obj_Delete(obj);
				Obj_Delete(obj9);
				break;
			}
			yield;	
		}
	}
}


task PhotoSelectChange//スペル終了時写真選択するための変数を変えるタスク
{
while(GetCommonDataDefault("ShootingEnd",false)==false){yield;}
let num=photoNo;
PhotoSelectCorsol=GetCommonDataDefault("BestShootNo",0);
yield;
loop
{
	if(GetKeyState(VK_LEFT) == KEY_PUSH)
	{
		PhotoSelectCorsol-=1;
		if(PhotoSelectCorsol<=-1)
		{
			PhotoSelectCorsol=num-1;
		}
	}
	if(GetKeyState(VK_RIGHT) == KEY_PUSH)
	{
		PhotoSelectCorsol+=1;
		if(PhotoSelectCorsol>=num)
		{
			PhotoSelectCorsol=0;
		}
	}
	yield;
}
}