
function SetSpellCard(let text,let number)
{
	SetText(text);
	SetCommonData("SpellFlg",true);
	spellbonus=GetCommonDataDefault("ItemPoint",10000)*point;
	SetScore(spellbonus/30);
	SetDurableSpellCard;
	Draw_SpellBackGround(tex_spellbg,bg_rect[0],bg_rect[1],bg_rect[2],bg_rect[3]);
	
	spell_number=number;
	
	let data_total=GetCommonData("SpellResult_TotalCount");
	let data_get=GetCommonData("SpellResult_GetCount");
	
	spell_totalcount=data_total[number]+1;
	spell_getcount=data_get[number];
	SetCommonData("SpellResult_TotalCount",data_total);
}

function GetSpellCard
{
	let score=GetCommonData("Score");
	let rate=GetCommonDataDefault("Rate",1);
	score+=spellbonus*(rate*rate);
	spell_getcount++;
	SetCommonData("Score",score);
}

function SetMove(let x,let y,let w)
{
	SetMovePositionHermite(x,y,0,0,0,0,w);
	SetAction(ACT_MOVE,w);
}

function SetTargeting(let x,let y,let scale,let limit,let type)
{
	Target;
	Effect;
	task Effect
	{
		let L=5;
		if(type==1){L=1;}
		if(type==2){L=0;}
		loop(L)
		{
			Line_w(y-60);
			Line_w(y+60);
			Line_h(x-60);
			Line_h(x+60);
			wait(5);
		}
	}
	task Target
	{
		let obj=SetEffectObject(tex_targeting,2);
		ObjEffect_SetRenderState(obj,ADD);
		SetEffectObjectRect(obj,0,0,240,240);
		let count=0;
		let alpha=160;
		let rot=0;
		Effect(scale);
		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj,x,y);
			ObjEffect_SetAngle(obj,0,0,rot);
			ObjEffect_SetScale(obj,scale,scale);
			ascent(a in 0..4){ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);}
			
			if(count>limit){alpha-=10;}
			if(alpha<10){Obj_Delete(obj);}
			count++;
			rot+=1.5;
			yield;
		}
		
		task Effect(let scale)
		{
			let obj=SetEffectObject(tex_targeting,2);
			ObjEffect_SetRenderState(obj,ADD);
			SetEffectObjectRect(obj,0,0,240,240);
			let alpha=240;
			while(!Obj_BeDeleted(obj))
			{
				Obj_SetPosition(obj,x,y);
				ObjEffect_SetScale(obj,scale,scale);
				ascent(a in 0..4){ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);}
				scale+=0.015;
				alpha-=4;
				if(alpha<4){Obj_Delete(obj);}
				yield;
			}
		}
	}
	task Line_w(let sy)
	{
		let obj=SetEffectObject(tex_targeting,2);
		ObjEffect_SetRenderState(obj,ADD);
		SetEffectObjectRect(obj,0,240,256,256);
		let count=0;
		let alpha=200;
		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj,x,sy);
			ObjEffect_SetScale(obj,5,1);
			ascent(a in 0..4){ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);}
			if(sy<y){sy++;}
			if(sy>y){sy--;}
			if(alpha<10){Obj_Delete(obj);}
			alpha-=200/limit;
			yield;
		}
	}
	task Line_h(let sx)
	{
		let obj=SetEffectObject(tex_targeting,2);
		ObjEffect_SetRenderState(obj,ADD);
		SetEffectObjectRect(obj,240,0,256,240);
		let count=0;
		let alpha=200;
		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj,sx,y);
			ObjEffect_SetScale(obj,1,5);
			ascent(a in 0..4){ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);}
			if(sx<x){sx++;}
			if(sx>x){sx--;}
			if(alpha<10){Obj_Delete(obj);}
			alpha-=200/limit;
			yield;
		}
	}
}

function ReflectShot(
	let x,			// 発射点x座標
	let y,			// 発射点y座標
	let speed,		// 速度（大きすぎると、画面端より前で反射する場合がある）
	let angle,		// 角度
	let reflect,	// 反射回数
	let L,			// 画面左端で反射 true/false
	let U,			// 画面上端で反射 true/false
	let R,			// 画面右端で反射 true/false
	let D,			// 画面下端で反射 true/false
	let graphic,	// 画像
	let delay		// 遅延フレーム数
){
	let totalFrame=0;
	let reflectEdge=[U,D,L,R];
	SetShotDirectionType(ABSOLUTE);
	CreateShotA(0,x,y,delay);
	SetShotDataA(0,0,speed,angle,0,0,0,graphic);
	while(reflect>=1){
		while(angle<0){angle+=360;}
		if(angle>=360){angle%=360;}
		let angleLU=atan2(y-GetClipMinY,x-GetClipMinX)+180;
		let angleRU=atan2(y-GetClipMinY,x-GetClipMaxX)+180;
		let angleLD=atan2(y-GetClipMaxY,x-GetClipMinX)+180;
		let angleRD=atan2(y-GetClipMaxY,x-GetClipMaxX)+180;
		if(angleRU==0){angleRU=360;}
		if(angleRD==360){angleRD=0;}
		let rLength=0;
		let rFrame=0;
		let rx=0;
		let ry=0;
		let rAngle=0;
		let rEdge=0;
		if(angle>=angleRU||angle<angleRD){
			rLength=(GetClipMaxX-x)/cos(angle);
			rFrame=rLength/speed;
			rx=GetClipMaxX;
			ry=y+rLength*sin(angle);
			rAngle=180-angle;
			rEdge=3;
		}
		else if(angle>=angleLD&&angle<angleLU){
			rLength=(GetClipMinX-x)/cos(angle);
			rFrame=rLength/speed;
			rx=GetClipMinX;
			ry=y+rLength*sin(angle);
			rAngle=180-angle;
			rEdge=2;
		}
		else if(angle>=angleLU&&angle<angleRU){
			rLength=(GetClipMinY-y)/sin(angle);
			rFrame=rLength/speed;
			rx=x+rLength*cos(angle);
			ry=GetClipMinY;
			rAngle=-angle;
			rEdge=0;
		}
		else{
			rLength=(GetClipMaxY-y)/sin(angle);
			rFrame=rLength/speed;
			rx=x+rLength*cos(angle);
			ry=GetClipMaxY;
			rAngle=-angle;
			rEdge=1;
		}
		if(!reflectEdge[rEdge]){break;}
		x=rx;
		y=ry;
		angle=rAngle;
		totalFrame+=rFrame;
		SetShotDataA(0,totalFrame,NULL,angle,0,0,0,graphic);
		reflect--;
	}
	FireShot(0);
}


function GravityShot(
	let x,			// 発射点x座標
	let y,			// 発射点y座標
	let speed,		// 速度
	let angle,		// 角度（絶対角度）
	let gravSpeed,	// 重力加速度
	let gravAngle,	// 重力角度（絶対角度）
	let graphic,	// 画像
	let delay		// 遅延フレーム数
){                  
	let xSpeed=speed*cos(angle);
	let ySpeed=speed*sin(angle);
	let accXSpeed=gravSpeed*cos(gravAngle);
	let accYSpeed=gravSpeed*sin(gravAngle);
	let maxXSpeed=99;
	let maxYSpeed=99;
	if(accXSpeed<0){maxXSpeed=-99;}
	if(accYSpeed<0){maxYSpeed=-99;}
	CreateShot12(x,y,xSpeed,ySpeed,accXSpeed,accYSpeed,maxXSpeed,maxYSpeed,graphic,delay);
}


task SetLaserEffect(
let x,
let y,
let leng,
let width,
let angle,
let gra,
let del
){
	let count=0;
	let l=leng;
	let w=width;
	let alpha=0;
	let obj=Obj_Create(OBJ_LASER);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetAngle(obj,angle);
	Obj_SetAlpha(obj,0);
	ObjLaser_SetLength(obj,leng);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetGraphic(obj,gra);
	ObjShot_SetDelay(obj,0);
	Obj_SetAutoDelete(obj,false);
	ObjShot_ToItem(obj,false);
	while( !Obj_BeDeleted(obj))
	{
		Obj_SetAlpha(obj,alpha);
		ObjLaser_SetLength(obj,leng);
		ObjLaser_SetWidth(obj,width);
		leng-=l/(del);
		width-=w/(del);
		if(count>=5&&alpha<200){alpha+=40;}
		
		if(count<4||width<=w/2){Obj_SetCollisionToPlayer(obj,false);}
		else{Obj_SetCollisionToPlayer(obj,true);}
		
		if(count==del)
		{
			ObjShot_FadeDelete(obj);
		}
		count++;
		yield;
	}
}

task SetLaserEffect_NotCollision(
let x,
let y,
let leng,
let width,
let angle,
let gra,
let del
){
	let count=0;
	let l=leng;
	let w=width;
	let alpha=0;
	let obj=Obj_Create(OBJ_LASER);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetAngle(obj,angle);
	Obj_SetAlpha(obj,0);
	ObjLaser_SetLength(obj,leng);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetGraphic(obj,gra);
	ObjShot_SetDelay(obj,0);
	Obj_SetAutoDelete(obj,false);
	ObjShot_ToItem(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
	while( !Obj_BeDeleted(obj))
	{
		Obj_SetAlpha(obj,alpha);
		ObjLaser_SetLength(obj,leng);
		ObjLaser_SetWidth(obj,width);
		leng-=l/(del);
		width-=w/(del);
		if(count>5&&alpha<100){alpha+=10;}
		
		if(count==del)
		{
			ObjShot_FadeDelete(obj);
		}
		count++;
		yield;
	}
}

task SetLaserObject(
let x,
let y,
let leng,
let width,
let angle,
let alpha,
let gra,
let delay,
let del
){
	let count=0;
	let obj=Obj_Create(OBJ_LASER);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetAngle(obj,angle);
	Obj_SetAlpha(obj,alpha);
	ObjLaser_SetLength(obj,leng);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetGraphic(obj,gra);
	ObjShot_SetDelay(obj,delay);
	Obj_SetAutoDelete(obj,false);
	ObjShot_ToItem(obj,false);
	while(!Obj_BeDeleted(obj))
	{
		if(count==del)
		{
			ObjShot_FadeDelete(obj);
		}
		count++;
		yield;
	}
}


