#東方弾幕風
#Title[想起「ヒバチノハオト」]
#Text[トラウマの一つ。]
#ScriptVersion[2]

script_enemy_main
{
	let scroll=0;
	let flag=0;
	let cx=GetCenterX();
	let cy=GetCenterY();
	let boss=GetCurrentScriptDirectory~"img\boss7-2.png";
	let eye=GetCurrentScriptDirectory~"img\bg7-1.png";
	let asa=GetCurrentScriptDirectory~"img\bg7-2.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetLife(600);
		SetInvincibility(240);
		LoadGraphic(boss);
		LoadGraphic(eye);
		LoadGraphic(asa);
		shottask;
		drawtask;
		bombtask;
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
		DeleteGraphic(boss);
		DeleteGraphic(eye);
		DeleteGraphic(asa);
	}
	@DrawLoop
	{
		SetTexture(boss);	
		if(flag==1)
		{
			SetGraphicRect(52,0,81,63);
		}
		else if(flag==2)
		{
			SetGraphicRect(24,0,52,63);
		}
		else
		{
			SetGraphicRect(0,0,24,63);
		}
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetX,GetY);
	}
	@BackGround
	{
		SetColor(128,128,128);
		SetTexture(eye);	
		SetGraphicRect(0,0,384,448);
		SetAlpha(255);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(cx,cy);
		SetColor(255,255,255);
		SetTexture(asa);	
		SetGraphicRect(0,0,888,189*5);
		SetAlpha(64);
		SetGraphicScale(0.5,0.75);
		SetGraphicAngle(0,0,0);
		DrawGraphic(cx+scroll,cy);
		DrawGraphic(cx+scroll-444,cy);
		if(scroll>444)
		{
			scroll=0;
		}
	}
	task shottask
	{
		let angle=0;
		let a=0;
		wait(120);
		SetScore(30000);
		SetDamageRate(10,0);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(120);
		CutIn(YOUMU,"想起「ヒバチノハオト」",0,0,0,0,0);
		SetEffectForZeroLife(60,100,2);
		wait(120);
		loop
		{
			loop(a)
			{
				CreateShot01(GetX,GetY,3,angle+rand(-3,3),76,5);
				angle+=15;
			}
			if(a<24)
			{
				a++;
			}
			angle+=4;
			wait(6);
			if(GetEnemyLife<400)
			{
				shottask2;
				DeleteEnemyShot(SHOT);
				break;
			}
			if(GetTimer<30)
			{
				shottask4;
				DeleteEnemyShot(SHOT);
				break;
			}
		}
	}
	task shottask2
	{
		let angle=0;
		wait(60);
		loop(60)
		{
			CreateObjLaser(GetX,GetY,angle,480,8,254);
			angle+=6;
		}
		loop
		{
			if(GetEnemyLife<200)
			{
				shottask3;
				DeleteEnemyShot(ALL);
				break;
			}
			if(GetTimer<30)
			{
				shottask4;
				DeleteEnemyShot(ALL);
				break;
			}
			yield;
		}
	}
	task shottask3
	{
		let angle=0;
		wait(60);
		loop
		{
			loop(15)
			{
				CreateShotA(1,GetX,GetY,5);
				SetShotDataA(1,0,2,angle+rand(-2,2),2,0.05,4,35);
				SetShotDataA(1,60,NULL,NULL,0,0,4,35);
				FireShot(1);
				angle+=24;
			}
			angle-=8;
			wait(9);
			if(GetTimer<30)
			{
				shottask4;
				DeleteEnemyShot(ALL);
				break;
			}
		}
	}
	task shottask4
	{
		let angle=0;
		wait(60);
		loop
		{
			loop(15)
			{
				CreateShotA(1,GetX-120,GetY,5);
				SetShotDataA(1,0,2,-angle+rand(-2,2),-2,0.05,4,35);
				SetShotDataA(1,60,NULL,NULL,0,0,4,35);
				FireShot(1);
				angle+=24;
			}
			loop(15)
			{
				CreateShotA(1,GetX+120,GetY,5);
				SetShotDataA(1,0,2,angle+rand(-2,2),2,0.05,4,35);
				SetShotDataA(1,60,NULL,NULL,0,0,4,35);
				FireShot(1);
				angle+=24;
			}
			angle-=8;
			wait(12);
		}
	}
	task drawtask
	{
		let x=0;
		loop
		{	
			if(GetX>x+0.5)
			{
				flag=1;
			}
			else if(GetX<x-0.5)
			{
				flag=2;
			}
			else
			{
				flag=0;
			}
			x=GetX;
			scroll++;
			yield;
		}
	}
	task bombtask
	{
		loop
		{
			if(OnBomb)
			{
				SetAlpha(64);
				SetDamageRate(0,0);
			}
			else
			{
				SetAlpha(255);
				SetDamageRate(7,0);
				SetCollisionA(GetX(),GetY(),24);
			}
			yield;
		}
	}
	task CreateObjLaser(let x, let y, let angle, let length,let width, let graphic)
	{
		let count=0;
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, 0);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, 90);
		ObjLaser_SetLength(obj, length);
		ObjLaser_SetWidth(obj, width);
		Obj_SetAutoDelete(obj,false);ObjLaser_SetSource(obj,false);

		while(!Obj_BeDeleted(obj))
		{
			if(Obj_GetAngle(obj)<180&&Obj_GetAngle(obj)>90)
			{
				length-=5;
			}
			if(Obj_GetAngle(obj)<90&&Obj_GetAngle(obj)>30&&length<480)
			{
				length+=12;
			}
			if(angle<0)
			{
				angle+=360;
			}
			if(count%12==0&&count>120)
			{
				CreateShot01(ObjLaser_GetEndX(obj),ObjLaser_GetEndY(obj),1,angle+rand(-12,12),76,5);
			}
			Obj_SetAngle(obj, angle);
			ObjLaser_SetLength(obj, length);
			angle--;
			count++;
			yield;
		}
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}