Here's some of the code to illustrate what I mean. I would like to load the initial array from a text file. I'm very new to this, so, I apologize if it is horribly written:
struct TILE
{
int type;
};
// Set map width and height
const int MAP_WIDTH = 20;
const int MAP_HEIGHT = 15;
// Load array to create tiles off of
int TileMap[MAP_HEIGHT][MAP_WIDTH] =
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
};
TILE Map[MAP_HEIGHT][MAP_WIDTH];
void setupScenery ( )
{
// Set color key for sprites to bright pink
dbSetImageColorKey ( 255, 0, 255 );
// Draw backdrop
dbLoadImage ( "Data\Mario Backdrop HQ.png", 20 );
dbSprite ( 20, 0, 0, 20 );
// Load tiles images
dbLoadImage ( "Data\Rock Tile.bmp", 1 );
dbLoadImage ( "Data\Brick Tile.bmp", 2 );
dbLoadImage ( "Data\Brick Tile.bmp", 3 );
dbLoadImage ( "Data\Brick Tile.bmp", 4 );
dbLoadImage ( "Data\Question Mark Tile.bmp", 5 );
int x;
int y;
int n;
// Transfer number in first array to type of second
for ( y = 0; y < MAP_HEIGHT; y++ )
{
for ( x = 0; x < MAP_WIDTH; x++ )
{
Map[y][x].type = TileMap[y][x];
}
}
for ( y = 0, n = 21; y < MAP_HEIGHT; y++ )
{
for ( x = 0; x < MAP_WIDTH; x++, n++ )
{
if ( Map[y][x].type != 0 )
{
if ( Map[y][x].type == 1 )
dbSprite ( n, x * 32, y * 32, 1 );
else if ( Map[y][x].type == 2 )
dbSprite ( n, x * 32, y * 32, 2 );
else if ( Map[y][x].type == 3 )
dbSprite ( n, x * 32, y * 32, 3 );
else if ( Map[y][x].type == 4 )
dbSprite ( n, x * 32, y * 32, 4 );
else if ( Map[y][x].type == 5 )
dbSprite ( n, x * 32, y * 32, 5 );
else if ( Map[y][x].type == 6 )
dbSprite ( n, x * 32, y * 32, 6 );
}
}
}
}