script_enemy_main{

let effect1=0;
let object1=[];
let timer1=[];
let size1=[];

let effect2=0;
let object2=[];
let timer2=[];
let angle2=[];
let scale2=[];

let effect3=0;

let phase=0;

let number=GetArgument;

let GRunlocked=("\script\Images\Menu\TrumpCardUnlocked.png");
let GRstar=("\script\Images\OtherEffects\Star.png");
let GRwall=("\script\Images\OtherEffects\Wall.png");

let SEunlock1=("\script\SoundEffects\unlock1.wav");
let SEselect1=("\script\SoundEffects\select1.wav");

let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx2=320; let cy2=240;
let frame=0; let time=0;

@Initialize{
	LoadGraphic("\script\Images\Menu\TrumpCardUnlocked.png");
	LoadGraphic("\script\Images\OtherEffects\Star.png");
	LoadGraphic("\script\Images\OtherEffects\Wall.png");

	LoadSE("\script\SoundEffects\unlock1.wav");
	LoadSE("\script\SoundEffects\select1.wav");

	SetLife(10);
	SetX(GetCenterX);
	SetY(miny-1000);
}
	
@MainLoop{

SetCommonData("InEvent",1);
SetCommonData("TrumpCardScreenWait",1);

if(time==0){
let xsize=640;
let ysize=480;
	effect3=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect3,cx2,cy2);
	ObjEffect_SetScale(effect3,1,1); ObjEffect_SetAngle(effect3,0,0,0);
	ObjEffect_SetLayer(effect3,8); ObjEffect_SetTexture(effect3,GRwall); ObjEffect_SetRenderState(effect3,ALPHA);
	ObjEffect_SetPrimitiveType(effect3,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect3,4);
	ObjEffect_SetVertexXY(effect3,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect3,0,0,0);
	ObjEffect_SetVertexXY(effect3,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect3,1,xsize,0);
	ObjEffect_SetVertexXY(effect3,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect3,2,0,ysize);
	ObjEffect_SetVertexXY(effect3,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect3,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect3,0,255,0,0,0); ObjEffect_SetVertexColor(effect3,1,255,0,0,0);
	ObjEffect_SetVertexColor(effect3,2,255,0,0,0); ObjEffect_SetVertexColor(effect3,3,255,0,0,0);
let xsize=400;
let ysize=400;
let xpos=(number-1)*400;
let size=0.5;
	loop(10){
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,cx2,cy2);
	ObjEffect_SetScale(effect1,0,0); ObjEffect_SetAngle(effect1,0,0,0);
	ObjEffect_SetLayer(effect1,8); ObjEffect_SetTexture(effect1,GRunlocked); ObjEffect_SetRenderState(effect1,ALPHA);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0+xpos,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize+xpos,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0+xpos,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize+xpos,ysize);
	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];
	size1=size1~[effect1];
	size1[length(object1)-1]=size;
	timer1=timer1~[effect1];
	timer1[length(object1)-1]=0;
	size+=0.5/9;
	}
PlaySE(SEunlock1);
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); size1=erase(size1,i); timer1=erase(timer1,i);
	i--;
	}
	else{
	ObjEffect_SetScale(object1[i],(timer1[i]/20)*size1[i],(timer1[i]/20)*size1[i]);
if(size1[i]<1){
	ObjEffect_SetVertexColor(object1[i],0,160*size1[i],255,255,255);
	ObjEffect_SetVertexColor(object1[i],1,160*size1[i],255,255,255);
	ObjEffect_SetVertexColor(object1[i],2,160*size1[i],255,255,255);
	ObjEffect_SetVertexColor(object1[i],3,160*size1[i],255,255,255);
}
if(size1[i]>=1){
	ObjEffect_SetVertexColor(object1[i],0,255,255,255,255);
	ObjEffect_SetVertexColor(object1[i],1,255,255,255,255);
	ObjEffect_SetVertexColor(object1[i],2,255,255,255,255);
	ObjEffect_SetVertexColor(object1[i],3,255,255,255,255);
}
	if(timer1[i]<20){ timer1[i]=timer1[i]+1; }
	}
i++;
}

if(time>=30 && time%6==0){
let xsize=50;
let ysize=50;
let size=rand(0.2,0.7);
let angle=rand_int(0,360);
let red=rand_int(100,255);
let green=rand_int(100,255);
let blue=rand_int(100,255);
	effect2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect2,cx2+rand(-330,330),miny+rand(-25,-50));
	ObjEffect_SetScale(effect2,size,size); ObjEffect_SetAngle(effect2,0,0,angle);
	ObjEffect_SetLayer(effect2,8); ObjEffect_SetTexture(effect2,GRstar); ObjEffect_SetRenderState(effect2,ADD);
	ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
	ObjEffect_SetVertexXY(effect2,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect2,0,0,0);
	ObjEffect_SetVertexXY(effect2,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect2,1,xsize,0);
	ObjEffect_SetVertexXY(effect2,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect2,2,0,ysize);
	ObjEffect_SetVertexXY(effect2,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect2,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect2,0,255,red,green,blue); ObjEffect_SetVertexColor(effect2,1,255,red,green,blue);
	ObjEffect_SetVertexColor(effect2,2,255,red,green,blue); ObjEffect_SetVertexColor(effect2,3,255,red,green,blue);
	object2=object2~[effect2];
	timer2=timer2~[effect2];
	timer2[length(object2)-1]=0;
	scale2=scale2~[effect2];
	scale2[length(object2)-1]=size;
	angle2=angle2~[effect2];
	angle2[length(object2)-1]=angle;
}

let i=0;
while(i<length(object2)){
	if(Obj_BeDeleted(object2[i])){
	object2=erase(object2,i); timer2=erase(timer2,i); scale2=erase(scale2,i); angle2=erase(angle2,i);
	i--;
	}
	else{
	ObjEffect_SetScale(object2[i],scale2[i],scale2[i]);
	ObjEffect_SetAngle(object2[i],0,0,angle2[i]);
	Obj_SetY(object2[i],Obj_GetY(object2[i])+(scale2[i]*4));
	if(angle2[i]%2==0){ angle2[i]=angle2[i]+2; }
	if(angle2[i]%2!=0){ angle2[i]=angle2[i]-2; }
	timer2[i]=timer2[i]+1;
	}
i++;
}


if(time==20){ phase=1; }

if(phase==1 && GetKeyState(VK_SHOT)==KEY_PUSH){ PlaySE(SEselect1); phase=2; frame=0; }

if(phase==2 && frame>=20){
	let array=GetCommonData("TrumpCardUnlocked");
	array[number]=2;
	SetCommonData("TrumpCardUnlocked",array);

	SetCommonData("TrumpCardScreenWait",0);
	SetCommonData("PauseSpellcardPractise",0);
	SetCommonData("BackToSpellcardPractise",1);

	SetCommonData("TrumpCardsUnlocked",true);
	SaveCommonData;
	VanishEnemy;
}


time++;
frame++;
}

}