#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YuukaSpell2"]
#Text["With those walls of vines coming down, it kind of makes you think of a split sea, or something."]
//#BGM["script/Kazami/resources/sounds/area4_boss.wav"]

#include"script/Kazami/AllStars shot/AllStarShot_Const.dnh"
#include"script/default_system/Default_Effect.txt"

let objYuuka;
let bConcentrationMotion = false;
let frame=0;
let objPlayer;
let Target=90;
let Wave=0;
let leaf=0;
let animation=0;
let Aim=GetStgFrameWidth;
let stem=0;
let objtext;
let spellname=1;
let shot=0;
let angle1=0;

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

@Initialize
{	

	objYuuka = ObjEnemy_Create(OBJ_ENEMY_BOSS);

	ObjEnemy_Regist(objYuuka);

	let imgYuuka = GetCurrentScriptDirectory ~ "resources/images/dot_yuka.png"; //file path to enemy image

	ObjPrim_SetTexture(objYuuka, imgYuuka); //Setting the above image file as a texture to the enemy object(objEnemy)

	ObjSprite2D_SetSourceRect(objYuuka, 39, 30, 95, 101); //Setting the rectangle coordinates in the enemy image to use(Left, Top, Right, Bottom).

	ObjSprite2D_SetDestCenter(objYuuka); //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(objYuuka, cx, 80, 40);
	
 
}

@MainLoop{

	if(spellname==1){

	objtext = ObjText_Create();
	ObjText_SetText(objtext, "Ruined Paradise: Murder in the Garden of Eden");
     	Obj_SetRenderPriority(objtext, 0.74);//Render above cutin
     	ObjText_SetFontSize(objtext, 14);
     	ObjText_SetFontColorTop(objtext, 0, 136, 0);
     	ObjText_SetFontColorBottom(objtext, 0, 136, 0);
     	ObjText_SetFontBold(objtext, false);
     	ObjText_SetFontBorderType(objtext, BORDER_SHADOW);
    	ObjText_SetFontBorderColor(objtext, 232, 232, 232);
     	ObjText_SetFontBorderWidth(objtext, 1);
     	ObjRender_SetPosition(objtext, GetStgFrameLeft-10, 20, 0);
     	ObjMove_SetDestAtFrame(objtext, GetStgFrameLeft-10, 23, 6);

	}

	spellname++;

	let yx = ObjMove_GetX(objYuuka);

	let yy = ObjMove_GetY(objYuuka);
	
	let px = GetPlayerX();
	let py = GetPlayerY();

	let Player = atan2(py - yy, px - yx);
	if(animation==45){
	//	Concentration(objYuuka)
		}
		
	if(animation==85){
		MCircle(objYuuka);
		}
		
	if(animation>=90){
		if(frame==4){
			let angle=360/10;
			//let angle1=180;
			
			loop(10){
				angle+=360/10;
				//angle1-=360/10;
			
				CreateShotA1(yx+140*cos(Target), yy+30*sin(Target), 3, angle, ARROWHEAD_GREEN, 20);
				
				}
			

			frame=0;
	
			}
			
		if(Wave==10){
			
			loop(15){
				//angle+=360/20;
				angle1-=360/15;
			
				let obj = CreateShotA1(yx+140*cos(Target+180), yy+30*sin(Target+180), 3, angle1, KUNAI_RED, 20);
				ObjMove_SetAngularVelocity(obj, 0.15);
				
				}
			angle1+=20;
			Wave=0;
			}
			
		if(stem==20){
			let angle=rand(0,360);
			loop(10){
				angle+=360/10;
				let obj = CreateShotA1(yx, yy, 3, angle, LARGE_ORANGE, 10);
							
				}
			stem=0;
			}
			
		Wave++;

		frame++;
		
				
			
		Target-=1.8;
		Aim+=1.8;
		

		stem++;

		ObjEnemy_SetIntersectionCircleToShot(objYuuka, yx, yy, 32);

		ObjEnemy_SetIntersectionCircleToPlayer(objYuuka, yx, yy, 24);

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

			Obj_Delete(objYuuka);

			Obj_Delete(objtext);
	
			DeleteShotAll(TYPE_ALL, TYPE_ITEM);
			
			CloseScript(GetOwnScriptID());
	
			return;
		}

		}

	animation++;	
	yield;
}

task MCircle(tobj){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let path = "script/Kazami/resources/images/e_ef_61.png";
	ObjPrim_SetTexture(obj,path);
	
	Obj_SetRenderPriorityI(obj,20);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj,200);
	let sx = (300-0)/2; let sy = (300-0)/2; //taken from BG code, don't know what it does.
	ObjSprite2D_SetSourceRect(obj,0,0,256, 256);
	
	ObjRender_SetPosition(obj,ObjMove_GetX(objYuuka),ObjMove_GetY(objYuuka),0);
	ObjSprite2D_SetDestRect(obj,-sx,-sy,sx,sy); //taken from BG code, don't know what it does.
	
	spinBG;
 
	task spinBG{
		let spin = 0;
		loop{
		let life = ObjEnemy_GetInfo(objYuuka, INFO_LIFE);
		ObjRender_SetAngleXYZ(obj,0,0,spin);
		ObjRender_SetPosition(obj,ObjMove_GetX(tobj),ObjMove_GetY(tobj),0);
		ObjRender_SetScaleXYZ(obj,life/4000,life/4000,0);
		spin+=-0.5;
		yield;
		}
	}
	
	}
	
task Concentration(tobj){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let path = "script/Kazami/resources/images/e_ef_02.png";
	ObjPrim_SetTexture(obj,path);
	
	Obj_SetRenderPriorityI(obj,20);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj,255);
	let sx = (300-0)/2; let sy = (300-0)/2;
	ObjSprite2D_SetSourceRect(obj,0,0,256, 256);
	
	ObjRender_SetPosition(obj,ObjMove_GetX(objYuuka),ObjMove_GetY(objYuuka),0);
	ObjSprite2D_SetDestRect(obj,-sx,-sy,sx,sy);
	
	spinBG;
 
	task spinBG{
		let spin = 0;
		let conc = 1.5;
		loop{
		let life = ObjEnemy_GetInfo(objYuuka, INFO_LIFE);
		ObjRender_SetAngleXYZ(obj,0,0,spin);
		ObjRender_SetPosition(obj,ObjMove_GetX(tobj),ObjMove_GetY(tobj),0);
		ObjRender_SetScaleXYZ(obj,conc,conc,0);
		
		conc-=0.03;
		spin+=-1;
		
		if(conc<=0){
		Obj_Delete(obj)
			}
		yield;
		}
		}
	
	}