#東方弾幕風
#Title[鵺符「アンアイデンティファイドブレット」]
#Text[難易度:Extra

すべてが正体不明の弾幕
……とおもいきや自機狙いという
ことだけは判ってたりする]
#BGM[.\..\..\bgm\bgm.wav]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
	let objeffect = 0;
	let dark = true;
	
	@Initialize{
		InitializeData();
		
		LoadGraphic(imgBoss_Nue);
		LoadGraphic(imgCutin_Nue);
		
		SetLife(1000);
		
		SetX( GetCenterX() );
		SetY( GetClipMinY() + 130 );
		
		alternative( GetPlayerType() )
			case(REIMU_A){
				SetDamageRate(23,20);
			}
			case(REIMU_B){
				SetDamageRate(17,20);
			}
			case(MARISA_A){
				SetDamageRate(22,20);
			}
			case(MARISA_B){
				SetDamageRate(26,20);
			}
			others{
				SetDamageRate(26,20);
			}
		
		SetCollisionEx(800,0,false,660);
		SetEnemyMarker(true);
		
		SetEffectForZeroLife(1,0,0);
		
		if(GetKeyState(VK_USER) == KEY_HOLD && GetKeyState(VK_SKIP) == KEY_HOLD ){
			dark = false;
		}
		
		TMain();
	}
	
	@MainLoop{
		yield;
	}
	
	@DrawLoop{
		DrawBoss_NoAction(imgBoss_Nue);
	}
	
	@Finalize{
		FinalizeData();
	}
	
	task TMain(){
		Wait(60);
		
		DeclareSpell();
		
		Atack();
		
		if(dark){
			Dark();
		}
	}
	
	function DeclareSpell(){
		CutIn(KOUMA,"鵺符「アンアイデンティファイドブレット」",imgCutin_Nue,0,0,256,320);
		SetScore(3000000);
		SetTimer(75);
		Wait(180);
	}
	
	task Atack(){
		let x = GetClipMinX();
		let y = GetClipMinY();
		
		let num = 20;
		let mx = ( GetClipMaxX() - GetClipMinX() ) / num;
		
		loop{
			Concentration01(120);
			PlaySE(se2);
			Wait(120);
			
			x = GetClipMinX();
			y = GetClipMinY();
			
			loop(num){
				GrowEffect(x,y,RED01,60);
				ChimeraLaser(x,y,400,GetGapAngle( x,y,GetPlayerX(),GetPlayerY() ),18,200,3,17);
				x += mx;
				Wait(4);
			}
			
			Wait(400 - 4 * num);
		}
	}
	
	task ChimeraLaser(x,y,rad,angle,wid,leng,speed,graph){
		let shotleng = 12;
		let mx = speed * cos(angle);
		let my = speed * sin(angle);
		
		let sx = 0;
		let sy = 0;
		let swait = 0;
		
		let shotnum = truncate( leng / shotleng ) - 3;
		
		PlaySE(selaser2);
		let obj = CreateObjLaserA(x,y,speed,angle,graph,0,leng,wid,false);
		ObjShot_SetBombResist(obj,true);
		
		while( !Obj_BeDeleted(obj) ){
			if( ObjLaser_GetEndX(obj) < GetClipMinX() - 30 || GetClipMaxX() + 30 < ObjLaser_GetEndX(obj) ){
				break;
			}
			
			if( ObjLaser_GetEndY(obj) < GetClipMinY() - 30 || GetClipMaxY() + 30 < ObjLaser_GetEndY(obj) ){
				break;
			}
			
			yield;
		}
		
		if( !Obj_BeDeleted(obj) ){
			sx = ObjLaser_GetEndX(obj);
			sy = ObjLaser_GetEndY(obj);
			swait = 120 + 140;
			
			loop(shotnum){
				AccShot( sx,sy,speed,GetGapAngle( sx,sy,GetPlayerX(),GetPlayerY() ),graph,0,swait );
				sx += shotleng * cos(angle + 180);
				sy += shotleng * sin(angle + 180);
				swait -= 10;
			}
			
			Obj_Delete(obj);
		}
	}
	
	task AccShot(x,y,speed,angle,graph,delay,swait){
		let aspeed = 0.08;
		
		let obj = CreateObjShot(x,y,0,angle,graph,delay);
		
		Wait(delay + swait);
		
		PlaySE(seshot4);
		Obj_SetAngle( obj,GetGapAngle( x,y,GetPlayerX(),GetPlayerY() ) );
		
		while( !Obj_BeDeleted(obj) ){
			Obj_SetSpeed( obj,Obj_GetSpeed(obj) + aspeed );
			
			yield;
		}
	}
	
	task Dark(){
		let scale = 0;
		
		Wait(660);
		
		objeffect = CreateObjEffect(imgDark,GetX(),GetY(),0,0,256,256,6,255,1,1,1);
		ObjEffect_SetScale(objeffect,0,0);
		ObjEffect_SetRenderState(objeffect,MULTIPLY);
		
		loop(240){
			scale += 0.04;
			ObjEffect_SetScale(objeffect,scale,scale);
			
			yield;
		}
		
		SetEnemyMarker(false);
	}
	
	task HPCheck(){
		while( GetLife() > 1 ){
			yield;
		}
		
		if( !Obj_BeDeleted(objeffect) ){
			Obj_Delete(objeffect);
		}
	}
	
	#include_function ".\..\..\initialize_boss.txt"
	#include_function ".\imgpath.txt"
	
	#include_function ".\..\..\lib\lib_value.txt"
	#include_function ".\..\..\lib\lib_obj.txt"
	#include_function ".\..\..\lib\lib_effect.txt"
}