Tile identifiers

Started by
2 comments, last by Laroche 22 years, 3 months ago
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
Advertisement
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
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
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 Tilemapfwrite(&Height,sizeof(int),1,TileFileOut); // so, later you know whats the Height of the Tilemapfwrite(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 Mapfread(&Height,sizeof(int),1,TileFileIn); // Get Height of the MapTileArray = new int[Width*Height]; // allocate memory for the mapfreaf(TileArray,sizeof(int),(Width*Height),TileFileIn);fclose(TileFileIn);  




This topic is closed to new replies.

Advertisement