home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume13
/
thricken
/
part01
/
files.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-03
|
2KB
|
112 lines
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include "thricken.h"
char *readline(FILE *fp);
int read_sprites();
char *spr_file, *data_file;
int load_level(int level) {
int i,j;
FILE *fp;
char *level_file = strdup("xxlevel");
level_file[0]='0'+((level<10)?0:(level/10));
level_file[1]='0'+level%10;
if ((fp = fopen(level_file,"r")) == NULL)
return -1;
spr_file = strdup(readline(fp));
data_file = strdup(readline(fp));
rows = atoi(readline(fp));
cols = atoi(readline(fp));
x = atoi(readline(fp));
y = atoi(readline(fp));
diamonds = atoi(readline(fp));
for (i=0; i<rows; i++)
map[i]=strdup(readline(fp));
if (dname)
free(dname);
dname = strdup(readline(fp));
if (lname)
free(lname);
lname = strdup(readline(fp));
if (author)
free(author);
author = strdup(readline(fp));
fclose(fp);
read_sprites();
read_sprdata();
}
char *readline(FILE *fp) {
/*
* buf is big enough for anything I'm going to use, but it's still
* a bit of a kludge.
*/
static char buf[1024];
int i=0;
char c = '\0';
if (fgets(buf,1000,fp) == (char *)0)
return (char *)-1;
buf[strlen(buf)-1] = '\0';
return buf;
}
read_sprites() {
FILE *fp;
char spr;
char *ptr;
int j,i;
if ((fp = fopen(spr_file,"r")) == NULL)
return -2;
while ((ptr = readline(fp)) != (char *)-1) {
spr = ptr[0];
for (j=0; j<SPRHEIGHT; j++) {
ptr = readline(fp);
for (i=0; i<SPRWIDTH; i++)
sprite[spr][j][i] = ptr[i];
}
}
}
read_sprdata() {
FILE *fp;
int i;
char *ptr;
struct coll *c, *c2;
for (i=0; i<256; i++) {
if (c = sprdata[i]) {
do {
c2 = c->next;
free(c->dirs);
free(c->coll);
free(c);
c = c2;
} while (c);
}
sprdata[i]=0;
}
if ((fp = fopen(data_file,"r")) == NULL)
return -2;
walkable = strdup(readline(fp));
pushable = strdup(readline(fp));
while ((ptr = readline(fp)) != (char *)-1) {
if (sprdata[ptr[0]]) {
c = (struct coll *)malloc(sizeof(struct coll));
c->next = sprdata[ptr[0]];
sprdata[ptr[0]] = c;
} else {
c = sprdata[ptr[0]] = (struct coll *)malloc(sizeof(struct coll));
c->next = 0;
}
sscanf(ptr+8,"%d",&(c->score));
*(ptr+8)=0;c->dirs = strdup(ptr+4);
*(ptr+4)=0;c->coll = strdup(ptr+1);
}
}