#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Konn Spell 1"]
//#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=0;
let shot=0;
let move=0;
let s = 1;

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(6700)
	}
	
	case(EV_REQUEST_TIMER){
		SetScriptResult(140);
		}
}

@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);
	
	ObjCutin_SetSpellcardS4("Nebula Sword\"Star Cutting Blade\"", GetCurrentScriptDirectory~"AmaneImage.png", YABUSAME, 104, 104, 104);
	ObjCutin_LaunchS3(YABUSAME, GetCurrentScriptDirectory~"KonnCutin.png", "Hard");

	KonnBG(objBoss, GetCurrentScriptDirectory~"woodblock10d.jpg", GetCurrentScriptDirectory~"eff02.png", -5, 0, 250, 300, 256, 256, 1.7, 1.8);
	//BG;
	MCircle(objBoss, GetCurrentScriptDirectory~"e_ef_61.png");

}

@MainLoop{
	animation++;
	
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){
		death(objBoss);
		}
		
	if(animation==40){
		//Slash(objBoss);
		Concentration(objBoss, "STAR", 100, 70, 4, 250, 4, 250, 4, 250);
		BulletConcentration(0, GetStgFrameHeight/2, "STAR", 100, 70, 4, 250, 4, 250, 4, 250);
		BulletConcentration(GetStgFrameWidth, GetStgFrameHeight/2, "STAR", 100, 70, 4, 250, 4, 250, 4, 250);
		}
	
	if(!Obj_IsDeleted(objBoss)){
	if(animation>=130){
	
		ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32);

		ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
		
		move++;
		
		if(move==300){
			ObjMove_SetDestAtFrame(objBoss, rand(80, GetStgFrameWidth-80), rand(90,130), 150);
			move=0;
			}
			
		//frame++;
		
		if(frame==10){
			SlashBullet(rand(0, GetStgFrameWidth), GetStgFrameHeight, 2, 2.6, 270, rand(0, 360), PELLET_GRAY, FIRE_AQUA+500, C_LASER_GRAY, 20, objBoss);
			SlashBullet(rand(0, GetStgFrameWidth), 0, 2, 2.6, 90, rand(0, 360), PELLET_GRAY, FIRE_RED+500, C_LASER_GRAY, 20, objBoss);
			loop(20){
				let obj = CreateShotA1(rand(0, GetStgFrameWidth), GetStgFrameHeight, 0, 0, FIRE_AQUA, 20);
				let obj1 = CreateShotA1(rand(0, GetStgFrameWidth), 0, 0, 0, FIRE_RED, 20);
				ObjShot_SetDeleteFrame(obj, 0);
				ObjShot_SetDeleteFrame(obj1, 0);
				}
			frame=0;
			}
			
		shot++;
		
		if(shot==20){
			SlashBullet2(GetStgFrameWidth, rand(0, GetStgFrameHeight), rand(1, 2.5), 180, rand(0, 360), rand(163, 176), STAR_RED, STAR_GREEN, C_LASER_GRAY, 20, objBoss);
			SlashBullet2(0, rand(0, GetStgFrameHeight), rand(1, 2.5), 0, rand(0, 360), rand(163, 176), STAR_RED, STAR_GREEN, C_LASER_GRAY, 20, objBoss);
			shot=0;
			}
		}
		}
		
	yield;
	}

task SlashBullet(x, y, speed, speed1, angle, angle5, graphic2, graphic1, graphic3, delay, tobj){

	let obj = CreateShotA1(x, y, speed, angle, graphic1, delay);
	//ObjMove_SetAngularVelocity(obj, rand(-1.5, 1.5));
	
	let endX = ObjMove_GetX(obj);
	let endY = ObjMove_GetY(obj);
	
	let ANGLE = angle5;
	let explode=0;

	
	while(!Obj_IsDeleted(obj)){
		let dist = (((ObjMove_GetX(obj)-ObjMove_GetX(tobj))^2)+((ObjMove_GetY(obj)-ObjMove_GetY(tobj))^2))^0.5;
		
		endX = ObjMove_GetX(obj);
		endY = ObjMove_GetY(obj);
	
		if((dist<=50)){
			explode=1;
			Obj_Delete(obj);
			}
		
		yield;
		}
		
		
	if(explode==1){
	let obj1 = CreateStraightLaserA1(endX+120*cos(angle5), endY+120*sin(angle5), angle5+180, 150, 10, 20, graphic3, 0);
	ObjStLaser_SetSource(obj1, false);
	
	loop(3){
		//CreateShotA1(endX, endY, speed1, rand(0, 360), graphic2, 0);
		CreateShotB2(endX, endY, rand(-1, 1), -1, 0.05, 0.03, rand(-1, 1), 4, graphic2, 20);
		}
	}
	}
	
task SlashBullet2(x, y, speed, angle, angle5, graphic2, graphic1, graphic4, graphic3, delay, tobj){

	
	//ObjMove_SetAngularVelocity(obj, rand(-1.5, 1.5));
	
	
	
	let ANGLE = angle5;
	let explode=0;
	let GRAPHIC = graphic1;
	let SLASHCOUNT=truncate(rand(-40, 220));
	if(SLASHCOUNT<=120){
		GRAPHIC=graphic4;
		}

	let obj = CreateShotA1(x, y, speed, angle, GRAPHIC, delay);
	let endX = ObjMove_GetX(obj);
	let endY = ObjMove_GetY(obj);
	while(!Obj_IsDeleted(obj)){
		
		
		endX = ObjMove_GetX(obj);
		endY = ObjMove_GetY(obj);
		
		let dist = (((ObjMove_GetX(obj)-ObjMove_GetX(tobj))^2)+((ObjMove_GetY(obj)-ObjMove_GetY(tobj))^2))^0.5;
	
		if((dist<=80)){
			explode=1;
			Obj_Delete(obj);
			let angle=rand(0, 360);
			CreateStraightLaserA1(endX+80*cos(angle), endY+80*sin(angle), angle+180, 160, 20, 5, graphic3, 0);
			}
		
		
		if(SLASHCOUNT==119){
			angle = rand(0, 360);
			let lasY = endY+80*cos(angle+rand(0, 360));
			let lasX = endX+80*cos(angle+rand(0, 360));
			let obj1 = CreateStraightLaserA1(lasX, lasY, atan2(endY - lasY, endX - lasX), 160, 20, 20, graphic3, 10);
			ObjStLaser_SetSource(obj1, false);
			//ObjLaser_SetIntersectionWidth(obj1, 0);
			
			//let obj2 = CreateLooseLaserA1(lasX, lasY, 60, atan2(endY - lasY, endX - lasX), 400, 20, graphic3, 0);
			ObjShot_SetIntersectionEnable(obj1, false);
			
			explode=1;
			Obj_Delete(obj);
			}	
		SLASHCOUNT++;
		yield;
		}
		
		
	if(explode==1){
	
	
	loop(4){
		//CreateShotA1(endX, endY, speed1, rand(0, 360), graphic2, 0);
		//CreateShotB2(endX, endY, rand(-1, 1), -1, 0.05, 0.03, rand(-1, 1), rand(2, 5), graphic2, 10);
		let angle=rand(0, 360);
		
		CreateShotA1(endX, endY, rand(1, 1.6), angle, graphic2, 10);
		angle+=360/4;
		}
		

	}
	}
	
task Slash(tobj){
	let obj = CreateStraightLaserA1(ObjMove_GetX(tobj), ObjMove_GetY(tobj), 270, 150, 60, 6000, KNIFE_GRAY, 0);
	let ANGLE=270;
	
	while(ObjStLaser_GetAngle(obj)<=270+360){
		ObjStLaser_SetAngle(obj, ANGLE);
		ANGLE+=4;
		yield;
		}
		
	Obj_Delete(obj);
	}