#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non3"]
#Text["The third 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=270;
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 id=165;
let move=0;

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

@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);

}

@MainLoop{
	animation++;
	
	let PatchX = ObjMove_GetX(Patch);
	let PatchY = ObjMove_GetY(Patch);
	
	let px = GetPlayerX();
	let py = GetPlayerY();
	
	let Player = atan2(py - PatchY, px - PatchX);
	
	if(animation==30){
		//Crosshair(Patch, DS_BEAM_WHITE);
		}
	
	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;
		}
		
		if(allow==100){
		
			Shot4SE;
			
			let obj5 = CreateShotA1(PatchX, PatchY, 6, Player, id, 0);
			ObjMove_SetAcceleration(obj5, -0.1);
			ObjMove_SetMaxSpeed(obj5, 1.3);
			
			if(id==165){
				id=167;
				}
			else if(id==167){
				id=168;
				}
			else if(id==168){
				id=170;
				}
			else if(id==170){
				id=172;
				}
			else if(id==172){
				id=165;
				}
			allow=0;
			}
		
		frame++;
		shot++;
		allow++;
		
		if(shot==20){
			let ADDI = 360/5;
			let ANGLE = 0;
			
			//Shot5SE;
			
			loop(7){
				CreateShotA1(PatchX, PatchY, 2, angle+ANGLE, DS_LIGHT_WHITE, 20);
				CreateShotA1(PatchX, PatchY, 2, angle+ADDI+ANGLE, DS_LIGHT_RED, 20);
				CreateShotA1(PatchX, PatchY, 2, angle+ADDI*2+ANGLE, DS_LIGHT_GREEN, 20);
				CreateShotA1(PatchX, PatchY, 2, angle+ADDI*3+ANGLE, DS_LIGHT_YELLOW, 20);
				CreateShotA1(PatchX, PatchY, 2, angle+ADDI*4+ANGLE, DS_LIGHT_BLUE, 20);
				
				ANGLE+=2;
				}
			
			shot=0;
			angle+=20;
			}
		if(frame==60){
			cast2;
			RedLaser;
			WHOOOP;
			}
			
		if(frame==120){
			WHOOOP;
			BlueLaser;
			if(shot>=100){
				shot=0;
				}
			}
			
		if(frame==180){
			frame=0;
			}
		}
	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, 120, DS_NEEDLE_BLUE, 60);
	let obj1 = CreateStraightLaserA1(PatchX+30*cos(angle+90), PatchY+30*sin(angle+90), angle1, 500, 40, 120, DS_NEEDLE_BLUE, 60);
	let obj2 = CreateStraightLaserA1(PatchX+30*cos(angle+180), PatchY+30*sin(angle+180), angle2, 500, 40, 120, DS_NEEDLE_BLUE, 60);
	let obj3 = CreateStraightLaserA1(PatchX+30*cos(angle+270), PatchY+30*sin(angle+270), angle3, 500, 40, 120, 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, 120, DS_NEEDLE_RED, 60);
	let obj1 = CreateStraightLaserA1(PatchX+30*cos(angle+90), PatchY+30*sin(angle+90), angle1, 500, 40, 120, DS_NEEDLE_RED, 60);
	let obj2 = CreateStraightLaserA1(PatchX+30*cos(angle+180), PatchY+30*sin(angle+180), angle2, 500, 40, 120, DS_NEEDLE_RED, 60);
	let obj3 = CreateStraightLaserA1(PatchX+30*cos(angle+270), PatchY+30*sin(angle+270), angle3, 500, 40, 120, 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;
		}
	}
	
