
#ScriptVersion[3]
#Title["TsurubamiN2"]
#Text["TsurubamiN2"]
#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(85);
	}
		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(67,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;
	PatternMonochrome1;
	
	}



             task PatternMonochrome1{ 
	let Wait = 180;
              while( !Obj_IsDeleted( objBoss )){
	loop( 1 ){
		            let angle = rand( 0, 360 );
	                                let way = 10;
                                                    let shote = 855;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0, 0, shote, delay );
				ObjectRotation( sht1, objBoss, 0, 500, angle, 3, 0.73, 0, 0 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				Sub( sht1, -180 );

				angle -= 360 / way;

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

	}
	loop( 1 ){
		            let angle = rand( 0, 360 );
	                                let way = 10;
                                                    let shote = 855;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0, 0, shote, delay );
				ObjectRotation( sht1, objBoss, 0, 500, angle, 3, -0.73, 0, 0 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				Sub( sht1, 180 );

				angle -= 360 / way;

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

	}
	}

   }

	function GetDotAngle(x1,y1,x2,y2){
	let angle=atan2(y1-y2,x1-x2);
	return angle;
}
	task Sub( obj, plus ){
	yield;	
	let x = 0;
	while( !Obj_IsDeleted( obj )){

	let angle = GetDotAngle( ObjMove_GetX( obj ), ObjMove_GetY( obj ), ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss )) + x;

	                                let way = 1;
                                                    let shote = 97;
		            let delay = 0;
		            let speed = 2.5;

			loop( way ){

                      	                    let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0.01, speed, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				//ObjRender_SetColor( sht1, 90, 90, 90 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

			}
			x += plus;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 3 ) ){ return; }
		}
	}



task ObjectRotation( obj, target, rstart, rmax, angle, ad, av, aad, aav ){

   let ox;
   let oy;
   let r = rstart;
   while(!Obj_IsDeleted(obj)){

      ox = ObjMove_GetX( target ) + r*cos( angle );
      oy = ObjMove_GetY( target ) + r*sin( angle );

      ObjMove_SetPosition(obj,ox,oy);
      ObjMove_SetAngle( obj, angle );
      ObjStLaser_SetAngle(obj,angle);

      if(r < rmax){
      r += ad;
      ad += aad; }

      if(r > rmax){
      r += ad;
      ad += aad; }

      angle += av;
      av += aav;

      yield;

      
 
   }
}

	task StartCountDown
	{
		wait((85*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());
	}