
#ScriptVersion[3]
#Title["TsurubamiN8"]
#Text["TsurubamiN8"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#include"./system/Default_Effect.Txt"


let objBoss;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let atk = false;
let fog = 0;
let objScene=GetEnemyBossSceneObjectID();
let color = [0,0];
@Initialize
{
SetCommonData("Scroll",0);
SetBoss("Doremy",false);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),18);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(5000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(95);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	SetCommonData("ForceLifebar",1);
	StartCountDown;
	ObjMove_SetDestAtWeight(objBoss,stgx,110,10,10);
	SetCommonData("Scroll",1);
	wait( 160 );
	TShot1;
	SetCommonData("ForceLifebar",0);
	DamageRateAtFrame(65,0,0);
	yield;
	}

//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	Loop;
	}

	task Loop{
	while( !Obj_IsDeleted( objBoss )){
	First( 90 );
	FirstFirst;
	wait( 320 );
	Second;
	wait( 500 );
	ThirdThirdThird;
	ObjMove_SetDestAtWeight( objBoss, stgx, stgy - rand( 120, 140 ), 6, 2.3 );
	wait( 60 );
	ThirdThirdThird;
	ObjMove_SetDestAtWeight( objBoss, GetStgFrameWidth - 90, stgy - rand( 120, 140 ), 6, 2.3 );
	wait( 60 );
	ThirdThirdThird;
	TMovement( 100, 10, 2.3 );
	wait( 360 );
	First( GetStgFrameWidth - 90 );
	FirstFirst;
	wait( 320 );
	Second;
	wait( 500 );
	ThirdThirdThird;
	ObjMove_SetDestAtWeight( objBoss, stgx, stgy - rand( 120, 140 ), 6, 2.3 );
	wait( 60 );
	ThirdThirdThird;
	ObjMove_SetDestAtWeight( objBoss, 90, stgy - rand( 120, 140 ), 6, 2.3 );
	wait( 60 );
	ThirdThirdThird;
	TMovement( 100, 10, 2.3 );
	wait( 360 );
	}
	}

	function GetDotAngle(x1,y1,x2,y2){
	let angle=atan2(y1-y2,x1-x2);
	return angle;
}

	task First( x ){
	let stop = [ 90, GetStgFrameWidth - 90 ];
	loop( 40 ){
	let speed = 0.45;
	loop( 6 ){
		            let angle = 90;
	                                let way = 2;
                                                    let shote = 97;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjMove_AddPatternA2( sht1, 300, NO_CHANGE, NO_CHANGE, 0.03, 0, 5 ); 
				angle += 360/way;

			}
			speed += 0.72;
			}
			PlaySound("LenenShot1",92,0);
			ObjMove_SetPosition( objBoss, rand( 0, GetStgFrameWidth ), rand( 40, GetStgFrameHeight / 2 - 50 ));
                       		if( wait( 3 ) ){ return; }
		}
			ObjMove_SetPosition( objBoss, x, stgy - 130 );
	}

	task FirstFirst{
	loop( 20 ){
	let speed = 5;
		            let angle = 45;
	                                let way = 4;
                                                    let shote = 855;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, -0.12, 0, shote, delay );
				Slow( sht1 );
				angle += 360/way;

			}
			PlaySound("LenenShot1",92,0);
                       		if( wait( 6 ) ){ return; }
		}
	}

	task Slow( obj ){
	while( ObjMove_GetSpeed( obj ) != 0 ){ yield; }
	wait( 10 );
	ObjMove_AddPatternA2( obj, 0, 0, GetAngleToPlayer( obj ), 0.012, 0, 10 );
	}

	task Second{

                                                    	let shote = 830;
		            	let delay = 0;
                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
			let sht1 = TShotA2( sx, sy, 0, 0, 0, 0, shote, delay );
			ObjRender_SetBlendType( sht1, BLEND_ALPHA );
			ObjRender_SetColor( sht1, 0, 0, 0 );
			Obj_SetRenderPriorityI( sht1, 60 );
			ObjShot_SetSpellResist( sht1, true );
			FlashyOrb( sht1, shote );
			Appearing( sht1 );
			DarkAngle( sht1, 0.58, 420 );
			SecondSecond( sht1 );
			Fading( sht1, 360 );
			
			PlaySound("LenenLaserDelayShort",92,0);
	
	}

	task FlashyOrb( core, shot ){
	while( !Obj_IsDeleted( core )){
	FlashyOrb1( core, shot );
	wait( 5 );
	}
	}

	task FlashyOrb1(core, shot)
	{
		let obj = CreateShotOA1(core,0,0,shot,0);
		ObjShot_SetSpellResist(obj,true);
		ObjShot_SetIntersectionEnable(obj,false);
		ascent(i in 0..10)
		{
			ObjRender_SetScaleXYZ(obj,1+i/10,1+i/10,0);
			ObjRender_SetAlpha( obj, 255 -i*51 );
			ObjRender_SetBlendType( obj, BLEND_ALPHA );
			ObjRender_SetColor(obj,0,0,0);
			wait( 1 );
		}
		Obj_Delete(obj);
	}

	task SecondSecond( obj ){
	let angle = GetAngleToPlayer( obj );
	let a = 0;
	let speed = 1.8;
	let t = 0;
	loop( 120 ){

	                                let way = 6;
                                                    let shote = 97;
		            let delay = 0;

			loop( way ){
			let r = 20;
                      	                    let sx = ObjMove_GetX( obj ) + r*cos( angle );
                        		let sy = ObjMove_GetY( obj ) + r*sin( angle );
				
				let sht2 = TShotA2( sx, sy, speed +0.03, angle, 0, speed +0.03, shote, delay );
				ObjMove_AddPatternA2( sht2, 420 - t, NO_CHANGE, NO_CHANGE, 0.01, 0, 5 );
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjMove_AddPatternA2( sht1, 420 - t, NO_CHANGE, NO_CHANGE, 0.01, 0, 5 );
				angle += 360/way;

			}
			speed -= 0.01;
			angle += a;
			a += 0.55;
			t += 3;
			PlaySound("LenenShot1",92,0);
                       		if( wait( 3 ) ){ return; }
		}
	}

task DarkAngle(obj,speed, time){
   let x = GetAngleToPlayer( obj );
   loop( time ){
   ObjMove_SetDestAtSpeed( obj, GetPlayerX, GetPlayerY, speed );
	yield;
	}
}

	task Fading( obj, t ){
	wait( t );
	descent( i in 0..255/12 ){
	ObjRender_SetAlpha(obj,i*12);	
	yield;
	}
	Obj_Delete( obj );
	}

	task Appearing( obj ){
	ascent( i in 0..255/12 ){
	ObjRender_SetAlpha(obj,i*12);	
	yield;
	}
	}


	task ThirdThirdThird{
	let angle = GetAngleToPlayer( objBoss );
	let speed = 4.5;
	let way = 10;
	loop( 30 ){

                                                    let shote = 97;
		            let delay = 0;

			loop( way ){
                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				angle += 360/way;

			}
			speed -= 0.124;
			way += 1;
			PlaySound("LenenShot1",92,0);
                       		if( wait( 0 ) ){ return; }
		}

	}

	task StartCountDown
	{
		wait((95*60) - (10*60));
		loop(10)
		{
			PlaySound("time",100,0);
			wait(60);
		}

	}






//----------------------------------------------------

task SizeCircle
{
	ascent(i in 0..60)
	{
		SetCommonData("CircleSize",sin(i*1.5));
		yield;
	}
}	

//----------------------------------------------------

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		EndBoss(0);
		yield;
		CloseScript(GetOwnScriptID());
	}