Hello,
As a projekt in my school we are supposed to create a game, and my job was to make a map maker.
Ive got the mapmaker working, but i cant seem to save the map into a binary file.
We are using SDL,OpenGl and C.
The map is divided in a 30*30 "tile field" and my idea i to write all tiles to a binary like this:
Code:
utfil=fopen("test.dat","wb");
for(i=0;i<MAP_WIDTH;i++)
for(u=0;u<MAP_HEIGHT;u++)
{
fwrite(&map[i][u].background,sizeof(int),1,infil);
fwrite(&map[i][u].walkable,sizeof(int),1,infil);
fwrite(&map[i][u].decoration,sizeof(int),1,infil);
}
And then load it in the same way, i just chnage fwrite to fread like so:
Code:
infil=fopen("test.dat","rb");
for(i=0;i<MAP_WIDTH;i++)
for(u=0;u<MAP_HEIGHT;u++)
{
fread(&map[i][u].background,sizeof(int),1,infil);
fread(&map[i][u].walkable,sizeof(int),1,infil);
fread(&map[i][u].decoration,sizeof(int),1,infil);
}
fclose(infil);
The struct im using for the map looks líke this:
Code:
struct Tile
{
int background;
int walkable;
int decoration;
};
I've been stuck at this for maaany hours now, and im geeting tired of it. Been googling alot, but found nothing that worked.
Does any of your brilliant minds have a solution?
If u need more of my code please let me know.
Best Regards