#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YuukaNon2"]
#Text["Yuuka's signature spinning red and yellow bullets. it's a bit disorienting..."]
#BGM["script/Kazami/resources/sounds/lullaby of a magical girl.ogg"]

#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(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, 30);


 
}

@MainLoop{

	if(animation==49){
		//Concentration(objYuuka);
		}
	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>=80){
		
		if(frame==60){
		
			Spin;
				
			loop(15){
				angle2+=360/15;
				//CreateShotA1(yx, yy, 1, angle2, BL_SMALL_BLUE, 0);
				//CreateShotA1(yx, yy, 3, angle2, BL_SMALL_GREEN, 0);
				}
			}
			
		if(frame==90){
			Spin;
			}
		
		if(frame==120){
			Spin;
			}
		
		leaf++;
		
		if(leaf==150){
			let DELAY=5;
			ObjMove_SetDestAtSpeed(objYuuka, rand(50, GetStgFrameWidth-50), rand(80, 120), 4);
			loop(10){
				let angle= Player;
				DELAY+=8;
				
				loop(30){
					angle+=360/30;
					CreateShotA1(yx, yy, 5, angle, ARROWHEAD_GREEN, DELAY);
					}

				}
			}
		
		if(leaf==160){
			frame=0;
			leaf=0;
			}
					
			
		frame++;
		
		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_RGB);
	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;
		}
		}
	
	}
	
task Spin{

	let angle=rand(0,360);
	let angle1=rand(0,360);
	
	let yx = ObjMove_GetX(objYuuka);

	let yy = ObjMove_GetY(objYuuka);
			
	loop(30){
		angle+=360/30;
			
		let obj = CreateShotA1(yx, yy, 2, angle, BL_SMALL_YELLOW, 20);
		ObjMove_SetAngularVelocity(obj, -0.3);
		}
			
		loop(35){
			angle1+=360/35;
				
			let obj = CreateShotA1(yx, yy, 2, angle1, BL_SMALL_RED, 20);
			ObjMove_SetAngularVelocity(obj, 0.3);
				
			}
		}