Advertisement

making custom files

Started by November 27, 2000 01:53 PM
2 comments, last by OoMMMoO 24 years, 1 month ago
How do you create a file with like a header and stuff like that? What I want to do is make my own map files that holds all the data for a map that I need. Can anyone help me?
Making files is a lot like making your own structs and classes. It''s your responsibility to decide what needs to be stored. It''s your responsibility to use the information contained therein properly. With files, it''s also your responsibility to properly read and write them. It''s all up to you. If you want to put on a header, feel free. If you want to have an entire file full of binary junk that makes no sense when brought up in a text editor, also fine. Just give yourself guidelines and follow them to the letter. Here''s an example of a file template I''m arbitrarily making up to store a map.


Header:
BYTE STORES
0-32 map name
33-34 width of map
35-36 height of map


Information:
We already know what X and Y we are at because we know how many we have read so far, and we know what the map width is. Say we have a struct as follows:


struct tile
{
int surface; // player cannot step on this tile, or slips, or falls, or whatever
int type; // determines which bitmap to display
}


You can simply put the bytes for each tile in the file, as long as you read them out in the same order. So, for instance, if your first tile was of surface 3 (ice) with type 6 (blue ice picture), and the second tile were surface 2 (wall) with type 9 (brick wall picture), it would be shown in the file as hex as:

03 06 02 09

It would be your responsibility to start reading in the right place and dumping the information you read into the structs. I''m sure you can look up and understand the methods of binary file reads and writes yourself.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Advertisement
How would you write your header to the file?
open a file.
FILE* open = fopen(bla bla);

then:

fwrite(, 1, 32, open);
fwrite(width, 1, 2, open);
fwrite(height, 1, 2, open);
.
.
.
Hope that helped..
cya,
Phil

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )

This topic is closed to new replies.

Advertisement