Author Topic: Generic Random Maze Maker  (Read 6029 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Generic Random Maze Maker
« on: August 26, 2019, 12:57:35 am »
Something else I always wanted to make. Was pretty easy to make the random maze maker. But finding a maze that you can actually solve is a completely different story LOL. I tried for hours to find ways to do it but I couldn't figure it out. So, instead I just threw a bunch of blank random boxes on the maze to make it more of a chance that you can solve it. lol That's why I call it "Generic Random Maze Maker". If any of you wish to toss in some ideas on how to make a maze that someone can solve every time that would be really cool. I know they have been made before and I know there's a link to one on the thread about Maze Crawlers. But it's too much code for me to figure out. In the mean time, here is what I made. You can keep making mazes until you find one with an exit. I also added Printer support just for the fun of it. It has a white background with black lines. Also, I made it so you can choose how hard you want the maze, from hallways 20 pixels wide to 100 pixels wide. One thing I did try for a long time was re-making a background colored maze on top of the already made-maze with an IF/THEN statement of when it goes from the bottom to the top of the maze. But every time I did that, with all the possibilities I messed with, it always made just a huge CLUMP of background making the mazes way too easy. lol I know it has something to do with the way I make the maze in the first place, non-stop over-drawing lines after lines, until enough is eventually made to fill the screen. But I found out that's not the way to make a path to beat the game. lol I also tried making it so it wouldn't draw background over already drawn background, but I couldn't figure that out either.

Code: QB64: [Select]
  1. _TITLE "Random Maze Maker"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. begin:
  4. x = 400: y = 300
  5. PRINT "                               Generic Random Maze Maker"
  6. PRINT "                                      by Ken G."
  7. PRINT "                 This program creates a random maze using the size"
  8. PRINT "                 of hallways that you enter."
  9. PRINT "                 The mazes this program makes are only random, so many"
  10. PRINT "                 of them will not be able to solve. In order to make one"
  11. PRINT "                 that has a way out, you must look at each one and keep"
  12. PRINT "                 making them to find one you like that has an entrance and an exit."
  13. PRINT "                 To make another maze, press the Space Bar, Esc key to quit, or P"
  14. PRINT "                 to print to paper."
  15. INPUT "                 Type a hallway width here (20-100): "; h
  16. IF h < 20 OR h > 100 OR h <> INT(h) THEN GOTO begin:
  17. LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  18.     again:
  19.     t = t + 1
  20.     IF t = 30000000 THEN EXIT DO
  21.     oldx = x
  22.     oldy = y
  23.     oldd = d
  24.     d = INT(RND * 4) + 1
  25.     IF d = oldd THEN GOTO again:
  26.     IF d = 1 THEN x = x + h
  27.     IF d = 2 THEN x = x - h
  28.     IF d = 3 THEN y = y + h
  29.     IF d = 4 THEN y = y - h
  30.     IF x > 785 OR x < 15 OR y > 585 OR y < 15 THEN x = 400: y = 300: GOTO again:
  31.     IF POINT(x, y) = _RGB32(0, 0, 0) THEN GOTO again:
  32.     LINE (oldx, oldy)-(x, y), _RGB32(0, 0, 0)
  33. t = 0
  34. y = 585
  35. x = 400
  36. FOR tt = 1 TO INT(1000 / h)
  37.     x2 = INT(RND * 800) + 1
  38.     y2 = INT(RND * 600) + 1
  39.     d2 = INT(RND * 2) + 1
  40.     IF d2 = 1 THEN LINE (x2, y2)-(x2 + h, y2 + h), _RGB32(255, 255, 255), BF
  41.     IF d2 = 2 THEN LINE (x2, y2)-(x2 + h, y2 + h), _RGB32(255, 255, 255), BF
  42. NEXT tt
  43.  
  44.  
  45. _TITLE "Esc To Quit. Or Space Bar to make another one. Or (P)rint To Printer."
  46. waiting:
  47. a$ = INKEY$
  48. IF a$ = "p" OR a$ = "P" THEN
  49.     j& = _COPYIMAGE(0)
  50.     SCREEN j&
  51.     _DELAY .25
  52.     _PRINTIMAGE j&
  53.     a$ = ""
  54.     GOTO waiting:
  55. IF a$ = CHR$(27) THEN END
  56. IF a$ = "q" OR a$ = "Q" THEN END
  57. IF a$ = " " THEN GOTO begin:
  58. GOTO waiting:
  59.  
« Last Edit: August 26, 2019, 01:04:59 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Generic Random Maze Maker
« Reply #1 on: August 26, 2019, 01:39:31 am »
This code generates a maze that is completely connected:
https://www.qb64.org/forum/index.php?topic=277.msg1598#msg1598

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Generic Random Maze Maker
« Reply #2 on: August 26, 2019, 12:16:43 pm »
That's incredible B+! Beyond what I can do for sure. But I will keep working on mine.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Generic Random Maze Maker
« Reply #3 on: August 26, 2019, 01:08:05 pm »
That's incredible B+! Beyond what I can do for sure. But I will keep working on mine.

And you will come up with something very interesting, I am sure! looking forward to seeing what :)

Oh hey! talk about amazing fun:
https://easylang.online/apps/monster-maze.html
« Last Edit: August 26, 2019, 01:11:16 pm by bplus »

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
    • View Profile
Re: Generic Random Maze Maker
« Reply #4 on: August 26, 2019, 04:52:31 pm »
If you have a commodore 64 and need a maze in one line (that does not have a clear path probably) try this

10 PRINT CHR$(205.5+RND(1)); : GOTO 10
QB64 is the best!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Generic Random Maze Maker
« Reply #5 on: August 26, 2019, 08:52:06 pm »
I'm working on a game using most of this code called Search-Man. Don't expect too much lol. So far you can move a little green square guy around the maze with the arrow keys and collect dots. I really like how it chooses a random maze for every level. But it's nothing like Pac-Man. It's more of a "search the maze" game. I hope to be done within a few days or less. Next I have to figure out how to make the bad guy or some way to lose. lol

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Generic Random Maze Maker
« Reply #6 on: August 27, 2019, 04:54:56 am »
Bplus,

Thanks for the link to the maze... Fired it up, hand poised over the cursor keys, NO... Mouse controlled... Finally got the hang of it and successfully got through... Cool game.
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Generic Random Maze Maker
« Reply #7 on: August 27, 2019, 09:38:12 am »
Bplus,

Thanks for the link to the maze... Fired it up, hand poised over the cursor keys, NO... Mouse controlled... Finally got the hang of it and successfully got through... Cool game.

Yeah, I was considering cloning a QB64 version, hadn't gotten around to it, so offered it up to Ken. But you do need to get code for generating a maze worked out, the reason for the link to Amazing Mouse which has that already in QB64.

Offline petoro

  • Newbie
  • Posts: 27
    • View Profile
Re: Generic Random Maze Maker
« Reply #8 on: August 27, 2019, 10:00:13 am »
Amazing mazes... I've been fiddling with the B + version. I reduced the second occurrence of _DELAY to .002 to turn the little mouse into a Speedy Gonzales superhero!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Generic Random Maze Maker
« Reply #9 on: August 30, 2019, 06:18:40 pm »
Ken, you've got me studying maze making but first I had to settle a question about collision detection with the walls.

What are walls but simple blocks that won't let our hero at the mouse position pass through, need a detector not based on POINT.

so I found and modified code to stop hero from entering box (thanks again Johnno) :
Code: QB64: [Select]
  1. _TITLE "Bounding Box Collision Detection"
  2. ' 2019-08-30 rewrite this so mouse box never gets inside the sides of box for maze study
  3.  
  4. '
  5. '   Collision - Test 1  orig by johnno copied and mod b+ 2018-06-10
  6. '
  7. '   Bounding Box
  8. '
  9. ' 2018-06-10 mod by B+ change for x, y, w, h of images
  10. ' by readjusting all the variables and use STEP for box drawing
  11. ' Generalize the specific gosub routine from this one app so can reuse IN ANY APP using sprites / tiles / images
  12.  
  13. SCREEN _NEWIMAGE(800, 600, 32) '<<< something more standard center is 400, 300
  14.  
  15. ' sprites / tiles / images are typically referred to by their left top corner ie X, Y  and their width and height
  16.  
  17. 'lets do the height and width first
  18. box1Width = 400 '<<< mod add this instead of above
  19. box1Height = 100 '<<< mod add this instead of above
  20.  
  21. 'now center box
  22. box1Left = 400 - box1Width / 2 'same as box1X
  23. box1Top = 300 - box1Height / 2 'same as box1Y
  24.  
  25. mouseboxWidth = 50 '<<< mod add these constants
  26. mouseboxHeight = 40 '<<< mod add these constants
  27.  
  28. f& = _RGB32(255, 255, 255)
  29. b& = _RGB32(0, 0, 0)
  30.  
  31. DIM hey$(10)
  32. hey$(0) = "Hey!"
  33. hey$(1) = "I beg your pardon."
  34. hey$(2) = "Bang!"
  35. hey$(3) = "Yikes!"
  36. hey$(4) = "Ouch!"
  37. hey$(5) = "Watch where you are going."
  38.     k$ = INKEY$
  39.     WHILE _MOUSEINPUT: WEND '<<< this is all the loop needed for mouse input
  40.     CLS
  41.     LINE (box1Left, box1Top)-STEP(box1Width, box1Height), _RGB32(255, 255, 255), BF
  42.  
  43.     ombx = mouseboxX: omby = mouseboxy
  44.  
  45.     mouseboxX = _MOUSEX - mouseboxWidth / 2
  46.     mouseboxy = _MOUSEY - mouseboxHeight / 2
  47.  
  48.     IF collision%(box1Left, box1Top, box1Width, box1Height, mouseboxX, mouseboxy, mouseboxWidth, mouseboxHeight) = 1 THEN
  49.         COLOR _RGB32(100, 0, 85), _RGB32(255, 255, 255)
  50.         r$ = hey$(INT(RND * 6))
  51.         _PRINTSTRING (box1Left + (box1Width - LEN(r$) * 8) / 2, 292), r$
  52.         COLOR f&, b&
  53.         mouseboxX = ombx: mouseboxy = omby
  54.         lim = 1
  55.     ELSE
  56.         lim = 200
  57.     END IF
  58.     LINE (mouseboxX, mouseboxy)-STEP(mouseboxWidth, mouseboxHeight), _RGB32(255, 128, 0), BF '<<< use step with width and height
  59.     _DISPLAY
  60.     _LIMIT lim '<<< save the fan
  61. LOOP UNTIL k$ = CHR$(27)
  62.  
  63. FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
  64.     ' x, y represent the box left most x and top most y
  65.     ' w, h represent the box width and height which is the usual way sprites / tiles / images are described
  66.     ' such that boxbottom = by + bh
  67.     '        and boxright = bx + bw
  68.     'so the specific gosub above is gerealized to a function procedure here!
  69.     IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN
  70.         collision% = 0
  71.     ELSE
  72.         collision% = 1
  73.     END IF
  74.  
« Last Edit: August 30, 2019, 06:20:08 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Generic Random Maze Maker
« Reply #10 on: August 30, 2019, 09:23:09 pm »
Collision detection in a maze without POINT:

Code: QB64: [Select]
  1. _TITLE "Study Maze Making" 'B+ 2019-08-30
  2. CONST sw = 800, sh = 600
  3. SCREEN _NEWIMAGE(sw, sh, 32)
  4. _SCREENMOVE 300, 60
  5.  
  6. TYPE box
  7.     x AS INTEGER
  8.     y AS INTEGER
  9.     w AS INTEGER
  10.     h AS INTEGER
  11. REDIM SHARED mazeBoxes(1 TO 1) AS box
  12. DIM SHARED vCells AS INTEGER, hCells AS INTEGER, wallThk AS INTEGER, xl, yl
  13. hCells = 28: vCells = 15
  14. DIM SHARED maze(hCells + 1, vCells + 1) AS INTEGER 'walls always +1 than cells to surround them
  15. DIM x, y, mx, my, mw, mh, oldx, oldy
  16. xl = sw / (hCells + 2)
  17. yl = sh / (vCells + 2)
  18. wallThk = 10
  19. mw = .7 * xl
  20. mh = .7 * yl
  21.  
  22. FOR y = 1 TO vCells 'read in data for maze
  23.     FOR x = 1 TO hCells
  24.         READ maze(x, y)
  25.     NEXT
  26. mx = xl + 5 + mw / 2: my = yl + 5 + mh / 2
  27.     CLS
  28.     drawMaze
  29.     oldx = mx: oldy = my
  30.     mx = _MOUSEX - mw / 2: my = _MOUSEY - mh / 2
  31.     IF MazeCollision(mx, my, mw, mh) THEN
  32.         mx = oldx: my = oldy: BEEP
  33.     END IF
  34.     LINE (mx, my)-STEP(mw, mh), &HFF0000FF, BF
  35.     _DISPLAY
  36.     _LIMIT 100
  37.  
  38. 'test maze
  39. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
  40. DATA 1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  41. DATA 1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1
  42. DATA 1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1
  43. DATA 1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1
  44. DATA 1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  45. DATA 1,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1
  46. DATA 1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1
  47. DATA 1,0,1,0,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
  48. DATA 1,0,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1
  49. DATA 1,0,1,0,0,0,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1
  50. DATA 1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1
  51. DATA 1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1
  52. DATA 1,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1
  53. DATA 1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1
  54.  
  55. FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
  56.     ' x, y represent the box left most x and top most y
  57.     ' w, h represent the box width and height which is the usual way sprites / tiles / images are described
  58.     ' such that boxbottom = by + bh
  59.     '        and boxright = bx + bw
  60.     'so the specific gosub above is gerealized to a function procedure here!
  61.     IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN
  62.         collision% = 0
  63.     ELSE
  64.         collision% = 1
  65.     END IF
  66.  
  67. SUB drawMaze 'while drawing maze build mazeBoxes array for detecting collisions
  68.     DIM x, y, cnt AS INTEGER
  69.     FOR y = 1 TO vCells
  70.         FOR x = 1 TO hCells
  71.             IF maze(x, y) AND maze(x, y + 1) THEN
  72.                 LINE (x * xl, y * yl)-STEP(wallThk, yl + wallThk), , BF
  73.                 cnt = cnt + 1
  74.                 REDIM _PRESERVE mazeBoxes(1 TO cnt) AS box
  75.                 mazeBoxes(cnt).x = x * xl
  76.                 mazeBoxes(cnt).y = y * yl
  77.                 mazeBoxes(cnt).w = wallThk
  78.                 mazeBoxes(cnt).h = yl + wallThk
  79.             END IF
  80.             IF maze(x, y) AND maze(x + 1, y) THEN
  81.                 LINE (x * xl, y * yl)-STEP(xl + wallThk, wallThk), , BF
  82.                 cnt = cnt + 1
  83.                 REDIM _PRESERVE mazeBoxes(1 TO cnt) AS box
  84.                 mazeBoxes(cnt).x = x * xl
  85.                 mazeBoxes(cnt).y = y * yl
  86.                 mazeBoxes(cnt).w = xl + wallThk
  87.                 mazeBoxes(cnt).h = wallThk
  88.             END IF
  89.         NEXT
  90.     NEXT
  91.  
  92. FUNCTION MazeCollision% (mx, my, mw, mh)
  93.     DIM i
  94.     MazeCollision% = -1 'assume true
  95.     FOR i = 1 TO UBOUND(mazeBoxes)
  96.         IF collision%(mx, my, mw, mh, mazeBoxes(i).x, mazeBoxes(i).y, mazeBoxes(i).w, mazeBoxes(i).h) THEN EXIT FUNCTION
  97.     NEXT
  98.     MazeCollision% = 0
  99.  
  100.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Generic Random Maze Maker
« Reply #11 on: August 30, 2019, 10:32:38 pm »
Pretty neat B+, but it's the same problem as before. The block can still jump the walls when the mouse is pointing it farther to the other side. It did that in both of your examples here.  It was the same thing with POINT I believe, the mouse just goes to a coordinate that has no walls and goes there. Although, these examples are better because the walls are thicker and it gives the player a feeling that he is blocked. That is if the player doesn't point it too far.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Generic Random Maze Maker
« Reply #12 on: August 31, 2019, 10:29:26 am »
Pretty neat B+, but it's the same problem as before. The block can still jump the walls when the mouse is pointing it farther to the other side. It did that in both of your examples here.  It was the same thing with POINT I believe, the mouse just goes to a coordinate that has no walls and goes there. Although, these examples are better because the walls are thicker and it gives the player a feeling that he is blocked. That is if the player doesn't point it too far.

Yeah, I think there is a better way to do this, to force the square directed by the mouse to stay the course like with the arrows PLUS without collision detection!

Do you remember or even know of an old kids game called Operation?
You had to remove body parts with tweezers's and if your touch a wall BUZZZZZ! you lost the patient!

This collision detection reminded me of that game. :D
« Last Edit: August 31, 2019, 10:34:28 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Generic Random Maze Maker
« Reply #13 on: August 31, 2019, 05:21:40 pm »
OK 3 ways to move mouse through maze
1 arrow keys without momentum
2 arrow keys with momentum, Ken's style (space bar toggles momentum on and off)
3 mouse magnet when mouse is close to player avatar it will attract it but avatar does NOT go through walls anymore.

Also except for arrow stepping #1, the others are clunky... ;(

But look ma! no numbers crunching collision code to wade through! ;-))

Code: QB64: [Select]
  1. _TITLE "Study Maze Making 2 mouse navigation" 'B+ 2019-08-30 Collision detection
  2. CONST sw = 800, sh = 600
  3. SCREEN _NEWIMAGE(sw, sh, 32)
  4. _SCREENMOVE 300, 60
  5.  
  6. '        GLOBALs
  7. DIM SHARED vCells AS INTEGER, hCells AS INTEGER, wallThk AS INTEGER, xl, yl, xwo, ywo
  8. hCells = 28: vCells = 15
  9. DIM SHARED maze(hCells + 1, vCells + 1) AS INTEGER 'walls always +1 than cells to surround them
  10.  
  11. '        Locals for Main module code
  12. DIM x, y, px, py, pw, ph, mx, my, k$, d, a, dist, momentum, lastD
  13.  
  14. 'set globals and locals
  15. wallThk = 10 '          maze wall thickness shared
  16. xl = (sw - wallThk) / (hCells + 2) 'horz length of cell shared
  17. yl = (sh - wallThk) / (vCells + 2) 'vert length of cell shared
  18.  
  19. pw = xl '               player avatar width
  20. ph = yl '               player avatar height
  21. xwo = (xl - wallThk) / 2 'x wall offset  ' horz ofset of walls so player has space on each side between it and walls
  22. ywo = (yl - wallThk) / 2 'y wall offset  ' vert offset of walls
  23.  
  24. FOR y = 1 TO vCells 'read in data for maze
  25.     FOR x = 1 TO hCells
  26.         READ maze(x, y)
  27.     NEXT
  28. px = 2: py = 2
  29.     CLS
  30.     drawMaze
  31.  
  32.  
  33.     d = lastD
  34.     mx = _MOUSEX - xl: my = _MOUSEY - yl 'offset by 1/2 character size
  35.     'if the mouse is near the player then it will act as magnet drawing player to it unless wall in way
  36.     dist = (mx - px * xl + xwo + wallThk / 2) ^ 2 + (my - py * yl + ywo + wallThk / 2) ^ 2
  37.     IF dist <= 9 * xl * yl AND dist >= .1 * xl * yl THEN 'mouse over char
  38.         a = _R2D(_ATAN2(my - py * yl + ywo + wallThk / 2, mx - px * xl + xwo + wallThk / 2))
  39.         IF a < 0 THEN a = a + 360
  40.         'LOCATE 1, 1: PRINT SPACE$(10)
  41.         'LOCATE 1, 1: PRINT a
  42.         'END
  43.         IF a > 250 AND a < 290 THEN d = 1
  44.         IF a > 70 AND a < 110 THEN d = 2
  45.         IF (a >= 0 AND a < 20) OR (a > 340 AND a <= 360) THEN d = 3
  46.         IF a > 160 AND a < 200 THEN d = 4
  47.     END IF
  48.  
  49.     k$ = INKEY$ 'key press takes precedence over mouse
  50.     IF k$ = " " THEN momentum = 1 - momentum
  51.  
  52.     IF LEN(k$) = 2 THEN
  53.         SELECT CASE ASC(k$, 2)
  54.             CASE 72: d = 1 'up
  55.             CASE 80: d = 2 'down
  56.             CASE 77: d = 3 'right
  57.             CASE 75: d = 4 'left
  58.         END SELECT
  59.     END IF
  60.     SELECT CASE d
  61.         CASE 1 'up
  62.             IF py - 1 >= 0 THEN
  63.                 IF maze(px, py - 1) = 0 THEN py = py - 1
  64.             END IF
  65.         CASE 2 'down
  66.             IF py + 1 <= vCells + 1 THEN
  67.                 IF maze(px, py + 1) = 0 THEN py = py + 1
  68.             END IF
  69.         CASE 3 'right
  70.             IF px + 1 <= hCells + 1 THEN
  71.                 IF maze(px + 1, py) = 0 THEN px = px + 1
  72.             END IF
  73.         CASE 4 'left
  74.             IF px - 1 >= 0 THEN
  75.                 IF maze(px - 1, py) = 0 THEN px = px - 1
  76.             END IF
  77.     END SELECT
  78.     LINE (px * xl + wallThk / 2, py * yl + wallThk / 2)-STEP(pw, ph), &HFF0000FF, BF 'draw player
  79.     IF momentum THEN
  80.         lastD = d: _TITLE "Mouse in amazement: spaceBar toggles momentum: ON"
  81.     ELSE
  82.         lastD = 0: _TITLE "Mouse in amazement: spaceBar toogles momentum: OFF"
  83.     END IF
  84.     _DISPLAY
  85.     _LIMIT 5
  86.  
  87. 'test maze
  88. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
  89. DATA 1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  90. DATA 1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1
  91. DATA 1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1
  92. DATA 1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1
  93. DATA 1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  94. DATA 1,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1
  95. DATA 1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1
  96. DATA 1,0,1,0,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
  97. DATA 1,0,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1
  98. DATA 1,0,1,0,0,0,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1
  99. DATA 1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1
  100. DATA 1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1
  101. DATA 1,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1
  102. DATA 1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1
  103.  
  104. SUB drawMaze 'while drawing maze build mazeBoxes array for detecting collisions
  105.     DIM x, y, cnt AS INTEGER
  106.     FOR y = 1 TO vCells
  107.         FOR x = 1 TO hCells
  108.             IF maze(x, y) AND maze(x, y + 1) THEN
  109.                 LINE (x * xl + xwo + wallThk / 2, y * yl + ywo + wallThk / 2)-STEP(wallThk, yl + wallThk), , BF
  110.                 cnt = cnt + 1
  111.             END IF
  112.             IF maze(x, y) AND maze(x + 1, y) THEN
  113.                 LINE (x * xl + xwo + wallThk / 2, y * yl + ywo + wallThk / 2)-STEP(xl + wallThk, wallThk), , BF
  114.                 cnt = cnt + 1
  115.             END IF
  116.         NEXT
  117.     NEXT
  118.  
  119.  
  120.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Generic Random Maze Maker
« Reply #14 on: August 31, 2019, 06:21:31 pm »
That's neat. My mouse is very sticky but still cool.