Alright, on startup the program run Init() which has the following relevant code:
Code:
for(int y = 0; y < BOARD_HEIGHT; y++)
{
for(int x = 0; x < BOARD_WIDTH; x++)
{
//Do a switch on the value of the current index
// Since we are using a 1D array, we use the equation:
// x + y * BOARD_WIDTH - This allows us to treat it like a 2D array
switch( g_BoardArray[ screen[1]+y+TEST ][ x + screen[0] ] )
{
case W01:
g_bmpTiles[x][y] = LoadABitmap("WA01.bmp");
break;
case W02:
g_bmpTiles[x][y] = LoadABitmap("WA02.bmp");
break;
case F01:
g_bmpTiles[x][y] = LoadABitmap("FL01.bmp");
break;
}
}
}
This code I run once, I found that out the hardway (I'm using gametutorials tilemaze and modifying it to scroll in-case you wanted to know. In WinMain():
Code:
for(int y = 0; y < BOARD_HEIGHT; y++)
{
for(int x = 0; x < BOARD_WIDTH; x++)
{
// Display each title according to their index.
// We take the x and y index and times it by the width and height
// in pixels to get the tile position. This makes the nice tile effect we see on screen
DisplayBitmap(&g_Buffer, g_bmpTiles[x][y], TILE_WIDTH * x, TILE_WIDTH * y);
}
}
Now this works all fine and dandy IF you want the images to stay the same, (remember how init was run once?) anyway, to be able to scroll I put that loop from Init() into winmain (right before the DisplayBitmap loop, but this caused crashing, so I merged the two loops into one:
Code:
for(int y = 0; y < BOARD_HEIGHT; y++)
{
for(int x = 0; x < BOARD_WIDTH; x++)
{
g_bmpTiles[x][y] = 0;
//Do a switch on the value of the current index
// Since we are using a 1D array, we use the equation:
// x + y * BOARD_WIDTH - This allows us to treat it like a 2D array
switch( g_BoardArray[ screen[1]+y ][ x + screen[0] ] )
{
case W01:
DisplayBitmap(&g_Buffer, LoadABitmap("WA01.bmp"), TILE_WIDTH * x, TILE_WIDTH * y);
break;
case W02:
DisplayBitmap(&g_Buffer, LoadABitmap("WA02.bmp"), TILE_WIDTH * x, TILE_WIDTH * y);
break;
case F01:
DisplayBitmap(&g_Buffer, LoadABitmap("FL01.bmp"), TILE_WIDTH * x, TILE_WIDTH * y);
break;
}
}
}
But this still caused errors, note: all three arrays screen[], g_BoardArray[] and g_bmpTiles[] are global variables.