Join 307,141 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,761 people online right now. Registration is fast and FREE... Join Now!
I recently began with game programming, after finishing tetris clone and a pong clone, but the collision detection was easier. How is the collision detection implemented in pacman?
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
This is a way I tried but it cant move, I think may be because the box of the pacman always collides with the box of another tile, I could post all my code but I think this was the most important part of the collision I hope the code is at least understandable.
The way I'm reading it is that Pacman can only move if he's not on a dot, energy, or empty space, but this is just me assuming things about your code. I'm thinking you should change the !=s to ==s and the &&s to ||s as such.
You should be using the center-point of your objects for collision detection. You seem do be using their position (which I'm assuming is their upper left corner and then adding their width and height). It really should be mid-point +/- width>>1 height>>1, for proper collision detection!
The original pacman did not do collision detection. The game is based on a non scrolling tile map. Each position on the map is in a XY matrix. As each sprite moves a quick is done to see if there are any other sprites in the adjacent cell for the direction in which the pacman is moving. There is no check for ghost on ghost action. Only pacman vs ghost checks are done. The same is done for checking whether a maze wall exists or not.
Pacman is such a simple game, the original game was less than 1k.
If you are using XNA or Direct-X there are very useful samples on the XNA website.
REALLY? REALLY?! Is it really that hard for people? 1. Ghosts may not even need collision detection, other than colliding with pacman, considering that they will (should) have predetermined paths that are randomly chosen, so that the game is random each time. 2. Per-Pixel Collision would not suit this type of game, so if the origanal graphic is a square but you make the backround transperant, then it will still act as though it were a square but looks like it isnt. Then simply make it so when "wall" contacts "pacman" then stop pacman from moving. I dont know if i explained well... this is the most basic of basic collision detection, and if your using C# with XNA, then I know that its help file could explain this perfectly to you.
define a basic rectangle object that has the following variables x1, y1, x2, y2
fill the level up with these rectangle objects
when moving the character move a dummy object into the desired position. If the desired position is a pre-difened rectange, then its a collision remove the dummy and continue the game. if there isnt a collision set the characters position to the dummy position.
its actually a very simple collision test.
edit: or even better define the rectange object as startX, startY, width, height that way you can make the startX and Y always the lower point. It may make the logic less confusing if (character.x >= startX && character.x <= startX+width) //collision on X
This post has been edited by bobjob: 9 Oct, 2009 - 10:01 PM
If I remember correctly.. the arcade version did not use per pixel collision, you could actually touch the ghosts or they could touch the pacman and overlap just a tiny bit without a death occuring. The collision test used some smaller object to check the collision taking up about maybe 1/2 of the sprite size.. 1/4 of the sprite on each size overlap was possible (or close to that).
Also.. just FYI, the ghosts were not on random paths. They may have seemed that way but it was possible to navigate a specific path through the maze every time and not get killed, well .. at least on Ms. Pacman it was. The ghosts took the same route every time, if YOU took the same route.
Yep, the actual collision detection isn't pixel per pixel and if everything went perfectly, pacman was able to go through the ghost without actually dying.