#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["hitbox"]
#System["./../system/NSystem.dnh"]
#Player["./../player/Reimu by plasmaflame22/Reimu_A.txt"]

#include "./../ZUNShot/shotMathsCons.txt"
#include "./../ZUNShot/ZUNShot_Const.txt"
#include "./sharedFuncSamir.dnh"


let objBoss;
let width = 420;
let height = 440;
let life = 1000;
let time= 55;
let scene = GetEnemyBossSceneObjectID();

@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(life);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(time);
    }
}




@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	SetPlayerClip(5,5, 415, 435);
	
	animSpell(objBoss, 1);
	TFinalizeNon(scene, objBoss);
	
	ObjMove_SetDestAtFrame(objBoss, width/2, height/3, 60);
	Main;
}

@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 28);
    yield;
}


task circle(obj){
    wait(300);
	loop(20){
		ascent(i in 0..10){
			CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 2, 36*i, 317, 0);
		}
		wait(30);
	}
}



task ellipse(point1, point2, littleRad, inc){
	let angRad = findAngRad(point2[0], point1[0], point2[1], point1[1]); 
	let x; let y; let bigRad = angRad[1]/2; let ang = angRad[0]; let theta =0;
	let centre = [(point1[0]+point2[0])/2, (point1[1]+point2[1])/2];
	while(true){
		x = centre[0] + bigRad*cos(theta) *cos(ang) -littleRad*sin(theta)*sin(ang);
		y= centre[1] +bigRad*cos(theta)*sin(ang)+ littleRad * sin(theta) *cos(ang);
		CreateShotA1(x,y, 0,0, 258, 0);
		theta+= inc; yield;
	}
}



task Main{
	wait(120); let x; let y; let theta=0;
	CreateShotA1(width/4, 0.4*height, 0,0,138,0);
	CreateShotA1(3*width/4, 3*height/4, 0,0,139,0);
	CreateShotA1(3*width/4, height/2, 0,0,240,0);
	//move(objBoss, width/2-40, width/2+40, height/3 -10 ,height/3 +30, 0, 180, 30, objBoss, 0, scene, 0);
	//BoWaP(9);
	
	
	/*let obj = CreateShotA1(width, 0, 7, 135, 284, 0);
	trail(obj, 40, [4,8], [241,248], 4, 1);
	wait(120);
	let obj1 = CreateShotA1(0, 0, 7, 45, 284, 0);
	trail(obj1, 60, [4,10], [241,248], 4, 1);
	wait(120);
	let obj2 = CreateShotA1(0, height/4, 7, 0, 284, 0);
	trail(obj2, 60, [4,10], [241,248], 6, 1);
	wait(20);
	let obj3 = CreateShotA1(width, height/2, 7, 180, 284, 0);
	trail(obj3, 60, [4,10], [241,248], 7, 1);
	wait(20);
	let obj4 = CreateShotA1(0, 3*height/4, 7, 0, 284, 0);
	trail(obj4, 50, [4,10], [241,248], 6, 1);*/
	
	/*let obj = CreateShotA1(width/2 + 60, height/2, 0,0, 453, 0);
	ObjRender_SetAngleZ(obj, -90);
	loop(300){
		x = width/2 + 60*cos(i); y = height/2 + 40*sin(i);
		i+=2;
		ObjMove_SetPosition(obj, x,y);
		yield;
	}*/
	
	/*let ang = rand(0,360); let numLas = 25;
	let bul = CreateShotA1(width/2,height/2, 0, 0, 400, 0);
	wait(60);
	
	ascent(i in 0.. numLas){
		let obj = CreateCurveLaserA1(width/2, height/2, 3.4, ang+ 360/numLas *i, 100, 25, 39, 0);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	}
	let numBul =25;
	ascent(i in 0..8){
	    if(i%2 ==1){
			ang = rand(0,360);
		    ascent(j in 0.. 25){
				CreateShotA2(width/2, height/2, 5, ang + 360/25 *j, -0.2, rand(1.2, 1.5), 328, 5);
			}
		}
	    ascent(j in 0.. numBul){
			CreateShotA2(width/2, height/2, rand(4,5), rand(0,360), rand(-0.25,-0.05), rand(1.5, 2), 100, 5);
		}
		wait(10);
	}*/
	    
	/*let numBul = 40;
	ascent(i in 0..8){
	    ascent(j in 0.. numBul){
			CreateShotA2(width/2, height/2, rand(4,5), ang + 360/numBul *j + rand(-3,3), rand(-0.25,-0.05), rand(1.6, 2.2), 100, 5);
		}
		wait(10);
	}*/
	
	
	
	
  
}

task slowSpir(numBranch, numBul, speed, ang, smallAngInc, angInc, graphic, delay, pause){
    let inc = (speed[1]-speed[0])/numBul;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
		ascent(i in 0..numBul){
			ascent(j in 0..numBranch){
				CreateShotA1(X(objBoss),Y(objBoss), speed[0]+inc*i, ang + smallAngInc*i + 360/numBranch *j, graphic, 4);
			}
			wait(delay);
		}
		wait(pause); ang+= angInc;
	}
}


task BoWarp(numBranch){	
	let ang = rand(0, 360);
	let inc = 0;
	while(absolute(inc)<500){	
		ascent(i in 0..numBranch){
			let obj = CreateShotA1(X(objBoss), Y(objBoss), 2.5, ang+360/numBranch *i, 192, 5);
		}
		//ang += f1(inc) * 9;
		inc+=rand(0.5,1.4); wait(2);
	}
}
	
	
	
	
