script_enemy_main{

let angle=90;
let phase=0;

let familiar=0;
let familiarobject=[];
let familiartimer=[];

let angle1=0;
let angle2=0;
let angle3=0;
let speed1=0;
let speed2=0;
let speed3=0;

let shotx1=0;
let bulletx1=[];
let timerx1=[];
let bouncex1=[];

let win=0;
let wintime=0;

let newloop=[0,0,0];
let graphic=[0,0,0];
let speed=[10,10,10];
let picturesgenerated=[0,0,0];
let waittime=[0,0,0];
let combination=[0,0,0];
let choice=[0,0,0];
let stop=[0,0,0];

let a=0;
let olda=0;
let timesspun=0;

let effect1=0; let effect2=0; let effect3=0;
let object1=[]; let object2=[]; let object3=[];
let timer1=[]; let timer2=[]; let timer3=[];
let belowcenter1=[]; let belowcenter2=[]; let belowcenter3=[];
let scale1=[]; let scale2=[]; let scale3=[];

let effect4=0; let effect5=0;
let object4=[]; let object5=[];

let character="Tomomi";
let cutin=character;
let dispelled=0;
let spellcards=5;
let spellcardnumber=29;
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 SEslot1=("script\SoundEffects\slotmachine1.wav");
let SEslot2=("script\SoundEffects\slotmachine2.wav");
let SEslot3=("script\SoundEffects\slotmachine3.wav");
let SEcoin=("script\SoundEffects\slotmachinecoin.wav");
let SEwrong=("script\SoundEffects\slotmachinewrong.wav");
let SEjackpot=("script\SoundEffects\slotmachinejackpot.wav");

let SEshots5=("\script\SoundEffects\shots5.wav");
let SEshotm2=("\script\SoundEffects\shotm2.wav");
let SEshotm7=("\script\SoundEffects\shotm7.wav");
let SEshotm8=("\script\SoundEffects\shotm8.wav");
let SEshotb1=("\script\SoundEffects\shotb1.wav");
let SEshotb5=("\script\SoundEffects\shotb5.wav");
let SElaserm2=("\script\SoundEffects\laserm2.wav");
let SEmagics5=("\script\SoundEffects\magics5.wav");

let GReffect1=("\script\Images\OtherEffects\SlotMachineA.png");
let GReffect2=("\script\Images\OtherEffects\SlotMachineB.png");
let GRfamiliar=("\script\Images\OtherEffects\SpellCircle1a.png");

let BG1=("\script\Images\BackgroundLayers\Tomomi3.png");
let BG2=("\script\Images\BackgroundLayers\Tomomi1.png");
let GRboss=("\script\Images\CharacterSprites\Tomomi.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\ShotsTomomi1.txt");

	LoadSE("script\SoundEffects\slotmachine1.wav");
	LoadSE("script\SoundEffects\slotmachine2.wav");
	LoadSE("script\SoundEffects\slotmachine3.wav");
	LoadSE("script\SoundEffects\slotmachinecoin.wav");
	LoadSE("script\SoundEffects\slotmachinewrong.wav");
	LoadSE("script\SoundEffects\slotmachinejackpot.wav");

	LoadSE("\script\SoundEffects\shots5.wav");
	LoadSE("\script\SoundEffects\shotm2.wav");
	LoadSE("\script\SoundEffects\shotm7.wav");
	LoadSE("\script\SoundEffects\shotm8.wav");
	LoadSE("\script\SoundEffects\shotb1.wav");
	LoadSE("\script\SoundEffects\shotb5.wav");
	LoadSE("\script\SoundEffects\laserm2.wav");
	LoadSE("\script\SoundEffects\magics5.wav");

	LoadGraphic("\script\Images\OtherEffects\SlotMachineA.png");
	LoadGraphic("\script\Images\OtherEffects\SlotMachineB.png");
	LoadGraphic("\script\Images\OtherEffects\SpellCircle1a.png");

	LoadGraphic("\script\Images\CharacterSprites\Tomomi.png");
	LoadGraphic("\script\Images\BackgroundLayers\Tomomi1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Tomomi3.png");

	SetScore(300000);
	SetLife(500);
	SetTimer(60);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+70,50);

	SetCommonData("Difficulty",4);

	if(GetCommonData("Difficulty")==4){ a=rand_int(1,3); } //jackpot to diamonds
	if(GetCommonData("Difficulty")==3){ a=rand_int(2,6); } //triple bar to melons
	if(GetCommonData("Difficulty")==2){ a=rand_int(5,9); } //cherries to miss
	if(GetCommonData("Difficulty")==1){ a=rand_int(7,10); } //grapes to miss
}
	
@MainLoop{

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

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=9; }
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("One Armed Bandit [Gambler`s Conceit] ("~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+80,miny+100),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+80,miny+100),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+80,miny+100),1.5);
	}
}


if(time%25==0 && time>=60){
let color=0;
if(GetCommonData("Difficulty")==1){ color=4; }
if(GetCommonData("Difficulty")==2){ color=7; }
if(GetCommonData("Difficulty")==3){ color=2; }
if(GetCommonData("Difficulty")==4){ color=9; }
	loop(40){
		if(phase%2==0){ CreateShot02(GetX-20,GetY-45,5,angle,-0.08,2.5,72+color,10); }
		if(phase%2!=0){ CreateShot02(GetX-20,GetY-45,5,angle,-0.08,2.5,84+color,10); }
	angle+=360/40;
	}
angle+=360/80;
phase++;
usespell=30;
PlaySE(SEshotm7);
}

if(win==1 && wintime<180){
if(wintime==0){ angle1=-20; }
let shot1=0;
	CreateLaserA(shot1,Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),700,10,97,50);
	SetLaserDataA(shot1,0,angle1,0,0,0,0);
	SetShotKillTime(shot1,100);
	FireShot(shot1);
	CreateLaserA(shot1,Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),700,10,101,50);
	SetLaserDataA(shot1,0,angle1,0,0,0,0);
	SetShotKillTime(shot1,100);
	FireShot(shot1);
	CreateLaserA(shot1,Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),700,10,105,50);
	SetLaserDataA(shot1,0,angle1,0,0,0,0);
	SetShotKillTime(shot1,100);
	FireShot(shot1);
angle1+=5.6;
wintime++;
}

if(win==2 && wintime<150){
	if(time%3==0){
	let angle=time*5+rand(0,0);
	let color=rand_int(0,1);
	if(color==0){ color=0; }
	if(color==1){ color=36; }
		CreateShot12(Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),3*cos(angle),rand(-2,-3.5),-0.03*cos(angle),0.045,0.1*cos(angle),rand(2.5,3.5),25+color,10);
		CreateShot12(Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),3*cos(angle),rand(-2,-3.5),-0.03*cos(angle),0.045,0.1*cos(angle),rand(2.5,3.5),29+color,10);
		CreateShot12(Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),3*cos(angle),rand(-2,-3.5),-0.03*cos(angle),0.045,0.1*cos(angle),rand(2.5,3.5),32+color,10);
	}
if(time%5==0){ PlaySE(SEshots5); }
wintime++;
}

if(win==3 && wintime<240){
let angle=0;
	loop(25){
	SetShotDirectionType(PLAYER);
		if((time+0)%30==0){ CreateLaser01(Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),5,angle,80,10,97,10); PlaySE(SElaserm2); }
		if((time+10)%30==0){ CreateLaser01(Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),5,angle,80,10,101,10); PlaySE(SElaserm2); }
		if((time+20)%30==0){ CreateLaser01(Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),5,angle,80,10,104,10); PlaySE(SElaserm2); }
	SetShotDirectionType(ABSOLUTE);
	angle+=360/25;
	}
wintime++;
}

if(win==4 && wintime<240){
	if(time%15==0){
	let shot1=0;
	let speed=5;
	let aim=20;
SetShotDirectionType(PLAYER);
		CreateShotA(shot1,Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),10);
		SetShotDataA(shot1,0,speed,0-90,1,-0.1,0,35);
		SetShotDataA(shot1,30,0,-aim,0.3,0.05,5,25);
		FireShot(shot1);
		CreateShotA(shot1,Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),10);
		SetShotDataA(shot1,0,speed,0+90,-1,-0.1,0,35);
		SetShotDataA(shot1,30,0,aim,-0.3,0.05,5,25);
		FireShot(shot1);

		CreateShotA(shot1,Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),10);
		SetShotDataA(shot1,0,speed,0-90,-1,-0.1,0,35);
		SetShotDataA(shot1,30,0,-aim,0.3,0.05,5,29);
		FireShot(shot1);
		CreateShotA(shot1,Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),10);
		SetShotDataA(shot1,0,speed,0+90,1,-0.1,0,35);
		SetShotDataA(shot1,30,0,aim,-0.3,0.05,5,29);
		FireShot(shot1);

		CreateShotA(shot1,Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),10);
		SetShotDataA(shot1,0,speed,0-90,1,-0.1,0,35);
		SetShotDataA(shot1,30,0,-aim,0.3,0.05,5,32);
		FireShot(shot1);
		CreateShotA(shot1,Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),10);
		SetShotDataA(shot1,0,speed,0+90,-1,-0.1,0,35);
		SetShotDataA(shot1,30,0,aim,-0.3,0.05,5,32);
		FireShot(shot1);
	PlaySE(SEshotm8);
	}
SetShotDirectionType(ABSOLUTE);
wintime++;
}

if(win==5 && wintime<240){
	if(wintime==0){
	let angle=rand(0,360);
		loop(100){
		CreateShot02(Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),5,angle,-0.1,0.75,25,0);
		angle+=360/100;
		}
	let angle=rand(0,360);
		loop(100){
		CreateShot02(Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),5,angle,-0.1,0.75,29,0);
		angle+=360/100;
		}
	let angle=rand(0,360);
		loop(100){
		CreateShot02(Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),5,angle,-0.1,0.75,32,0);
		angle+=360/100;
		}
	PlaySE(SEshotb1);
	}
wintime++;
}

if(win==6 && wintime<240){
	if(wintime==0){
	let angle=rand(0,360);
	let shot1=0;
		loop(20){
		let speed=2;
			loop(4){
			CreateShotA(shot1,Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),0);
			SetShotDataA(shot1,0,speed,angle,0,0,0,109);
			SetShotDataA(shot1,25,NULL,NULL,2,0,0,109);
			SetShotDataA(shot1,70,NULL,NULL,0,0,0,109);
			FireShot(shot1);
			speed-=0.15;
			CreateShotA(shot1,Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),0);
			SetShotDataA(shot1,0,speed,angle,0,0,0,109);
			SetShotDataA(shot1,25,NULL,NULL,-2,0,0,109);
			SetShotDataA(shot1,70,NULL,NULL,0,0,0,109);
			FireShot(shot1);
			speed-=0.15;
			}
		angle+=360/20;
		}
	let angle=rand(0,360);
	let shot1=0;
		loop(20){
		let speed=2;
			loop(4){
			CreateShotA(shot1,Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),0);
			SetShotDataA(shot1,0,speed,angle,0,0,0,113);
			SetShotDataA(shot1,25,NULL,NULL,2,0,0,113);
			SetShotDataA(shot1,70,NULL,NULL,0,0,0,113);
			FireShot(shot1);
			speed-=0.15;
			CreateShotA(shot1,Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),0);
			SetShotDataA(shot1,0,speed,angle,0,0,0,113);
			SetShotDataA(shot1,25,NULL,NULL,-2,0,0,113);
			SetShotDataA(shot1,70,NULL,NULL,0,0,0,113);
			FireShot(shot1);
			speed-=0.15;
			}
		angle+=360/20;
		}
	let angle=rand(0,360);
	let shot1=0;
		loop(20){
		let speed=2;
			loop(4){
			CreateShotA(shot1,Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),0);
			SetShotDataA(shot1,0,speed,angle,0,0,0,116);
			SetShotDataA(shot1,25,NULL,NULL,2,0,0,116);
			SetShotDataA(shot1,70,NULL,NULL,0,0,0,116);
			FireShot(shot1);
			speed-=0.15;
			CreateShotA(shot1,Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),0);
			SetShotDataA(shot1,0,speed,angle,0,0,0,116);
			SetShotDataA(shot1,25,NULL,NULL,-2,0,0,116);
			SetShotDataA(shot1,70,NULL,NULL,0,0,0,116);
			FireShot(shot1);
			speed-=0.15;
			}
		angle+=360/20;
		}
	PlaySE(SEshotb1);
	}
wintime++;
}

if(win==7 && wintime<180){
	if(wintime==0){ angle1=rand(0,360); speed1=1; angle2=rand(0,360); speed2=1; angle3=rand(0,360); speed3=1; }
	if(time%8==0){
		loop(10){
		CreateShot01(Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),speed1,angle1,25,0);
		angle1+=360/10;
		}
	speed1+=0.15;
	angle1-=0.7;
		loop(10){
		CreateShot01(Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),speed2,angle2,29,0);
		angle2+=360/10;
		}
	speed2+=0.15;
		loop(10){
		CreateShot01(Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),speed3,angle3,32,0);
		angle3+=360/10;
		}
	speed3+=0.15;
	angle3+=0.7;
	}
	if(time%8==0){ PlaySE(SEshotm2); }
wintime++;
}

if(win==8 && wintime<240){
	if(wintime==0){
	let angle=rand(0,360);
		loop(12){
		shotx1=(Obj_Create(OBJ_SHOT));
		Obj_SetPosition(shotx1,Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]));
		Obj_SetAngle(shotx1,angle);
		Obj_SetSpeed(shotx1,2);
		ObjShot_SetGraphic(shotx1,121);
		bulletx1=bulletx1~[shotx1];
		timerx1=timerx1~[shotx1];
		timerx1[length(bulletx1)-1]=0;
		bouncex1=bouncex1~[shotx1];
		bouncex1[length(bulletx1)-1]=0;

		shotx1=(Obj_Create(OBJ_SHOT));
		Obj_SetPosition(shotx1,Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]));
		Obj_SetAngle(shotx1,angle);
		Obj_SetSpeed(shotx1,2);
		ObjShot_SetGraphic(shotx1,125);
		bulletx1=bulletx1~[shotx1];
		timerx1=timerx1~[shotx1];
		timerx1[length(bulletx1)-1]=0;
		bouncex1=bouncex1~[shotx1];
		bouncex1[length(bulletx1)-1]=0;

		shotx1=(Obj_Create(OBJ_SHOT));
		Obj_SetPosition(shotx1,Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]));
		Obj_SetAngle(shotx1,angle);
		Obj_SetSpeed(shotx1,2);
		ObjShot_SetGraphic(shotx1,128);
		bulletx1=bulletx1~[shotx1];
		timerx1=timerx1~[shotx1];
		timerx1[length(bulletx1)-1]=0;
		bouncex1=bouncex1~[shotx1];
		bouncex1[length(bulletx1)-1]=0;

		angle+=360/12;
		}
	PlaySE(SEshotb5);
	}
wintime++;
}
let i=0;
while(i<length(bulletx1)){
	if(Obj_BeDeleted(bulletx1[i])){
	bulletx1=erase(bulletx1,i); timerx1=erase(timerx1,i); bouncex1=erase(bouncex1,i);
	i--;
	}
	else{
	let obj=bulletx1[i];
		if(bouncex1[i]<1){
			if(Obj_GetX(obj)<=minx){
			Obj_SetAngle(obj,180-Obj_GetAngle(obj));
			Obj_SetX(obj,Obj_GetX(obj)+1); bouncex1[i]=bouncex1[i]+1;
			PlaySE(SEmagics5);
			}
			if(Obj_GetX(obj)>=maxx){
			Obj_SetAngle(obj,180-Obj_GetAngle(obj));
			Obj_SetX(obj,Obj_GetX(obj)-1); bouncex1[i]=bouncex1[i]+1;
			PlaySE(SEmagics5);
			}
		}
	timerx1[i]=timerx1[i]+1;
	}
i++;
}


if(win>=9 && wintime<180){
if(wintime==0){ angle1=rand(0,360); angle2=rand(0,360); angle3=rand(0,360);  }
	if(time%8==0){
		loop(5){
		CreateShot02(Obj_GetX(familiarobject[0]),Obj_GetY(familiarobject[0]),rand(4,5),angle1,-0.1,rand(1,1.5),133,10);
		CreateShot02(Obj_GetX(familiarobject[1]),Obj_GetY(familiarobject[1]),rand(4,5),angle2,-0.1,rand(1,1.5),137,10);
		CreateShot02(Obj_GetX(familiarobject[2]),Obj_GetY(familiarobject[2]),rand(4,5),angle3,-0.1,rand(1,1.5),140,10);
		angle1+=360/5;
		angle2+=360/5;
		angle3+=360/5;
		}
	angle1+=6;
	angle2-=6;
	angle3+=6;
	PlaySE(SEshots5);
	}
wintime++;
}




if(time==60){
	newloop[0]=1; graphic[0]=(choice[0]*40);
	newloop[1]=1; graphic[1]=(choice[1]*40);
	newloop[2]=1; graphic[2]=(choice[2]*40);
}

if(newloop[0]==1){
	newloop[0]=newloop[0]+1;
	graphic[0]=graphic[0]+40;
	if(graphic[0]>=320){ graphic[0]=0; }

	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,cx-50,miny+40);
	ObjEffect_SetScale(effect1,1,1);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,GReffect1); ObjEffect_SetRenderState(effect1,ALPHA);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-20,-20); ObjEffect_SetVertexUV(effect1,0,0+graphic[0],0);
	ObjEffect_SetVertexXY(effect1,1,20,-20); ObjEffect_SetVertexUV(effect1,1,40+graphic[0],0);
	ObjEffect_SetVertexXY(effect1,2,-20,20); ObjEffect_SetVertexUV(effect1,2,0+graphic[0],40);
	ObjEffect_SetVertexXY(effect1,3,20,20); ObjEffect_SetVertexUV(effect1,3,40+graphic[0],40);
	ObjEffect_SetVertexColor(effect1,0,255,255,255,255); ObjEffect_SetVertexColor(effect1,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,255,255,255,255); ObjEffect_SetVertexColor(effect1,3,255,255,255,255);
	object1=object1~[effect1];
	timer1=timer1~[effect1];
	timer1[length(object1)-1]=0;
	belowcenter1=belowcenter1~[effect1];
	belowcenter1[length(object1)-1]=0;
	scale1=scale1~[effect1];
	scale1[length(object1)-1]=0;

	picturesgenerated[0]=picturesgenerated[0]+1;
	newloop[0]=0;
}
if(newloop[1]==1){
	newloop[1]=newloop[1]+1;
	graphic[1]=graphic[1]+40;
	if(graphic[1]>=320){ graphic[1]=0; }

	effect2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect2,cx,miny+40);
	ObjEffect_SetScale(effect2,1,1);
	ObjEffect_SetLayer(effect2,1); ObjEffect_SetTexture(effect2,GReffect1); ObjEffect_SetRenderState(effect2,ALPHA);
	ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
	ObjEffect_SetVertexXY(effect2,0,-20,-20); ObjEffect_SetVertexUV(effect2,0,0+graphic[1],0);
	ObjEffect_SetVertexXY(effect2,1,20,-20); ObjEffect_SetVertexUV(effect2,1,40+graphic[1],0);
	ObjEffect_SetVertexXY(effect2,2,-20,20); ObjEffect_SetVertexUV(effect2,2,0+graphic[1],40);
	ObjEffect_SetVertexXY(effect2,3,20,20); ObjEffect_SetVertexUV(effect2,3,40+graphic[1],40);
	ObjEffect_SetVertexColor(effect2,0,255,255,255,255); ObjEffect_SetVertexColor(effect2,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect2,2,255,255,255,255); ObjEffect_SetVertexColor(effect2,3,255,255,255,255);
	object2=object2~[effect2];
	timer2=timer2~[effect2];
	timer2[length(object2)-1]=0;
	belowcenter2=belowcenter2~[effect2];
	belowcenter2[length(object2)-1]=0;
	scale2=scale2~[effect2];
	scale2[length(object2)-1]=0;

	picturesgenerated[1]=picturesgenerated[1]+1;
	newloop[1]=0;
}
if(newloop[2]==1){
	newloop[2]=newloop[2]+1;
	graphic[2]=graphic[2]+40;
	if(graphic[2]>=320){ graphic[2]=0; }

	effect3=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect3,cx+50,miny+40);
	ObjEffect_SetScale(effect3,1,1);
	ObjEffect_SetLayer(effect3,1); ObjEffect_SetTexture(effect3,GReffect1); ObjEffect_SetRenderState(effect3,ALPHA);
	ObjEffect_SetPrimitiveType(effect3,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect3,4);
	ObjEffect_SetVertexXY(effect3,0,-20,-20); ObjEffect_SetVertexUV(effect3,0,0+graphic[2],0);
	ObjEffect_SetVertexXY(effect3,1,20,-20); ObjEffect_SetVertexUV(effect3,1,40+graphic[2],0);
	ObjEffect_SetVertexXY(effect3,2,-20,20); ObjEffect_SetVertexUV(effect3,2,0+graphic[2],40);
	ObjEffect_SetVertexXY(effect3,3,20,20); ObjEffect_SetVertexUV(effect3,3,40+graphic[2],40);
	ObjEffect_SetVertexColor(effect3,0,255,255,255,255); ObjEffect_SetVertexColor(effect3,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect3,2,255,255,255,255); ObjEffect_SetVertexColor(effect3,3,255,255,255,255);
	object3=object3~[effect3];
	timer3=timer3~[effect3];
	timer3[length(object3)-1]=0;
	belowcenter3=belowcenter3~[effect3];
	belowcenter3[length(object3)-1]=0;
	scale3=scale3~[effect3];
	scale3[length(object3)-1]=0;

	picturesgenerated[2]=picturesgenerated[2]+1;
	newloop[2]=0;
}


if(time==60){
let hpos=0;
	loop(3){
	effect5=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect5,cx-50+hpos,miny+100);
	ObjEffect_SetScale(effect5,1,1);
	ObjEffect_SetLayer(effect5,1); ObjEffect_SetTexture(effect5,GReffect2); ObjEffect_SetRenderState(effect5,ALPHA);
	ObjEffect_SetPrimitiveType(effect5,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect5,4);
	ObjEffect_SetVertexXY(effect5,0,-22,-62); ObjEffect_SetVertexUV(effect5,0,40,0);
	ObjEffect_SetVertexXY(effect5,1,22,-62); ObjEffect_SetVertexUV(effect5,1,80,0);
	ObjEffect_SetVertexXY(effect5,2,-22,62); ObjEffect_SetVertexUV(effect5,2,40,120);
	ObjEffect_SetVertexXY(effect5,3,22,62); ObjEffect_SetVertexUV(effect5,3,80,120);
	ObjEffect_SetVertexColor(effect5,0,255,255,255,255); ObjEffect_SetVertexColor(effect5,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect5,2,255,255,255,255); ObjEffect_SetVertexColor(effect5,3,255,255,255,255);
	object5=object5~[effect5];
	hpos+=50;
	}
let hpos=0;
	loop(3){
	effect4=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect4,cx-50+hpos,miny+100);
	ObjEffect_SetScale(effect4,1,1);
	ObjEffect_SetLayer(effect4,1); ObjEffect_SetTexture(effect4,GReffect2); ObjEffect_SetRenderState(effect4,ALPHA);
	ObjEffect_SetPrimitiveType(effect4,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect4,4);
	ObjEffect_SetVertexXY(effect4,0,-22,-65); ObjEffect_SetVertexUV(effect4,0,0,0);
	ObjEffect_SetVertexXY(effect4,1,22,-65); ObjEffect_SetVertexUV(effect4,1,40,0);
	ObjEffect_SetVertexXY(effect4,2,-22,65); ObjEffect_SetVertexUV(effect4,2,0,120);
	ObjEffect_SetVertexXY(effect4,3,22,65); ObjEffect_SetVertexUV(effect4,3,40,120);
	ObjEffect_SetVertexColor(effect4,0,255,255,255,255); ObjEffect_SetVertexColor(effect4,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect4,2,255,255,255,255); ObjEffect_SetVertexColor(effect4,3,255,255,255,255);
	object4=object4~[effect4];
	hpos+=50;
	}
}

let i=0;
while(i<length(object1)){
timer1[i]=timer1[i]+speed[0];
	if(Obj_BeDeleted(object1[i])){
		object1=erase(object1,i); timer1=erase(timer1,i); belowcenter1=erase(belowcenter1,i); scale1=erase(scale1,i);
		i--;
	}
	else{
	Obj_SetPosition(object1[i],cx-50,miny+35+timer1[i]);
		if(Obj_GetY(object1[i])>miny+75 && belowcenter1[i]!=1){ newloop[0]=1; belowcenter1[i]=1; }
		if(Obj_GetY(object1[i])>miny+155){ Obj_Delete(object1[i]); belowcenter1[i]=0; }

		scale1[i]=scale1[i]+((4/3)*speed[0]);
		ObjEffect_SetScale(object1[i],1,1*sin(scale1[i]));
	}
i++;
}
if(picturesgenerated[0]>=14){ speed[0]=speed[0]-0.1; }
if(speed[0]<=0){ speed[0]=0; if(stop[0]==0){ PlaySE(SEslot1); stop[0]=1; } }


let i=0;
while(i<length(object2)){
timer2[i]=timer2[i]+speed[1];
	if(Obj_BeDeleted(object2[i])){
		object2=erase(object2,i); timer2=erase(timer2,i); belowcenter2=erase(belowcenter2,i); scale2=erase(scale2,i);
		i--;
	}
	else{
	Obj_SetPosition(object2[i],cx,miny+35+timer2[i]);
		if(Obj_GetY(object2[i])>miny+75 && belowcenter2[i]!=1){ newloop[1]=1; belowcenter2[i]=1; }
		if(Obj_GetY(object2[i])>miny+155){ Obj_Delete(object2[i]); belowcenter2[i]=0; }

		scale2[i]=scale2[i]+((4/3)*speed[1]);
		ObjEffect_SetScale(object2[i],1,1*sin(scale2[i]));
	}
	i++;
}
if(picturesgenerated[1]>=27){ speed[1]=speed[1]-0.1; }
if(speed[1]<=0){ speed[1]=0; if(stop[1]==0){ PlaySE(SEslot2); stop[1]=1; } }

let i=0;
while(i<length(object3)){
timer3[i]=timer3[i]+speed[2];
	if(Obj_BeDeleted(object3[i])){
		object3=erase(object3,i); timer3=erase(timer3,i); belowcenter3=erase(belowcenter3,i); scale3=erase(scale3,i);
		i--;
	}
	else{
	Obj_SetPosition(object3[i],cx+50,miny+35+timer3[i]);
		if(Obj_GetY(object3[i])>miny+75 && belowcenter3[i]!=1){ newloop[2]=1; belowcenter3[i]=1; }
		if(Obj_GetY(object3[i])>miny+155){ Obj_Delete(object3[i]); belowcenter3[i]=0; }

		scale3[i]=scale3[i]+((4/3)*speed[2]);
		ObjEffect_SetScale(object3[i],1,1*sin(scale3[i]));
	}
i++;
}
if(picturesgenerated[2]>=40){ speed[2]=speed[2]-0.1; }
if(speed[2]<=0){
	speed[2]=0;
	if(stop[2]==0 && a==1){ PlaySE(SEjackpot); stop[2]=1; win=a; wintime=0; }
	if(stop[2]==0 && a>1 && a<=8){ PlaySE(SEslot3); stop[2]=1; win=a; wintime=0; }
	if(stop[2]==0 && a>=9){ PlaySE(SEwrong); stop[2]=1; win=a; wintime=0; }
}

if((time+280)%340==0){
if(a>8){
	if(GetCommonData("Difficulty")==4){ a=rand_int(1,3); } //jackpot to diamonds
	if(GetCommonData("Difficulty")==3){ a=rand_int(2,6); } //triple bar to melons
	if(GetCommonData("Difficulty")==2){ a=rand_int(5,9); } //cherries to miss 1
	if(GetCommonData("Difficulty")==1){ a=rand_int(7,9); } //grapes to miss 3
}
if(a<=8){
	if(GetCommonData("Difficulty")==4){ a+=rand_int(1,2); if(a>3){ a-=3; }  } //jackpot to diamonds
	if(GetCommonData("Difficulty")==3){ a+=rand_int(2,3); if(a>6){ a-=5; }  } //triple bar to melons
	if(GetCommonData("Difficulty")==2){ a+=rand_int(1,3); if(olda>8){ a=olda-4; }  } //cherries to miss
	if(GetCommonData("Difficulty")==1){ a+=rand_int(1,2); if(olda>8){ a=olda-2; } } //grapes to miss 3
}
	if(a==1){ choice=[0,3,6]; } //jackpot
	if(a==2){ choice=[1,4,7]; } //triple bar
	if(a==3){ choice=[2,5,0]; } //diamonds
	if(a==4){ choice=[3,6,1]; } //bells
	if(a==5){ choice=[4,7,2]; } //cherries
	if(a==6){ choice=[5,0,3]; } //melons
	if(a==7){ choice=[6,1,4]; } //grapes
	if(a==8){ choice=[7,2,5]; } //oranges
olda=a;
	if(a>8){  a=rand_int(9,14); }
	if(a==9){ choice=[0,3,7]; } //miss 1
	if(a==10){ choice=[3,2,1]; } //miss 2
	if(a==11){ choice=[6,3,5]; } //miss 3
	if(a==12){ choice=[1,3,7]; } //miss 4
	if(a==13){ choice=[2,7,2]; } //miss 5
	if(a==14){ choice=[6,6,6]; } //miss 6

	picturesgenerated[0]=0; speed[0]=10; graphic[0]=choice[0]*40; stop[0]=0;
	picturesgenerated[1]=0; speed[1]=10; graphic[1]=choice[1]*40; stop[1]=0;
	picturesgenerated[2]=0; speed[2]=10; graphic[2]=choice[2]*40; stop[2]=0;
PlaySE(SEcoin);
}


if(time==60){
let xsize=199;
let ysize=199;
let count=0;
	loop(3){
	familiar=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(familiar,GetX,GetY);
	ObjEffect_SetScale(familiar,0.25,0.25);
	ObjEffect_SetLayer(familiar,2); ObjEffect_SetTexture(familiar,GRfamiliar); ObjEffect_SetRenderState(familiar,ALPHA);
	ObjEffect_SetPrimitiveType(familiar,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(familiar,4);
	ObjEffect_SetVertexXY(familiar,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(familiar,0,0,0);
	ObjEffect_SetVertexXY(familiar,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(familiar,1,xsize,0);
	ObjEffect_SetVertexXY(familiar,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(familiar,2,0,ysize);
	ObjEffect_SetVertexXY(familiar,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(familiar,3,xsize,ysize);
		if(count==0){
		Obj_SetSpeed(familiar,3.5);
		Obj_SetAngle(familiar,90+60);
		ObjEffect_SetVertexColor(familiar,0,255,255,0,0); ObjEffect_SetVertexColor(familiar,1,255,255,0,0);
		ObjEffect_SetVertexColor(familiar,2,255,255,0,0); ObjEffect_SetVertexColor(familiar,3,255,255,0,0);
		}
		if(count==1){
		Obj_SetSpeed(familiar,3.5);
		Obj_SetAngle(familiar,90);
		ObjEffect_SetVertexColor(familiar,0,255,0,255,0); ObjEffect_SetVertexColor(familiar,1,255,0,255,0);
		ObjEffect_SetVertexColor(familiar,2,255,0,255,0); ObjEffect_SetVertexColor(familiar,3,255,0,255,0);
		}
		if(count==2){
		Obj_SetSpeed(familiar,3.5);
		Obj_SetAngle(familiar,90-60);
		ObjEffect_SetVertexColor(familiar,0,255,0,0,255); ObjEffect_SetVertexColor(familiar,1,255,0,0,255);
		ObjEffect_SetVertexColor(familiar,2,255,0,0,255); ObjEffect_SetVertexColor(familiar,3,255,0,0,255);
		}
	familiarobject=familiarobject~[familiar];
	familiartimer=familiartimer~[familiar];
	familiartimer[length(familiarobject)-1]=0;
	count++;
	}
}

let i=0;
while(i<length(familiarobject)){
	if(Obj_BeDeleted(familiarobject[i])){
	familiarobject=erase(familiarobject,i); familiartimer=erase(familiartimer,i);
	i--;
	}
	else{
		ObjEffect_SetAngle(familiarobject[i],0,0,time*6);
		if(Obj_GetSpeed(familiarobject[i])>0){ Obj_SetSpeed(familiarobject[i],Obj_GetSpeed(familiarobject[i])-0.05); }
		if(Obj_GetSpeed(familiarobject[i])<0){ Obj_SetSpeed(familiarobject[i],0); }
	familiartimer[i]=familiartimer[i]+1;
	}
i++;
}


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(2,2);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(150,150,150);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,-time/4);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0,400,400);
	SetTexture(BG2);
	SetGraphicScale(1,1);
	SetGraphicAngle(0,0,time*2);
	DrawGraphic(cx,cy);
}

@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";
}

}