script_enemy_main{

let character="Shinichi";
let cutin=character;
let dispelled=0;
let spellcards=2;
if(GetCommonData("Difficulty")==4){ spellcards=3; }
let damagerate=10;
let outfit=1;
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 SEshot1=("script\SoundEffects\shotm4.wav");
let SEshot2=("script\SoundEffects\shotm2.wav");
let GRboss=("\script\Images\CharacterSprites\Shinichi.png");

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

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

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

	LoadSE("script\SoundEffects\shotm4.wav");
	LoadSE("script\SoundEffects\shotm2.wav");

	SetLife(225);
	SetTimer(26);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);

	SetX(GetCommonData("Boss2X"));
	SetY(GetCommonData("Boss2Y"));

	SetCommonData("Boss1Move",6);
	SetMovePosition03(cx,miny+120,4,5);
}
	
@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);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }
HealthBar();

if((frame==240 || frame==40) && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+80,miny+100),0.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(20,30),rand(miny+80,miny+100),0.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(20,30),rand(miny+80,miny+100),0.5);
	}
}


if(GetCommonData("Difficulty")==1){
	if(time==60){
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Nonspell 1 - Familiar.txt"),GetX,GetY,0,0,[1,100]);
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Nonspell 1 - Familiar.txt"),GetX,GetY,0,0,[2,100]);
	}
	if(frame>=210 && frame<330 && time>=120){
	CreateShot01(GetX-10,GetY-25,rand(2.2,2.6),90+70*cos((time*25)+rand(-60,60)),49,10);
	if(time%4==0){ PlaySE(SEshot2); }
	usespell=2;
	}
	if(frame==300){ frame=0; }
} //Easy

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

if(GetCommonData("Difficulty")==2){
	if(time==60){
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Nonspell 1 - Familiar.txt"),GetX,GetY,0,0,[1,80]);
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Nonspell 1 - Familiar.txt"),GetX,GetY,0,0,[2,80]);
	}
	if(frame>=150 && frame<270 && time>=120){
	CreateShot01(GetX-10,GetY-25,rand(2.4,2.8),90+60*cos((time*25)+rand(-60,60)),49,10);
	if(time%4==0){ PlaySE(SEshot2); }
	usespell=2;
	}
	if(frame==240){ frame=0; }
} //Normal

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

if(GetCommonData("Difficulty")==3){
	if(time==60){
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Nonspell 1 - Familiar.txt"),GetX,GetY,0,0,[1,60]);
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Nonspell 1 - Familiar.txt"),GetX,GetY,0,0,[2,60]);
	}
	if(frame>=40 && frame<180 && time>=300){
	CreateShot01(GetX-10,GetY-25,rand(2.6,3),90+50*cos((time*25)+rand(-60,60)),49,10);
	if(time%4==0){ PlaySE(SEshot2); }
	usespell=2;
	}
	if(frame==360){ frame=0; }
} //Hard

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

if(GetCommonData("Difficulty")==4){
	if(time==60){
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Nonspell 1 - Familiar.txt"),GetX,GetY,0,0,[1,50]);
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Nonspell 1 - Familiar.txt"),GetX,GetY,0,0,[2,50]);
	}
	if((frame>=20 && frame<180) && time>=300){
	CreateShot01(GetX-10,GetY-25,rand(2.8,3.2),90+40*cos((time*25)+rand(-60,60)),49,10);
	if(time%4==0){ PlaySE(SEshot2); }
	usespell=2;
	}
	if(frame==360){ frame=0; }
} //Lunatic



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

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

SetCommonData("Boss2X",GetX); SetCommonData("Boss2Y",GetY);
}

@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); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
//	SetCommonData("Conversation",1);
}

}