#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["DISCO"]
#Text["DISCODISCODISCODISCO"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#Player["./MoF_Reimu/Reimu.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();
@Initialize
{
Sound(GCSD ~ "Little.mp3");
SetBoss("Yuyuko",true);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	if(GetCommonData("IsFan",false)==true){
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss)-90,ObjMove_GetY(objBoss),26*3.5);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss)+90,ObjMove_GetY(objBoss),26*3.5);
	}
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(2750);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(55);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(50,10,180);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy,10,7);
	Cutin("\"Yuyuko love DISCO!\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	/*if(GetCommonData("IsFan",false)==true)
	{
		CallFan(0);
	}
	else
	{
		CallFan(1);
	}*/
	wait(90);
	Test3D;
	}
//----------------------------------------------------
task Test3D{
	let ang1=0;
	let ang2=0;
	let rad=0;
	let fcount = 0;
		ascent(i in 0..24){
			ascent(j in 0..12){
				let color = round(rand(323,330));
				Point(i*15,j*15,color);
			}
		}
		while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
		{
			if(rad<192+75){rad+=1;}
			fcount+=0.5;
			ang1=fcount/2;
			ang2=fcount/3;
			yield;
		}
			task Point(a,b,co){
			let obj=TShotA1(GetEnemyX,GetEnemyY,0,0,co,12); //These will be real bullets on foreground of sphere
			let backobj=TShotA1(GetEnemyX,GetEnemyY,0,0,co,12); // These will be fake bullets on background
			ObjRender_SetAlpha(backobj,64);
			ObjShot_SetSpellResist(obj,true);
			ObjShot_SetSpellResist(backobj,true);
			ObjShot_SetAutoDelete(obj,false);
			ObjShot_SetAutoDelete(backobj,false);
			//ObjRender_SetScaleXYZ(obj,0.5,0.5,0.5);
			//ObjRender_SetScaleXYZ(backobj,0.5,0.5,0.5);
			let x0; let y0; let z0; let x; let y; let z; let xtmp;
			while(!Obj_IsDeleted(obj)){
				if(fcount%3==0)
				{
					let color = round(rand(323,330));
					ObjShot_SetGraphic(obj,color);
					ObjShot_SetGraphic(backobj,color);
				}
				if(rad<192+75){
					//Definition of sphere points. See http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates
					x0=rad*sin(a)*cos(b);
					y0=rad*sin(a)*sin(b);
					z0=rad*cos(a);
				}
				//Rotation around X and Y axis. See http://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions
				x=x0;
				y=y0*cos(ang1)-z0*sin(ang1);
				z=y0*sin(ang1)+z0*cos(ang1);
				xtmp=x; // Needed to save x value for z calculation
				x=x*cos(ang2)+z*sin(ang2);
				z=-xtmp*sin(ang2)+z*cos(ang2);
				if(z>=0){
					//Show bullet, hide effect
					ObjMove_SetPosition(obj,GetEnemyX+x,GetEnemyY+y);
					ObjMove_SetPosition(backobj,-100,-100);
					ObjShot_SetIntersectionEnable(backobj,true);
				}else{
					//Show effect, hide bullet
					ObjMove_SetPosition(backobj,GetEnemyX+x,GetEnemyY+y);
					ObjMove_SetPosition(obj,-100,-100);
					ObjShot_SetIntersectionEnable(backobj,false);
				}
				yield;
			}
		}
	}

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

task FEffect(x, y, x2, y2, angle, angle2,color,time){
				let vx=(x2-x)/time;
				let vy=(y2-y)/time;
				let r=0;
				let a=0;
					loop(time){
					//angle+=1; angle2+=1;
					x+=vx; y+=vy;
					a+=360/time; r=150-150*cos(a);
					let sangle = GetPointAngle(x,y,x+r*cos(angle),y+r*sin(angle2));
					let dummy = ShotA1(x+r*cos(angle), y+r*sin(angle2),0,sangle,color,0,12);
					ObjShot_SetDeleteFrame(dummy,0);
					yield;
					}
}

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

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