I'm trying to write(in c++ using sdl) a mario like game as in a tile based world with by pixel movement for the character and I've run into some problems I cannot seem to find the source of:

1.The player won't collide with the walls.

2.when moving through open space the player sometimes stops moving and then becomes unmovable in either direction.

I'm not sure where the problem is and I would love your help finding these issues and any advice in general is appreciated. thanks!

Here is all the code:

http://pastebin.com/FGxW2x3T //sorry I can only post two links cause I don't have 10 rep.

Here is the collision detection function and player input/movement functions. http://pastebin.com/jWaZPDBm

  • 3
    \$\begingroup\$ Not sure if anybody will be willing to wade through all that code. You should learn some basic debugging to pinpoint your problem area and then ask a question with that area of code. One link with some basic tutorials (assuming you are using VC++): cplus.about.com/od/learningc/ss/vc6compile_6.htm \$\endgroup\$
    – Samaursa
    Commented Feb 20, 2012 at 1:21
  • \$\begingroup\$ Thanks ill post some specifically relevant code and take a look at the link. \$\endgroup\$
    – tuby
    Commented Feb 20, 2012 at 1:40
  • \$\begingroup\$ Thanks again for the link that is very interesting I will try to narrow this down some more. \$\endgroup\$
    – tuby
    Commented Feb 20, 2012 at 2:02

1 Answer 1


I was using SDL_Rect for my collision box. The x and y variables for an SDL_Rect are of type short and I was using a double for my velocity so my player.xPos and player.yPos(which are doubles) were not equal to the collision box's position because of lost decimal points when converting my double xVel to the int of collisionBox.x I assume.

Thank you Samaursa for the link to the guide on debugging this is how I found my issue!


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .