script_enemy_main{

let playsound=0;
let alivetime=0;

let shot1=0;
let bullet1=[];

let character="Ryo";
let cutin=character;
let dispelled=0;
let spellcards=2;
let spellcardnumber=18;
let damagerate=10;
let outfit=4;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=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 SEthrow1=("\script\SoundEffects\throw1.wav");
let SEreflect2=("\script\SoundEffects\reflect2.wav");
let SEshotm2=("\script\SoundEffects\shotm2.wav");
let SEshotb5=("\script\SoundEffects\shotb5.wav");

let BG1=("\script\Images\BackgroundLayers\Ryo1b.png");
let BG2=("\script\Images\BackgroundLayers\Ryo2.png");
let GRboss=("\script\Images\CharacterSprites\Ryo.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

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

	LoadSE("\script\SoundEffects\throw1.wav");
	LoadSE("\script\SoundEffects\reflect2.wav");
	LoadSE("\script\SoundEffects\shotm2.wav");
	LoadSE("\script\SoundEffects\shotb5.wav");

	LoadGraphic("\script\Images\BackgroundLayers\Ryo1b.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ryo2.png");
	LoadGraphic("\script\Images\CharacterSprites\Ryo.png");

	SetScore(200000);
	SetLife(200);
	SetTimer(40);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);

	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetCommonData("Boss1Vanish",1);

	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,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"; }

SpellcardName("Yoji Gakure [Backstabber] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

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((time+130)%180==0 && time>=50){
let shot1=0;
let xaxis=0+rand(0,420/35);
	loop(35){
	CreateShotA(shot1,xaxis,miny,10);
	SetShotDataA(shot1,0,0,rand(85,95),0,0,0,rand_int(25,27));
	SetShotDataA(shot1,60,rand(4.9,5.2),NULL,0,-0.025,0,NULL);
	SetShotDirectionType(PLAYER);
	SetShotDataA(shot1,220,0,0,0,0.08,rand(2,3),36);
	SetShotDirectionType(ABSOLUTE);
	FireShot(shot1);
	xaxis+=420/35;
	}
}

if((time+70)%180==0 && time>=100 && OnPlayerMissed==false && alivetime>=60){ PlaySE(SEshotb5); }

if((time+70)%180==0 || (time+63)%180==0 || (time+56)%180==0  || (time+49)%180==0 && time>=200 && alivetime>=230){ PlaySE(SEshotm2); }
if(OnPlayerMissed==true){ alivetime=0; }
alivetime++;


if(time%65==0 && time>=300){
let angle=-20;
let random=GetAngleToPlayer+rand(-40,40);
	loop(2){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX-10,GetY-25);
	Obj_SetAngle(shot1,random+angle);
	Obj_SetSpeed(shot1,2.5);
	ObjShot_SetGraphic(shot1,38);
	bullet1=bullet1~[shot1];
	angle+=40;
	}
PlaySE(SEthrow1);
usespell=20;
}

let i=0;
while (i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); i--; }
	else{
		let obj=bullet1[i];
		if(Obj_GetX(obj)<=minx) {
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)+1);
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
		if(Obj_GetX(obj)>=maxx) {
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)-1);
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
	}
i++;
}
if(playsound>0){ playsound--; } if(playsound<0){ playsound=0; }


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

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

@BackGround{
	if(bgfade<255){ bgfade+=5; }
	
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(4,4);
	SetTexture(BG2);
	SetAlpha(bgfade*0.75);
	SetGraphicAngle(0,0,time/2);
	DrawGraphic(cx,maxy+40);
}

@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);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}