Maze Game Advice

Hey again, I have another noobie question :frowning:

It’s not so much a coding one but I may need help with that in the end. Also, something that might be necessary is that I’m using the BlackBerry JDE 5.0.0 so I’m restricted to using the Graphics package that comes with it. I’m sure a lot of you probably do not have these libraries however like I said my question isn’t really a coding one.

  1. Is it practical to create a bunch of tiles, and define the walkable pathways using a certain number, so that i wouldn’t have to worry about collision detection for a simple maze game.
  2. How would I store the co-ordinates of the walkable tiles, so that I can iterate through like an array to see in what directions the player can walk.

Thanks for any advice!

Hi.
Some quick answers to your questions:

  1. Yes, it’s a good idea to make your mazes tile based. It will be useful when you would like to generate random mazes.
  2. You can do it by dozens of different ways, however here is a pretty primitive solution:
    Refer numbers to your tiles so it’ll be like:
    0 = Nothing
    1 = Wall
    2 = Player
    And to store these values create a multidimensional array (int[][] level = new level[100][100] <- Here’s the code to create 100*100 level).
    After this all you have to do on movement is to check if the position where you want to move is a wall or not, with something like this:

int playerPosition_x = 10;
int playerPosition_y = 10;
if(Keys.Right.isPressed()){
   if(level[playerPosition_x+1][playerPosition_y] == 0){
      //You can move here because there's nothing
   }
}

Please keep in my that I don’t know how you have to handle inputs on BlackBerry JDE so Keys.Right.isPressed() is just an example.
Also don’t forget to check if playerPosition_x+1 (or whatever tile you want to move to) is out of your array’s bounds. (e.g. level[101][100], this will throw an OutOfBoundException since our level in my example is only 100 by 100 and not 101 by 100).
If you didn’t understand anything just let me know and I’ll try to explain it.
Good luck with your project! :slight_smile:

Thanks that helped a lot! The code example is excellent! Thanks a lot :slight_smile: