Original Post
Hi,
i am using a Map File Format like the example from Dino at Iso Engines.
There is a Error in the New Map Function but what? Please help me. I don`t know what i do wrong.
Lutz Hören
[ Power Productions ]
// Map Header
struct map_header
{
public:
int Version; // 4
char Name[64]; // 64
char Author[64]; // 64
// int Width; // 4
// int Height; // 4
// int Padding[126]; // 126
}; // 256 total
#define DATAVERSION 3
#define TILE_WIDTH 64
#define TILE_HEIGHT 32
// Definition of our map structure
typedef struct
{
unsigned char TileID; // The ID of this tile
unsigned char Type; // What type of tile is this
bool walkable;
} MAPTILE;
// New Map Function
void CMap::New( const char *FileName, char *MapName, char *MapAuthor )
{
ofstream File( FileName, ios::out|ios::binary );
Header.Version = DATAVERSION; // 4
memcpy(Header.Name, MapName, 64); // Set Name
memcpy(Header.Author, MapName, 64); // Set Author
// Initialize the elements of the map
for(int lyr = 0; lyr < 3; lyr++)
{
for( int x = 0; x < 255; x++)
{
for(int y = 0; y < 255; y++)
{
Map[lyr][x][y].TileID = 0;
Map[lyr][x][y].Type = 0;
Map[lyr][x][x].walkable = true;
}
}
}
// header is supposed to be 256 bytes
File.write( (char *)&Header, sizeof( Header ));
for ( int layer =0; layer < 3; layer++ )
{
for ( int MapX =0; MapX < 255; MapX++ )
{
for ( int MapY =0; MapY < 255; MapY++ )
{
File.write( (char *)&(Map[layer][MapX][MapY]), sizeof( Map ) );
}
}
}
}
|