#東方弾幕風
#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
	{
		SetScore(30000);
		SetLife(600);
		SetDamageRate(10,0);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(80);
		SetInvincibility(60);
		LoadGraphic(boss);
		LoadGraphic(eye);
		LoadGraphic(asa);
		LoadGraphic(GetCurrentScriptDirectory~".\img\shot\bullet.png");
		shottask;
		shottask2;
		drawtask;
		bombtask;
		CutIn(YOUMU,"想起「おきのどくですが」",0,0,0,0,0);
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
		loop(16)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-30,30),GetY+rand(-30,30));
		}
		DeleteGraphic(boss);
		DeleteGraphic(eye);
		DeleteGraphic(asa);
		DeleteGraphic(GetCurrentScriptDirectory~".\img\shot\bullet.png");
	}
	@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 x=0;
		let y=0;
		let angle=0;
		wait(120);
		loop
		{
			x=rand(GetClipMinX,GetClipMaxX);
			y=rand(GetClipMinY-20,GetClipMinY+20);
			CreateObjLaser(x+180,y+90,180,360,2);
			CreateObjLaser(x-180,y+90,270,180,2);
			CreateObjLaser(x+180,y-90,90,180,2);
			CreateObjLaser(x-180,y-90,0,360,2);
			loop(60)
			{
				CreateObjShot(x,y,1,angle,87,60);
				angle+=6;
			}
			wait(90);
			x=rand(GetClipMinX,GetClipMaxX);
			y=rand(cy-20,cy+20);
			CreateObjLaser(x+180,y+90,180,360,2);
			CreateObjLaser(x-180,y+90,270,180,2);
			CreateObjLaser(x+180,y-90,90,180,2);
			CreateObjLaser(x-180,y-90,0,360,2);
			loop(60)
			{
				CreateObjShot(x,y,1,angle,87,60);
				angle+=6;
			}
			wait(90);
			x=rand(GetClipMinX,GetClipMaxX);
			y=rand(GetClipMaxY-20,GetClipMaxY+20);
			CreateObjLaser(x+180,y+90,180,360,2);
			CreateObjLaser(x-180,y+90,270,180,2);
			CreateObjLaser(x+180,y-90,90,180,2);
			CreateObjLaser(x-180,y-90,0,360,2);
			loop(60)
			{
				CreateObjShot(x,y,1,angle,87,60);
				angle+=6;
			}
			wait(90);
		}
	}
	task shottask2
	{
		let angle=0;
		wait(120);
		loop
		{
			angle=rand(0,360);
			loop(12)
			{
				CreateShot01(GetX,GetY,1,angle,21,3);
				angle+=30;
			}
			wait(30);
		}
	}
	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(10,0);
				SetCollisionA(GetX(),GetY(),24);
				SetCollisionB(GetX(),GetY(),24);
			}
			yield;
		}
	}
	task CreateObjLaser(let x, let y, let angle, let length,let width)
	{
		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,254);
		ObjShot_SetDelay(obj,0);
		ObjLaser_SetLength(obj, length);
		ObjLaser_SetWidth(obj, width);
		ObjLaser_SetSource(obj,false);
		Obj_SetAutoDelete(obj,false);
		Obj_SetCollisionToPlayer(obj,false);
		while(!Obj_BeDeleted(obj))
		{
			if(count==480)
			{
				Obj_Delete(obj);
			}
			ObjLaser_SetWidth(obj, width);
			count++;
			yield;
		}
	}
	task CreateObjShot(let x, let y,let speed,let angle, let graphic, let delay)
	{
		let count=0;
		let alpha=255;
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		Obj_SetAlpha(obj,alpha);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, delay);
		while(!Obj_BeDeleted(obj))
		{
			if(Obj_GetX(obj)<x-180)
			{
				Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
			}
			if(Obj_GetX(obj)>x+180)
			{
				Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
			}
			if(Obj_GetY(obj)<y-90)
			{
				Obj_SetAngle(obj, 360 - Obj_GetAngle(obj));
			}
			if(Obj_GetY(obj)>y+90)
			{
				Obj_SetAngle(obj, 360 - Obj_GetAngle(obj));
			}
			if(count==480)
			{
				Obj_Delete(obj);
			}
			if(count>429)
			{
				alpha-=5;
			}
			Obj_SetAlpha(obj,alpha);
			count++;
			yield;
		}
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}