#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YuukaNon5"]
#Text["Yuuka is calling in the magic of the world for her final attack."]
//#BGM["script/Kazami/resources/sounds/area4_boss.wav"]

#include"script/Kazami/AllStars shot/AllStarShot_Const.dnh"


let objYuuka;
let clone;
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;
let level = 1;
let spellname = 0;
let objtext;

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

@Initialize
{	
	objYuuka= ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objYuuka);
	
	clone= ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(clone);

	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).
	
	ObjSprite2D_SetSourceRect(clone, 39, 30, 95, 101); //Setting the rectangle coordinates in the enemy image to use(Left, Top, Right, Bottom).

	ObjSprite2D_SetDestCenter(clone); //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, 120, 60);
	
	MCircle(objYuuka);


 
}

@MainLoop{

	if(spellname==1){

		objtext = ObjText_Create();
		ObjText_SetText(objtext, "Sky Buster: Emerald Sunlight on the Glades");
     	Obj_SetRenderPriority(objtext, 0.74);//Render above cutin
     	ObjText_SetFontSize(objtext, 13);
     	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+5, 20, 0);
     	ObjMove_SetDestAtFrame(objtext, 267, 23, 6);

	}
	
	spellname++;
	
	//
	
	if(ObjEnemy_GetInfo(objYuuka, INFO_LIFE) <= 5000){
		level++;
		}
		
	if(level==2){
		DeleteShotAll(TYPE_ALL, TYPE_FADE);
		}
	
	
	//

	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){
	
		//
		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;
		}
		//
	
		frame++;
		
		leaf++;
			
		if(level<=1){
		
			if(frame==30){
			let angle=rand(0, 360);
			loop(28){
				angle+=360/28;
				let id = rand(130, 143);
				let cx = GetStgFrameWidth() / 2;
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2, angle+75, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2.06, angle+75, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2.12, angle+75, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2.18, angle+75, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2.24, angle+75, id, 20);
				}
			frame=0;
			}
			
			stem++;
			if(stem==300){
				//ObjMove_SetDestAtFrame(objYuuka, GetPlayerX(), 120, 1);
				}
			if(stem==305){
				let angle1 = rand(0, 360);
				let delay = 60;
				loop(50){
					angle1+=360/50;
					let obj = CreateShotA1(yx+35*cos(angle1), yy+35*sin(angle1), rand(1, 3), rand(0, 360), rand(276, 282), 140);
					let obj1 = CreateShotA1(yx+35*cos(angle1), yy+35*sin(angle1), rand(1, 3), rand(0, 360), rand(276, 282), 140);
					let obj2 = CreateShotA1(yx, yy, rand(1, 3), rand(0, 360), rand(276, 282), 140);
					}
				CreateStraightLaserA1(yx, yy, Player+10, 530, 110, 30, SMALL_GREEN, 60);
				CreateStraightLaserA1(yx, yy, Player, 530, 110, 30, SMALL_GREEN, 60);
				CreateStraightLaserA1(yx, yy, Player-10, 530, 110, 30, SMALL_GREEN, 60);
				stem=0;
				}
			}
		if(level>=10){
		
			ObjEnemy_SetDamageRate(objYuuka, 75, 0);
			
			let cx = GetStgFrameWidth() / 2;
			
			ObjMove_SetDestAtFrame(objYuuka, cx, 120, 1);
			ObjMove_SetDestAtFrame(clone, GetStgFrameWidth-50, 110, 1);
			
			let clonex=ObjMove_GetX(clone);
			let cloney=ObjMove_GetY(clone);
			
			stem=0;
		
			wind++;
			petal++;
			
			if(frame==30){
			let angle=rand(0, 360);
			loop(28){
				angle+=360/28;
				let id = rand(130, 143);
				let cx = GetStgFrameWidth() / 2;
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2, angle+1, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2, angle-1, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2, angle+2, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2, angle-2, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2, angle+3, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2, angle-3, id, 20);
				CreateShotA1(cx+70*cos(angle), 120+25*sin(angle), 2, angle, id, 20);
				}
			frame=0;
			}
			
			if(petal==120){
			let angle1=rand(0, 360);
				loop(30){
				angle1+=360/30;
				let obj = CreateLooseLaserA1(50+45*cos(angle1), 120+45*sin(angle1), 1.4, angle1, 120, 10, LARGE_GREEN+500, 100);
				
				let obj3 = CreateLooseLaserA1(clonex+45*cos(angle1), cloney+45*sin(angle1), 1.4, angle1, 120, 10, LARGE_GREEN+500, 100);

				petal=0;
				}
				}
			if(wind==60){
			
				CreateStraightLaserA1(50, 110, 80, 530, 170, 100000, SMALL_GREEN, 60);
				CreateStraightLaserA1(50, 110, 90, 530, 170, 100000, SMALL_GREEN, 60);
				CreateStraightLaserA1(50, 110, 100, 530, 170, 100000, SMALL_GREEN, 60);
				
				CreateStraightLaserA1(ObjMove_GetX(clone), ObjMove_GetY(clone), 80, 530, 170, 100000, SMALL_GREEN, 60);
				CreateStraightLaserA1(ObjMove_GetX(clone), ObjMove_GetY(clone), 90, 530, 170, 100000, SMALL_GREEN, 60);
				CreateStraightLaserA1(ObjMove_GetX(clone), ObjMove_GetY(clone), 100, 530, 170, 100000, SMALL_GREEN, 60);
				}
			}
		}
	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;
		}
	}
	
	}