script_shot Sun
{
	let shotx=GetX;
	let shoty=GetY;
	let shotspeed=GetSpeed;
	let shotangle=GetAngle;
	let shotscalemax=GetArgument;
	let shotscalemaxtime=GetDelayTime;
	let shotscale=0;
	
	let tex=GetCurrentScriptDirectory~"./Image/Utsuho_SunShot.png";
	
	let vanishflg=false;
	
	@Initialize
	{
		SetX(shotx);
		SetY(shoty);
		SetSpeed(shotspeed);
		SetAngle(shotangle);
		LoadGraphic(tex);
		SetBombResist;
		
		MainThread;
		DrawThread;
	}
	
	@MainLoop
	{
		yield;
	}
	
	@Finalize{}
	
	
	task MainThread
	{
		if(shotscalemaxtime==0){shotscalemaxtime=1;}
		let clipleng=256*shotscalemax+32;
		while(GetY>GetClipMinY-clipleng&&GetY<GetClipMaxY+clipleng&&GetX>GetClipMinX-clipleng&&GetX<GetClipMaxX+clipleng)
		{
			local
			{
				let col_radius=175;
				let leng=col_radius*shotscale;
				SetCollisionB(GetX,GetY,leng);
			}
			if(shotscale<shotscalemax){shotscale+=shotscalemax/shotscalemaxtime;}
			
			yield;
		}
		vanishflg=true;
		yield;
		End;
	}
	
	
	task DrawThread
	{
		let tuning=GetCommonData("Memory_ConfigData");
		task Base(let type)
		{
			let obj=SetObject(5);
			SetRect(obj,512,0,1024,512);
			let alpha=224;
			let count=0;
			if(tuning[1]&&type){LightEffect;}
			while(!vanishflg)
			{
				DrawObject(obj,alpha,shotscale);
				if(!(count%2)&&!tuning[1]&&type){Effect;}
				count++;
				yield;
			}
			Obj_Delete(obj);
		}
		task Effect
		{
			let obj=SetObject(3);
			SetRect(obj,0,0,512,512);
			let alpha=20;
			let scale=shotscale;
			while(alpha>1)
			{
				DrawObject(obj,alpha,scale);
				scale+=0.03;
				alpha-=3;
				yield;
			}
			Obj_Delete(obj);
		}
		
		task LightEffect
		{
			let obj=SetObject(3);
			let alpha=16;
			while(!vanishflg)
			{
				SetRect(obj,0,0,512,512);
				DrawObject(obj,alpha,shotscale);
				yield;
			}
			Obj_Delete(obj);
		}
		
		function SetObject(let layer)
		{
			let obj=Obj_Create(OBJ_EFFECT);
			ObjEffect_SetTexture(obj,tex);
			ObjEffect_SetLayer(obj,layer);
			ObjEffect_SetRenderState(obj,ADD);
			ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
			ObjEffect_CreateVertex(obj,4);
			Obj_SetPosition(obj,GetX,GetY);
			return obj;
		}
		
		function SetRect(let obj,let left,let up,let right,let down)
		{
			let texture_rect=[left+1,up+1,right-1,down-1];
			let leng_h=texture_rect[2]-texture_rect[0];
			let leng_v=texture_rect[3]-texture_rect[1];
			
			ObjEffect_SetVertexXY(obj,0,-leng_h/2,-leng_v/2);
			ObjEffect_SetVertexXY(obj,1,-leng_h/2, leng_v/2);
			ObjEffect_SetVertexXY(obj,2, leng_h/2,-leng_v/2);
			ObjEffect_SetVertexXY(obj,3, leng_h/2, leng_v/2);
			
			ObjEffect_SetVertexUV(obj,0,texture_rect[0],texture_rect[1]);
			ObjEffect_SetVertexUV(obj,1,texture_rect[0],texture_rect[3]);
			ObjEffect_SetVertexUV(obj,2,texture_rect[2],texture_rect[1]);
			ObjEffect_SetVertexUV(obj,3,texture_rect[2],texture_rect[3]);
		}
		
		function DrawObject(let obj,let alpha,let scale)
		{
			Obj_SetPosition(obj,GetX,GetY);
			ObjEffect_SetScale(obj,scale,scale);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
			}
		}
		
		Base(1);
		Base(0);
	}
	
	function GetGapLength(x1,y1,x2,y2){return((x2-x1)^2+(y2-y1)^2)^0.5;}
}