#東方弾幕風
#Title[夜天「ロマンティックスターズ」]
#Text[難易度:Normal

夜の満天の星空
某魔道書とは関係ないと思う]
#BGM[.\..\..\bgm\bgm.wav]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
	
	@Initialize{
		InitializeData();
		InitializeAction();
		
		SetLife(1000);
		
		SetX( GetCenterX() );
		SetY( GetClipMinY() + 130 );
		
		SetDamageRate(25,20);
		SetCollisionEx(32,16,false,240);
		SetEnemyMarker(true);
		
		TMain();
	}
	
	@MainLoop{
		yield;
	}
	
	@DrawLoop{
		DrawBoss(imgBoss_Marisa);
	}
	
	@Finalize{
		FinalizeData();
	}
	
	task TMain(){
		Wait(60);
		
		DeclareSpell();
		
		Atack();
		Atack2();
	}
	
	function DeclareSpell(){
		SetAction(ACT_SPELL,180);
		CutIn(KOUMA,"夜天「ロマンティックスターズ」",imgCutin_Marisa,0,0,256,320);
		SetScore(260000);
		SetTimer(55);
		Wait(180);
	}
	
	task Atack(){
		let sx = 0;
		let sy = 0;
		let ex = 0;
		let ey = 0;
		let turn = 1;
		let wtime = 90;
		let color = 2;
		
		RandMove(60,90,50,GetClipMinX() + 128,GetClipMaxX() - 128,GetClipMinY() + 60,GetClipMinY() + 200);
		
		loop{
			if(turn == 1){
				sx = GetClipMaxX() + 32;
				sy = 150 - rand(0,100);
				ex = GetClipMinX() - 32;
				ey = 350 + rand(0,100);
			}else{
				sx = GetClipMinX() - 32;
				sy = 150 - rand(0,100);
				ex = GetClipMaxX() + 32;
				ey = 350 + rand(0,100);
			}
			
			ShootingStar(sx,sy,ex,ey,color);
			
			color += 1;
			if(color > 6){
				color = 0;
			}
			
			if(wtime >70){
				wtime -= 8;
			}
			
			turn *= -1;
			
			Wait(wtime);
		}
	}
	
	task ShootingStar(sx,sy,ex,ey,color){
		let angle = GetGapAngle(sx,sy,ex,ey);
		let sangle = 0;
		
		let obj = GravityShotObj(sx,sy,1,angle,161 + color,0,0.06,angle,99);
		
		PlaySE(seshot4);
		
		while( !Obj_BeDeleted(obj) ){
			sangle = angle + 180 + rand(-60,60);
			GravityShot(Obj_GetX(obj),Obj_GetY(obj),0.4,sangle,153 + color,0,0.04,sangle,99);
			
			yield;
		}
	}
	
	task Atack2(){
		let angle = 0;
		
		Wait(240);
		
		loop{
			angle = rand(0,360);
			
			ascent(i in 0..14){
				TailShot(GetX(),GetY(),3,angle + i * 360 / 14,truncate(i / 2),0);
			}
			
			Wait(180);
		}
	}
	
	task TailShot(x,y,speed,angle,color,delay){
		let dangle = 0;
		
		let obj = CreateObjShot(x,y,speed,angle,161 + color,delay);
		
		while( !Obj_BeDeleted(obj) ){
			dangle = angle + 180 + rand(-30,30);
			StarDustShot( GetGapX(Obj_GetX(obj),20,dangle),GetGapY(Obj_GetY(obj),20,dangle),0,0,color,0 );
			
			Wait(3);
		}
	}
	
	task StarDustShot(x,y,speed,angle,color,delay){
		let obj = CreateObjShot(x,y,0,angle,153 + color,delay);
		
		if( !Obj_BeDeleted(obj) ){
			ObjShot_FadeDelete(obj);
		}
	}
	
	#include_function ".\..\..\initialize_boss.txt"
	#include_function ".\..\..\lib\lib_anime_marisa.txt"
	
	#include_function ".\..\..\lib\lib_obj.txt"
	#include_function ".\..\..\lib\lib_bullet.txt"
	#include_function ".\..\..\lib\lib_value.txt"
}