//SET UP ALL OF THE GRAPHICS AND OTHER JUNK//////////////////////////////////
void init()
{
int loop;
x_set_mode(X_MODE_320x240,320); //SET MODE X//
x_set_tripplebuffer(240); //INSTALL TRIPPLE BUFFER//
install_new_key_handler(); //INSTALL KEYBOARD HANDLER//
x_install_vsync_handler(1); //INSTALL VSYNC HANDLER//
for (loop=0;loop<52;loop++) //ALLOCATE MEM FOR GRAPHICS//
if ((data.block[loop]=(char far *)malloc(258))==NULL)
exitgame();
for (loop=0;loop<3;loop++)
if ((data.coin[loop]=(char far *)malloc(258))==NULL)
exitgame();
if ((bcoin=(cointype *)malloc(sizeof(cointype)))==NULL)
exitgame();
bcoin->next=NULL;
if ((bscore=(scoretype *)malloc(sizeof(scoretype)))==NULL)
exitgame();
bscore->next=NULL;
for (loop=0;loop<2;loop++)
{
player[loop].lives=3;
player[loop].level=1;
player[loop].screenx=0;
}
}
//FILL SCREEN ///////////////////////////////////////////////////////////////
void fillscreen(int color)
{
x_rect_fill(32,0,288,224,HiddenPageOffs,color);
}
//GET INPUTS FROM DATA FILES/////////////////////////////////////////////////
int getinputs()
{
FILE *in;
int count,loop1,loop2,loop3,yinit,blocknum,backnum;
char *temp,ch,levelfile[13],graphfile[13];
char far *tempbm;
strcpy(levelfile,"LEVEL000.DAT");
levelfile[7]=player[curplay].level%10+48;
if (player[curplay].level>9)
levelfile[6]=player[curplay].level/10+48;
if ((in=fopen(levelfile,"r"))==NULL)
{
exitgame();
printf("%s could not be found!\n",levelfile);
exit(1);
}
data.maxlength=(int)fgetc(in);
yinit=(int)fgetc(in);
data.startpos[0]=(int)fgetc(in);
data.startpos[1]=(int)fgetc(in);
blocknum=(int)fgetc(in);
backnum=(int)fgetc(in);
fseek(in,0,SEEK_SET);
for (loop1=0;loop1<14;loop1++)
for (loop2=0;loop2<=data.maxlength;loop2++)
{
ch=getc(in);
if(ch<='0')
data.world[loop1][loop2]=0;
if (ch>='a' && ch<='z')
data.world[loop1][loop2]=ch-70;
if (ch>='A' && ch<='Z')
data.world[loop1][loop2]=ch-64;
if (loop1==0)
data.world[loop1][loop2]=0;
}
fclose(in);
strcpy(graphfile,"BLOCK000.PCX");
graphfile[7]=blocknum;
if ((in=fopen(graphfile,"rb"))==NULL)
{
exitgame();
printf("%s could not be found!\n",graphfile);
exit(1);
}
temp=getpcx(in,temp,6000);
tempbm=(char far *)farmalloc(258);
tempbm[0]=tempbm[1]=16;
for (loop1=0;loop1<26;loop1++)
{
count=2;
for (loop2=0;loop2<16;loop2++)
for (loop3=0;loop3<16;loop3++)
tempbm[count++]=temp[loop1*17+(loop2+1)*320+loop3+1];
x_bm_to_pbm(tempbm,data.block[loop1+26]);
}
free(temp);
fseek(in,-768,SEEK_END);
for (loop1=0;loop1<256;loop1++)
{
data.palette[loop1].red=(getc(in)>>2);
data.palette[loop1].green=(getc(in)>>2);
data.palette[loop1].blue=(getc(in)>>2);
}
fclose(in);
strcpy(graphfile,"BGRND000.PCX");
graphfile[7]=backnum;
if ((in=fopen(graphfile,"rb"))==NULL)
{
exitgame();
printf("%s could not be found!\n",graphfile);
exit(1);
}
temp=getpcx(in,temp,6000);
for (loop1=0;loop1<26;loop1++)
{
count=2;
for (loop2=0;loop2<16;loop2++)
for (loop3=0;loop3<16;loop3++)
tempbm[count++]=temp[loop1*17+(loop2+1)*320+loop3+1];
x_bm_to_pbm(tempbm,data.block[loop1]);
}
free(temp);
fclose(in);
strcpy(graphfile,"COIN.PCX");
if ((in=fopen(graphfile,"rb"))==NULL)
{
exitgame();
printf("%s could not be found!\n",graphfile);
exit(1);
}
temp=getpcx(in,temp,6000);
for (loop1=0;loop1<3;loop1++)
{
count=2;
for (loop2=0;loop2<16;loop2++)
for (loop3=0;loop3<16;loop3++)
tempbm[count++]=temp[loop1*17+(loop2+1)*320+loop3];
x_bm_to_pbm(tempbm,data.coin[loop1]);
}
farfree(tempbm);
free(temp);
fclose(in);
for (loop1=0;loop1<256;loop1++)
setpalette(loop1,data.palette[loop1]);
return(yinit);
}
//GET MARIO DATA/////////////////////////////////////////////////////////////
void getmario()
{
FILE *marioin;
int loop1,loop2,loop3;
char *temp;
if ((marioin=fopen("MARIO.PCX","rb"))==NULL)
{
exitgame();
printf("MARIO.PCX could not be found!\n");
exit(1);
}
fseek(marioin,128,SEEK_SET);
temp=(char *)malloc(6000);
temp=getpcx(marioin,temp,6000);
for (loop1=0;loop1<7;loop1++)
for (loop2=0;loop2<=15;loop2++)
for (loop3=0;loop3<=15;loop3++)
data.mario[loop1][loop2][loop3]=temp[loop1*17+(loop2+1)*320+loop3+1];
fseek(marioin,-765,SEEK_END);
for (loop1=0;loop1<2;loop1++)
{
data.marioc[loop1].red=(getc(marioin)>>2);
data.marioc[loop1].green=(getc(marioin)>>2);
data.marioc[loop1].blue=(getc(marioin)>>2);
}
fseek(marioin,-750,SEEK_END);
for (loop1=0;loop1<2;loop1++)
{
data.luigic[loop1].red=(getc(marioin)>>2);
data.luigic[loop1].green=(getc(marioin)>>2);
data.luigic[loop1].blue=(getc(marioin)>>2);
}
fclose(marioin);
free(temp);
}
char *getpcx(FILE *file, char *temp, int length)
{
long int count=0;
int numbytes,loop;
unsigned char ch;
fseek(file,128,SEEK_SET);
temp=(char *)malloc(length);
while(count<length)
{
ch=fgetc(file);
if ((ch>=192 && ch<=255))
{
numbytes=ch-192;
ch=fgetc(file);
for(loop=0;loop<numbytes;loop++)
temp[count++]=ch;
}
else
temp[count++]=ch;
}
return(temp);
}
//SET PALETTE////////////////////////////////////////////////////////////////
void setpalette(int index, colorpal color)
{
outp(0x3c6,0xff);
outp(0x3c8,index);
outp(0x3c9,color.red);
outp(0x3c9,color.green);
outp(0x3c9,color.blue);
}
//CALCULATE CURRENT SCREEN///////////////////////////////////////////////////
void drawscreen(int x)
{
int loop1,loop2,back,x2;
static int dy;
status();
x2=x;
back=0;
while(x2>=16)
{
x2-=16;
back++;
}
for (loop1=1;loop1<=13;loop1++)
for (loop2=back;loop2<=back+16;loop2++)
if (data.world[loop1][loop2]>0)
{
if (data.bumped[0]==loop2 && data.bumped[1]==loop1)
{
dy+=data.bumploop;
x_put_masked_pbm((loop2<<4)-x+32,(loop1<<4)+dy,HiddenPageOffs,data.block[data.world[loop1][loop2]-1]);
data.bumploop++;
if(data.bumploop==3)
{
data.bumploop=0;
data.bumped[0]=0;
data.bumped[1]=0;
dy=0;
}
}
else
x_put_masked_pbm((loop2<<4)-x+32,(loop1<<4),HiddenPageOffs,data.block[data.world[loop1][loop2]-1]);
}
drawcoin(x);
drawscore(x);
x_rect_fill(15,0,32,224,HiddenPageOffs,0);
x_rect_fill(288,0,306,224,HiddenPageOffs,0);
}
//DRAW INFO ON TOP OF SCREEN/////////////////////////////////////////////////
void status()
{
static char pscore[7]="000000";
char pscore2[7];
char slevel[4]="1-1";
char scoins[3]="00";
static char stime[4]=" ";
int loop1,loop2;
if (curplay==0)
graphstring(34,1,"MARIO",TEXTCOLOR,HiddenPageOffs);
else
graphstring(34,1,"LUIGI",TEXTCOLOR,HiddenPageOffs);
graphstring(180,1,"WORLD",TEXTCOLOR,HiddenPageOffs);
graphstring(254,1,"TIME",TEXTCOLOR,HiddenPageOffs);
if(player[curplay].score[1]!=player[curplay].score[0])
{
itoa(player[curplay].score[1],pscore2,10);
loop2=5;
for(loop1=strlen(pscore2)-1;loop1>=0;loop1--)
pscore[loop2--]=pscore2[loop1];
graphstring(34,9,pscore,BACKGROUND,HiddenPageOffs);
}
strcpy(pscore,"000000");
itoa(player[curplay].score[0],pscore2,10);
loop2=5;
for(loop1=strlen(pscore2)-1;loop1>=0;loop1--)
pscore[loop2--]=pscore2[loop1];
graphstring(34,9,pscore,TEXTCOLOR,HiddenPageOffs);
player[curplay].score[1]=player[curplay].score[0];
if (times[1]!=times[2])
{
itoa(times[0],stime,10);
graphstring(260,9,stime,BACKGROUND,HiddenPageOffs);
times[2]=times[1];
times[0]--;
itoa(times[0],stime,10);
}
graphstring(260,9,stime,TEXTCOLOR,HiddenPag