#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non5"]
#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=0;
let allow=1;
let move=0;
let pos=51;

@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;
		}
		angle3++;
		frame++;
		shot++;
		
		if(angle3==10){
			let ADD = 360/5;
			
			CreateShotA1(PatchX+pos*cos(angle), PatchY+pos*sin(angle), 2, -angle, DS_LIGHT_RED, 20);
			CreateShotA1(PatchX+pos*cos(angle+ADD), PatchY+pos*sin(angle+ADD), 2, -angle+ADD, DS_LIGHT_GREEN, 20);
			CreateShotA1(PatchX+pos*cos(angle+ADD*2), PatchY+pos*sin(angle+ADD*2), 2, -angle+ADD*2, DS_LIGHT_YELLOW, 20);
			CreateShotA1(PatchX+pos*cos(angle+ADD*3), PatchY+pos*sin(angle+ADD*3), 2, -angle+ADD*3, DS_LIGHT_WHITE, 20);
			CreateShotA1(PatchX+pos*cos(angle+ADD*4), PatchY+pos*sin(angle+ADD*4), 2, -angle+ADD*4, DS_LIGHT_BLUE, 20);
			
			angle3=0;
			}
		
		if(frame==5){
			let ADD = 360/5;
			
			CreateShotA1(PatchX+pos*cos(angle), PatchY+pos*sin(angle), 2, -angle, DS_LIGHT_RED, 20);
			CreateShotA1(PatchX+pos*cos(angle+ADD), PatchY+pos*sin(angle+ADD), 2, -angle+ADD, DS_LIGHT_GREEN, 20);
			CreateShotA1(PatchX+pos*cos(angle+ADD*2), PatchY+pos*sin(angle+ADD*2), 2, -angle+ADD*2, DS_LIGHT_YELLOW, 20);
			CreateShotA1(PatchX+pos*cos(angle+ADD*3), PatchY+pos*sin(angle+ADD*3), 2, -angle+ADD*3, DS_LIGHT_WHITE, 20);
			CreateShotA1(PatchX+pos*cos(angle+ADD*4), PatchY+pos*sin(angle+ADD*4), 2, -angle+ADD*4, DS_LIGHT_BLUE, 20);
			
			angle+=20;
			
			if(pos>=70){
				allow=1;
				}
			if(pos<=-120){
				allow=2;
				}
				
			if(allow==1){
				pos-=3.1;
				}
			if(allow==2){
				pos+=3.1;
				}
				
			frame=0;
			}
			
		if(shot==200){
			cast2;
			
			LaserSE;		
			
			CreateStraightLaserA1(rand(0, GetStgFrameWidth-0), 0, 90, 600, 60, 80, DS_BEAM_RED, 60);
			CreateStraightLaserA1(rand(0, GetStgFrameWidth-0), 0, 90, 600, 60, 80, DS_BEAM_GREEN, 60);
			CreateStraightLaserA1(rand(0, GetStgFrameWidth-0), 0, 90, 600, 60, 80, DS_BEAM_WHITE, 60);
			CreateStraightLaserA1(rand(0, GetStgFrameWidth-0), 0, 90, 600, 60, 80, DS_BEAM_BLUE, 60);
			CreateStraightLaserA1(rand(0, GetStgFrameWidth-0), 0, 90, 600, 60, 80, DS_BEAM_YELLOW, 60);
			CreateStraightLaserA1(rand(0, GetStgFrameWidth-0), 0, 90, 600, 60, 80, DS_BEAM_ORANGE, 60);
			CreateStraightLaserA1(rand(0, GetStgFrameWidth-0), 0, 90, 600, 60, 80, DS_BEAM_SKY, 60);
			
			shot=0;
			}
			
		move++;
		
		if(move==300){
		
			let pos = rand(100, GetStgFrameWidth-100);
			if(pos>=PatchX){
				rightmove;
				}
				
			if(pos<=PatchX){
				leftmove;
				}
				
			ObjMove_SetDestAtFrame(Patch, pos, rand(80, 120), 55);
			
			move=0;
			}
			
		}
	yield;
	}