Original Post
Me and some friends are working on a school-project where we decided to create a RPG game, with a very similar gameplay as Zelda: A link to the past to the SNES. We're constructing our own engine, but the following code contains a segfault which I've been, for the last 3-4 hours, unable to find.
class Sector
{
public: int posx;
int posy;
char spritefile[50];
bool passable;
};
class Room
{
public: Room(const char *file);
void LoadRoom(const char *file);
void DrawRoom(SDL_Surface *surface);
int rootx;
int rooty;
Sector rmap[100][100];
};
Room::Room(const char *file)
{
LoadRoom(file);
}
void Room::LoadRoom(const char *file)
{
FILE *roomfile;
int posx;
int posy;
int pass;
char sprfile[50];
roomfile = fopen(file, "r");
char tag[20];
char params[100];
while(fscanf(roomfile, "%s = %s", tag, params) != EOF)
{
if (strcmp(tag, "WALL") == 0)
{
sscanf(params, "%d - %d - %d - %s", &posx, &posy, &pass, sprfile);
rmap[posy][posx].posx = posx;
rmap[posy][posx].posy = posy;
if (pass == 0)
{
rmap[posy][posx].passable = true;
}
else
{
rmap[posy][posx].passable = false;
}
strcpy(rmap[posy][posx].spritefile, sprfile);
}
else if (strcmp(tag, "COMMENT") == 0)
{
}
}
}
void Room::DrawRoom(SDL_Surface *surface)
{
int i2, i;
SDL_Surface *spr;
SDL_Rect pos;
for(i2=0;i2<100;i2++)
{
for(i=0;i<100;i++)
{
pos.x = rmap[i2].posx * 50;
pos.y = rmap[i2].posy * 50;
pos.w = 50;
pos.h = 50;
spr = SDL_LoadBMP(rmap[i2].spritefile);
SDL_SetColorKey(spr, SDL_SRCCOLORKEY, SDL_MapRGB(spr->format, 0x00, 0x00, 0xFF));
SDL_BlitSurface(spr, &spr->clip_rect, surface, &pos);
}
}
}