As you see in the title, I’ve some problems in preparing the field for my PacMan.
I had the idea of basing it all on an int matrix, which is going to be filled with numbers: as it is -1, I have the walls; as it is 1, it’s gonna be the player coords; from 2 to 5 we have the ghosts coords.
Is there any algorithm that I can add to my program to help myself on setting the walls? Because I thought about a function that adds manually every single wall block; but it’s soooo long and time consuming, moreover it makes the readability of the code very difficult…
PS if you think that having a matrix is a bad idea plz suggest me something else because I’ve no better ones…
If you actually want to generate such a field without anything being predefined it’s going to be rather more complicated. And thereason I say that is that’s the game pac-mac requires a maze without any dead-ends.
So while you could place walls haphazardly (random gen) you would have a decent chance of generating an invalid map. So I would advise going with predefined map ‘blocks’ of even dimensions (2x2, 4x4, 8x8) you can place against each other. You can use single grid space ‘blocks’ too but that will require a little bit more computational time.
I would recommend that you consider keeping wall data separate from where the player and ghosts are, the former shouldn’t change over the course of the game/level and the latter are constantly changing.
Depending on how much of a clone you’re going for, you may want to read this section of the wiki page: