Skip to main content
GameDev.net gamedev.net
🔒 Locked

Tile identifiers

Started by Laroche Dec 29, 2001 at 8:41 PM 2 replies 150+ views
Original Post
Laroche
Laroche
In every tutorial it says that all you do is give a tile a number, like 1 = grass, 2 = dirt, etc. This is then saved into a map file called "Whatever.Whatever" and looks like: 02030406020 87432689672 83409908835 24782935699 or whatever. This is ridiculous though. Does this mean we are limited to 10 tiles? (0-9) how does the computer know what number is a single digit number and how can it seperate it from the double or triple digit ones? how do you go around this? what will the map save-game look like? thanks (im using c++ with msvs6)
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Martee
Martee
Easy solution: Use 16 bit values for each tile, and store the number in binary, not ascii. You can now have about 65,000 different tiles.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Laroche
Laroche
could you show me an example in a c++ struct please? im not sure to store the numbers in binary.
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Kwizatz
Kwizatz
you dont need a struct, just an array of numbers

int Width; // contains width of the map in tiles, or number of columns
int Height; // contains Height of the map in tiles, or number of rows

int *TileArray = new int[Width*Height];

and then you just access each tile with TileArray[(y*Width)+x] where x,y is the coordinate of the tile you want to access, when you want to save your information then:
  
FILE *TileFileOut = fopen("yourfilename.bin","wb");
fwrite(&Width,sizeof(int),1,TileFileOut); // so, later you know whats the Width of the Tilemap

fwrite(&Height,sizeof(int),1,TileFileOut); // so, later you know whats the Height of the Tilemap

fwrite(TileArray,sizeof(int),(Width*Height),TileFileOut);
fclose(TileFileOut);

later when you want to load a saved map:
  
FILE *TileFileIn = fopen("yourfilename.bin","rb");
fread(&Width,sizeof(int),1,TileFileIn); // Get The Width of the Map

fread(&Height,sizeof(int),1,TileFileIn); // Get Height of the Map

TileArray = new int[Width*Height]; // allocate memory for the map

freaf(TileArray,sizeof(int),(Width*Height),TileFileIn);
fclose(TileFileIn);




Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.