#東方弾幕風
#Title[日＆月＆土符「ルナティックエクリプション」]
#Text[難易度:Hard

これこそ夜ができる仕組み
地球丸焦げだけど気にしない]
#BGM[.\..\..\bgm\bgm.wav]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
	
	let earthangle = 0;
	
	@Initialize{
		InitializeData();
		InitializeAction();
		
		SetLife(1000);
		
		SetX( GetCenterX() );
		SetY( GetCenterY() );
		
		alternative( GetPlayerType() )
			case(REIMU_A){
				SetDamageRate(18,25);
			}
			case(REIMU_B){
				SetDamageRate(13,25);
			}
			case(MARISA_A){
				SetDamageRate(18,25);
			}
			case(MARISA_B){
				SetDamageRate(25,25);
			}
			others{
				SetDamageRate(20,25);
			}
		
		SetCollisionEx(600,16,false,240);
		SetEnemyMarker(true);
		
		SetShotAutoDeleteClip(64,44,64,44);
		
		TMain();
	}
	
	@MainLoop{
		yield;
	}
	
	@DrawLoop{
		DrawBoss(imgBoss_Patchouli);
	}
	
	@Finalize{
		FinalizeData();
	}
	
	task TMain(){
		Wait(60);
		
		DeclareSpell();
		
		Atack();
	}
	
	function DeclareSpell(){
		SetAction(ACT_SPELL,180);
		CutIn(KOUMA,"日＆月＆土符「ルナティックエクリプション」",imgCutin_Patchouli,0,0,256,320);
		SetScore(280000);
		SetTimer(75);
		Wait(180);
	}
	
	task Atack(){
		let angle = 0;
		
		Earth();
		
		SunFire();
		
		loop{
			angle = earthangle + 26;
			
			ascent(i in 0..20){
				SunBeam(GetX(),GetY(),4,angle + i * 360 / 20,185,17,110,60,120, 0.428,12);
				SunBeam(GetX(),GetY(),4,angle + i * 360 / 20,185,17,110,60,120,-0.428,12);
			}
			
			Wait(120);
			
			Concentration01(60);
			PlaySE(se2);
			Wait(60);
			
			PlaySE(selaser1);
			
			Wait(360);
		}
	}
	
	task Earth(){
		let rad = 0;
		let maxrad = 70;
		let x = GetX();
		let y = GetY();
		
		earthangle = 30;
		
		let obj = CreateObjShot(x,y,0,earthangle,54,0);
		ObjShot_SetBombResist(obj,true);
		
		while( !Obj_BeDeleted(obj) ){
			if(rad < maxrad){
				rad += 1;
			}
			
			x = GetX() + rad * cos(earthangle);
			y = GetY() + rad * sin(earthangle);
			
			Obj_SetPosition(obj,x,y);
			
			earthangle += 1.1;
			
			if(earthangle >= 360){
				earthangle -= 360;
			}
			
			yield;
		}
	}
	
	task SunBeam(x,y,longspeed,angle,graph1,graph2,wait1,wait2,wait3,roll,shotwid){
		let leng = 0;
		let vleng = 0;
		let wid = 6;
		let count = 0;
		let shotnum = 0;
		let shotx = x;
		let shoty = y;
		let shotangle = 0;
		let shotwait = 0;
		
		let obj = CreateObjLaserB(x,y,0,angle,graph1,0,leng,wid,false);
		Obj_SetCollisionToPlayer(obj,false);
		
		while( !Obj_BeDeleted(obj) ){
			if(count <= wait1){
				leng += longspeed;
			}else if(count <= wait1 + wait2){
				
			}else if(count <= wait1 + wait2 + wait3){
				Obj_SetCollisionToPlayer(obj,true);
				ObjLaser_SetWidth(obj,16);
			}else{
				break;
			}
			
			if(earthangle - 26 < 0){
				if( angle >= 360 - 26 + earthangle || angle <= earthangle + 26 ){
					vleng = 50;
				}else{
					vleng = leng;
				}
			}else if(earthangle + 26 > 360){
				if( angle >= earthangle - 26 || angle + 360 <= earthangle + 26 ){
					vleng = 50;
				}else{
					vleng = leng;
				}
			}else if(angle >= earthangle - 26 && angle <= earthangle + 26){
				vleng = 50;
			}else{
				vleng = leng;
			}
			ObjLaser_SetLength(obj,vleng);
			
			angle += roll;
			Obj_SetAngle(obj,angle);
			
			if(angle <= 0){
				angle += 360;
			}
			
			if(angle >= 360){
				angle -= 360;
			}
			
			count += 1;
			
			yield;
		}
		
		shotnum = truncate(vleng / shotwid);
		
		if( !Obj_BeDeleted(obj) ){
			shotangle = angle + 60;
			shotwait = 70;
			
			loop(shotnum){
				PlaySE(selaser2);
				CreateShotA(1,shotx,shoty,20);
				SetShotDataA(1,0,0,shotangle,0,0,0,graph2);
				SetShotDataA(1,shotwait,0,NULL,0,0.02,3,graph2);
				FireShot(1);
				
				shotx += shotwid * cos(angle);
				shoty += shotwid * sin(angle);
				
				shotangle += 4.55;
				shotwait -= 2;
				
				Wait(2);
			}
			
			Obj_Delete(obj);
		}
	}
	
	task SunFire(){
		let angle = 0;
		
		loop(5){
			PlaySE(seshot1);
			
			angle = rand(0,360);
			
			ascent(i in 0..8){
				SunFireShot(GetX(),GetY(),rand(1,2.5),angle + 360 * i / 8 + rand(-5,5),241,40);
			}
			
			Wait(6);
		}
	}
	
	task SunFireShot(x,y,speed,angle,graph,delay){
		let obj = CreateObjShot(x,y,speed,angle,graph,delay);
		Obj_SetAutoDelete(obj,false);
		
		while( !Obj_BeDeleted(obj) ){
			Obj_SetAngle(obj,Obj_GetAngle(obj) + 0.7);
			yield;
		}
	}
	
	#include_function ".\..\..\initialize_boss.txt"
	#include_function ".\..\..\lib\lib_anime_patchouli.txt"
	
	#include_function ".\..\..\lib\lib_obj.txt"
}