
#ScriptVersion[3]
#Title["KurojiS1"]
#Text["KurojiS1"]
#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 action = false;
let objScene=GetEnemyBossSceneObjectID();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetBoss("Doremy",true);
SetCommonData("Life",2);
SetCommonData("Bomb",1);
}

@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(1250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(65);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(50000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	PlaySound("SpellStart",100,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("Axis 'Hyperplane Reflexion'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(120);
	DamageRateAtFrame(28,5,0);
	TShot1;
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	FlipCheck;
	while( !Obj_IsDeleted( objBoss )){
	Stairs;
	wait( 20 );
	Sub;
	wait( 220 );
	Stairs2;
	wait( 20 );
	Sub;
	wait( 220 );
	}
}

              task Stairs{ 
              let gap = 10;
              let sx = 0;
              loop( 40 ){

			let shote = 301;
                                                	let speed = 2;
	                                	let way = 1;
              			let angle = 90;
			let delay = 0;

			loop( way ){

                        			let sy = -5;
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
			sx += gap;
                        		wait( 3 );

	}
}

              task Stairs2{ 
              let gap = 10;
              let sx = GetStgFrameWidth;
              loop( 40 ){

			let shote = 301;
                                                	let speed = 2;
	                                	let way = 1;
              			let angle = 90;
			let delay = 0;

			loop( way ){

                        			let sy = -5;
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
			sx -= gap;
                        		wait( 3 );

	}
}

              task Sub{ 
              loop( 3 ){

			let shote = 35;
	                                	let way = 24;
			let delay = 20;

			loop( way ){

                                                		let speed = rand( 0.85, 1.85 );
              				let angle = rand( 0, 360 );

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );
				SuddenDeleteLeft( sht1 );
				SuddenDeleteRight( sht1 );

				angle += 360 / way;

			}
			PlaySound("LenenShot3",92,0);
                        		wait( 30 );

	}
}

	task SuddenDeleteLeft( obj ){
	while( ObjMove_GetX( obj ) > -15 ){ yield; }
	Obj_Delete( obj );
	}

	task SuddenDeleteRight( obj ){
	while( ObjMove_GetX( obj ) < GetStgFrameWidth + 15 ){ yield; }
	Obj_Delete( obj );
	}

task FlipCheck{
wait( 40 );
while(!Obj_IsDeleted( objBoss )){
wait( 80 );
TMovement( 60, 6, 2 );	
PlaySound("LenenBulletWave",92,0);
let shotarray = GetShotIdInCircleA2( GetPlayerX, GetPlayerY, 1000, TARGET_ALL );

ascent( i in 0..length( shotarray )){

     let ang = ObjMove_GetAngle( shotarray[ i ] );
     let spe = ObjMove_GetSpeed( shotarray[ i ] );

if( ObjShot_GetImageID( shotarray[ i ] ) == 301 ){ 
     let x;
     if( ObjMove_GetX( shotarray[ i ] ) < stgx ){ x = stgx*2 - ObjMove_GetX( shotarray[ i ] );  
				      ObjRender_SetAngleZ( shotarray[ i ], 90 );
				      ObjShot_SetGraphic( shotarray[ i ], 299 );}
     if( ObjMove_GetX( shotarray[ i ] ) > stgx ){ x = stgx*2 - ObjMove_GetX( shotarray[ i ] );  
				      ObjRender_SetAngleZ( shotarray[ i ], 270 );
				      ObjShot_SetGraphic( shotarray[ i ], 299 );}
     ObjMove_SetDestAtFrame( shotarray[ i ], x, ObjMove_GetY( shotarray[ i ] ), 120 ); 
     Continue( shotarray[ i ], 120, spe, ang, 301 );}

if( ObjShot_GetImageID( shotarray[ i ] ) == 35 ){ 
     let x;
     if( ObjMove_GetX( shotarray[ i ] ) < stgx ){ x = stgx*2 - ObjMove_GetX( shotarray[ i ] );  
				      ObjShot_SetGraphic( shotarray[ i ], 33 );}
     if( ObjMove_GetX( shotarray[ i ] ) > stgx ){ x = stgx*2 - ObjMove_GetX( shotarray[ i ] );  
				      ObjShot_SetGraphic( shotarray[ i ], 33 );}
     ObjMove_SetDestAtFrame( shotarray[ i ], x, ObjMove_GetY( shotarray[ i ] ), 120 ); 
     Continue( shotarray[ i ], 120, spe, -ang + 180, 35 );}

                                                                   }
		wait( 160 );
	              }
	}

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

task Continue( obj, t, speed, angle, shote ){
wait( t );
PlaySound("LenenBulletWave",92,0);
ObjMove_AddPatternA3( obj, 0, speed, angle, 0, 0, speed, shote );
ObjRender_SetAngleZ( obj, 0 );

}

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

	}


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

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