#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Konn Nonspell 4"]
//#Background["./AmaneBG/bg.txt"]
#BGM["./LegendofKAGE.mp3"]
#Player["./Reimu_ultimadragon/Reimu.txt"]

#include"./Include.txt"

let objBoss;
let frame=0;
let Aim=0;
let Around=0;
let animation=0;
let angle=90;
let angle1=90;
let shot=0;
let move=0;
let s = -1;
let allow=0;
let DIRECTION=1;

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(6000)
	}
	
	case(EV_REQUEST_TIMER){
		SetScriptResult(120);
		}
}

@Initialize
{	
	objBoss= ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);

	let imgExRumia = GetCurrentScriptDirectory ~ "Kongaara.png"; //file path to enemy image

	ObjPrim_SetTexture(objBoss, imgExRumia); //Setting the above image file as a texture to the enemy object(objBoss)

	ObjSprite2D_SetSourceRect(objBoss, 0, 0, 56, 62); //Setting the rectangle coordinates in the enemy image to use(Left, Top, Right, Bottom).

	ObjSprite2D_SetDestCenter(objBoss); //Positioning the center of the rectangle(w/texture) at (0, 0) on the stage(top left corner).

	ObjRender_SetScaleXYZ(objBoss, 1.2, 1.2, NULL);
	
	let cx = GetStgFrameWidth() / 2;

	ObjMove_SetDestAtFrame(objBoss, cx, 110, 30);
	
	//BACKG(path3, path1, objBoss);
	
	//CutinS2("NAZRIN", "Nebula Sword \"Star Cutting Sword\"", GetCurrentScriptDirectory~"AmaneImage.png", 104, 104, 104, "Hard");

	//BG;

	SpellBG(objBoss, GetCurrentScriptDirectory~"Smoke.png");
	MCircle(objBoss, GetCurrentScriptDirectory~"p_ef_17.png");
}

@MainLoop{
	animation++;
	
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){
		death(objBoss);
		}
		
	if(animation==40){
		//Slash(objBoss);
		}
		
	if(animation==60){
		Concentration(objBoss, "STAR", 80, 40, 250, 250, 4, 104, 4, 40);
		//EndLasers(objBoss);
		}
		
	if(!Obj_IsDeleted(objBoss)){
	if(animation>=140){

	
		ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32);

		ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
		
		
			
		move++;
		
		if(move==400){
			ObjMove_SetDestAtFrame(objBoss, rand(40, GetStgFrameWidth-40), rand(50, 120), 80);
			
			
			move=0;
			}
			
		frame++;
		
		if(frame==12){
			let NUM = 3;
			angle+=12.31;
			angle1-=12.31;
			
			loop(NUM){
				angle+=360/NUM;
				angle1+=360/NUM;
				
				let obj1 = CreateShotA1(ObjMove_GetX(objBoss)+30*cos(angle1), ObjMove_GetY(objBoss)+30*sin(angle1), 2, angle1+1.3, KNIFE_RED, 10);
				let obj2 = CreateShotA1(ObjMove_GetX(objBoss)+30*cos(angle1), ObjMove_GetY(objBoss)+30*sin(angle1), 2, angle1-1.3, KNIFE_RED, 10);
				SetSpecialDelete(obj1, KNIFE_RED);
				SetSpecialDelete(obj2, KNIFE_RED);
				
				let obj3 = CreateShotA1(ObjMove_GetX(objBoss)+60*cos(angle), ObjMove_GetY(objBoss)+60*sin(angle), 1.7, angle+1.3+180, AMULET_ORANGE, 10);
				let obj4 = CreateShotA1(ObjMove_GetX(objBoss)+60*cos(angle), ObjMove_GetY(objBoss)+60*sin(angle), 1.7, angle-1.3+180, AMULET_ORANGE, 10);
				SetSpecialDelete(obj3, AMULET_ORANGE);
				SetSpecialDelete(obj4, AMULET_ORANGE);
				}
			
			frame=0;
			}
			
		shot++;
		
		if(shot==150){
			let angle1=rand(0, 360);
			
			Shot4SE;
			
			loop(10){
				angle1+=360/10;
				OHGODSHOT(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), ObjMove_GetX(objBoss)+90*cos(angle1), ObjMove_GetY(objBoss)+90*sin(angle1), BL_SMALL_BLUE, BUTTERFLY_BLUE, 16, 1, 0.15);
				}
				
			shot=-100;
			}
			
		
		}
		}
		
	yield;
	}
	
task OHGODSHOT(X, Y, DESTX, DESTY, GRAPHIC, GRAPHIC1, BULLCOUNT, INSPEED, MOD){

	let obj = CreateShotA1(X, Y, 0, 0, GRAPHIC, rand(0, 20));
	
	ObjMove_SetDestAtFrame(obj, DESTX, DESTY, 70);
	ObjShot_SetSpellResist(obj, true);
	
	let endX = ObjMove_GetX(obj);
	let endY = ObjMove_GetY(obj);
	
	let frame=0;
	
	while(!Obj_IsDeleted(obj)){
		
		endX = ObjMove_GetX(obj);
		endY = ObjMove_GetY(obj);
		
		frame++;
		
		if(frame>=70){
			Obj_Delete(obj);
			}
		
		yield;
		}
		
	Shot4SE;
		
	let angle = atan2(GetPlayerY() - endY, GetPlayerX - endX)+rand(-6, 6);
	let SPEED = INSPEED;
	loop(BULLCOUNT){
		let obj3 = CreateShotA1(endX, endY, SPEED, angle, GRAPHIC1, 10);
		SetSpecialDelete(obj3, GRAPHIC1);
		SPEED+=MOD;
		}
	}