try making a hitbox costume bigger than pacman that perfectly fits the size of the maze, then use this hitbox to determine collision. when you want to detect something 5 pixels right of pacman, move the costume 5 pixels to the right and do what you want, then move it back 5 pixels left to get it back to the previous position. you can do the same for the other directions. then at the end of the script, put the costume back to normal so when the screen refreshes it will show pac-man.
or you could use a 2D table or something to represent walls and stuff and then calculate pacman's position on the list, then you can use this info to determine collision. i think this is the least expensive solution, though it is less intuitive than the solution listed above.