SFML map collision

I want to know, if anyone would be so kind to tell me, what would be the best way to make your character not be able to exit the map.
Let's say you want to make a Snake game clone.
What's the best way to stop your "snake" to get out of the game frame?
Thank you in advance, kind cplusplus users!

EDIT: Using C++ and SFML, of course!
Last edited on
It is not an SFML question, but general one. From the wording I fear that you are not using SFML properly. Ideally your game logic code should not know about SFML existence at all. SFML should only present state of your game to the screen.

As for your question: I would check current coordinates of characters vs map bounds each step. It it tries to move out of the map, some action would be taken (negating move it this direction, game over, etc.)
Thanks for your answer!
So what you're saying is
1
2
3
4
if (snake.getGlobalBounds().top < map.getGlobalBounds().top)
{
// set snake's position so that snake.getGlobalBounds().top will be equal to 0
}

right?
and do this for all 4 sides
right?
Well, I do not know how your code works, but it looks like it would do the trick.
Well, this isn't mine, it's SFML's. :P it all was just conceptual. Thank yo for your answer.
Topic archived. No new replies allowed.