Like already mentioned, for a game like Pac-Man, you dont really need
collision detection on pixel level. If you really want to do this I
would use a collision map to make it really simple. This is black and
white pixelmap where black is the area you can move, and white means you
have a collision.
approach when making a Pac-Man game. I have already tried this, and it
just introduced too many problems for such a simple game. If you want
your Pacman to move freely in any direction (not just
up,down,left,right), be aware that you will get challenge in other
dimensions. Just imagine trying to take a left turn around a sharp
corner or just trying to move in a tight spot. You will get stuck all
the time, and that will eventually introduce a new extremesport
involving talking turns at the right pixel.
If you want to make a classic Pac-Man clone, just restrict the movement
to up, down, reft and right. Devide the screen into eg. 16 x 16 squares
and make a map editor or just use an ascii file to define what each of
the squares should be.
To make the movement much easier, imagine a Pacman as a 14x14 image in
the middle of one of the 16x16 squares. Moving to another square in any
of the four directions would mean moving 16 pixels. While our Pacman
move between two squares the only thing that should interrupt the
movement is if you want to go the oposite direction. For each frame,
check the key events and store the last direction input from the user.
Every time you reach a square, check what direction the used wanted to
go and check in your levelmap if this is a valid move. If not, just
continue moving to the next square. If you hit a wall, just stop there
intil the used give a valid direction.
The collision between enemies can be the distace between them. eg. 1/2 a
square = 8 pixels.
Good luck with the game
Anthony Ardito wrote:From my personal experience I would strongly advise you to avoid this
How would I do pixel perfect collision detection?
Example: I am making a Pac-Man clone as an exercise. The level is a
bitmap file which is loaded into a surface. I want to see if the
rectangle containing the player image has intersected the level by
checking if the rectangle touched any of the “on” pixels of the level.
Simpler version of the question: How do I check to see if a certain
pixel has a non-black color?
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl