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

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(7500)
	}
	
	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("Legends \"The Storyteller Calls Out to the Crowd\"", GetCurrentScriptDirectory~"KonnCutin.png", YABUSAME, 104, 104, 104);
	ObjCutin_LaunchS3(YABUSAME, GetCurrentScriptDirectory~"KonnCutin.png", "Hard");
	
	//BG;
	
	KonnBG(objBoss, GetCurrentScriptDirectory~"woodblock10d.jpg", GetCurrentScriptDirectory~"eff02.png", -5, 0, 250, 300, 256, 256, 1.7, 1.8);
	MCircle(objBoss, GetCurrentScriptDirectory~"e_ef_61.png");
	}

@MainLoop{
	animation++;
	
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){
		death(objBoss);
		}
		
	if(animation==40){
		//Slash(objBoss);
		}
		
	if(animation==60){
		Concentration(objBoss, "STAR", 100, 70, 4, 250, 4, 250, 4, 250);
		}
	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){
			Concentration(objBoss, "STAR", 100, 70, 4, 250, 4, 250, 4, 250);
			}
		
		if(frame==20){
			Wave3SE;
			let NUM = 12;
			let NUM2 = 16;
			let angle = rand(0, 360);
			let MOD = 0.5;
			
			
			
			loop(NUM){
				angle+=360/NUM;
				let SPEED = 0.8;
				let ACCELCAP = SPEED;
				
				loop(NUM2){
					PeopleCreation(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), SPEED, angle, T_NOTE_ORANGE, KNIFE_RED, 20, 0.05, ACCELCAP);
					
					ACCELCAP+=MOD;
					}
					
				}
			
			s*=-1;
				
			//frame=-400;
			}
			
		if(frame==450){
		
			loop(2){
			let posX1 = rand(0, GetStgFrameWidth);
			let posX2 = rand(0, GetStgFrameWidth);
			let posX3 = 0;
			let posX4 = GetStgFrameWidth;
			
			let posY1 = 0;
			let posY2 = GetStgFrameHeight;
			let posY3 = rand(0, GetStgFrameHeight);
			let posY4 = rand(0, GetStgFrameHeight);
			
			BulletConcentration(posX1, posY1, "STAR", 100, 40, 4, 250, 4, 250, 4, 250);
			BulletConcentration(posX2, posY2,"STAR", 100, 40, 4, 250, 4, 250, 4, 250);
			BulletConcentration(posX3, posY3, "STAR", 100, 40, 4, 250, 4, 250, 4, 250);
			BulletConcentration(posX4, posY4, "STAR", 100, 40, 4, 250, 4, 250, 4, 250);
			
			let ANGLE = 0;
			
			loop(4){
				let obj1 = CreateStraightLaserA1(posX1, posY1, ANGLE, 640, 20, 30, ST_LASER_GRAY, 60);
				let obj2 = CreateStraightLaserA1(posX2, posY2, ANGLE, 640, 20, 30, ST_LASER_GRAY, 60);
				let obj3 = CreateStraightLaserA1(posX3, posY3, ANGLE, 640, 20, 30, ST_LASER_GRAY, 60);
				let obj4 = CreateStraightLaserA1(posX4, posY4, ANGLE, 640, 20, 30, ST_LASER_GRAY, 60);
				
				CreateLooseLaserA1(posX1, posY1, 40, ANGLE, 640, 40, PELLET_GRAY, 60);
				CreateLooseLaserA1(posX2, posY2, 40, ANGLE, 640, 40, PELLET_GRAY, 60);
				CreateLooseLaserA1(posX3, posY3, 40, ANGLE, 640, 40, PELLET_GRAY, 60);
				CreateLooseLaserA1(posX4, posY4, 40, ANGLE, 640, 40, PELLET_GRAY, 60);
				
				ANGLE+=360/4;
				}
				}
			
			}
			
		if(frame==450+50){
			CHINK;
			}
			
		if(frame==520){
			Crowd;
			frame=-560;
			}
			
		}
		}
	yield;
	}
	
task PeopleCreation(x, y, speed, angle, graphic, graphic2, delay, acceleration, accelcap){
	let obj = CreateShotA1(x, y, speed, angle, graphic, delay);
	SetSpecialDelete(obj, graphic);
	
	ObjMove_SetAcceleration(obj, acceleration);
	ObjMove_SetMaxSpeed(obj, accelcap);
	
	ObjMove_SetAngularVelocity(obj, 0.2*s);
	
	let endX = ObjMove_GetX(obj);
	let endY = ObjMove_GetY(obj);
	
	let angle1 = 0;
	
	let explode=0;
	
	while(!Obj_IsDeleted(obj)){
		endX = ObjMove_GetX(obj);
		endY = ObjMove_GetY(obj);
		
		if(endX >= GetStgFrameWidth){
			explode=1;
			Obj_Delete(obj);
			angle1 = 180;
			}
			
		if(endX <=0){
			explode=1;
			Obj_Delete(obj);
			angle1 = 0;
			}
		
		if(endY >= GetStgFrameHeight){
			explode=1;
			Obj_Delete(obj);
			angle1 = 270;
			}
		
		if(endY <=0){
			explode=1;
			Obj_Delete(obj);
			angle1 = 90;
			}
		
		yield;
		}
		
	//let obj1 = CreateShotA1(endX, endY, 0, 0, graphic, 30);
	//ObjShot_SetDeleteFrame(obj1, 0);
	
	let obj2 = CreateShotA1(endX, endY, 1.5, angle1, graphic2, 0);
	SetSpecialDelete(obj2, graphic2);
		
	}
	
task Crowd{
	let angle = rand(0, 360);
	WHOOOP;
	loop(16){
		angle+=360/16;
		
		Crowdmember(angle);
		}
		
	task Crowdmember(angle1){
		let CrowdMember= ObjEnemy_Create(OBJ_ENEMY);
		ObjEnemy_Regist(CrowdMember);
		ObjEnemy_SetLife(CrowdMember,300);
		
		ObjMove_SetPosition(CrowdMember, ObjMove_GetX(objBoss)+400*cos(angle1), ObjMove_GetY(objBoss)+400*sin(angle1));
		
		ObjMove_SetAngle(CrowdMember, angle1+180);
		ObjMove_SetAngularVelocity(CrowdMember, 0.08);
		ObjMove_SetSpeed(CrowdMember, 2);
		
		let imgExRumia = GetCurrentScriptDirectory ~ "enm7.png"; //file path to enemy image

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

		ObjSprite2D_SetSourceRect(CrowdMember, 0, 384-96, 32, 384-128); //Setting the rectangle coordinates in the enemy image to use(Left, Top, Right, Bottom).

		ObjSprite2D_SetDestCenter(CrowdMember); //Positioning the center of the rectangle(w/texture) at (0, 0) on the stage(top left corner).
		
		let shot=0;
		let DEATHCOUNT = 0;
		
		while(!Obj_IsDeleted(CrowdMember)){
			let X = ObjMove_GetX(CrowdMember);
			let Y = ObjMove_GetY(CrowdMember);
			
			DEATHCOUNT++;
			shot++;
			
			if(shot==18){
				let obj2 = CreateShotA1(X, Y, 0, angle1-29, T_NOTE_GREEN, 5);
				SetSpecialDelete(obj2, T_NOTE_GREEN);
				ObjMove_SetAcceleration(obj2, 0.01);
				ObjMove_SetMaxSpeed(obj2, 1.5);
				shot=0;
				}
				
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){
				Obj_Delete(CrowdMember);
				}
				
			if(DEATHCOUNT>=600){
				Obj_Delete(CrowdMember);
				}
				
			yield;
			}
		}
	}
			
			
	
	