SDL2 Collision Detection


Hello !

I want to make a maze game and i follow the tutoriel from LazyFoo to make it i want to test collision detection but my code is different form the tutorial i don’t know how to handle the collision box of each wall .
This is my code:
I have a class for the wall:

 //Set the collision box
mBox.x = 0;
mBox.y = 0;

mBox.w = MUR_WIDTH;
mBox.h = MUR_HEIGHT;

I declared a map in my main.cpp


But in the tutorial it’s like this:
//The level tiles
Tile* tileSet[ TOTAL_TILES ];

//If the dot went too far to the left or right or touched a wall
if( ( mBox.x < 0 ) || ( mBox.x + DOT_WIDTH > LEVEL_WIDTH ) || touchesWall( mBox, tiles ) )
    //move back
    mBox.x -= mVelX;

Can you see something that can help me please ?I want to get the collision box of the wall to my function touchesWall instead of tiles.

Thanks in advance :wink:


I think you should rephrase your question clearly.
It’s hard to find out what you are really asking for.


Also, you need to show more of your code. The code you’re having in your post doesn’t help much when it comes to helping you. Be more clear on what it is you need help with.