I am back here needing help =D
I am doing this "Ninja game" similar to Mario but with my ninja character, and I am having problems when loading the map I created in my level editor in different layers.
**The game is in C and SDL.
In my level editor, I create the map and save the different layers in three files (one for each layer)... one example of the file is this:
Code: Select all
22 09 08 1
06 13 07 0
08 13 07 0
10 13 07 0
12 13 07 0
14 13 07 0
16 13 07 0
18 13 07 0
19 13 07 0
//Where the first number is the "x" position (multiplied by 32, the tile width, will give the right value for the position on the screen)
//Where the second number is the "y" position (same)
//Where the third number is the tile type (the code of the tile)
//And where the last number represents if the tile is collideable or not (0 = no / 1 = yes)
Code: Select all
SDL_Surface *loadLayer1(char filename[50])
{
MAPLAYER1 = fopen(filename, "r");
for(int b = 0; b < 19; b++)
{
for(int a = 0; a < 50; a++)
{
fgets(cellX, 5, MAPLAYER1);
fgets(cellY, 5, MAPLAYER1);
fgets(tileNum, 5, MAPLAYER1);
fgets(coll, 2, MAPLAYER1);
fgets(temp, 2, MAPLAYER1);
//Use the atoi(char *str) to convert a string to an int
printf("%d\n", atoi(cellX));
printf("%d\n", atoi(cellY));
printf("%d\n", atoi(tileNum));
printf("%d\n", atoi(coll));
tileX = atoi(cellX) * 32;
tileY = atoi(cellY) * 32;
tileType1[a][b].x = tileX;
tileType1[a][b].y = tileY;
tileType1[a][b].type = atoi(tileNum);
tileType1[a][b].coll = atoi(coll);
DrawIMG(tileType1[a][b].x, tileType1[a][b].y, tileSheet, layer1, &clips[tileType1[a][b].type]);
//SDL_Flip(layer1);
}
}
fclose(MAPLAYER1);
optMap = SDL_DisplayFormat(layer1);
SDL_FreeSurface(layer1);
return optMap;
}
Code: Select all
Game::Game()
{
mapLayer1 = loadLayer1("Maps/map2_layer1.dat");
}
Code: Select all
void Game::render()
{
DrawIMG(0, 0, mapLayer1, screen);
SDL_Flip(screen);
}
So my problem is that when I try rendering the layer that I have loaded in this function, it renders the layer plus what was loaded before this function...
I dont know if I was clear enough... but please help me on that... can you guys see any mistake on my loading function, or is there a better way of doing it??
Thanks in advance!!