#東方弾幕風
#Title[月符「サイレントムーン」]
#Text[難易度:Easy

能力の使い道が間違ってる気が。
能力使ったほうが簡単って
それどこのうどんげ]
#BGM[.\..\..\bgm\bgm.wav]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
	
	@Initialize{
		InitializeData();
		
		SetLife(1000);
		
		SetX( GetCenterX() );
		SetY( GetClipMinY() + 130 );
		
		SetDamageRate(25,25);
		SetCollisionEx(32,16,false,240);
		SetEnemyMarker(true);
		
		TMain();
	}
	
	@MainLoop{
		yield;
	}
	
	@DrawLoop{
		DrawBoss_NoAction(imgBoss_Luna);
	}
	
	@Finalize{
		FinalizeData();
	}
	
	task TMain(){
		Wait(60);
		
		DeclareSpell();
		
		Atack();
	}
	
	function DeclareSpell(){
		CutIn(KOUMA,"月符「サイレントムーン」",NULL,0,0,0,0);
		SetScore(3000000);
		SetTimer(48);
		Wait(180);
	}
	
	task Atack(){
		let angle = 0;
		let stime = 0;
		let sspan = 10;
		let speed = 3;
		let twait = 0;
		let wtime = 320;
		
		loop{
			angle = 180;
			stime = rand_int(0,10);
			twait = 180;
			
			loop(10 + stime){
				PlaySE(seshot4);
				MoonA(GetX(),GetY(),speed,angle      ,35,0,twait);
				MoonA(GetX(),GetY(),speed,angle + 180,35,0,twait);
				angle -= 4.5;
				twait -= 3;
				Wait(3);
			}
			
			loop(sspan){
				MoonB(GetX(),GetY(),speed,angle      ,35,0,twait);
				MoonA(GetX(),GetY(),speed,angle + 180,35,0,twait);
				angle -= 4.5;
				twait -= 3;
				Wait(3);
			}
			
			loop(30 - stime - sspan){
				PlaySE(seshot4);
				MoonA(GetX(),GetY(),speed,angle      ,35,0,twait);
				MoonA(GetX(),GetY(),speed,angle + 180,35,0,twait);
				angle -= 4.5;
				twait -= 3;
				Wait(3);
			}
			
			speed += 0.5;
			
			if(wtime >= 140){
				wtime -= 40;
			}
			
			Wait(45);
			PlaySE(seshot5);
			
			Wait(wtime - 45);
		}
	}
	
	task MoonA(x,y,speed,angle,graph,delay,twait){
		let rad = 40;
		let shotnum = 4;
		let shotspan = 20;
		
		loop(shotnum){
			MoonAShot(GetGapX(x,rad,angle),GetGapY(y,rad,angle),speed,angle,graph,delay,twait);
			rad += shotspan;
			twait -= 6;
		}
	}
	
	task MoonB(x,y,speed,angle,graph,delay,twait){
		let rad = 40;
		let shotnum = 4;
		let shotspan = 20;
		
		loop(shotnum){
			MoonBShot(GetGapX(x,rad,angle),GetGapY(y,rad,angle),speed,angle,graph,delay,twait);
			rad += shotspan;
		}
	}
	
	task MoonAShot(x,y,speed,angle,graph,delay,twait){
		SetShotColor(255,242,216);
		let obj = CreateObjShot(x,y,0,angle,graph,delay);
		SetShotColor(255,255,255);
		
		Wait(twait);
		
		if( !Obj_BeDeleted(obj) ){
			Obj_SetSpeed(obj,speed);
			loop(rand_int(1,2)){
				GravityShot(Obj_GetX(obj),Obj_GetY(obj),rand(1,1.5),angle + 180 + rand(-35,35),155,0,0.026 + rand(0,0.014),angle,2 + rand(0,2));
			}
		}
	}
	
	task MoonBShot(x,y,speed,angle,graph,delay,twait){
		let obj = CreateObjShot(x,y,0,angle,graph,delay);
		
		Wait(twait);
		
		if( !Obj_BeDeleted(obj) ){
			Obj_Delete(obj);
			GravityShot(x,y,rand(1,1.5),GetAngleToPlayer() + 180,155,0,0.03 + rand(0,0.01),GetAngleToPlayer(),1 + rand(0,3));
		}
	}
	
	#include_function ".\..\..\initialize_boss.txt"
	
	#include_function ".\..\..\lib\lib_value.txt"
	#include_function ".\..\..\lib\lib_obj.txt"
	#include_function ".\..\..\lib\lib_bullet.txt"
}