Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to make a pacman game in c#. I have done some basic work and have previously replicated games like copter-it and minesweeper. I am confused about how to implement the map in pacman. Which datastructure to use, so it can be used 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.

share|improve this question
Why did a 2d array of ints not make sense to you? –  Ian Nov 24 '12 at 21:07
coz i thought that if screen size of my game is going to be 640*480, then i*ll have to make a 2d array of (640x480 ints) which is huge. –  Sam Fisher Nov 25 '12 at 9:12
That's only 307200 elements. Not necessarily elegant, but not that bad for a first start. –  GlenH7 Nov 26 '12 at 1:32
@GlenH7 - and 307200 8-byte (let's presume 64bit for a minute) elements is only what? 2.4MB? That is nothing! –  warren Mar 5 '13 at 21:45
Please don't cross post identical questions to multiple sites. If you get the wrong site it can be migrated (if we know about it soon enough) –  ChrisF Mar 5 '13 at 22:34
add comment

closed as off topic by ChrisF Mar 5 '13 at 22:35

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

I used to write pacman style games on the Spectrum as a kid. A 2d array is perfectly adequate, all you need is a value for wall, a value for road and a value for road with dot on. Your position is x,y, you can decide whether you can move, or eat a dot by interrogating the cells around.

A common tip is to create a fake wall around the map so you don't have to check that you're not running off the edge of the array. It means all the checks are "is cell of type" rather than "is x >=0 and x < dimension length AND is cell of type"

share|improve this answer
add comment

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