#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non4"]
#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 angle1 = 270;
let angle3 = 0;
let shot=150;
let allow=0;
let id=165;
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, GetStgFrameHeight/2, 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==100){
		let ADD=360/5;
	
		PatchyLaser(PatchX, PatchY, angle, 400, 40, 400000000, DS_BEAM_WHITE, 120, 1, 160,160);
		PatchyLaser(PatchX, PatchY, angle+ADD, 400, 40, 400000000, DS_BEAM_BLUE, 120, 1, 160,160);
		PatchyLaser(PatchX, PatchY, angle+ADD*2, 400, 40, 400000000, DS_BEAM_GREEN, 120, 1, 160,160);
		PatchyLaser(PatchX, PatchY, angle+ADD*3, 400, 40, 400000000, DS_BEAM_YELLOW, 120, 1, 160,160);
		PatchyLaser(PatchX, PatchY, angle+ADD*4, 400, 40, 400000000, DS_BEAM_RED, 120, 1, 160,160);
		
		PatchyLaser(PatchX, PatchY, angle, 400, 40, 400000000, DS_BEAM_WHITE, 120, -1, 160,160);
		PatchyLaser(PatchX, PatchY, angle+ADD, 400, 40, 400000000, DS_BEAM_BLUE, 120, -1, 160,160);
		PatchyLaser(PatchX, PatchY, angle+ADD*2, 400, 40, 400000000, DS_BEAM_GREEN, 120, -1, 160,160);
		PatchyLaser(PatchX, PatchY, angle+ADD*3, 400, 40, 400000000, DS_BEAM_YELLOW, 120, -1, 160,160);
		PatchyLaser(PatchX, PatchY, angle+ADD*4, 400, 40, 400000000, DS_BEAM_RED, 120, -1, 160,160);
		
		}
	
	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(frame==60){
			
			Walls;
			angle1+=1;
			angle2-=1;
			}
			
		if(frame==64){
			
			Walls;
			angle1+=1;
			angle2-=1;
			}
		
		if(frame==68){
			
			Walls;
			angle1+=1;
			angle2-=1;
			}
			
		if(frame==72){
			
			Walls;
			angle1+=1;
			angle2-=1;
			}
		
		if(frame==76){
			
			Walls;
			angle1+=1;
			angle2-=1;
			
			frame=50;
			angle1+=5;
			angle2-=5;
			}
			
		if(allow==300){
			let pos = rand(100, GetStgFrameWidth-100);
			if(pos>=PatchX){
				rightmove;
				}
				
			if(pos<=PatchX){
				leftmove;
				}
				
			ObjMove_SetDestAtFrame(Patch, pos, rand(80, GetStgFrameHeight-80), 55);
			allow=0;
			
			if(shot>=100){
				shot=0;
				}
			}
			
		frame++;			
		shot++;
		allow++;
		
		if(shot==60){
			let Speed=3;
			loop(6){
				CreateShotA1(PatchX, PatchY, Speed, Player, DS_RICE_M_ORANGE, 20);
				Speed-=0.3;
				}
			shot=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_BEAM_BLUE, 60);
	let obj1 = CreateStraightLaserA1(PatchX+30*cos(angle+90), PatchY+30*sin(angle+90), angle1, 500, 40, 120, DS_BEAM_BLUE, 60);
	let obj2 = CreateStraightLaserA1(PatchX+30*cos(angle+180), PatchY+30*sin(angle+180), angle2, 500, 40, 120, DS_BEAM_BLUE, 60);
	let obj3 = CreateStraightLaserA1(PatchX+30*cos(angle+270), PatchY+30*sin(angle+270), angle3, 500, 40, 120, DS_BEAM_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_BEAM_RED, 60);
	let obj1 = CreateStraightLaserA1(PatchX+30*cos(angle+90), PatchY+30*sin(angle+90), angle1, 500, 40, 120, DS_BEAM_RED, 60);
	let obj2 = CreateStraightLaserA1(PatchX+30*cos(angle+180), PatchY+30*sin(angle+180), angle2, 500, 40, 120, DS_BEAM_RED, 60);
	let obj3 = CreateStraightLaserA1(PatchX+30*cos(angle+270), PatchY+30*sin(angle+270), angle3, 500, 40, 120, DS_BEAM_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 PatchyLaser(x, y, angle, length, width, time, graphic, delay, speed, distx, disty) {
 

        let laser = 0;
       

        let obj = CreateStraightLaserA1(x, y, angle, length, width, time, graphic, delay);
	       
        while(!Obj_IsDeleted(obj)){
                laser+=speed;
               
                ObjMove_SetPosition(obj, x+distx*cos(angle+laser), y+disty*sin(angle+laser));
				
				let obj10 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 5, angle+90, graphic, 20);
				ObjShot_SetDeleteFrame(obj10, 0);

               
                ObjStLaser_SetAngle(obj, angle+laser);

                yield;
                }
        }

task Walls {
	
	let id = 17;
	loop(5){
		let PatchX = ObjMove_GetX(Patch);
		let PatchY = ObjMove_GetY(Patch);
		
				
		angle1+=360/5;
		angle2-=360/5;
					
		let obj5 = CreateShotA1(PatchX+10*cos(angle1), PatchY+10*sin(angle1), 2, angle1, id, 0);
		let obj6 = CreateShotA1(PatchX+10*cos(angle2), PatchY+10*sin(angle2), 2, angle2, id, 0);
				
					
		if(id==17){
			id=19;
			}
		else if(id==19){
			id=20;
			}
		else if(id==20){
			id=22;
			}
		else if(id==22){
			id=24;
			}
		else if(id==24){
			id=17;
			}
		//angle1+=1;
		}
	}