script_shot Sun2
{
	let shotx=GetX;
	let shoty=GetY;
	let leng=GetDelayTime;
	let shotangle=GetAngle;
	let shotscalemax=GetArgument;
	let shotvector=GetSpeed;
	let shotscale=shotscalemax;
	
	let tex=GetCurrentScriptDirectory~"./Image/Utsuho_SunShot.png";
	
	let vanishflg=false;
	
	@Initialize
	{
		SetX(shotx+leng*cos(shotangle));
		SetY(shoty+leng*sin(shotangle));
		LoadGraphic(tex);
		SetBombResist;
		
		MainThread;
		DrawThread;
	}
	
	@MainLoop
	{
		yield;
	}
	
	@Finalize{}
	
	
	task MainThread
	{
	//	SetShot;
		let clipleng=256*shotscalemax+32;
		while(GetGapLength(GetX,GetY,GetEnemyX,GetEnemyY)>10)
		{
			SetX(shotx+leng*cos(shotangle));
			SetY(shoty+leng*sin(shotangle));
			local
			{
				let col_radius=175;
				let leng=col_radius*shotscale;
				SetCollisionB(GetX,GetY,leng);
			}
			
			leng-=1.5;
			shotangle+=shotvector;
			shotscale-=shotscalemax/300;
			
			yield;
		}
		
		task SetShot
		{
			loop
			{
				let speed=1;
				let angle=shotangle;
				let gra=43;
				let delay=20;
				CreateShot02(GetX,GetY,0,angle,speed/120,speed,gra,delay);
				loop(15){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.01;
				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 reft,let up,let right,let down)
		{
			let texture_rect=[reft+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;}
}