   tile based engine
  Hello everyone, this is my first post hereI've been working on my tile based engine and i'm having problem with collision detection... my map is an array char map[10][10] and i'm using 32x32 tiles. My map is like 1111111111000110011110000111 is the wall and 0 are the places that i can walkCode:switch(event.key.keysym.sym){ case SDLK_UP:if(map[player.x / TILESIZE][player.y / TILESIZE - 1] == 0)    player.y = player.y - player.p_speed;break; case SDLK_DOWN:if(map[player.x / TILESIZE][player.y / TILESIZE + 1] == 0)    player.y = player.y + player.p_speed;break; case SDLK_RIGHT:if(map[player.x / TILESIZE + 1][player.y / TILESIZE ] == 0)    player.x = player.x + player.p_speed;break; case SDLK_LEFT:if(map[player.x / TILESIZE - 1][player.y / TILESIZE ] == 0)    player.x = player.x - player.p_speed;break; default:break;  }My other question is, are there any ways to print a text onto the screen? I'm using sfont but i'm having problems... i check everything and it keeps saying that couldn't open the font fileCode:int Write_Text(int x, int y, char *string){SFont_Font* Font;    Font = SFont_InitFont(IMG_Load("font\24P_Copperplate_Blue.png"));    if(!Font) {  fprintf(stderr, "An error occured while loading the font.");  exit(1);    }    // a simple text blit to (0/0)    SFont_Write (screen, Font, x,y,string);    // Update the screen    SDL_UpdateRect(screen, 0, 0, 0, 0);    // Let the user time to look at the font    // Don't forget to free our font    SFont_FreeFont(Font); } Thanks everyone for your attentionbest regards[Edited by - BrasiLokau on January 3, 2006 11:44:42 AM]
  Please reformat your post using the [ source ] tags.   ;  Here is what I would do (didnt check this, so sorry if there are errors) :// UPif(map[player.x / TILESIZE][(player.y - player.p_speed) / TILESIZE] == 0...// DOWNif(map[player.x / TILESIZE][(player.y / TILESIZE) + 1] == 0...// RIGHTif(map[(player.x / TILESIZE) + 1][player.y / TILESIZE] == 0...// LEFTif(map[(player.x - player.p_speed) / TILESIZE][player.y / TILESIZE] == 0...This is assuming your players starting positiong and speed allows him to exactly touch walls (if not I think it might give some strange results at times). With that I mean, for instance, if your TILESIZE is 32, your players speed should be 1, 2, 4, 8, 16, or 32, and the starting position should be accordingly. TILESIZE = 32, speed = 4, startx = 32, starty = 32 for instance should work with this method. You would probably want that in most cases anyway, so the player sprite wount stop like 5 pixels away from the wall, because its supposed to walk 6.Cheers.;  Yeah, but my player's speed is 32, Its tilebased movement.   ;  Well in that case you only have to move your paranteses. You should add and subtract 1 after you divide :// UPif(map[player.x / TILESIZE][(player.y -  / TILESIZE) - 1] == 0...// DOWNif(map[player.x / TILESIZE][(player.y / TILESIZE) + 1] == 0...// RIGHTif(map[(player.x / TILESIZE) + 1][player.y / TILESIZE] == 0...// LEFTif(map[(player.x / TILESIZE) - 1][player.y / TILESIZE] == 0...Cheers.PS! Never used SDL so no idea about the font, sorry.   ;  it doesn't work...i don't know why because the logic seems to be fine...;  more time is commonly spent on optimization and corrections than figuring out the logic behind it.Ur supposedly making a mistake somewhere.   ;  Is the intention that X be the row and Y be the column?  Just wondering if perhaps you have them transposed from what you intended?if(map[player.y / TILESIZE][player.x / TILESIZE - 1] == 0) Hope that helps.;  Have you traced through the program through a debugger to figure out if the player's and tile's position are correctly set?;Quote:Original post by ApoxolIs the intention that X be the row and Y be the column?  Just wondering if perhaps you have them transposed from what you intended?*** Source Snippet Removed ***Hope that helps.OMG!!!!THANK YOU SO MUCH!!! that was the problem :( i usually do this kind of shit, like mistyping something or lack of attentionbut thanks everyone for helping mebest regards