#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YuukaNon1"]
#Text["Simple yet wild, like nature."]
//#BGM["script/Kazami/resources/sounds/area4_boss.wav"]

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


let objYuuka;
let bConcentrationMotion = false;
let frame=0;
let objPlayer;
let Target=0;
let wave=0;
let leaf=0;
let animation=0;
let Aim=0;
let stem=120;
let wind=0;
let petal=0;
let angle=0;
let angle1=0;
let angle2=0;

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

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


 
}

@MainLoop{

	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==60){
		//Concentration(objYuuka);
		}

	if(animation>=80){
		if(frame==120){
			wave= rand(0, 360);
			
			loop(30){
				wave+= 360/30;
				let spin = 0.3;
				
				//let obj1 = CreateShotA1(yx, yy, 2, wave, BL_SMALL_RED, 20);
				//let obj2 = CreateShotA1(yx, yy, 2, wave, BL_SMALL_ORANGE, 20);
				
				
				//ObjMove_SetAngularVelocity(obj1, spin);
				//ObjMove_SetAngularVelocity(obj2, -spin);
				
				
				}						
			
			frame=0;
			}

		if(petal==7){
			angle+=5;
			angle2+=5;
			angle1+=8;
			
			loop(8){
				angle+=360/6;
				angle1+=360/6;
				angle2+=360/6;
				angle2+=3;
				
				CreateShotA1(yx+stem*cos(angle), yy+stem*sin(angle), 3, angle+160, PELLET_GREEN, 10);
				CreateShotA1(yx+-stem*cos(angle), yy+-stem*sin(angle), 3, -angle+1+160+180, PELLET_BLUE, 30);
				CreateShotA1(yx+20*cos(angle1), yy+20*sin(angle1), 3, angle1+45+180, PELLET_AQUA, 13);
				}
				

			petal=0;
			}

		if(wind==320){
			
			ObjMove_SetDestAtSpeed(objYuuka, rand(70, GetStgFrameWidth-70), rand(60, 120), 1);	

			wind=0;
			
			}

		petal++;

		wind++;

		frame++;
		
		if(stem<=-160){
			leaf=1;
			}
		if(stem>=160){
			leaf=0;
			}
		if(leaf==0){
			stem--;
			}
		if(leaf==1){
			stem++;
			}

		ObjEnemy_SetIntersectionCircleToShot(objYuuka, yx, yy, 32);

		ObjEnemy_SetIntersectionCircleToPlayer(objYuuka, yx, yy, 24);

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

			Obj_Delete(objYuuka);
	
			DeleteShotAll(TYPE_ALL, TYPE_ITEM);
			
			CloseScript(GetOwnScriptID());
	
			return;
		}
		}
	
	animation++;
	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);
	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;
		}
		}
	
	}