
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Suika_AnimeLib.txt";
	
	tex_enemy=filedir~"Suika_Main.png";
	tex_spellbg=filedir~"Suika_SpellBG.png";
	
	bg_rect=[0,0,512,768];
	
	@Initialize
	{
		point=450;
		SetLife(1200);
		SetTimer(64);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("王地「羅生門の鬼」",85);
		wait(100);
		Sub;
		SetAction(ACT_SHOT_A,60);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			let wide=0;
			let p=GetAngleToPlayer;
			loop(5)
			{
				let way=3;
				let speed=4;
				let gra=54;
				let delay=0;
				let ag=p;
				while(ag<p+360)
				{
					if(wide==0)
					{
						let angle=ag;
						CreateShot02(GetX,GetY,0,angle,speed/100,speed,gra,delay);
					}
					else
					{
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+1)
						{
							CreateShot02(GetX,GetY,0,angle,speed/100,speed,gra,delay);
							angle+=wide;
						}
					}
					ag+=360/way;
				}
				wide+=20;
				wait(30);
			}
			wait(30);
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(+110,140),0,0,0,0,90);
			SetAction(ACT_MOVE,90);
		}
		
		task Sub
		{
			local
			{
				let sx=[minX,maxX,maxX,minX];
				let sy=[minY,minY,maxY,maxY];
				ascent(a in 0..4)
				{
					SetShot(sx[a],sy[a]);
				}
				let sx=[minX,maxX,cenX,cenX];
				let sy=[cenY,cenY,minY,maxY];
				ascent(a in 0..4)
				{
					SetShot(sx[a],sy[a]);
				}
			}
			task SetShot(let sx,let sy)
			{
				let way=4;
				let leng=0;
				while(leng<=700)
				{
					let width=20;
					let gra=191;
					let angle=0;
					let delay=60;
					let del=10;
					while(angle<360)
					{
						SetLaserObject(sx,sy,leng,width,angle,32,gra,delay,del);
						angle+=360/way;
					}
					leng+=10;
					yield;
				}
				Explosion01(sx,sy,3,0.1,120);
				
				let lp=0;
				let v=40;
				let i=0;
				loop
				{
					let leng=700;
					let width=20;
					let gra=191;
					if(lp%(v*2)<=v)
					{
						let angle=i;
						let delay=60;
						let del=10;
						while(angle<i+360)
						{
							SetLaserObject(sx,sy,leng,width,angle,64,gra,delay,del);
							angle+=360/way;
						}
					}
					else
					{
						let angle=i;
						let delay=0;
						let del=9;
						while(angle<i+360)
						{
							SetLaserObject(sx,sy,leng,width,angle,128,gra,delay,del);
							angle+=360/way;
						}
					}
					i+=0.2;
					lp++;
					wait(2);
				}
			}
		}
	}
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("鬼門「平安京四地封鎖」",86);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let obj_ar=SetObject(r);
		wait(60);
		Explosion01(GetX,GetY,3,0.1,120);
		wait(50);
		MoveThread;
		loop
		{
			let p=rand(0,360);
			let ip=0;
			let lp=0;
			loop
			{
				let way=6;
				
				let speed=[3,1];
				let angle=p;
				let gra=147;
				let delay=10;
				let s=0;
				while(angle<p+360)
				{
					let v=30;
					let sx=GetX+v*cos(angle);
					let sy=GetY+v*sin(angle);
					SetObjShot(sx,sy,speed[s],angle,gra,delay);
					angle+=360/way;
					s=(s+1)%length(speed);
				}
				wait(3);
				p+=ip*r;
				ip=5*cos(lp);
				lp++;
			}
			wait(100);
			r=-r;
		}
		
		task MoveThread
		{
			wait(180);
			loop
			{
				let wt=150;
				SetMovePositionHermite(cenX+rand(-90,90),minY+rand(100,130),0,0,0,0,wt);
				SetAction(ACT_MOVE,wt);
				wait(wt);
				wait(120);
			}
		}
		
		function SetObject(let r)
		{
			let o=[];
			let rot=rand(0,360);
			ascent(a in 0..4)
			{
				
				let obj=[Obj_Create(OBJ_LASER)];
				o=o~obj;
				SquareLaser(obj[0],rot+a*90,a);
			}
			return o;
			task SquareLaser(let obj,let rot,let a)
			{
				let gra=[185,191,190,192];
				let v=0;
				let leng=0;
				let width=20;
				Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
				Obj_SetAlpha(obj,96);
				ObjLaser_SetWidth(obj,width);
				ObjShot_SetGraphic(obj,gra[a]);
				ObjShot_SetDelay(obj,0);
				
				Obj_SetCollisionToPlayer(obj,false);
				ObjShot_SetBombResist(obj,true);
				Obj_SetAutoDelete(obj,false);
				while(!Obj_BeDeleted(obj))
				{
					
					let sx=GetPlayerX+v*cos(rot);
					let sy=GetPlayerY+v*sin(rot);
					leng=v*cos(45)*2;
					Obj_SetPosition(obj,sx,sy);
					Obj_SetAngle(obj,135+rot);
					ObjLaser_SetLength(obj,leng);
					
					if(v<120){v+=1;}
					rot+=1*r;
					yield;
					
				}
			}
		}
		
		task SetObjShot(let sx,let sy,let speed,let angle,let gra,let delay)
		{
			let obj=Obj_Create(OBJ_SHOT);
			Obj_SetX(obj,sx);
			Obj_SetY(obj,sy);
			Obj_SetSpeed(obj,speed);
			Obj_SetAngle(obj,angle);
			ObjShot_SetGraphic(obj,gra);
			ObjShot_SetDelay(obj,delay);
			Obj_SetCollisionToObject(obj,true);
			
			while(!Obj_BeDeleted(obj))
			{
				ascent(a in 0..length(obj_ar))
				{
					if(Collision_Obj_Obj(obj,obj_ar[a]))
					{
						Explosion01(Obj_GetX(obj),Obj_GetY(obj),10,0.05,10);
						
						let speed=1;
						let angle=Obj_GetAngle(obj_ar[a])+90;
						let gra=[73,79,78,80];
						let delay=20;
						CreateShot01(Obj_GetX(obj),Obj_GetY(obj),speed,angle,gra[a],delay);
						
						Obj_Delete(obj);
					}
				}
				yield;
			}
		}
	}
	
	
	task MainThread_Unlimited{}
	
}