#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell 1A"]
#Text["Patchouli combines Fire and Wood."]
//#Background["./fractal-art-08.jpg"]
#Player["./Reimu/ReimuB.dnh"]


#include"./include.txt"

let Patch;
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=0;
let move=0;

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

@Initialize
{	

	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
	
	Patch = ObjEnemy_Create(OBJ_ENEMY_BOSS);

	//Patch_Regist(objfamiliar1);

	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, 120, 10);
	
	let Stand = GetCurrentScriptDirectory ~ "/Patch_Stand.png";
	
	//cutin(BYAKUREN,Cutin,0,0,500, 600);
	CutinS2("NAZRIN", "Wood and Fire Sign \"Blazing Leaf Hurricane\"", Stand, 240, 104, 104, "Normal");
	
	let imgcircle = GetCurrentScriptDirectory ~ "/e_ef_07.png";
	MCircle(Patch, imgcircle);
	
	Crosshair(Patch, DS_BEAM_WHITE);
	
	let path1 = GetCurrentScriptDirectory ~ "/fractal-art-08.png";
	let path2 = GetCurrentScriptDirectory ~ "/Tex_Stage5BG_04.png";
	
	BG(path1, path2, Patch);
}

@MainLoop{
	animation++;
	
	if(animation==20){
		declare;
		}
	
	let PatchX = ObjMove_GetX(Patch);
	let PatchY = ObjMove_GetY(Patch);
	
	if(animation==80){
		cast2;
		}
	
	if(animation>=85){
	
		ObjEnemy_SetIntersectionCircleToShot(Patch, PatchX, PatchY, 32);

		ObjEnemy_SetIntersectionCircleToPlayer(Patch, PatchX, PatchY, 24);

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

			death;
		}
		
		frame++;
		
		if(frame==8){
			let angle1= angle;
			loop(NUMBER){
				angle1+=360/NUMBER;
				
				let obj = CreateShotA1(GetStgFrameWidth/2, 120, 4, angle1, DS_SCALE_GREEN, 20);
				ObjMove_SetAngularVelocity(obj, -0.7);
								
				ObjMove_AddPatternA3(obj, 40, speed, angle1+rand(45, 90+45), 0, ANG, 0, DS_FIRE_RED);
				
				}
				
			angle+=10;
			Variance+=5;
			frame=0;
			}		
			
		if(move==120){
			ObjMove_SetDestAtSpeed(Patch, rand(PatchX-20, PatchX+20), rand(PatchY-20, PatchX-20), 0.5);
			move=0;
			}
			
		if(angle>=200){
				angle+=rand(0, 360);
				ANG=rand(-0.7, 0.7);
				NUMBER=10;
				speed=rand(1.9, 2.5);
				allow++;
				move++;
				}
				
			if(allow==1){
				ExtraFire;
				}
		
		}
		
	yield;
	}
		
task ExtraFire {

	ChargeSE;
	
	loop{
	
	let PatchX = ObjMove_GetX(Patch);
	let PatchY = ObjMove_GetY(Patch);
	
	shot++;

	if(shot==12){
	
		//Wave3SE;
		
		loop(1){
			angle2+=360/1;
			angle3+=360/1;
				
			CreateShotA1(PatchX, PatchY, 1.5, angle2, DS_BALL_L_YELLOW, 60);
			CreateShotA1(PatchX, PatchY, 1.5, angle3, DS_BALL_L_ORANGE, 60);
			}
		angle2+=18.1;
		angle3-=18.1;
		shot=0;
		}
			
	yield;
	}
	}
	
task death {

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