Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

OoMMMoO

making custom files

This topic is 6587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!