
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Murasa_AnimeLib.txt";
	
	tex_enemy=filedir~"Murasa_Main.png";
	tex_spellbg=filedir~"Murasa_SpellBG.png";
	bg_rect=[0,0,640,480];
	
	@Initialize
	{
		boss_texcolor_r=120;
		boss_texcolor_g=120;
		boss_texcolor_b=255;
		boss_texalpha=240;
		
		point=450;
		SetLife(1);
		SetTimer(58);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
		MagicCircle(false);
		PlaySE("seUseSpellCard.wav");
		SetShotAutoDeleteClip(120,120,120,120);
	}
	@MainLoop{EnemyBossMainLoopSystem(0,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard{}
	task MainThread_Advanced{}
	
	task MainThread_Unlimited
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("禁忌「祀られざる閉ざされた海域」",44);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lwt=0;
		loop
		{
			SetWarpPosition;
			wait(100);
			SetAction(ACT_SHOT_B,60);
			local
			{
				let way=2;
				let i=rand(0,360);
				let L=60;
				let wt=0;
				loop(L)
				{
					let bspeed=7;
					let speed=1.5;
					let bangle=i;
					let gra=150;
					let delay=150-wt;
					while(bangle<i+360)
					{
						let angle=[bangle+90*r,bangle+300*r];
						ascent(a in 0..2)
						{
							SetObjectShot(GetX,GetY,bspeed,speed,bangle,angle[a],gra,delay);
						}
						bangle+=360/way;
					}
					i+=(360/way)/L;
					wait(1);
					wt+=1;
				}
				
				local
				{
					let way=120;
					let bspeed=5;
					let speed=[1.5,0.8];
					let bangle=0;
					let gra=29;
					let delay=90;
					let lp=0;
					while(bangle<360)
					{
						let v=5;
						let angle=bangle;
						if(lp%(v*2)<v){angle=bangle+180;}
						ascent(a in 0..length(speed))
						{
							SetObjectShot(GetX,GetY,bspeed,speed[a],bangle,angle,gra,delay);
						}
						lp++;
						bangle+=360/way;
					}
				}
			}
			wait(200-lwt);
			if(lwt<180){lwt+=25;}
			r=-r;
		}
		
		task SetWarpPosition
		{
			let leng=GetGapLength(GetX,GetY,GetPlayerX,GetPlayerY);
			leng*=0.75;
			
			let angle=atan2(GetPlayerY-GetY,GetPlayerX-GetX);
			
			let mx=GetGapX(GetX,leng,angle);
			let my=GetGapY(GetY,leng,angle);
			SetWarp(mx,my);
		}
		
		task SetWarp(let mx,let my)
		{
			let v=0.4;
			let leng=0;
			let bx=GetX;
			let by=GetY;
			let r=1;
			loop(50)
			{
				SetX(bx+leng/2*r);
				SetY(by);
				r=-r;
				leng+=v;
				yield;
			}
			bx=mx;
			by=my;
			while(leng>0)
			{
				SetX(bx+leng/2*r);
				SetY(by);
				r=-r;
				leng-=v;
				yield;
			}
			SetX(mx);
			SetY(my);
		}
		
		task SetObjectShot(
		let x,
		let y,
		let bsspeed,
		let speed,
		let bsangle,
		let angle,
		let gra,
		let limit)
		{
			let flame=0;
			
			let base=bsspeed;
			let sx=x;
			let sy=y;
			let leng=32;
			let wd=15;
			let al=64;
			let ag=angle;
			
			let o=Obj_Create(OBJ_LASER);
			Obj_SetX(o,x);
			Obj_SetY(o,y);
			Obj_SetSpeed(o,0);
			Obj_SetAngle(o,angle);
			Obj_SetAlpha(o,al);
			Obj_SetCollisionToPlayer(o,false);
			ObjShot_SetGraphic(o,gra);
			ObjShot_SetDelay(o,0);
			ObjShot_SetBombResist(o,true);
			ObjLaser_SetSource(o,false);
			ObjLaser_SetLength(o,wd);
			ObjLaser_SetWidth(o,wd);
			
			while(!Obj_BeDeleted(o))
			{
/*				if(flame>=limit-30)
				{
					Obj_SetX(o,x-leng/2*cos(angle));
					Obj_SetY(o,y-leng/2*sin(angle));
					ObjLaser_SetLength(o,leng);
					ObjLaser_SetWidth(o,leng);
					Obj_SetAlpha(o,al);
					Obj_SetAngle(o,angle);
					
					leng-=0.2;
					al+=6;
				}
				else
				{*/
					Obj_SetX(o,x-wd/2*cos(ag));
					Obj_SetY(o,y-wd/2*sin(ag));
					Obj_SetAngle(o,ag);
			//	}
				if(flame==limit-1){CreateShot02(x,y,0,angle,speed/60,speed,gra,10);}
				
				x+=bsspeed*cos(bsangle);
				y+=bsspeed*sin(bsangle);
				ag+=20;
				
				if(bsspeed>0){bsspeed+=-(base/60);}
				else{bsspeed=0;}
				
				if(flame>=limit){Obj_Delete(o);}
				flame++;
				yield;
			}
		}
	}
}