#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Konn Nonspell 3"]
//#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=270;
let angle1=90;
let shot=0;
let move=0;
let s = -1;
let allow=1;
let DIRECTION=1;

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

@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);
		}
	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==300){
			if(allow<=110){
				//ObjMove_SetDestAtFrame(objBoss, rand(80, GetStgFrameWidth-80), rand(90,130), 150);
				}
			move=0;
			}
			
		frame++;
		
		if(frame==15){
			if(allow==1){
				angle+=8.31;
				}
			if(allow==2){
				angle-=8.31;
				}
			if(angle>=360-55){
				allow=2;
				}
				
			if(angle<=180+55){
				allow=1;
				}
			
			Wave(objBoss, angle);
			frame=0;
			}
			
		shot++;
		
		if(shot==120){
			let lasX = rand(-20, GetStgFrameWidth+20);
			let lasY = rand(-10, -30);
			
			let LASANGLE = atan2(GetPlayerY()-lasY, GetPlayerX() - lasX)+rand(-2, 2);
			
			CreateStraightLaserA1(lasX, lasY, LASANGLE, 640, 20, 40, ST_LASER_GRAY, 50);
			CreateLooseLaserA1(lasX, lasY, 40, LASANGLE, 640, 40, PELLET_GRAY, 50);
			CHINK;
			}
			
			
		if(shot==140){
			let lasX = rand(-20, GetStgFrameWidth+20);
			let lasY = rand(-10, -30);
			
			let LASANGLE = atan2(GetPlayerY()-lasY, GetPlayerX() - lasX)+rand(-2, 2);
			
			CreateStraightLaserA1(lasX, lasY, LASANGLE, 640, 20, 40, ST_LASER_GRAY, 50);
			CreateLooseLaserA1(lasX, lasY, 40, LASANGLE, 640, 40, PELLET_GRAY, 50);
			CHINK;
			}
			
		if(shot==160){
			let lasX = rand(-20, GetStgFrameWidth+20);
			let lasY = rand(-10, -30);
			
			let LASANGLE = atan2(GetPlayerY()-lasY, GetPlayerX() - lasX)+rand(-2, 2);
			
			CreateStraightLaserA1(lasX, lasY, LASANGLE, 640, 20, 40, ST_LASER_GRAY, 50);
			CreateLooseLaserA1(lasX, lasY, 40, LASANGLE, 640, 40, PELLET_GRAY, 50);
			CHINK;
			shot=60;
			}
		}
		}
	yield;
	}
	
task Wave(tobj, angle){
	let MOD = 15.1;
	let obj = CreateShotB2(ObjMove_GetX(tobj)+5, ObjMove_GetY(tobj)-35, 2*cos(angle), 2*sin(angle), 0, 1/30, 1, rand(1.5, 2.5), FIRE_RED+500, 10);
	SetSpecialDelete(obj, FIRE_RED);
	loop(5){
		let obj1 = CreateShotB2(ObjMove_GetX(tobj)+5, ObjMove_GetY(tobj)-35, 2*cos(angle-MOD), 2*sin(angle-MOD), 0, 1/30, 1, rand(1.5, 2.5), FIRE_RED+500, 10);
		let obj2 = CreateShotB2(ObjMove_GetX(tobj)+5, ObjMove_GetY(tobj)-35, 2*cos(angle+MOD), 2*sin(angle+MOD), 0, 1/30, 1, rand(1.5, 2.5), FIRE_RED+500, 10);
		SetSpecialDelete(obj1, FIRE_RED);
		SetSpecialDelete(obj2, FIRE_RED);
		MOD+=15.1;
		}
	}
		