LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Help with maze program

Root / Programming Questions / [.]

PtcguyCreated:
I'm making a maze program and I wasn't sure how to go about storing the mazes. I could put a list of sprite x and y coordinates for the maze walls in a dat file and load them into an array in the program, but how would I do that? I was also wondering (because of the 512 management number limit) if I could make a map in SBMAP and load that in and have it detect collision with that (but I'm not sure it's possible). Any ideas?

One way to store mazes is in a 2-dimensional array. For array entry [x,y], store a 0 if the square x paces East and y paces South from the North-West corner is a 'floor' square, and store a 1 if it is a 'wall' square. If your maze has other features that are affixed to squares (such as, an exit, or a trap, or a shop), you can use the same array. You can even store temporary features of the maze: e.g. use the value 2 to indicate this square contains treasure, or a sword, and when the player steps on that square, update the player's status and overwrite the 2 with 0.

If you use map, you can use a layer to store collision and other stuff. For example, in my platform program, I use the map to store collision with the background cell "C" on the layer 3, then on the layer behind it I put a wall, floor, etc. To check if a sprite is touching a background cell, use BGGET. Also, I don't recommend using the sprites to create the map because 512 sprites is a low number. Beside, if you'll plan use both the upper and lower screen, keep in mind that you still has 512 sprites in total.

So, I could use a for loop to load in sprites for the locations in the array, right? How could I load a 2d array from a DAT file? EDIT: So I could use a map? I think I'll try that.