1
\$\begingroup\$

I am trying to make a Pac-Man game in C# using GDI+. I have done some basic work and I have previously replicated games like Copter-It and Minesweeper, but I am confused about how I can implement the map in Pac-Man. I mean: which data structure to use, so I can use it for moving AI controlled objects and check collisions with walls.

I thought of a 2D array of ints but that didn't make sense to me. Looking for some help.

\$\endgroup\$
3
\$\begingroup\$

Why not use a simple 2d array of chars, and use some text editor as your level editor?

Something like this:

Pacman level in ASCII

\$\endgroup\$
  • \$\begingroup\$ that was my first thought. but im a little confused about how do i use it properly, i mean a single character represents how many pixels? and if lets say it represents 10x10, then would it be the smallest reachable area on screen? i mean what if i want to draw something like 5x5, then the collision detection will still be related to 10x10. sorry for bad english. \$\endgroup\$ – Sam Fisher Nov 24 '12 at 21:02
  • \$\begingroup\$ This would only be a logical representation of the model. How you choose to render it is entirely up to you. If you need a fined 'resolution' let's say you want to be able to have three 'dots' in one 'wall width' then simply use three characters as the with of 'one unit' and as such a solid horizontal wall would go from (###) for the three first to ex ( # # # ) \$\endgroup\$ – AlexanderBrevig Nov 24 '12 at 21:11
  • \$\begingroup\$ @SamFisher I did something like this once. The size is 1 char (in this case*) = 1 PacMan. That is, this will work for tiles such that PacMan is 1 tile. You can make it as big or small as you want. *: In my case it was a hardcoded int array. You can use an autotile algorithm to give it the classic argon blue look. \$\endgroup\$ – Theraot May 10 '17 at 1:35
1
\$\begingroup\$

Perhaps a graph can be used. I imagine the vertices would represent intersections or corners in the maze and the edges would be the connections between the intersections.
Each edge should probably contain a length, and if the graph is used for rendering as well, each edge would have to contain a vertical/horizontal value too, i guess.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.