dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Maze generation with tiles using AS3

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    5

    Maze generation with tiles using AS3

    Long story short, I have to make a random maze generator in AS3. I've seen plenty of tutorials on maze generation but nothing that matches the my needs. The maze has to be made of ten tiles (they are MovieClips), that are possible states of parts of the maze (for example: just wall; just opened space; wall north, wall east; wall west; etc). I have to figure out how to generate the maze using these ten tiles. Could someone please give me a light on how to do this? Anything I think of sounds extremely complicated, there must be an easier way to do this!

    Thank you so much!

  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    One simple approach would be to nest two arrays for the rows and columns of your maze layout. Something like this:

    Code:
    var cols:int = 40;
    var rows:int = 30;
    var blockSize:Number = 20;
    
    for(var x:int = 0; x < cols; ++x){
         for(var y:int = 0; y < rows; ++y){
              var thisBlock:MovieClip = getRandomMazeBlock();
              thisBlock.x = x * blockSize;
              thisBlock.y = y * blockSize;
              addChild(thisBlock);
         }
    }
    The above code assumes you have a function "getRandomMazeBlock" that returns a random block. You can change the number of rows and columns and the block size to meet your needs.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Not sure why I said "arrays" above. I meant "for loops". But you get the idea.

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    5
    Quote Originally Posted by solidgoldrobot View Post
    One simple approach would be to nest two arrays for the rows and columns of your maze layout. Something like this:

    Code:
    var cols:int = 40;
    var rows:int = 30;
    var blockSize:Number = 20;
    
    for(var x:int = 0; x < cols; ++x){
         for(var y:int = 0; y < rows; ++y){
              var thisBlock:MovieClip = getRandomMazeBlock();
              thisBlock.x = x * blockSize;
              thisBlock.y = y * blockSize;
              addChild(thisBlock);
         }
    }
    The above code assumes you have a function "getRandomMazeBlock" that returns a random block. You can change the number of rows and columns and the block size to meet your needs.
    Hello! And thank you for your help!
    However, I already did that... I need a completely random maze, but it has to be usable, like this one: http://www.emanueleferonato.com/2008...d-version-as3/
    I tried using this tutorial, but I really couldn't figure it out with the different tiles.

    Thank you!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center