Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
3  
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 –  Samaursa Feb 20 '12 at 1:21
    
Thanks ill post some specifically relevant code and take a look at the link. –  tuby Feb 20 '12 at 1:40
    
Thanks again for the link that is very interesting I will try to narrow this down some more. –  tuby Feb 20 '12 at 2:02

1 Answer 1

up vote 0 down vote accepted

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.