OK, the total code isn't extremely long so I'll post it:
Code:
// Map declaration
byte MAP[800] = {0};
// Map loading code
void LoadWorld (const char* fn)
{
FILE *f;
if ((f = fopen(fn, "r")) == NULL)
return;
for (int y = 0; y < MainMap.Height; ++y) {
for (int x = 0; x < MainMap.Width; ++x) {
int c;
if (fscanf(f, "%d,", &c) == 1) {
MAP[(y * MainMap.Width) + x] = c;
} else {
if (feof(f))
break;
}
}
}
fclose(f);
}
// code to get tile at y, x
inline byte GetTile (int y, int x) {
return (MAP[(y * MainMap.Width) + x]);
}
// code where map generates error: "c" is unexpected value
#define MAP_PRIMARY_BLANK 254 // 254 id tiles == skip
void DrawMap (int mapID)
{
for (int y = 0; y < 16; ++y) {
for (int x = 0; x < 21; ++x) { // called 336 times
int c = GetTile(Cam.tCamy+y,Cam.tCamx+x);
if (c != MAP_PRIMARY_BLANK) {
masked_blit (tileset[mapID], vscreen,
pTiles[c]->xLoc, pTiles[c]->yLoc,
(x << 4) - (Cam.CamxOff),
(y << 4) - (Cam.CamyOff), 16, 16);
}
}
}
}
I don't think the problem would be in any of the other variables (CamxOff, tCamx,x,y,etc), because the only time c ever becomes a problem is when the initialization to 0 is taken off. I tried memset(MAP, 0, 800 * sizeof (byte)); and it didn't change anything.
= /