-
Help figuring out pacman barrier collision detect
Im making a pacman game, and im trying to figure out how to draw the barriers and make sure pacman cant cross the walls. How do i approach this? Thank you muchly.
im obviously no pro, so go easy on me :P
-
-
Store your map as a 2D grid.
0 = clear
1 = dot
2 = wall
Decide the size of each wall segment, say 10x10. So every 10 units you'd have a new wall segment or square from the grid.
- player_controls
- store old pacman position
- update new pacman position variables
- check where in grid new pacman position is. If its a wall, change position variables to old pacman position.
- draw pacman
So if pacman is at 152,36 in world coordinates, to find that in grid coordinates, divide by the dimensions of a grid square (10x10).
Code:
int gx = 152/10 //15
int gy = 36/10 //3
if (map[gx][gy] == 2) //pacman hit a wall
{
pacX = oldX
pacY = oldY
}
else if ( == 1) //pacman ate a dot
{
map[][] = 0
score++;
}
-
wow thank you so much, i would never have thought of that!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|