#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell 3"]
#Text["Patchouli combines Moon and Water."]
//#BGM["script/practice/resources/area2_boss.wav"]
#Player["./Reimu/ReimuB.dnh"]

#include"./include.txt"

let Patch;
let Koa;
let Koa1;
let frame=0;
let animation=0;
let angle=0;
let Variance = 5;
let ANG= 0;
let NUMBER = 8;
let speed=2;
let angle1 = 0;
let angle2 = 90;
let angle3 = 0;
let shot=0;
let allow=0;
let move=0;

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

@Initialize
{	
	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
	
	Patch = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Patch);
	
	Koa = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(Koa);
	//Koa1 = ObjEnemy_Create(OBJ_ENEMY);
	//ObjEnemy_Regist(Koa1);
	
	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, 100, 30);
	ObjMove_SetDestAtFrame(Koa, cx, 0, 30);
	//ObjMove_SetDestAtFrame(Koa1, cx, GetStgFrameHeight/2, 30);

	let Stand = GetCurrentScriptDirectory ~ "/Patch_Stand.png";
	
	CutinS2("NAZRIN", "Earth and Water Sign \"The Mariana Trench\"", Stand, 240, 104, 104, "Normal");
	
	let imgcircle = GetCurrentScriptDirectory ~ "/e_ef_07.png";
	MCircle(Patch, imgcircle);
	
	Crosshair(Patch, DS_BEAM_WHITE);
	Crosshair(Koa, DS_BEAM_WHITE); 
	Crosshair(Koa, DS_BEAM_WHITE); 
	Crosshair(Koa, DS_BEAM_WHITE); 
	
	let path1 = GetCurrentScriptDirectory ~ "/elements-water.jpg";
	let path2 = GetCurrentScriptDirectory ~ "/Tex_Stage5BG_04.png";
	
	BG(path1, path2, Patch);
}

@MainLoop{
	animation++;
	
	let PatchX = ObjMove_GetX(Patch);
	let PatchY = ObjMove_GetY(Patch);
	
	let FX = ObjMove_GetX(Koa);
	let FY = ObjMove_GetY(Koa);
	
	if(animation>=80){
	
		loop(2){
		//Trench1(0, rand(0, GetStgFrameHeight), Patch, -60, 5, 0, 90, DS_LIGHT_R_WHITE, 50);
		//Trench1(0, rand(0, GetStgFrameHeight), Patch, -60, 5, 0, 270, DS_LIGHT_R_WHITE, 50);
		//Trench2(GetStgFrameWidth, rand(0, GetStgFrameHeight), Patch, 60, 5, 180, 90, DS_LIGHT_R_WHITE, 50);
		//Trench2(GetStgFrameWidth, rand(0, GetStgFrameHeight), Patch, 60, 5, 180, 270, DS_LIGHT_R_WHITE, 50);
		
		CreateShotA1(rand(FX+60, GetStgFrameWidth), 0, 5, 90, DS_LIGHT_R_WHITE, 5);
		CreateShotA1(rand(FX+60, GetStgFrameWidth), 0, 5, 90, DS_LIGHT_R_BLUE, 5);
		CreateShotA1(rand(FX-60, 0), 0, 5, 90, DS_LIGHT_R_WHITE, 5);
		CreateShotA1(rand(FX-60, 0), 0, 5, 90, DS_LIGHT_R_BLUE, 5);
		}
		}
		
	if(animation>=120){
	
		ObjEnemy_SetIntersectionCircleToShot(Patch, PatchX, PatchY, 32);

		ObjEnemy_SetIntersectionCircleToPlayer(Patch, PatchX, PatchY, 24);
		
		ObjEnemy_SetIntersectionCircleToShot(Patch, FX, FY, 32);

		ObjEnemy_SetIntersectionCircleToPlayer(Patch, FX, FY, 24);
		
		if(ObjEnemy_GetInfo(Patch, INFO_LIFE) <= 0){

			death;
		}
		
		
	
		if(frame==160){
			let pos1 = rand(60, GetStgFrameWidth-60);
			
			if(pos1>=PatchX){
				//leftmove;
				}
			
			if(pos1<=PatchX){
				//rightmove;
				}
			ObjMove_SetDestAtFrame(Koa, pos1, rand(80, 110), 100);
			
			frame=-100;
			}
			
		if(shot==200){
		
			LaserSE;
			
			let obj20 = CreateCurveLaserA1(PatchX, PatchY, 3, 0, 100, 20, DS_RICE_S_WHITE, 20);
			let obj22 = CreateCurveLaserA1(PatchX, PatchY, 3, 0-45, 100, 20, DS_RICE_S_WHITE, 20);
			let obj23 = CreateCurveLaserA1(PatchX, PatchY, 3, 180+45, 100, 20, DS_RICE_S_WHITE, 20);
			let obj21 = CreateCurveLaserA1(PatchX, PatchY, 3, 180, 100, 20, DS_RICE_S_WHITE, 20);
			ObjCrLaser_SetTipDecrement(obj20, 0.0);
			ObjCrLaser_SetTipDecrement(obj23, 0.0);
			ObjCrLaser_SetTipDecrement(obj21, 0.0);
			ObjCrLaser_SetTipDecrement(obj22, 0.0);
			
			Obj_SetRenderPriorityI(obj20,70);
			Obj_SetRenderPriorityI(obj21,70);
			Obj_SetRenderPriorityI(obj22,70);
			Obj_SetRenderPriorityI(obj23,70);
			
			ObjMove_AddPatternA4(obj20, 40, NO_CHANGE, 0, 0, 0, 0, GetPlayerObjectID, NO_CHANGE);
			ObjMove_AddPatternA4(obj20, 80, NO_CHANGE, 0, 0, 0, 0, GetPlayerObjectID, NO_CHANGE);
			ObjMove_AddPatternA4(obj21, 40, NO_CHANGE, 0, 0, 0, 0, GetPlayerObjectID, NO_CHANGE);
			ObjMove_AddPatternA4(obj21, 80, NO_CHANGE, 0, 0, 0, 0, GetPlayerObjectID, NO_CHANGE);
			ObjMove_AddPatternA4(obj22, 40, NO_CHANGE, 0, 0, 0, 0, GetPlayerObjectID, NO_CHANGE);
			ObjMove_AddPatternA4(obj22, 80, NO_CHANGE, 0, 0, 0, 0, GetPlayerObjectID, NO_CHANGE);
			ObjMove_AddPatternA4(obj23, 40, NO_CHANGE, 0, 0, 0, 0, GetPlayerObjectID, NO_CHANGE);
			ObjMove_AddPatternA4(obj23, 80, NO_CHANGE, 0, 0, 0, 0, GetPlayerObjectID, NO_CHANGE);
			
			shot=0;
			
			}
			
		if(allow==20){
			angle+=5;
			angle2-=5;
			
			loop(20){
				angle+=360/20;
				angle2+=360/20;
				
				CreateShotA1(FX, FY, 2, angle, DS_SCALE_SKY, 30);
				CreateShotA1(FX, FY, 2, angle2, DS_SCALE_BLUE, 30);
				}
			allow=0;
			}
			
		allow++;
		shot++;
		frame++;
		}
		
	
	yield;
	
	}
	
task Trench1(x, y, tobj, wall, speed, angle, angle2, graphic, delay){

	let obj = CreateShotA1(x, y, speed, angle, graphic, delay);
	
	while(!Obj_IsDeleted(obj)){
		
		if(ObjMove_GetX(obj)>=ObjMove_GetX(tobj)+wall){
			ObjMove_SetAngle(obj, angle2);
			}
		yield;
		}
	}
	
task Trench2(x, y, tobj, wall, speed, angle, angle2, graphic, delay){

	let obj = CreateShotA1(x, y, speed, angle, graphic, delay);
	
	while(!Obj_IsDeleted(obj)){
		
		if(ObjMove_GetX(obj)<=ObjMove_GetX(tobj)+wall){
			ObjMove_SetAngle(obj, angle2);
			}
		yield;
		}
	}
	
task death {

	Obj_Delete(Patch);
	Obj_Delete(Koa);
	//Obj_Delete(Koa1);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	
	loop(100){	
		DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
		
		yield;
		}
		
	Obj_Delete(Patch);
		
	CloseScript(GetOwnScriptID());
	
	return;
	
	}