#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YuukaNon4"]
#Text["Simple yet wild, like nature."]
//#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=0;
let wind=0;
let petal=0;
let angle=0;
let angle1=0;
let angle2=0;
let wing1 = 45;
let wing2 = wing1+180;
let WINGS = 0;
let spiral=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, 100, 30);


 
}

@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>=80){
		frame++;
		//petal++;
		if(petal==8){
			CreateShotA1(yx, yy, 3, rand(0, 360), DOT_BLUE, 100);
			CreateShotA1(yx, yy, 3, rand(0, 360), DOT_GREEN, 100);
			CreateShotA1(yx, yy, 3, rand(0, 360), DOT_GREEN, 100);
			petal=0;
			}
		if(frame==200){

			loop(6){
				Player+=360/6;
				
				CreateShotA1(yx, yy, 1.2, Player, LARGE_GREEN, 30);
				CreateShotA1(yx, yy, 1.2, Player-3, LARGE_GREEN, 30);
				CreateShotA1(yx, yy, 1.2, Player+3, LARGE_GREEN, 30);
				CreateShotA1(yx, yy, 1.2, Player+6, LARGE_GREEN, 30);
				CreateShotA1(yx, yy, 1.2, Player-6, LARGE_GREEN, 30);
				CreateShotA1(yx, yy, 1.2, Player+9, LARGE_GREEN, 30);
				CreateShotA1(yx, yy, 1.2, Player-9, LARGE_GREEN, 30);
				CreateShotA1(yx, yy, 1.2, Player+12, LARGE_GREEN, 30);
				CreateShotA1(yx, yy, 1.2, Player-12, LARGE_GREEN, 30);
				
				}
			
			frame=0;
			}
		leaf++;
		if(leaf==5){
		
			loop(4){
				angle+=360/4;
				CreateShotA1(yx+30*cos(angle), yy+30*sin(angle), 2, angle, ARROWHEAD_YELLOW, 10);
				CreateShotA1(yx+30*cos(angle), yy+30*sin(angle), 2, -angle, ARROWHEAD_ORANGE, 10);
				}
			
			angle+=7;
			
			leaf=0;
			}
			
		stem++;
		
		if(stem==110){
			ObjMove_SetDestAtSpeed(objYuuka, rand(110, GetStgFrameWidth-110), rand(90, 110), 1);
			stem=0;
			}
			
		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 Wings{

	if(WINGS==0){
		wing1=wing1+1;
		wing2=wing2-1;
		}
		
	if(WINGS==1){
		wing1=wing1-1;
		wing2=wing2+1;
		}
		
	if(wing1>=80){
		WINGS=1;
		}
	
	if(wing1<=0){
		WINGS=0;
		}

	let yx = ObjMove_GetX(objYuuka);
	let yy = ObjMove_GetY(objYuuka);
	
	let va= rand(-5, 5);
	
	CreateShotA1(yx, yy, 5, wing1+va, PCB_LARGE_RED, 30);
	CreateShotA1(yx, yy, 5, wing1+180+va, PCB_LARGE_RED, 30);
	CreateShotA1(yx, yy, 5, wing1+270+va, PCB_LARGE_RED, 30);
	CreateShotA1(yx, yy, 5, wing2+va, PCB_LARGE_YELLOW, 20);
	CreateShotA1(yx, yy, 5, wing2+110+va, PCB_LARGE_YELLOW, 20);
	CreateShotA1(yx, yy, 5, wing2+270+va, PCB_LARGE_YELLOW, 20);
	
	}
	
task Wall{

	let angle=0;
	
	let yx = ObjMove_GetX(objYuuka);
	let yy = ObjMove_GetY(objYuuka);
	let px = GetPlayerX();
	let py = GetPlayerY();
	
	let player = atan2(py - yy, px - yx);
	
	loop(3){
		angle+=360/3;
		
		CreateShotA1(yx, yy, 0.6, player+angle, BUBBLE_RED, 0);
		CreateShotA1(yx, yy, 0.6, player+angle+6, BUBBLE_RED, 1);
		CreateShotA1(yx, yy, 0.6, player+angle-6, BUBBLE_RED, 1);
		CreateShotA1(yx, yy, 0.6, player+angle-12, BUBBLE_RED, 2);
		CreateShotA1(yx, yy, 0.6, player+angle+12, BUBBLE_RED, 2);
		}
	}

task BounceShotA1(x, y, speed, angle, graphic, delay)
{
		let obj = CreateShotA1(x, y, speed, angle, graphic, delay);
		let angle1=0;
		let explode=0;
		
		ObjShot_SetAutoDelete(obj, false);
		
		let endX = 0;
		let endY = 0;
		
		while(!Obj_IsDeleted(obj))
		{
			endX = ObjMove_GetX(obj);
			endY = ObjMove_GetY(obj);
			if(ObjMove_GetX(obj) > GetStgFrameWidth)
			{
				Obj_Delete(obj);
				angle1=180;
				explode=1;
			}
			if(ObjMove_GetX(obj) < 0)
			{
				Obj_Delete(obj);
				angle1=0;
				explode=1;
			}
			if(ObjMove_GetY(obj) < 0)
			{
				Obj_Delete(obj);
				angle1=90;
				explode=1;
			}
			if(ObjMove_GetY(obj) > GetStgFrameHeight){
				Obj_Delete(obj);
				angle1=270;
				//explode=1;
				}
			//ObjMove_SetAcceleration(obj, angVel);
			yield;
		}

		let obj1 = CreateShotA1(endX, endY, speed, angle, graphic, 10);
		ObjMove_AddPatternA4(obj1, 0, speed, 0, 0.1, 0, 2, GetPlayerObjectID, NO_CHANGE);
		}
