#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non1"]
#Text["The first take on Non Directional Laser!"]
//#BGM["script/practice/resources/area2_boss.wav"]
#Player["./Reimu/ReimuB.dnh"]


#include"./include.txt"

let Patch;
let Familiar;
let Familiar1;
let frame=0;
let animation=0;
let angle=0;
let Variance = 5;
let ANG= -0.5;
let NUMBER = 8;
let speed=2;
let angle2 = 0;
let angle3 = 0;
let shot=3000;
let allow=0;
let move=0;

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(6000)
	}
}

@Initialize
{	
	Patch = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Patch);

	let imgExRumia = GetCurrentScriptDirectory ~ "/dot_patchouli.png"; //file path to enemy image

	ObjPrim_SetTexture(Patch, imgExRumia); //Setting the above image file as a texture to the enemy object(Patch)

	ObjSprite2D_SetSourceRect(Patch, 0, 0, 128, 128); //Setting the rectangle coordinates in the enemy image to use(Left, Top, Right, Bottom).

	ObjSprite2D_SetDestCenter(Patch); //Positioning the center of the rectangle(w/texture) at (0, 0) on the stage(top left corner).

	//Moving to the coordinate (cx, 60) in 60 frames

	let cx = GetStgFrameWidth() / 2;

	ObjMove_SetDestAtFrame(Patch, cx, 110, 30);
	
	Crosshair(Patch, DS_BEAM_WHITE);
}

@MainLoop{
	animation++;
	
	let PatchX = ObjMove_GetX(Patch);
	let PatchY = ObjMove_GetY(Patch);
	
	if(animation>=60){
	
		ObjEnemy_SetIntersectionCircleToShot(Patch, PatchX, PatchY, 32);

		ObjEnemy_SetIntersectionCircleToPlayer(Patch, PatchX, PatchY, 24);

		if(ObjEnemy_GetInfo(Patch, INFO_LIFE) <= 0){

			Obj_Delete(Patch);
	
			DeleteShotAll(TYPE_CHILD, TYPE_ITEM);
			
			CloseScript(GetOwnScriptID());
	
			return;
		}
		
		frame++;
		
		if(frame==60){
			WHOOOP;
			BlueLaser;
			cast;
			}
			
		if(frame==120){
			WHOOOP;
			RedLaser;
			shot=0;
			}
		
		if(shot==210){
			cast2;
			Spiral;
			//ObjMove_SetDestAtSpeed(Patch, rand(100, GetStgFrameWidth-100), rand(80, 120), 0.5);
			}
			
		if(shot==500){
			Aimed;
			let pos = rand(100, GetStgFrameWidth-100);
			if(pos>=PatchX){
				rightmove;
				}
				
			if(pos<=PatchX){
				leftmove;
				}
				
			ObjMove_SetDestAtFrame(Patch, pos, rand(80, 120), 55);
			frame=0;
			}
			
			
		shot++;
			
		}
	yield;
	}
	
task BlueLaser {

	let PatchX = ObjMove_GetX(Patch);
	let PatchY = ObjMove_GetY(Patch);

	let laser = 0;
	
	let angle=0;
	let angle1=90;
	let angle2=180;
	let angle3=270;
	
	let obj = CreateStraightLaserA1(PatchX+30*cos(angle), PatchY+30*sin(angle), angle, 500, 40, 110, DS_NEEDLE_BLUE, 60);
	let obj1 = CreateStraightLaserA1(PatchX+30*cos(angle+90), PatchY+30*sin(angle+90), angle1, 500, 40, 110, DS_NEEDLE_BLUE, 60);
	let obj2 = CreateStraightLaserA1(PatchX+30*cos(angle+180), PatchY+30*sin(angle+180), angle2, 500, 40, 110, DS_NEEDLE_BLUE, 60);
	let obj3 = CreateStraightLaserA1(PatchX+30*cos(angle+270), PatchY+30*sin(angle+270), angle3, 500, 40, 110, DS_NEEDLE_BLUE, 60);
		
	while(!Obj_IsDeleted(obj)){
		laser+=0.5;
		
		ObjMove_SetPosition(obj, PatchX+30*cos(angle+laser), PatchY+30*sin(angle+laser));
		ObjMove_SetPosition(obj1, PatchX+30*cos(angle1+laser), PatchY+30*sin(angle1+laser));
		ObjMove_SetPosition(obj2, PatchX+30*cos(angle2+laser), PatchY+30*sin(angle2+laser));
		ObjMove_SetPosition(obj3, PatchX+30*cos(angle3+laser), PatchY+30*sin(angle3+laser));
		
		ObjStLaser_SetAngle(obj, angle+laser);
		ObjStLaser_SetAngle(obj1, angle1+laser);
		ObjStLaser_SetAngle(obj2, angle2+laser);
		ObjStLaser_SetAngle(obj3, angle3+laser);
		
		yield;
		}
	}
	
task RedLaser {

	let PatchX = ObjMove_GetX(Patch);
	let PatchY = ObjMove_GetY(Patch);

	let laser = 0;
	
	let angle=0;
	let angle1=90;
	let angle2=180;
	let angle3=270;
	
	let obj = CreateStraightLaserA1(PatchX+30*cos(angle), PatchY+30*sin(angle), angle, 500, 40, 110, DS_NEEDLE_RED, 60);
	let obj1 = CreateStraightLaserA1(PatchX+30*cos(angle+90), PatchY+30*sin(angle+90), angle1, 500, 40, 110, DS_NEEDLE_RED, 60);
	let obj2 = CreateStraightLaserA1(PatchX+30*cos(angle+180), PatchY+30*sin(angle+180), angle2, 500, 40, 110, DS_NEEDLE_RED, 60);
	let obj3 = CreateStraightLaserA1(PatchX+30*cos(angle+270), PatchY+30*sin(angle+270), angle3, 500, 40, 110, DS_NEEDLE_RED, 60);
		
	while(!Obj_IsDeleted(obj)){
		laser-=0.5;
		
		ObjMove_SetPosition(obj, PatchX+30*cos(angle+laser), PatchY+30*sin(angle+laser));
		ObjMove_SetPosition(obj1, PatchX+30*cos(angle1+laser), PatchY+30*sin(angle1+laser));
		ObjMove_SetPosition(obj2, PatchX+30*cos(angle2+laser), PatchY+30*sin(angle2+laser));
		ObjMove_SetPosition(obj3, PatchX+30*cos(angle3+laser), PatchY+30*sin(angle3+laser));
		
		ObjStLaser_SetAngle(obj, angle+laser);
		ObjStLaser_SetAngle(obj1, angle1+laser);
		ObjStLaser_SetAngle(obj2, angle2+laser);
		ObjStLaser_SetAngle(obj3, angle3+laser);
		
		yield;
		}
	}
	
task Spiral {

	allow=270;

	loop(10){
	
		Shot4SE;
		
		let px = GetPlayerX();
		let py = GetPlayerY();
		
		let A = 360/5;
	
		CreateShotA1(px+120*cos(allow), py+120*sin(allow), 1.5, allow+180, DS_LIGHT_GREEN, 20);
		CreateShotA1(px+120*cos(allow+A), py+120*sin(allow+A), 1.5, allow+A+180, DS_LIGHT_BLUE, 20);
		CreateShotA1(px+120*cos(allow+A*2), py+120*sin(allow+A*2), 1.5, allow+A*2+180, DS_LIGHT_RED, 20);
		CreateShotA1(px+120*cos(allow+A*3), py+120*sin(allow+A*3), 1.5, allow+A*3+180, DS_LIGHT_YELLOW, 20);
		CreateShotA1(px+120*cos(allow+A*4), py+120*sin(allow+A*4), 1.5, allow+A*4+180, DS_LIGHT_WHITE, 20);
		
		allow+=30;
		
		loop(20){
			yield;
			}
		}
	}
	
task Aimed {

	loop(3){
		let id = 88;

		loop(5){
			Shot5SE;
			
			let PatchX = ObjMove_GetX(Patch);
			let PatchY = ObjMove_GetY(Patch);
			let px = GetPlayerX();
			let py = GetPlayerY();
		
			let Player = atan2(py - PatchY, px - PatchX);
		
			let angle4 = Player;
		
			id++;
		
			loop(12){
				angle4+=360/12;
			
				CreateShotA1(PatchX, PatchY, 4, angle4, id, 10);
				CreateShotA1(PatchX, PatchY, 3.5, angle4, id, 10);
				CreateShotA1(PatchX, PatchY, 3, angle4, id, 10);
			
				}
			
			loop(10){
				yield;
				}
			}
		loop(15){
			yield;
			}
		}
	}
	
