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

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(7800)
	}
	
	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);
	
	//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==20){
			let lasY = rand(GetStgFrameHeight+20, GetStgFrameHeight+40);
			let lasX = rand(-10, GetStgFrameWidth+10);
			let obj1 = CreateStraightLaserA1(lasX, lasY, rand(250, 290), 640, 20, 20, C_LASER_GRAY, 50);
			
			frame=0;
			}
			
		shot++;
		
		if(shot==-65){
			Concentration(objBoss, "STAR", 80, 40, 250, 250, 4, 104, 4, 40);
			}
		
		if(shot==4){
			let obj= CreateShotA1(ObjMove_GetX(objBoss)+30*cos(angle), ObjMove_GetY(objBoss)+30*sin(angle), rand(1, 2), angle, KNIFE_RED, 10);
			let obj4 = CreateShotA1(ObjMove_GetX(objBoss)+30*cos(angle1), ObjMove_GetY(objBoss)+30*sin(angle1),rand(1, 2), angle1, KNIFE_RED, 10);
			SetSpecialDelete(obj, KNIFE_RED);
			SetSpecialDelete(obj4, KNIFE_RED);
			
			let obj2= CreateShotA1(ObjMove_GetX(objBoss)+30*cos(angle), ObjMove_GetY(objBoss)+30*sin(angle), rand(0.5, 1), angle, KNIFE_RED, 10);
			let obj5 = CreateShotA1(ObjMove_GetX(objBoss)+30*cos(angle1), ObjMove_GetY(objBoss)+30*sin(angle1),rand(0.5, 1), angle1, KNIFE_RED, 10);
			SetSpecialDelete(obj, KNIFE_RED);
			SetSpecialDelete(obj4, KNIFE_RED);
					
			angle+=8.13;
			angle1-=8.13;
			
			
			allow++;
			
			if(allow<=120){
				shot=0;
				}
			}
			
			
		if(shot==55){
			Concentration(objBoss, "STAR", 80, 40, 250, 250, 4, 104, 4, 40);
			Wave3SE;
			if(DIRECTION == 1){

				loop(30){
					let star1x = rand(-50, -30);
					let star2x = rand(GetStgFrameWidth+50, GetStgFrameWidth+30);
					let stary = rand(0, GetStgFrameHeight);
					let obj1 = CreateShotA1(star1x, stary, rand(0.5, 3), atan2(GetPlayerY() - stary, GetPlayerX() - star1x)+rand(-10, 10), S_STAR_GRAY, rand(5, 60));
					let obj2 = CreateShotA1(star2x, stary, rand(0.5, 3), atan2(GetPlayerY() - stary, GetPlayerX() - star2x)+rand(-10, 10), S_STAR_GRAY, rand(5, 60));
					SetSpecialDelete(obj1, S_STAR_GRAY);
					SetSpecialDelete(obj2, S_STAR_GRAY);
					}
				}
				
			if(DIRECTION == -1){
				
				loop(30){
					let starx = rand(0, GetStgFrameWidth);
					let star1y = rand(-50, -30);
					let star2y = rand(GetStgFrameHeight+30, GetStgFrameHeight+50);
					let obj1 = CreateShotA1(starx, star1y, rand(0.5, 3), atan2(GetPlayerY() - star1y, GetPlayerX() - starx)+rand(-10, 10), S_STAR_GRAY, rand(5, 60));
					let obj2 = CreateShotA1(starx, star2y, rand(0.5, 3), atan2(GetPlayerY() - star2y, GetPlayerX() - starx)+rand(-10, 10), S_STAR_GRAY, rand(5, 60));
					SetSpecialDelete(obj1, S_STAR_GRAY);
					SetSpecialDelete(obj2, S_STAR_GRAY);
					}
				}
				
			DIRECTION*=s;
			}
			
		if(shot==200){
			Concentration(objBoss, "STAR", 80, 40, 250, 250, 4, 104, 4, 40);
			}
			
		if(shot==280){			
			CreateStraightLaserA1(GetPlayerX(), -20, 90, 640, 20, 40, ST_LASER_GRAY, 30);
			CreateLooseLaserA1(GetPlayerX(), -50, 40, 90, 640, 40, PELLET_GRAY, 30);
			CHINK;
			}
			
		if(shot==320){
			CreateStraightLaserA1(GetPlayerX(), -20, 90, 640, 20, 40, ST_LASER_GRAY, 30);
			CreateLooseLaserA1(GetPlayerX(), -50, 40, 90, 640, 40, PELLET_GRAY, 30);
			CHINK;
			}
			
		if(shot==360){
			CreateStraightLaserA1(GetPlayerX(), -20, 90, 640, 20, 40, ST_LASER_GRAY, 30);
			CreateLooseLaserA1(GetPlayerX(), -50, 40, 90, 640, 40, PELLET_GRAY, 30);
			CHINK;
			}
			
		if(shot==400){
			CreateStraightLaserA1(GetPlayerX(), -20, 90, 640, 20, 40, ST_LASER_GRAY, 30);
			CreateLooseLaserA1(GetPlayerX(), -50, 40, 90, 640, 40, PELLET_GRAY, 30);
			CHINK;
			}
			
		if(shot==440){
			ObjMove_SetDestAtFrame(objBoss, GetPlayerX(),  rand(90,130), 30);
			move=-100;
			}
			
		if(shot==460){
			Concentration2(objBoss, GetCurrentScriptDirectory~"star.png", 150, 60, 128, 128, 0.003, 1.5);
			}
			
		if(shot==480){
			Warning;
			
			GreatSlash(objBoss);
			shot=-250;
			allow=0;
			}
		}
		}
		
	yield;
	}
	
task GreatSlash(tobj){
	let obj = CreateStraightLaserA1(ObjMove_GetX(objBoss)-80, -50, 90, 640, 250, 80, ST_LASER_GRAY, 100);
	let obj1 = CreateStraightLaserA1(ObjMove_GetX(objBoss)+80, -50, 90, 640, 250, 80, ST_LASER_GRAY, 100);
	
	ObjShot_SetDeleteFrame(obj1, 0);
	ObjShot_SetDeleteFrame(obj, 0);
	
	CreateLooseLaserA1(ObjMove_GetX(tobj), -50, 40, 90, 640, 340, PELLET_GRAY, 100);
	
	
	
	ObjStLaser_SetSource(obj, false);
	ObjStLaser_SetSource(obj1, false);
	
	DELAYSOUND;
	let POS = 110;
	//DelaySlash(POS);
	while(POS>0){
		let obj2 = CreateStraightLaserA1(ObjMove_GetX(objBoss)+rand(-POS, POS), 0, 90, 640, 5, 0, ST_LASER_GRAY, 0);
		let obj3 = CreateStraightLaserA1(ObjMove_GetX(objBoss)+rand(-POS, POS), 0, 90, 640, 5, 0, ST_LASER_GRAY, 0);
		
		ObjShot_SetDeleteFrame(obj2, 0);
		ObjShot_SetDeleteFrame(obj3, 0);
		
		ObjMove_SetX(obj, ObjMove_GetX(objBoss)-POS);
		ObjMove_SetX(obj1, ObjMove_GetX(objBoss)+POS);
		POS-=2.5;
		yield;
		}
		
	task DELAYSOUND {
		let COUNT = 0;
		
		while(COUNT<=100){
			COUNT++;
			if(COUNT==100){
				CHINK;
				}
			yield;
			}
		}
	}
	
task Concentration2(tobj, graphic, DIST, loopcount, graphicx, graphicy, DELETECOUNT, MOVEMOD){
	loop(loopcount){
		let X = ObjMove_GetX(tobj);
		let Y = ObjMove_GetY(tobj);
		let ANGLE = rand(0, 360);
		let SCALE = 0.4;
		let DIST1 = 0;
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, graphic);
		Obj_SetRenderPriorityI(obj,22);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetAlpha(obj,230);
		ObjSprite2D_SetSourceRect(obj,0,0,graphicx, graphicy);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj, X+DIST*cos(ANGLE),Y+DIST*sin(angle),0);
		ObjRender_SetScaleXYZ(obj, SCALE, SCALE, 0);		
		ObjRender_SetAngleXYZ(obj,0, 0, ANGLE+180);
		ObjRender_SetColor(obj, 250, rand(4, 104), rand(4, 40));
		
		SHRINK(obj, SCALE);
		MOVE(obj, X, Y, DIST, ANGLE, 0);
		
		task SHRINK(TOBJ, MOD){
			while(!Obj_IsDeleted(TOBJ)){
			ObjRender_SetScaleXYZ(TOBJ, MOD, MOD, 0);
			
			if(MOD>0){
				MOD-=DELETECOUNT;
				}
				
			if(MOD<=0){
				Obj_Delete(TOBJ);
				}
			
			yield;
			}
			}
			
		task MOVE(TOBJ1, XMOD, YMOD, MOD1, ANGLEMOD, MODCAP){
			while(!Obj_IsDeleted(TOBJ1)){
				ObjRender_SetPosition(TOBJ1, XMOD+MOD1*cos(ANGLEMOD), YMOD+MOD1*sin(ANGLEMOD), 0);
				
				if(MOD1>MODCAP){
					MOD1-=MOVEMOD;
					}
				yield;
				}
			}
			
		yield;
		}
	}