script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];
let direction1=[];
let yspeed1=[];
let color1=[];

let character="Kurumi";
let cutin=character;
let dispelled=0;
let spellcards=3;
if(GetCommonData("Difficulty")>=3){ spellcards=4; }
let damagerate=10;
let outfit=6;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0; let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshotb6=("\script\SoundEffects\shotb6.wav");
let SEfireworks5=("\script\SoundEffects\fireworks5.wav");

let GRboss=("\script\Images\CharacterSprites\Kurumi.png");

#include_function "script/Functions/HealthBarLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsKurumi1.txt");

	LoadSE("\script\SoundEffects\shotb6.wav");
	LoadSE("\script\SoundEffects\fireworks5.wav");

	LoadGraphic("\script\Images\CharacterSprites\Kurumi.png");

	SetLife(180);
	SetTimer(30);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);

	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetCommonData("Boss1Vanish",1);
	SetMovePosition02(cx,miny+100,50);
	
	SetCommonData("Boss2Move",4);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(64,64,64,64);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=4; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

HealthBar();

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}


if(GetCommonData("Difficulty")==1){

if(time%100==0 && time>=60 && GetTimer>0){
let angle=0;
	loop(12){
	let speed=3;
		loop(4){
		SetShotDirectionType(PLAYER);
		CreateShot01(GetX+10,GetY-35,speed,angle,155,0);
		SetShotDirectionType(ABSOLUTE);
		speed-=0.5;
		}
	angle+=360/12;
	}
usespell=20;
PlaySE(SEshotb6);
}


if(time%210==0 && time>=60 && GetTimer>0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,minx-60,miny+rand(150,250));
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,133);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	direction1=direction1~[shot1];
	direction1[length(bullet1)-1]=0;
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-3,-5);
	color1=color1~[shot1];
	color1[length(bullet1)-1]=rand_int(1,10);
PlaySE(SEfireworks5);
}
if((time+105)%210==0 && time>=60 && GetTimer>0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,maxx+60,miny+rand(150,250));
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,140);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	direction1=direction1~[shot1];
	direction1[length(bullet1)-1]=180;
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-3,-5);
	color1=color1~[shot1];
	color1[length(bullet1)-1]=rand_int(1,10);
PlaySE(SEfireworks5);
}


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); direction1=erase(direction1,i); yspeed1=erase(yspeed1,i); color1=erase(color1,i);
	i--;
	}
	else{
	let oldx=Obj_GetX(bullet1[i]);
	let oldy=Obj_GetY(bullet1[i]);
	if(direction1[i]==0){ Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])+6); Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+yspeed1[i]); }
	if(direction1[i]==180){ Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])-6); Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+yspeed1[i]); }
	let newangle=atan2(Obj_GetY(bullet1[i])-oldy,Obj_GetX(bullet1[i])-oldx);
	Obj_SetAngle(bullet1[i],newangle);

let random=rand_int(0,5);
	if(random<2){
	let angle=direction1[i]+rand(-45,45);
	if(direction1[i]==0){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(1.5,2.5),108+color1[i],10); }
	if(direction1[i]==0){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(1.5,2.5),120+color1[i],10); }
	if(direction1[i]==180){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(1.5,2.5),108+color1[i],10); }
	if(direction1[i]==180){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(1.5,2.5),120+color1[i],10); }
	}

	yspeed1[i]=yspeed1[i]+0.05;
	timer1[i]=timer1[i]+1;
	}
i++;
}

} //Easy

//=============================================================================================================

if(GetCommonData("Difficulty")==2){

if(time%100==0 && time>=60 && GetTimer>0){
let angle=0;
	loop(12){
	let speed=3;
		loop(4){
		SetShotDirectionType(PLAYER);
		CreateShot01(GetX+10,GetY-35,speed,angle,155,0);
		SetShotDirectionType(ABSOLUTE);
		speed-=0.5;
		}
	angle+=360/12;
	}
usespell=20;
PlaySE(SEshotb6);
}

if(time%180==0 && time>=60 && GetTimer>0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,minx-60,miny+rand(150,250));
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,133);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	direction1=direction1~[shot1];
	direction1[length(bullet1)-1]=0;
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-3,-5);
	color1=color1~[shot1];
	color1[length(bullet1)-1]=rand_int(1,10);
PlaySE(SEfireworks5);
}
if((time+90)%180==0 && time>=60 && GetTimer>0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,maxx+60,miny+rand(150,250));
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,140);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	direction1=direction1~[shot1];
	direction1[length(bullet1)-1]=180;
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-3,-5);
	color1=color1~[shot1];
	color1[length(bullet1)-1]=rand_int(1,10);
PlaySE(SEfireworks5);
}


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); direction1=erase(direction1,i); yspeed1=erase(yspeed1,i); color1=erase(color1,i);
	i--;
	}
	else{
	let oldx=Obj_GetX(bullet1[i]);
	let oldy=Obj_GetY(bullet1[i]);
	if(direction1[i]==0){ Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])+6); Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+yspeed1[i]); }
	if(direction1[i]==180){ Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])-6); Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+yspeed1[i]); }
	let newangle=atan2(Obj_GetY(bullet1[i])-oldy,Obj_GetX(bullet1[i])-oldx);
	Obj_SetAngle(bullet1[i],newangle);

let random=rand_int(0,4);
	if(random<2){
	let angle=direction1[i]+rand(-45,45);
	if(direction1[i]==0){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(1.5,2.5),108+color1[i],10); }
	if(direction1[i]==0){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(1.5,2.5),120+color1[i],10); }
	if(direction1[i]==180){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(1.5,2.5),108+color1[i],10); }
	if(direction1[i]==180){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(1.5,2.5),120+color1[i],10); }
	}

	yspeed1[i]=yspeed1[i]+0.05;
	timer1[i]=timer1[i]+1;
	}
i++;
}

} //Normal

//=============================================================================================================

if(GetCommonData("Difficulty")==3){

if(time%100==0 && time>=60 && GetTimer>0){
let angle=0;
	loop(12){
	let speed=3;
		loop(6){
		SetShotDirectionType(PLAYER);
		CreateShot01(GetX+10,GetY-35,speed,angle,155,0);
		SetShotDirectionType(ABSOLUTE);
		speed-=0.4;
		}
	angle+=360/12;
	}
usespell=20;
PlaySE(SEshotb6);
}

if(time%150==0 && time>=60 && GetTimer>0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,minx-60,miny+rand(150,250));
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,133);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	direction1=direction1~[shot1];
	direction1[length(bullet1)-1]=0;
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-3,-5);
	color1=color1~[shot1];
	color1[length(bullet1)-1]=rand_int(1,10);
PlaySE(SEfireworks5);
}
if((time+75)%150==0 && time>=60 && GetTimer>0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,maxx+60,miny+rand(150,250));
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,140);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	direction1=direction1~[shot1];
	direction1[length(bullet1)-1]=180;
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-3,-5);
	color1=color1~[shot1];
	color1[length(bullet1)-1]=rand_int(1,10);
PlaySE(SEfireworks5);
}


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); direction1=erase(direction1,i); yspeed1=erase(yspeed1,i); color1=erase(color1,i);
	i--;
	}
	else{
	let oldx=Obj_GetX(bullet1[i]);
	let oldy=Obj_GetY(bullet1[i]);
	if(direction1[i]==0){ Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])+6); Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+yspeed1[i]); }
	if(direction1[i]==180){ Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])-6); Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+yspeed1[i]); }
	let newangle=atan2(Obj_GetY(bullet1[i])-oldy,Obj_GetX(bullet1[i])-oldx);
	Obj_SetAngle(bullet1[i],newangle);

let random=rand_int(0,4);
	if(random<2){
	let angle=direction1[i]+rand(-45,45);
	if(direction1[i]==0){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(2,3),108+color1[i],10); }
	if(direction1[i]==0){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(2,3),120+color1[i],10); }
	if(direction1[i]==180){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(2,3),108+color1[i],10); }
	if(direction1[i]==180){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(2,3),120+color1[i],10); }
	}

	yspeed1[i]=yspeed1[i]+0.05;
	timer1[i]=timer1[i]+1;
	}
i++;
}

} //Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){

if(time%100==0 && time>=60 && GetTimer>0){
let angle=0;
	loop(12){
	let speed=3;
		loop(8){
		SetShotDirectionType(PLAYER);
		CreateShot01(GetX+10,GetY-35,speed,angle,155,0);
		SetShotDirectionType(ABSOLUTE);
		speed-=0.3;
		}
	angle+=360/12;
	}
usespell=20;
PlaySE(SEshotb6);
}

if(time%120==0 && time>=60 && GetTimer>0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,minx-60,miny+rand(150,250));
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,133);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	direction1=direction1~[shot1];
	direction1[length(bullet1)-1]=0;
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-3,-5);
	color1=color1~[shot1];
	color1[length(bullet1)-1]=rand_int(1,10);
PlaySE(SEfireworks5);
}
if((time+60)%120==0 && time>=90 && GetTimer>0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,maxx+60,miny+rand(150,250));
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,140);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	direction1=direction1~[shot1];
	direction1[length(bullet1)-1]=180;
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-3,-5);
	color1=color1~[shot1];
	color1[length(bullet1)-1]=rand_int(1,10);
PlaySE(SEfireworks5);
}


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); direction1=erase(direction1,i); yspeed1=erase(yspeed1,i); color1=erase(color1,i);
	i--;
	}
	else{
	let oldx=Obj_GetX(bullet1[i]);
	let oldy=Obj_GetY(bullet1[i]);
	if(direction1[i]==0){ Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])+6); Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+yspeed1[i]); }
	if(direction1[i]==180){ Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])-6); Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+yspeed1[i]); }
	let newangle=atan2(Obj_GetY(bullet1[i])-oldy,Obj_GetX(bullet1[i])-oldx);
	Obj_SetAngle(bullet1[i],newangle);

let random=rand_int(0,4);
	if(random<2){
	let angle=direction1[i]+rand(-45,45);
	if(direction1[i]==0){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(2,3),108+color1[i],10); }
	if(direction1[i]==0){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(2,3),120+color1[i],10); }
	if(direction1[i]==180){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(2,3),108+color1[i],10); }
	if(direction1[i]==180){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-1,-3),-0.03*cos(angle),0.04,rand(0,0.2)*cos(angle),rand(2,3),120+color1[i],10); }
	}

	yspeed1[i]=yspeed1[i]+0.05;
	timer1[i]=timer1[i]+1;
	}
i++;
}
} //Lunatic


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/HealthBar.txt";
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }

	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}
 
@Finalize{
}

}