script_enemy_main{

let type=1;
let frame2=0;

let color=0;
let circlecolor=1;
let scalespeed=1;
let shottype=1;
let deform=0;
let bgtype=1;

let playsound=0;

let shot1=0;
let bullet1=[];
let bounce1=[];
let color1=[];

let maxlife=500;
let fakelife=maxlife;
let fakedispel=false;
let faketimer=80;

let drainedlife=0;
let newname=1;
let phase=0;
let oldtimer=0;
let namefadecolor=0;
let cutintime=0;

let fadeblack=0;
let fadecolor=0;
let EFblack=("\script\Images\OtherEffects\Wall.png");
let cx2=320;
let cy2=240;

let playerx=GetPlayerX;
let playery=GetPlayerY;

let spellcardstars=[];

let character="Masahiro";
let cutin=character;
let dispelled=0;
let spellcards=2;
let spellcardnumber=66;
let damagerate=10;
let outfit=1;
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 SEspawn1=("\script\SoundEffects\spawn1.wav");

let EFblack=("\script\Images\OtherEffects\Wall.png");

let BG1=("\script\Images\BackgroundLayers\Nightmare3.png");
let BG2=("\script\Images\BackgroundLayers\Nightmare4a.png");
let BG3=("\script\Images\BackgroundLayers\Nightmare4b.png");
let GRboss=("\script\Images\CharacterSprites\"~character~".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\ShotsNightmare1.txt");

	LoadSE("\script\SoundEffects\spawn1.wav");
	
	LoadGraphic("\script\Images\OtherEffects\Wall.png");

	LoadGraphic("\script\Images\CharacterSprites\"~character~".png");
	LoadGraphic("\script\Images\BackgroundLayers\Nightmare3.png");
	LoadGraphic("\script\Images\BackgroundLayers\Nightmare4a.png");
	LoadGraphic("\script\Images\BackgroundLayers\Nightmare4b.png");

	SetScore(1000000);
	SetLife(550);
	SetTimer(80);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

if(phase==0){
	SetCollisionA(GetX,GetY,16);
	SetCollisionB(GetX,GetY,16);
}
SetShotAutoDeleteClip(400,400,400,400);

if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=0; }
SetDamageRate(damagerate,damagerate);

SpellcardName("Lucid Dream [False Awakening]",255-namefadecolor,255-namefadecolor,255-namefadecolor); 
HealthBar();
Portrait(cutin,1);

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



if(frame2==90 && phase==0 && type==1){
let angle=rand(0,360);
	loop(13){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"9 - False Awakening - Familiar.txt",GetX,GetY,0,0,[1,rand_int(1,2),angle,color,circlecolor,scalespeed,shottype,deform]);
	angle+=360/13;
	}
PlaySE(SEspawn1);
}
if((frame2+30)%60==0 && frame2>=60 && frame<600 && phase==0 && type==2){
let angle=rand(0,360);
	loop(9){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"9 - False Awakening - Familiar.txt",GetX,GetY,0,0,[2,rand_int(1,2),angle,color,circlecolor,scalespeed,shottype,deform]);
	angle+=360/9;
	}
PlaySE(SEspawn1);
}
if(frame2==90 && phase==0 && type==3){
let angle=rand(0,360);
	loop(15){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"9 - False Awakening - Familiar.txt",GetX,GetY,0,0,[3,rand_int(1,2),angle,color,circlecolor,scalespeed,shottype,deform]);
	angle+=360/15;
	}
PlaySE(SEspawn1);
}


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

//Fake End

if(time==0){ newname=1; }

if(time%60==0 && time>=60 && phase==0){ faketimer--; }

if(frame==600 && GetTimer>1){
	CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character);
	fakedispel=true;
	phase=1;
	frame=0;
	frame2=0;
	SetEnemyMarker(false);
	MagicCircle(false);
	DeleteEnemyShot(ALL);
}

if(frame<50 && phase==1){ Slow(1); }
else{ Slow(0); }

fakelife=GetLife+drainedlife;

if(phase==1){
ForbidBomb(true);
	if(frame==45){
	fadeblack=(Obj_Create(OBJ_EFFECT)); Obj_SetPosition(fadeblack,cx2,cy2); ObjEffect_SetLayer(fadeblack,7); ObjEffect_SetTexture(fadeblack,EFblack);
	ObjEffect_SetPrimitiveType(fadeblack,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(fadeblack,4); ObjEffect_SetRenderState(fadeblack,ALPHA);
	ObjEffect_SetVertexXY(fadeblack,0,-320,-240); ObjEffect_SetVertexUV(fadeblack,0,0,0);
	ObjEffect_SetVertexXY(fadeblack,1,320,-240); ObjEffect_SetVertexUV(fadeblack,1,640,0);
	ObjEffect_SetVertexXY(fadeblack,2,-320,240); ObjEffect_SetVertexUV(fadeblack,2,0,480);
	ObjEffect_SetVertexXY(fadeblack,3,320,240); ObjEffect_SetVertexUV(fadeblack,3,640,480);
	}

	ObjEffect_SetVertexColor(fadeblack,0,fadecolor,0,0,0); ObjEffect_SetVertexColor(fadeblack,1,fadecolor,0,0,0);
	ObjEffect_SetVertexColor(fadeblack,2,fadecolor,0,0,0); ObjEffect_SetVertexColor(fadeblack,3,fadecolor,0,0,0);

	if(frame>=45 && frame<120 && fadecolor<255){ fadecolor+=5; }
	if(OnBomb==true && frame>=120){ frame=120; }
	if(frame>120 && frame<150){
		SetPlayerX(playerx);
		SetPlayerY(playery);
		SetX(cx);
		SetY(miny+100);
		SetMovePosition01(cx,miny+100,1.5);
		faketimer=rand_int(10,75);
		fakelife=GetLife*rand(1,0.2);
		drainedlife=maxlife-GetLife;
		fakedispel=false;
		namefade=255;
	}
	if(frame==120){ spellcards=rand_int(1,10); }
	if(frame==130){
		SetColor(0,255,128);
		Concentration01(90);
		SetColor(255,255,255);
		Obj_Delete(OBJcutin);
		cutintime=0;
		cutinsize=1;
		cutinalpha=0;
	}
	if(frame>=150 && fadecolor>0){
		fadecolor-=5;
		SetEnemyMarker(true);
		MagicCircle(true);
	}
	if(frame>=150 && fadecolor<=0){
		Obj_Delete(fadeblack);
		phase=0;
		frame=60;
		frame2=60;
		ForbidBomb(false);
		newname=1;

		type=type+rand_int(0,2);
		if(type>3){ type-=3; }

		let rand=rand_int(0,5);
		if(rand==5){ color=rand_int(1,360); }
		else{ color=0; }

		let rand=rand_int(0,4);
		if(rand==4){ circlecolor=2; }
		else{ circlecolor=1; }

		let rand=rand_int(0,3);
		if(rand==3){ scalespeed=2; }
		else{ scalespeed=1; }
		
		let rand=rand_int(0,4);
		if(rand==2){ shottype=2; }
		else{ shottype=1; }

		let rand=rand_int(0,3);
		if(rand==1){ deform=rand_int(10,15); }
		else{ deform=0; }

		let rand=rand_int(0,3);
		if(rand==0){ bgtype=2; }
		else{ bgtype=2; }
	}
}

if(phase==0){ frame2++; }

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

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

function SpellcardName(name,red,green,blue){

if(time==0){

let i=0;
let wordsize=0;
let newword=0;
	while(i<(length(name))){
	
	let letterwidth=[0,0,0];
	if(name[i]=='a'){ letterwidth=[1,11,8]; } if(name[i]=='A'){ letterwidth=[249,261,11]; }
	if(name[i]=='b'){ letterwidth=[11,21,9]; } if(name[i]=='B'){ letterwidth=[262,274,10]; }
	if(name[i]=='c'){ letterwidth=[21,29,7]; } if(name[i]=='C'){ letterwidth=[274,284,9]; }
	if(name[i]=='d'){ letterwidth=[30,40,9]; } if(name[i]=='D'){ letterwidth=[285,297,12]; }
	if(name[i]=='e'){ letterwidth=[40,48,8]; } if(name[i]=='E'){ letterwidth=[298,308,10]; }
	if(name[i]=='f'){ letterwidth=[49,57,7]; } if(name[i]=='F'){ letterwidth=[309,319,9]; }	
	if(name[i]=='g'){ letterwidth=[58,68,9]; } if(name[i]=='G'){ letterwidth=[319,329,10]; }
	if(name[i]=='h'){ letterwidth=[68,78,10]; } if(name[i]=='H'){ letterwidth=[330,340,11]; }
	if(name[i]=='i'){ letterwidth=[79,85,4]; } if(name[i]=='I'){ letterwidth=[341,347,4]; }	
	if(name[i]=='j'){ letterwidth=[85,93,8]; } if(name[i]=='J'){ letterwidth=[347,355,8]; }
	if(name[i]=='k'){ letterwidth=[94,102,8]; } if(name[i]=='K'){ letterwidth=[356,366,10]; }
	if(name[i]=='l'){ letterwidth=[103,109,5]; } if(name[i]=='L'){ letterwidth=[367,377,9]; }
	if(name[i]=='m'){ letterwidth=[110,124,13]; } if(name[i]=='M'){ letterwidth=[377,391,12]; }
	if(name[i]=='n'){ letterwidth=[124,134,9]; } if(name[i]=='N'){ letterwidth=[391,403,11]; }
	if(name[i]=='o'){ letterwidth=[134,142,8]; } if(name[i]=='O'){ letterwidth=[403,415,11]; }
	if(name[i]=='p'){ letterwidth=[143,153,10]; } if(name[i]=='P'){ letterwidth=[415,425,10]; }
	if(name[i]=='q'){ letterwidth=[154,164,9]; } if(name[i]=='Q'){ letterwidth=[426,438,11]; }
	if(name[i]=='r'){ letterwidth=[164,172,7]; } if(name[i]=='R'){ letterwidth=[438,450,11]; }
	if(name[i]=='s'){ letterwidth=[172,180,7]; } if(name[i]=='S'){ letterwidth=[450,460,9]; }
	if(name[i]=='t'){ letterwidth=[180,188,7]; } if(name[i]=='T'){ letterwidth=[461,471,9]; }
	if(name[i]=='u'){ letterwidth=[188,196,8]; } if(name[i]=='U'){ letterwidth=[471,483,11]; }
	if(name[i]=='v'){ letterwidth=[197,207,9]; } if(name[i]=='V'){ letterwidth=[483,495,11]; }
	if(name[i]=='w'){ letterwidth=[207,221,12]; } if(name[i]=='W'){ letterwidth=[495,511,14]; }
	if(name[i]=='x'){ letterwidth=[221,231,9]; } if(name[i]=='X'){ letterwidth=[511,523,11]; }
	if(name[i]=='y'){ letterwidth=[231,239,8]; } if(name[i]=='Y'){ letterwidth=[523,535,11]; }
	if(name[i]=='z'){ letterwidth=[240,248,8]; } if(name[i]=='Z'){ letterwidth=[535,545,9]; }

	if(name[i]=='1'){ letterwidth=[545,551,6]; } if(name[i]=='2'){ letterwidth=[552,562,9]; }
	if(name[i]=='3'){ letterwidth=[562,572,9]; } if(name[i]=='4'){ letterwidth=[572,582,10]; }
	if(name[i]=='5'){ letterwidth=[583,591,8]; } if(name[i]=='6'){ letterwidth=[592,602,10]; }
	if(name[i]=='7'){ letterwidth=[603,611,8]; } if(name[i]=='8'){ letterwidth=[612,622,10]; }
	if(name[i]=='9'){ letterwidth=[623,633,9]; } if(name[i]=='0'){ letterwidth=[633,643,10]; }

	if(name[i]=='?'){ letterwidth=[644,654,9]; } if(name[i]=='!'){ letterwidth=[654,658,4]; } // ? !
	if(name[i]=='.'){ letterwidth=[659,663,3]; } if(name[i]==','){ letterwidth=[663,667,3]; } // . ,
	if(name[i]==':'){ letterwidth=[667,671,4]; } if(name[i]=='`'){ letterwidth=[672,676,3]; } // : '
	if(name[i]=='['){ letterwidth=[676,682,5]; } if(name[i]==']'){ letterwidth=[683,689,6]; } // " x2
	if(name[i]=='@'){ letterwidth=[690,702,12]; } if(name[i]=='#'){ letterwidth=[703,711,8]; } // @ #
	if(name[i]=='%'){ letterwidth=[712,728,15]; } if(name[i]=='&'){ letterwidth=[728,742,13]; } // % &
	if(name[i]=='('){ letterwidth=[754,760,6]; } if(name[i]==')'){ letterwidth=[761,767,5]; } // ( )
	if(name[i]=='<'){ letterwidth=[767,777,9]; } if(name[i]=='>'){ letterwidth=[777,787,9]; } // < >
	if(name[i]=='*'){ letterwidth=[742,754,11]; } if(name[i]=='-'){ letterwidth=[787,795,9]; } // * -

	if(name[i]=='+'){ letterwidth=[0,0,5]; newword=1; wordsize=300; } // Enter
	if(name[i]==' '){ letterwidth=[0,0,5]; newword=1; } // Space

	let xsize=letterwidth[1]-letterwidth[0];
	let ysize=18;
	let scale=1;
	let letterfade=0;
	namefade=255;
	letter=(Obj_Create(OBJ_EFFECT));
	if(wordsize>250 && newword==1){ wordsize=-5; nameypos+=16; newword=0; }
	Obj_SetPosition(letter,namexpos+wordsize,nameypos); ObjEffect_SetScale(letter,scale,scale);
	ObjEffect_SetLayer(letter,7); ObjEffect_SetTexture(letter,EFtext); ObjEffect_SetRenderState(letter,ALPHA);
	ObjEffect_SetPrimitiveType(letter,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(letter,4);
	ObjEffect_SetVertexXY(letter,0,0,-(ysize/2)); ObjEffect_SetVertexUV(letter,0,letterwidth[0],0);
	ObjEffect_SetVertexXY(letter,1,xsize,-(ysize/2)); ObjEffect_SetVertexUV(letter,1,letterwidth[1],0);
	ObjEffect_SetVertexXY(letter,2,0,ysize/2); ObjEffect_SetVertexUV(letter,2,letterwidth[0],ysize);
	ObjEffect_SetVertexXY(letter,3,xsize,ysize/2); ObjEffect_SetVertexUV(letter,3,letterwidth[1],ysize);
	ObjEffect_SetVertexColor(letter,0,letterfade,red,green,blue); ObjEffect_SetVertexColor(letter,1,letterfade,red,green,blue);
	ObjEffect_SetVertexColor(letter,2,letterfade,red,green,blue); ObjEffect_SetVertexColor(letter,3,letterfade,red,green,blue);
	letters=letters~[letter];
	lettertimer=lettertimer~[letter];
	lettertimer[length(letters)-1]=0;
	letterx=letterx~[letter];
	letterx[length(letters)-1]=Obj_GetX(letter);
	lettery=lettery~[letter];
	lettery[length(letters)-1]=Obj_GetY(letter);
	letterscale=letterscale~[letter];
	letterscale[length(letters)-1]=1;

	wordsize+=letterwidth[2];
	newword=0;
	
	i++;
	}
}

let i=0;
	while(i<length(letters)){
	if(frame==149 && phase==1){
		Obj_SetX(letters[i],Obj_GetX(letters[i])+rand(-1,1));
		Obj_SetY(letters[i],Obj_GetY(letters[i])+rand(-1,1));
	}
	ObjEffect_SetScale(letters[i],1,letterscale[i]);
	ObjEffect_SetVertexColor(letters[i],0,namefade,red,green,blue); ObjEffect_SetVertexColor(letters[i],1,namefade,red,green,blue);
	ObjEffect_SetVertexColor(letters[i],2,namefade,red,green,blue); ObjEffect_SetVertexColor(letters[i],3,namefade,red,green,blue);

	lettertimer[i]=lettertimer[i]+1;
	if(phase==1 && letterscale[i]>0){ letterscale[i]=letterscale[i]+0.15; }
	if(fakedispel==false && letterscale[i]!=1){ letterscale[i]=1; namefade=255; }
	i++;
	}
if(phase==1 && fakedispel==true && namefade>0){ namefade-=15; }
}

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

function HealthBar{

if(time==0){
maxlife=GetLife;

	loop(2){
	health=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(health,cx-20,miny+12);
	ObjEffect_SetScale(health,1,1);
	ObjEffect_SetLayer(health,7); ObjEffect_SetTexture(health,GRhealthbar); ObjEffect_SetRenderState(health,ALPHA);
	ObjEffect_SetPrimitiveType(health,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(health,4);
	ObjEffect_SetVertexXY(health,0,0,-11); ObjEffect_SetVertexUV(health,0,16,0);
	ObjEffect_SetVertexXY(health,1,1,-11); ObjEffect_SetVertexUV(health,1,16,0);
	ObjEffect_SetVertexXY(health,2,0,11); ObjEffect_SetVertexUV(health,2,17,22);
	ObjEffect_SetVertexXY(health,3,1,11); ObjEffect_SetVertexUV(health,3,17,22);
	ObjEffect_SetVertexColor(health,0,255,255,255,255); ObjEffect_SetVertexColor(health,1,255,255,255,255);
	ObjEffect_SetVertexColor(health,2,255,255,255,255); ObjEffect_SetVertexColor(health,3,255,255,255,255);
	health1=health1~[health];
	}

	sides=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(sides,cx-20-sidesmove,miny+12);
	ObjEffect_SetScale(sides,1,1); ObjEffect_SetAngle(sides,0,0,0);
	ObjEffect_SetLayer(sides,7); ObjEffect_SetTexture(sides,GRhealthbar); ObjEffect_SetRenderState(sides,ALPHA);
	ObjEffect_SetPrimitiveType(sides,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(sides,4);
	ObjEffect_SetVertexXY(sides,0,-6.5,-11); ObjEffect_SetVertexUV(sides,0,1,0);
	ObjEffect_SetVertexXY(sides,1,6.5,-11); ObjEffect_SetVertexUV(sides,1,14,0);
	ObjEffect_SetVertexXY(sides,2,-6.5,11); ObjEffect_SetVertexUV(sides,2,1,22);
	ObjEffect_SetVertexXY(sides,3,6.5,11); ObjEffect_SetVertexUV(sides,3,14,22);
	ObjEffect_SetVertexColor(sides,0,255,255,255,255); ObjEffect_SetVertexColor(sides,1,255,255,255,255);
	ObjEffect_SetVertexColor(sides,2,255,255,255,255); ObjEffect_SetVertexColor(sides,3,255,255,255,255);
	sides1=sides1~[sides];

	sides=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(sides,cx-20+sidesmove,miny+12);
	ObjEffect_SetScale(sides,1,1); ObjEffect_SetAngle(sides,0,0,0);
	ObjEffect_SetLayer(sides,7); ObjEffect_SetTexture(sides,GRhealthbar); ObjEffect_SetRenderState(sides,ALPHA);
	ObjEffect_SetPrimitiveType(sides,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(sides,4);
	ObjEffect_SetVertexXY(sides,0,-6.5,-11); ObjEffect_SetVertexUV(sides,0,19,0);
	ObjEffect_SetVertexXY(sides,1,6.5,-11); ObjEffect_SetVertexUV(sides,1,32,0);
	ObjEffect_SetVertexXY(sides,2,-6.5,11); ObjEffect_SetVertexUV(sides,2,19,22);
	ObjEffect_SetVertexXY(sides,3,6.5,11); ObjEffect_SetVertexUV(sides,3,32,22);
	ObjEffect_SetVertexColor(sides,0,255,255,255,255); ObjEffect_SetVertexColor(sides,1,255,255,255,255);
	ObjEffect_SetVertexColor(sides,2,255,255,255,255); ObjEffect_SetVertexColor(sides,3,255,255,255,255);
	sides1=sides1~[sides];

	timerbar=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(timerbar,maxx-30,miny+13);
	ObjEffect_SetLayer(timerbar,7); ObjEffect_SetTexture(timerbar,GRhealthbar); ObjEffect_SetRenderState(timerbar,ALPHA);
	ObjEffect_SetPrimitiveType(timerbar,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(timerbar,4);
	ObjEffect_SetVertexXY(timerbar,0,-20,-12); ObjEffect_SetVertexUV(timerbar,0,33,1);
	ObjEffect_SetVertexXY(timerbar,1,20,-12); ObjEffect_SetVertexUV(timerbar,1,73,1);
	ObjEffect_SetVertexXY(timerbar,2,-20,12); ObjEffect_SetVertexUV(timerbar,2,33,25);
	ObjEffect_SetVertexXY(timerbar,3,20,12); ObjEffect_SetVertexUV(timerbar,3,73,25);
	ObjEffect_SetVertexColor(timerbar,0,255,255,255,255); ObjEffect_SetVertexColor(timerbar,1,255,255,255,255);
	ObjEffect_SetVertexColor(timerbar,2,255,255,255,255); ObjEffect_SetVertexColor(timerbar,3,255,255,255,255);

	loop(3){
	timereffect=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(timereffect,maxx-30,miny+13);
	ObjEffect_SetLayer(timereffect,7); ObjEffect_SetTexture(timereffect,GRhealthbar); ObjEffect_SetRenderState(timereffect,ADD);
	ObjEffect_SetPrimitiveType(timereffect,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(timereffect,4);
	ObjEffect_SetVertexXY(timereffect,0,-5,-9); ObjEffect_SetVertexUV(timereffect,0,74,1);
	ObjEffect_SetVertexXY(timereffect,1,5,-9); ObjEffect_SetVertexUV(timereffect,1,84,1);
	ObjEffect_SetVertexXY(timereffect,2,-5,9); ObjEffect_SetVertexUV(timereffect,2,74,19);
	ObjEffect_SetVertexXY(timereffect,3,5,9); ObjEffect_SetVertexUV(timereffect,3,84,19);
	ObjEffect_SetVertexColor(timereffect,0,255,255,255,0); ObjEffect_SetVertexColor(timereffect,1,255,255,255,0);
	ObjEffect_SetVertexColor(timereffect,2,255,255,255,0); ObjEffect_SetVertexColor(timereffect,3,255,255,255,0);
	timercounter=timercounter~[timereffect];
	}
}

if(phase==1 && frame==149){
let i=0;
	loop(length(spellcardstars)){
	Obj_Delete(spellcardstars[0]);
	spellcardstars=erase(spellcardstars,0);
	}
}

if(time==0 || (phase==1 && frame==149)){
let ypos=0;
	loop(spellcards){
	spellseffect=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(spellseffect,minx+12,miny+12+ypos);
	ObjEffect_SetLayer(spellseffect,7); ObjEffect_SetTexture(spellseffect,GRhealthbar); ObjEffect_SetRenderState(spellseffect,ADD);
	ObjEffect_SetPrimitiveType(spellseffect,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(spellseffect,4);
	ObjEffect_SetVertexXY(spellseffect,0,-9,-9); ObjEffect_SetVertexUV(spellseffect,0,1,23);
	ObjEffect_SetVertexXY(spellseffect,1,9,-9); ObjEffect_SetVertexUV(spellseffect,1,17,23);
	ObjEffect_SetVertexXY(spellseffect,2,-9,9); ObjEffect_SetVertexUV(spellseffect,2,1,39);
	ObjEffect_SetVertexXY(spellseffect,3,9,9); ObjEffect_SetVertexUV(spellseffect,3,17,39);
	ObjEffect_SetVertexColor(spellseffect,0,255,255,255,255); ObjEffect_SetVertexColor(spellseffect,1,255,255,255,255);
	ObjEffect_SetVertexColor(spellseffect,2,255,255,255,255); ObjEffect_SetVertexColor(spellseffect,3,255,255,255,255);
	ypos+=15;
	spellcardstars=spellcardstars~[spellseffect];
	}
}


if(sidesmove<146 || time<110){ sidesmove+=5+6*cos(sidesmove); }
Obj_SetPosition(sides1[0],cx-20-sidesmove,miny+12);
Obj_SetPosition(sides1[1],cx-20+sidesmove,miny+12);

ObjEffect_SetScale(health1[0],(sidesmove*2),1);
ObjEffect_SetScale(health1[1],(sidesmove*2)*(fakelife/maxlife),1);
ObjEffect_SetVertexColor(health,0,255,255,255*(fakelife/maxlife),255*(fakelife/maxlife));
ObjEffect_SetVertexColor(health,1,255,255,255*(fakelife/maxlife),255*(fakelife/maxlife));
ObjEffect_SetVertexColor(health,2,255,255,255*(fakelife/maxlife),255*(fakelife/maxlife));
ObjEffect_SetVertexColor(health,3,255,255,255*(fakelife/maxlife),255*(fakelife/maxlife));
if(fakelife<=5){ Obj_Delete(health); SetLife(0);}

let number=0;
let digit=0;
let i=0;
loop(3){
	let horizontal=0;
	let vertical=0;
	Obj_SetPosition(timercounter[i],maxx-40+number,miny+14);
		if(i==2){ digit=floor(faketimer)%10; }
		if(i==1){ digit=floor(faketimer/10)%10; }
		if(i==0){ digit=floor(faketimer/100)%10; }
		loop(digit){
			horizontal+=11;
			if(horizontal>=55){ horizontal=0; vertical+=18; }
		}
	ObjEffect_SetVertexUV(timercounter[i],0,74+horizontal,1+vertical);
	ObjEffect_SetVertexUV(timercounter[i],1,84+horizontal,1+vertical);
	ObjEffect_SetVertexUV(timercounter[i],2,74+horizontal,19+vertical);
	ObjEffect_SetVertexUV(timercounter[i],3,84+horizontal,19+vertical);
	if(faketimer>=10 && faketimer>=10){
		ObjEffect_SetVertexColor(timercounter[i],0,255,255,255,0); ObjEffect_SetVertexColor(timercounter[i],1,255,255,255,0);
		ObjEffect_SetVertexColor(timercounter[i],2,255,255,255,0); ObjEffect_SetVertexColor(timercounter[i],3,255,255,255,0);
	}
	if(faketimer<10 && faketimer>=3){
		ObjEffect_SetVertexColor(timercounter[i],0,255,255,128,0); ObjEffect_SetVertexColor(timercounter[i],1,255,255,128,0);
		ObjEffect_SetVertexColor(timercounter[i],2,255,255,128,0); ObjEffect_SetVertexColor(timercounter[i],3,255,255,128,0);
	}
	if(faketimer<3){
		ObjEffect_SetVertexColor(timercounter[i],0,255,255,0,0); ObjEffect_SetVertexColor(timercounter[i],1,255,255,0,0);
		ObjEffect_SetVertexColor(timercounter[i],2,255,255,0,0); ObjEffect_SetVertexColor(timercounter[i],3,255,255,0,0);
	}
	i++;
	number+=11;
}

	if(GetLife<50 && oldlife>GetLife && (time+0)%4==0){ PlaySE(SElowhealth1); }
	if(GetLife<50 && oldlife>GetLife && (time+2)%4==0){ PlaySE(SElowhealth2); }
	oldlife=GetLife;

	if(GetLife>0){
		if(GetTimer<=10 && GetTimer>3 && time%60==0){ PlaySE(SEtimeout1); }
		if(GetTimer<=3 && time%60==0 && timercount<3){ PlaySE(SEtimeout2); timercount+=1; }
	}

}

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

function Portrait(character,cutintype){

if(cutintime==0){
let xcutinsize=599;
let ycutinsize=599;
	OBJcutin=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJcutin,6); Obj_SetPosition(OBJcutin,cx,cy);
	if(character=="Masahiro"){ ObjEffect_SetTexture(OBJcutin,CUTINmasahiro); }
	ObjEffect_SetRenderState(OBJcutin,ADD); ObjEffect_SetScale(OBJcutin,cutinsize,cutinsize);
	ObjEffect_SetPrimitiveType(OBJcutin,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJcutin,4);
	ObjEffect_SetVertexXY(OBJcutin,0,-(xcutinsize/2),-(ycutinsize/2)); ObjEffect_SetVertexUV(OBJcutin,0,0,0);
	ObjEffect_SetVertexXY(OBJcutin,1,xcutinsize/2,-(ycutinsize/2)); ObjEffect_SetVertexUV(OBJcutin,1,xcutinsize,0);
	ObjEffect_SetVertexXY(OBJcutin,2,-(xcutinsize/2),ycutinsize/2); ObjEffect_SetVertexUV(OBJcutin,2,0,ycutinsize);
	ObjEffect_SetVertexXY(OBJcutin,3,xcutinsize/2,ycutinsize/2); ObjEffect_SetVertexUV(OBJcutin,3,xcutinsize,ycutinsize);
	ObjEffect_SetVertexColor(OBJcutin,0,cutinalpha,255,255,255); ObjEffect_SetVertexColor(OBJcutin,1,cutinalpha,255,255,255);
	ObjEffect_SetVertexColor(OBJcutin,2,cutinalpha,255,255,255); ObjEffect_SetVertexColor(OBJcutin,3,cutinalpha,255,255,255);
}
	if(cutintime<50){ cutinalpha+=5; }
	if(cutinalpha>0 && cutintime>=50){ cutinalpha-=2; }
	if(cutintime>=50){
	Obj_SetPosition(OBJcutin,cx,Obj_GetY(OBJcutin)+10);
	cutinsize+=0.1;
	}
	ObjEffect_SetVertexColor(OBJcutin,0,cutinalpha,255,255,255); ObjEffect_SetVertexColor(OBJcutin,1,cutinalpha,255,255,255);
	ObjEffect_SetVertexColor(OBJcutin,2,cutinalpha,255,255,255); ObjEffect_SetVertexColor(OBJcutin,3,cutinalpha,255,255,255);
	ObjEffect_SetScale(OBJcutin,cutinsize,cutinsize);
	if(cutinalpha<=0){
	Obj_Delete(OBJcutin);
	}

cutintime++;
}

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

if(GetCommonDataDefault("NoAutoDispel",0)==0 && GetLife==0 && dispelled==0){
	if((GetLife==0 && dispelled==0 && spellcards==1) ||
	GetCommonDataDefault("SpellcardPractise",0)==1){
	CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character);
	dispelled=1;
	}
}

if(GetKeyState(VK_BOMB)==KEY_PUSH && GetCommonDataDefault("SpellcardPractise",0)==1){
	VanishEnemy;
	SetCommonData("RetrySpellcard",1);
	SetCommonData("BackToSpellcardPractise",1);
}
if((GetKeyState(VK_USER)==KEY_PUSH || GetMissCountInThisSpell>0) && GetCommonDataDefault("SpellcardPractise",0)==1){
	VanishEnemy;
	SetCommonData("RetrySpellcard",0);
	SetCommonData("BackToSpellcardPractise",1);
}


}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(4,4);
	SetTexture(BG1);
	SetAlpha(bgfade/2);
	SetColor(255,100,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time*2);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(2,2);
	if(bgtype==1){ SetTexture(BG2); }
	if(bgtype==2){ SetTexture(BG3); }
	SetAlpha(bgfade/2);
	SetColor(200,200,200);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,-time/3);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	if(fakedispel==false){
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(120,120,120);
	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("NightmareSpellcards",10);
	NewPointData(spellcardnumber,6);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}