#東方弾幕風
#Title[夜符「ミッドナイトコーラス」]
#Text[難易度:Normal

夜雀の大合唱
とりあえず五月蝿い。]
#BGM[.\..\..\bgm\bgm.wav]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
	let objeffect = 0;
	let dark = true;
	
	@Initialize{
		InitializeData();
		InitializeAction();
		
		SetLife(1000);
		
		SetX( GetCenterX() );
		SetY( GetClipMinY() + 130 );
		
		SetDamageRate(16,18);
		SetCollisionEx(32,16,false,240);
		SetEnemyMarker(true);
		
		SetEffectForZeroLife(1,0,0);
		
		if(GetKeyState(VK_USER) == KEY_HOLD && GetKeyState(VK_SKIP) == KEY_HOLD ){
			dark = false;
		}
		
		TMain();
	}
	
	@MainLoop{
		yield;
	}
	
	@DrawLoop{
		DrawBoss(imgBoss_Mystia);
	}
	
	@Finalize{
		FinalizeData();
	}
	
	task TMain(){
		Wait(60);
		
		DeclareSpell();
		
		Atack();
		HPCheck();
		
		if(dark){
			Dark();
		}
	}
	
	function DeclareSpell(){
		SetAction(ACT_SPELL,180);
		CutIn(KOUMA,"夜符「ミッドナイトコーラス」",imgCutin_Mystia,0,0,256,320);
		SetScore(2600000);
		SetTimer(65);
		Wait(180);
	}
	
	task Atack(){
		let angle = 0;
		
		loop{
			angle = GetAngleToPlayer();
			
			GreenShot(GetX(),GetY(),2,angle,36,0);
			
			ascent(i in 0..30){
				PlaySE(seshot3);
				StopShot(GetX(),GetY(),8,12,angle + 180 - i * 360 / 30,117,0,10,i + 30 + 30 + 60,20);
				yield;
			}
			
			Wait(30);
			
			ascent(i in 0..30){
				PlaySE(seshot3);
				StopShot(GetX(),GetY(),8,12,angle + 186 + i * 360 / 30,119,0,10,i + 60,20);
				yield;
			}
			
			Wait(60);
			
			loop(10){
				PlaySE(seshot3);
				Wait(15);
			}
			
			Wait(240 - 60 - 15 * 10);
		}
	}
	
	task GreenShot(x,y,speed,angle,graph,delay){
		loop(15){
			CreateShot01(x,y,speed,angle,graph,delay);
			Wait(20);
		}
	}
	
	task StopShot(x,y,speed1,speed2,angle,graph,delay,swait,twait,shotnum){
		let obj = CreateObjShot(x,y,speed1,angle,graph,delay);
		
		Wait(swait);
		
		if( !Obj_BeDeleted(obj) ){
			Obj_SetSpeed(obj,0);
		}
		
		Wait(twait);
		
		loop(shotnum){
			if( Obj_BeDeleted(obj) ){
				break;
			}
			
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),speed2,angle,graph,delay);
			
			speed2 -= 0.59;
			
			Wait(15);
		}
		
		if( !Obj_BeDeleted(obj) ){
			Obj_Delete(obj);
		}
	}
	
	task Dark(){
		let scale = 10;
		
		//PlaySE(se2);
		
		objeffect = CreateObjEffect(imgNight,GetX(),GetY(),0,0,1024,1024,6,255,255,255,255);
		ObjEffect_SetScale(objeffect,scale,scale);
		
		loop(180){
			scale -= 0.045;
			ObjEffect_SetScale(objeffect,scale,scale);
			Obj_SetPosition(objeffect,GetPlayerX(),GetPlayerY());
			
			yield;
		}
		
		loop{
			Obj_SetPosition(objeffect,GetPlayerX(),GetPlayerY());
			
			yield;
		}
	}
	
	task HPCheck(){
		while( GetLife() > 1 ){
			yield;
		}
		
		if( !Obj_BeDeleted(objeffect) ){
			Obj_Delete(objeffect);
		}
	}
	
	#include_function ".\..\..\initialize_boss.txt"
	#include_function ".\..\..\lib\lib_anime_mystia.txt"
	
	#include_function ".\..\..\lib\lib_obj.txt"
}