script_enemy_main{

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 speed=1;

let black=0;
let background=0;
let credits=0;
let creditsline=[];
let creditstime=[];
let creditsscale=[];
let creditsfade=[];

let backgroundpicture=0;
let backgroundfade=180;
let changebg=true;

let EFcredits=("\script\Images\Menu\CreditsText.png");
let EFbackground=("\script\Images\Menu\Credits1.png");
let EFblack=("\script\Images\OtherEffects\Wall.png");

@Initialize{
	LoadGraphic("\script\Images\OtherEffects\Wall.png");
	LoadGraphic("\script\Images\Menu\CreditsText.png");
	LoadGraphic("\script\Images\Menu\Credits1.png");
	LoadGraphic("\script\Images\Menu\Credits2.png");
	LoadGraphic("\script\Images\Menu\Credits3.png");
	LoadGraphic("\script\Images\Menu\Credits4.png");
	LoadGraphic("\script\Images\Menu\Credits5.png");
	LoadGraphic("\script\Images\Menu\Credits6.png");
	
	SetScore(0);
	SetLife(99999);
	SetTimer(108);

	SetCommonData("PlayMusic",3);
}
	
@MainLoop{

if(GetKeyState(VK_SKIP)==KEY_HOLD){ speed=20; }
else{ speed=1; }

//fast forward
loop(speed){

SetCommonData("InEvent",1);

if(time==0){
let xsize=640;
let ysize=480;
	black=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(black,320,240);
	ObjEffect_SetScale(black,1,1);
	ObjEffect_SetLayer(black,8); ObjEffect_SetTexture(black,EFblack); ObjEffect_SetRenderState(black,ALPHA);
	ObjEffect_SetPrimitiveType(black,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(black,4);
	ObjEffect_SetVertexXY(black,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(black,0,0,0);
	ObjEffect_SetVertexXY(black,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(black,1,xsize,0);
	ObjEffect_SetVertexXY(black,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(black,2,0,ysize);
	ObjEffect_SetVertexXY(black,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(black,3,xsize,ysize);
	ObjEffect_SetVertexColor(black,0,255,0,0,0); ObjEffect_SetVertexColor(black,1,255,0,0,0);
	ObjEffect_SetVertexColor(black,2,255,0,0,0); ObjEffect_SetVertexColor(black,3,255,0,0,0);

	background=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(background,320,240);
	ObjEffect_SetScale(background,1,1);
	ObjEffect_SetLayer(background,8); ObjEffect_SetTexture(background,EFbackground); ObjEffect_SetRenderState(background,ALPHA);
	ObjEffect_SetPrimitiveType(background,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(background,4);
	ObjEffect_SetVertexXY(background,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(background,0,0,0);
	ObjEffect_SetVertexXY(background,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(background,1,xsize,0);
	ObjEffect_SetVertexXY(background,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(background,2,0,ysize);
	ObjEffect_SetVertexXY(background,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(background,3,xsize,ysize);
	ObjEffect_SetVertexColor(background,0,backgroundfade,255,255,255); ObjEffect_SetVertexColor(background,1,backgroundfade,255,255,255);
	ObjEffect_SetVertexColor(background,2,backgroundfade,255,255,255); ObjEffect_SetVertexColor(background,3,backgroundfade,255,255,255);

let xsize=640;
let ysize=80;
let imagey=0;
let delay=-60;
let fade=0;
	loop(15){
	credits=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(credits,320,maxy);
	ObjEffect_SetScale(credits,2,2);
	ObjEffect_SetLayer(credits,8); ObjEffect_SetTexture(credits,EFcredits); ObjEffect_SetRenderState(credits,ALPHA);
	ObjEffect_SetPrimitiveType(credits,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(credits,4);
	ObjEffect_SetVertexXY(credits,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(credits,0,0,0+imagey);
	ObjEffect_SetVertexXY(credits,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(credits,1,xsize,0+imagey);
	ObjEffect_SetVertexXY(credits,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(credits,2,0,ysize+imagey);
	ObjEffect_SetVertexXY(credits,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(credits,3,xsize,ysize+imagey);
	ObjEffect_SetVertexColor(credits,0,fade,255,255,255); ObjEffect_SetVertexColor(credits,1,fade,255,255,255);
	ObjEffect_SetVertexColor(credits,2,fade,255,255,255); ObjEffect_SetVertexColor(credits,3,fade,255,255,255);
	creditsline=creditsline~[credits];
	creditstime=creditstime~[credits];
	creditstime[length(creditsline)-1]=delay;
	creditsscale=creditsscale~[credits];
	creditsscale[length(creditsline)-1]=2;
	creditsfade=creditsfade~[credits];
	creditsfade[length(creditsline)-1]=0;
	imagey+=80;
	delay-=350;
	}
}

let i=0;
while(i<length(creditsline)){
	if(Obj_BeDeleted(creditsline[i])){
	creditsline=erase(creditsline,i); creditstime=erase(creditstime,i); creditsscale=erase(creditsscale,i); creditsfade=erase(creditsfade,i);
	i--;
	}
	else{
	if(creditstime[i]>=0){
		Obj_SetY(creditsline[i],Obj_GetY(creditsline[i])-0.5);
		ObjEffect_SetScale(creditsline[i],creditsscale[i],creditsscale[i]);
		ObjEffect_SetVertexColor(creditsline[i],0,creditsfade[i],255,255,255); ObjEffect_SetVertexColor(creditsline[i],1,creditsfade[i],255,255,255);
		ObjEffect_SetVertexColor(creditsline[i],2,creditsfade[i],255,255,255); ObjEffect_SetVertexColor(creditsline[i],3,creditsfade[i],255,255,255);
		if(creditsscale[i]>1){ creditsscale[i]=creditsscale[i]-1/20; }
		if(creditsfade[i]<255){ creditsfade[i]=creditsfade[i]+255/20; }
	}
	creditstime[i]=creditstime[i]+1;
	if(Obj_GetY(creditsline[i])<miny-50){ Obj_Delete(creditsline[i]); }
	}
i++;
}

if(time%1000==0 && backgroundpicture<6){ changebg=true; backgroundpicture++; frame=0; }
if(backgroundpicture==1 && (backgroundfade+180)%360==0){ EFbackground=("\script\Images\Menu\Credits1.png"); ObjEffect_SetTexture(background,EFbackground); }
if(backgroundpicture==2 && (backgroundfade+180)%360==0){ EFbackground=("\script\Images\Menu\Credits2.png"); ObjEffect_SetTexture(background,EFbackground); }
if(backgroundpicture==3 && (backgroundfade+180)%360==0){ EFbackground=("\script\Images\Menu\Credits3.png"); ObjEffect_SetTexture(background,EFbackground); }
if(backgroundpicture==4 && (backgroundfade+180)%360==0){ EFbackground=("\script\Images\Menu\Credits4.png"); ObjEffect_SetTexture(background,EFbackground); }
if(backgroundpicture==5 && (backgroundfade+180)%360==0){ EFbackground=("\script\Images\Menu\Credits5.png"); ObjEffect_SetTexture(background,EFbackground); }
if(backgroundpicture==6 && (backgroundfade+180)%360==0){ EFbackground=("\script\Images\Menu\Credits6.png"); ObjEffect_SetTexture(background,EFbackground); }
if(changebg==true){ backgroundfade+=360/120; }
if(backgroundfade%360==0){ changebg=false; }

ObjEffect_SetVertexColor(background,0,255*cos(backgroundfade),255,255,255);
ObjEffect_SetVertexColor(background,1,255*cos(backgroundfade),255,255,255);
ObjEffect_SetVertexColor(background,2,255*cos(backgroundfade),255,255,255);
ObjEffect_SetVertexColor(background,3,255*cos(backgroundfade),255,255,255);

if(backgroundpicture==6 && frame>1100){ CreateEnemyFromFile("script\Functions\ExtraFadeout.txt",cx,cy,0,0,[8,600]); }
if(backgroundpicture==6 && frame>=1250){


if(Continued==false && GetCommonDataDefault("SpellcardsCaptured",0)>=25 && GetCommonData("TrumpCardUnlocked")[1]==0){
//Kurumi's
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[1]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[1]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[68]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
}
if(Continued==false && GetCommonData("PlayerType")==1 && GetCommonData("NotSwitchedElements")==0 && GetCommonData("TrumpCardUnlocked")[2]==0){
//Hotaru's
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[2]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[2]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[69]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
}
if(Continued==false && GetCommonData("Difficulty")>=2 && GetCommonData("TrumpCardUnlocked")[3]==0){
//Tomoko's
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[3]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[3]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[70]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
}
if(Continued==true && GetCommonData("TrumpCardUnlocked")[6]==0){
//Midori's
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[6]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[6]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[73]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
}
if(Continued==false && GetMissCount<=5 && GetCommonData("TrumpCardUnlocked")[7]==0){
//Tomomi's
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[7]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[7]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[74]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
}
if(Continued==false && GetCommonDataDefault("FocusTime",0)<(GetCommonDataDefault("TotalTime",0)/2) && GetCommonData("TrumpCardUnlocked")[12]==0){
//Haruna's
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[12]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[12]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[79]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
	
AddScore(-GetScore);
AddScore(GetCommonData("TotalTime"));
}
if(Continued==false && GetCommonData("PlayerType")==5 && GetCommonData("NotSwitchedElements")==0 && GetCommonData("TrumpCardUnlocked")[13]==0){
//Takeo's
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[13]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[13]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[80]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
}
if(Continued==false && GetGraze>=2500 && GetCommonData("TrumpCardUnlocked")[15]==0){
//Ryo's
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[15]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[15]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[82]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
}
if(Continued==false && GetBombCount<=5 && GetCommonData("TrumpCardUnlocked")[16]==0){
//Shinichi's
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[16]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[16]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[83]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
}
if(Continued==false && GetCommonDataDefault("ClearedFire",0)>=1 && GetCommonDataDefault("ClearedWater",0)>=1 && GetCommonDataDefault("ClearedEarth",0)>=1 &&
GetCommonDataDefault("ClearedWood",0)>=1 && GetCommonDataDefault("ClearedMetal",0)>=1 && GetCommonData("TrumpCardUnlocked")[18]==0){
//Witches'
	let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
	spellcarddataarray[18]=1;
	SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
	spellcarddataarray[18]=1;
	SetCommonData("TrumpCardUnlocked",spellcarddataarray);

	let spellcarddataarray=GetCommonData("SpellcardData");
	spellcarddataarray[85]=0.5;
	SetCommonData("SpellcardData",spellcarddataarray);
}

if(Continued==false){
	SetCommonData("ExtraUnlocked",true);
	if(GetCommonData("PlayerType")==1){ SetCommonData("ClearedFire",GetCommonData("Difficulty")); }
	if(GetCommonData("PlayerType")==2){ SetCommonData("ClearedWater",GetCommonData("Difficulty")); }
	if(GetCommonData("PlayerType")==3){ SetCommonData("ClearedEarth",GetCommonData("Difficulty")); }
	if(GetCommonData("PlayerType")==4){ SetCommonData("ClearedWood",GetCommonData("Difficulty")); }
	if(GetCommonData("PlayerType")==5){ SetCommonData("ClearedMetal",GetCommonData("Difficulty")); }
}

SaveCommonData;
SetCommonData("EndGame",1);
VanishEnemy;
}

time++;
frame++;

} //fast forward

}

@BackGround{
}

@DrawLoop{
}

@Finalize{
}

}