Author Topic: Simple Maze Designer  (Read 6620 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Simple Maze Designer
« on: June 26, 2019, 06:18:34 pm »
I just thought I would toss this little program I made this afternoon into the mix. It's a simple plotting/drawing program to mostly use with other games or programs we make in the future. There's no color changes, just white lines. I'm not very good at making a color picker and just using numbers would be pretty random for me so I just stuck with white. Of course you can add color or anything you wish to this if you want. It uses a 640 x 480 screen with 10 x 10 plots. There is a limit of 10,000 plots but that would fill up the whole screen and more and the size of the file that would save as would be around 100 KB. The saved files have an .aze ending (maze without the m). I couldn't find a file ending on Google that has that ending so I stuck with it. The file it makes doesn't have a color number on it so when you load it with your own programs, you will need to add that. You use the arrow keys and space bar to change from pen up to pen down and vice-versa, S to save, L to load. There is no printer support with this one because of the 10 x 10 pixels would be heavy on the ink. This is just something I tossed together within about 3 hours. :) Enjoy.

- Code deleted because of a much better update I made below on my post.
« Last Edit: June 27, 2019, 04:07:01 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Simple Maze Designer
« Reply #1 on: June 26, 2019, 08:07:35 pm »
Hi Ken,

Reminds me of Etch-A-Sketch. Have you thought about an eraser? change a cell back to black.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Simple Maze Designer
« Reply #2 on: June 26, 2019, 09:01:33 pm »
Oh, how can you compare Picaso with an "Etch-a-Sketch"?

But you could be right about an eraser. If so, would it not be better to have the 'cursor' as a empty box, just so you can tell where it is? Just a thought.
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple Maze Designer
« Reply #3 on: June 26, 2019, 10:56:34 pm »
I thought about an eraser but since I use t=t+1 x(t) y(t) and just create the picture file with those coords, it would be too hard to try and go back and erase it since I don't use colors. But I'm glad you guys like it. :) I also thought about a cursor, but that is a bit beyond me as well. I used to know more about such a thing but am not completely back to how I was in the 90's. I remember a command named XOR where you can put graphics over graphics. Someday I may look into it again, but I'm just going to keep this program the way it is. :)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Simple Maze Designer
« Reply #4 on: June 27, 2019, 01:54:28 am »
In a nutshell you can draw a square (or whatever shape you choose) for a cursor, use _hidemouse(), then display the shape at mouseX and mouseY. Well, that's what I think could work... you may have to check with the others...

J
Logic is the beginning of wisdom.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Simple Maze Designer
« Reply #5 on: June 27, 2019, 01:56:41 am »
Hi. Thank You for this program. It is going to be useful for me.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Simple Maze Designer
« Reply #6 on: June 27, 2019, 08:09:07 am »
Hi. And what to do a little differently. Left-click to paint the block, right-click to delete it. Save it by pressing S. Load map by pressing L. And moreover ... the map is not limited to one displayed field, so press the up, down, left and right keys to move around the map. It's just a quick sketch. Basically the basis in which I make a maze editor.

Code: QB64: [Select]
  1. 'maze edit fast
  2. SCREEN _NEWIMAGE(640, 480, 256)
  3. REDIM maze(100, 100) AS _BYTE 'total map contains 10.000 cells
  4. CONST map$ = "Mazemap_textfile.txt"
  5. 'create cells 20 x 20
  6. FOR y = 0 TO 460 STEP 20 '23 steps
  7.     FOR x = 0 TO 620 STEP 20 '31 steps
  8.         LINE (x, y)-(x + 19, y + 19), , B
  9. NEXT x, y
  10.  
  11. 'activate mouse for inserting / deleting cell:
  12.     PositionX = Sx + _CEIL(_MOUSEX / 20)
  13.     PositionY = Sy + _CEIL(_MOUSEY / 20)
  14.  
  15.     IF PositionX > UBOUND(maze, 1) THEN PositionX = UBOUND(maze, 1)
  16.     IF PositionY > UBOUND(maze, 2) THEN PositionY = UBOUND(maze, 2)
  17.  
  18.     IF _MOUSEBUTTON(1) THEN maze(PositionX, PositionY) = 1
  19.     IF _MOUSEBUTTON(2) THEN maze(PositionX, PositionY) = 0
  20.  
  21.     'add keyboard support for map edit move up, down, left and right
  22.  
  23.     i$ = INKEY$
  24.     SELECT CASE i$
  25.         CASE CHR$(0) + CHR$(72): Sy = Sy - 1 'up
  26.         CASE CHR$(0) + CHR$(80): Sy = Sy + 1 'dn
  27.         CASE CHR$(0) + CHR$(75): Sx = Sx - 1 'up
  28.         CASE CHR$(0) + CHR$(77): Sx = Sx + 1 'dn
  29.  
  30.             'and after "S" pressing it save this map to file:
  31.         CASE "S", "s": GOSUB SaveIt
  32.  
  33.             'and after "L" pressing, load it from file mazemap_textfile (if is previously saved)
  34.         CASE "L", "l": GOSUB LoadIt
  35.     END SELECT
  36.  
  37.     IF Sx > UBOUND(maze, 1) - 32 THEN Sx = UBOUND(maze, 1) - 32
  38.     IF Sx < LBOUND(maze, 1) THEN Sx = LBOUND(maze, 1)
  39.     IF Sy > UBOUND(maze, 2) - 24 THEN Sy = UBOUND(maze, 2) - 24
  40.     IF Sy < LBOUND(maze, 2) THEN Sy = LBOUND(maze, 2)
  41.  
  42.     Ex = Sx + 32
  43.     Ey = Sy + 24
  44.  
  45.     IF Ex > UBOUND(maze, 1) THEN Ex = UBOUND(maze, 1)
  46.     IF Ex < LBOUND(maze, 1) THEN Ex = LBOUND(maze, 1)
  47.     IF Ey > UBOUND(maze, 2) THEN Ey = UBOUND(maze, 2)
  48.     IF Ey < LBOUND(maze, 2) THEN Ey = LBOUND(maze, 2)
  49.  
  50.     'draw it to screen:
  51.  
  52.     FOR dy = Sy TO Ey
  53.         FOR dx = Sx TO Ex
  54.             SDx = 20 * (dx - Sx - 1) 'SDX = start draw X
  55.             SDy = 20 * (dy - Sy - 1) 'SDY = start draw Y
  56.             IF maze(dx, dy) THEN
  57.                 LINE (SDx, SDy)-(SDx + 18, SDy + 18), , BF
  58.             ELSE
  59.                 LINE (SDx, SDy)-(SDx + 18, SDy + 18), 0, BF
  60.             END IF
  61.     NEXT dx, dy
  62.  
  63. SaveIt:
  64. IF _FILEEXISTS(map$) THEN KILL map$
  65. OPEN map$ FOR OUTPUT AS #f
  66. FOR recX = LBOUND(maze, 1) TO UBOUND(maze, 1)
  67.     FOR recY = LBOUND(maze, 2) TO UBOUND(maze, 2)
  68.         IF maze(recX, recY) THEN
  69.             PRINT #f, STR$(recX); ","; STR$(recY); ","; STR$(maze(recX, recY))
  70.         END IF
  71. NEXT recY, recX
  72.  
  73. SOUND 150, .3
  74.  
  75. LoadIt:
  76.     REDIM maze(UBOUND(maze, 1), UBOUND(maze, 2)) AS _BYTE
  77.     f = FREEFILE
  78.     OPEN map$ FOR INPUT AS #f
  79.     DO WHILE NOT EOF(f)
  80.         INPUT #f, x, y, value
  81.         maze(x, y) = value
  82.     LOOP
  83.     CLOSE #f
  84.     SOUND 150, .3
  85. ELSE BEEP 'file not exists
  86.  
  87.  


As you can see, the value "1" is written for the filled cell in field. So here's a lot of options: Suppose 1 will be an ordinary wall. 2 will swamp, 3 need sand .... and everything will have different characteristics. Or with a small adjustment you can create a platform game. Anything. Of course, you can write more map layers to the same place (by adding more fields or just variables to the fields), for example, to run some timed activity, or for sound.
« Last Edit: June 27, 2019, 08:17:45 am by Petr »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple Maze Designer
« Reply #7 on: June 27, 2019, 04:06:05 pm »
That's really cool Petr! I liked the grid a lot so I put it into my program. I also figured out how to make a red box so you know where your plot is going to be before you make it. I'm still using the arrow keys because personally I think it's easier than choosing 1 square at a time with a mouse. I also renamed it and added an eraser. So here it is: :) 

Edit: Code deleted again because I keep adding more things. :)
« Last Edit: June 27, 2019, 04:53:09 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple Maze Designer
« Reply #8 on: June 27, 2019, 04:49:57 pm »
Sorry for always updating and posting, will try to test programs out more from now on before I post on here.
I made it so you don't see Eraser On when your Pen is Up since you can't erase when your pen is up anyway. Am still working on it and testing it.

« Last Edit: June 27, 2019, 04:52:31 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple Maze Designer
« Reply #9 on: June 27, 2019, 05:21:15 pm »
OK here it is, I'm 99.9% sure this is the final one. It's been tested, fixed, added to, everything. lol

Code: QB64: [Select]
  1. 'This plotter was made in 2 days by Ken G. and finished on June 27, 2019 using QB64 language.
  2. 'Thank you for some ideas from some people at the QB64.org Forum!
  3. 'Code to use the pictures made with this can be found marked out toward the end of this program.
  4. 'This program is Freeware and will always be Freeware.
  5. 'Feel free to use any of this code in your own programs.
  6. '-----------------------------------------------------------------------------------------------
  7. _TITLE "Ken's Plotter"
  8. _LIMIT 400
  9. start:
  10. DIM x$(10000), y$(10000), x(10000), y(10000)
  11. p = 0
  12. t = 0
  13. pn = 0
  14. e = 0
  15. SCREEN _NEWIMAGE(640, 480, 32)
  16. PRINT "                     Ken's Plotter"
  17. PRINT "                       By Ken G."
  18. PRINT "Use the arrow keys to move the red box."
  19. PRINT "Use Space Bar to move Pen Down to draw and Pen Up to just move."
  20. PRINT "Use E to turn the Eraser off and on."
  21. PRINT "Use Esc to start over."
  22. PRINT "**** You will need to have Pen Down to use Eraser."
  23. PRINT "There is a 10,000 plot limit. Don't worry about this limit"
  24. PRINT "because you can fill the entire screen and more and still be"
  25. PRINT "less than 10,000 plots."
  26. PRINT "Press S to save and L to load an already saved picture."
  27. PRINT "The saved .txt file will have X,Y plots on each line that"
  28. PRINT "can be used in your own programs."
  29. PRINT "This is a simple plotting/drawing program that doesn't change colors."
  30. PRINT "The saved files don't have any colors on them, so when"
  31. PRINT "you use them for your own programs, you will need to add a color."
  32. PRINT "The window scale is 640 x 480 pixels with each plot every 10 pixels."
  33. PRINT "So when using in your own programs, make sure and make X = X + 10 and"
  34. PRINT "Y = Y + 10 to display with LINE command."
  35. PRINT "Code to load your picture is marked out in the code of this program."
  36. PRINT "The coordinates and Pen Up, Pen Down, Eraser On, Eraser Off will be"
  37. PRINT "in the top Window title bar."
  38. INPUT "Press enter to start.", st$
  39. x = 320: y = 240
  40. FOR gridx = 0 TO 640 STEP 10
  41.     FOR gridy = 0 TO 480 STEP 10
  42.         LINE (gridx, gridy)-(gridx + 10, gridy + 10), _RGB32(255, 255, 255), B
  43.     NEXT gridy
  44. NEXT gridx
  45. LINE (x, y)-(x + 10, y + 10), _RGB(255, 0, 0), B
  46. pen$ = "Up": eraser$ = "Off"
  47. xx$ = STR$(x): yy$ = STR$(y)
  48. titl$ = "Ken's Plotter X=" + xx$ + " Y=" + yy$ + "     Pen: " + pen$ + "     Eraser: " + eraser$
  49. _TITLE titl$
  50. go:
  51. _LIMIT 400
  52. a$ = INKEY$
  53. IF a$ = CHR$(27) THEN GOTO start:
  54. IF a$ = "s" OR a$ = "S" THEN GOTO save:
  55. IF a$ = "l" OR a$ = "L" OR a$ = "m" OR a$ = "M" THEN GOTO load:
  56. IF a$ = CHR$(0) + CHR$(72) THEN
  57.     LINE (x, y)-(x + 10, y + 10), _RGB(255, 255, 255), B
  58.     y = y - 10
  59.     IF y < 0 THEN y = 0
  60.     LINE (x, y)-(x + 10, y + 10), _RGB(255, 0, 0), B
  61.     IF pn = 1 THEN
  62.         x2 = x + 10
  63.         y2 = y + 10
  64.         IF e = 0 THEN LINE (x, y)-(x2, y2), _RGB32(255, 255, 255), BF
  65.         t = t + 1
  66.         x$(t) = STR$(x): y$(t) = STR$(y)
  67.         IF e = 1 THEN
  68.             LINE (x, y)-(x2, y2), _RGB32(0, 0, 0), BF
  69.             GOSUB eraser:
  70.         END IF
  71.         GOSUB check:
  72.     END IF
  73.     xx$ = STR$(x): yy$ = STR$(y)
  74.     titl$ = "Ken's Plotter X=" + xx$ + " Y=" + yy$ + "     Pen: " + pen$ + "     Eraser: " + eraser$
  75.     _TITLE titl$
  76. IF a$ = CHR$(0) + CHR$(80) THEN
  77.     LINE (x, y)-(x + 10, y + 10), _RGB(255, 255, 255), B
  78.     y = y + 10
  79.     IF y > 470 THEN y = 470
  80.     LINE (x, y)-(x + 10, y + 10), _RGB(255, 0, 0), B
  81.     IF pn = 1 THEN
  82.         x2 = x + 10
  83.         y2 = y + 10
  84.         LINE (x, y)-(x2, y2), _RGB32(255, 255, 255), BF
  85.         t = t + 1
  86.         x$(t) = STR$(x): y$(t) = STR$(y)
  87.         IF e = 1 THEN
  88.             LINE (x, y)-(x2, y2), _RGB32(0, 0, 0), BF
  89.             GOSUB eraser:
  90.         END IF
  91.         GOSUB check:
  92.     END IF
  93.     xx$ = STR$(x): yy$ = STR$(y)
  94.     titl$ = "Ken's Plotter X=" + xx$ + " Y=" + yy$ + "     Pen: " + pen$ + "     Eraser: " + eraser$
  95.     _TITLE titl$
  96. IF a$ = CHR$(0) + CHR$(77) THEN
  97.     LINE (x, y)-(x + 10, y + 10), _RGB(255, 255, 255), B
  98.     x = x + 10
  99.     IF x > 630 THEN x = 630
  100.     LINE (x, y)-(x + 10, y + 10), _RGB(255, 0, 0), B
  101.     IF pn = 1 THEN
  102.         x2 = x + 10
  103.         y2 = y + 10
  104.         LINE (x, y)-(x2, y2), _RGB32(255, 255, 255), BF
  105.         t = t + 1
  106.         x$(t) = STR$(x): y$(t) = STR$(y)
  107.         IF e = 1 THEN
  108.             LINE (x, y)-(x2, y2), _RGB32(0, 0, 0), BF
  109.             GOSUB eraser:
  110.         END IF
  111.         GOSUB check:
  112.     END IF
  113.     xx$ = STR$(x): yy$ = STR$(y)
  114.     titl$ = "Ken's Plotter X=" + xx$ + " Y=" + yy$ + "     Pen: " + pen$ + "     Eraser: " + eraser$
  115.     _TITLE titl$
  116. IF a$ = CHR$(0) + CHR$(75) THEN
  117.     LINE (x, y)-(x + 10, y + 10), _RGB(255, 255, 255), B
  118.     x = x - 10
  119.     IF x < 0 THEN x = 0
  120.     LINE (x, y)-(x + 10, y + 10), _RGB(255, 0, 0), B
  121.     IF pn = 1 THEN
  122.         x2 = x + 10
  123.         y2 = y + 10
  124.         LINE (x, y)-(x2, y2), _RGB32(255, 255, 255), BF
  125.         t = t + 1
  126.         x$(t) = STR$(x): y$(t) = STR$(y)
  127.         IF e = 1 THEN
  128.             LINE (x, y)-(x2, y2), _RGB32(0, 0, 0), BF
  129.             GOSUB eraser:
  130.         END IF
  131.         GOSUB check:
  132.     END IF
  133.     xx$ = STR$(x): yy$ = STR$(y)
  134.     titl$ = "Ken's Plotter X=" + xx$ + " Y=" + yy$ + "     Pen: " + pen$ + "     Eraser: " + eraser$
  135.     _TITLE titl$
  136. IF a$ = "e" OR a$ = "E" THEN
  137.     e = e + 1
  138.     IF e = 2 THEN e = 0
  139.     IF e = 1 THEN
  140.         IF pen$ = "Down" THEN eraser$ = "On"
  141.         titl$ = "Ken's Plotter X=" + xx$ + " Y=" + yy$ + "     Pen: " + pen$ + "     Eraser: " + eraser$
  142.         _TITLE titl$
  143.     END IF
  144.     IF e = 0 THEN
  145.         eraser$ = "Off"
  146.         titl$ = "Ken's Plotter X=" + xx$ + " Y=" + yy$ + "     Pen: " + pen$ + "     Eraser: " + eraser$
  147.         _TITLE titl$
  148.     END IF
  149. IF a$ = " " THEN
  150.     pn = pn + 1
  151.     IF pn = 2 THEN pn = 0
  152. IF pn = 1 THEN
  153.     pen$ = "Down"
  154.     titl$ = "Ken's Plotter X=" + xx$ + " Y=" + yy$ + "     Pen: " + pen$ + "     Eraser: " + eraser$
  155.     _TITLE titl$
  156.  
  157. IF pn = 0 THEN
  158.     pen$ = "Up"
  159.     titl$ = "Ken's Plotter X=" + xx$ + " Y=" + yy$ + "     Pen: " + pen$ + "     Eraser: " + eraser$
  160.     _TITLE titl$
  161. GOTO go:
  162.  
  163. save:
  164. save2:
  165. INPUT "Type file name of maze to create (without the .txt ending):", nm$
  166. nm$ = nm$ + ".txt"
  167. 'Checking to see if the file already exists on your computer.
  168. theFileExists = _FILEEXISTS(nm$)
  169. IF theFileExists = -1 THEN
  170.     PRINT "File Already Exists"
  171.     PRINT "Saving will delete your old maze."
  172.     PRINT
  173.     PRINT "Would you like to still do it?"
  174.     PRINT "(Y/N). Esc ends program."
  175.     llloop:
  176.     _LIMIT 10
  177.     ag2$ = INKEY$
  178.     IF ag2$ = "" THEN GOTO llloop:
  179.     IF ag2$ = "y" OR ag$ = "Y" THEN GOTO save3:
  180.     IF ag2$ = CHR$(27) THEN END
  181.     GOTO save2:
  182. save3:
  183. OPEN nm$ FOR OUTPUT AS #1
  184. FOR plots = 1 TO t
  185.     _LIMIT 400
  186.     IF x$(plots) = "" OR y$(plots) = "" THEN GOTO skip2:
  187.     PRINT #1, x$(plots); ","; y$(plots)
  188.     skip2:
  189. NEXT plots
  190. PRINT nm$; " has been saved to your computer."
  191. INPUT "Press enter to start again."; a$
  192. GOTO start:
  193.  
  194. '------------------------------------------------------------------------------
  195. 'The following is the code you can use to load the graphic to your own program.
  196. '------------------------------------------------------------------------------
  197.  
  198. load:
  199. INPUT "Type file name to load (without the .txt ending):", nm$
  200. nm$ = nm$ + ".txt"
  201. OPEN nm$ FOR INPUT AS #1
  202. ggo:
  203. _LIMIT 400
  204. p = p + 1
  205. INPUT #1, x$(p), y$(p)
  206. x(p) = VAL(x$(p)): y(p) = VAL(y$(p))
  207. LINE (x(p), y(p))-(x(p) + 10, y(p) + 10), _RGB(255, 255, 255), BF
  208. IF EOF(1) THEN CLOSE #1: GOTO done:
  209. GOTO ggo:
  210. done:
  211. a$ = INKEY$
  212. IF a$ = "" THEN GOTO done:
  213. IF a$ = CHR$(27) THEN END
  214.  
  215. '------------------------------------------------------------------------------
  216.  
  217. GOTO start:
  218.  
  219. check:
  220. IF t = 10000 THEN
  221.     INPUT "Limit has been reached, do you want to save (Yes/No):"; yn$
  222.     IF yn$ = "YES" OR yn$ = "yes" OR yn$ = "Yes" OR yn$ = "YEs" OR yn$ = "yES" OR yn$ = "Y" OR yn$ = "y" THEN GOTO save:
  223.     GOTO start:
  224.  
  225. eraser:
  226. FOR ee = 1 TO t
  227.     IF x$(ee) = x$(t) AND y$(ee) = y$(t) THEN
  228.         x$(ee) = "": y$(ee) = ""
  229.     END IF
  230. NEXT ee
  231.  
  232.  



Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple Maze Designer
« Reply #10 on: June 27, 2019, 08:29:04 pm »
I just made something I've wanted to make since the 80's! I used the above program to make a bunch of hallways on 1 picture. Then I made this program below as an example to everyone on how to detect every single wall from the picture. You move the little red dot around with your arrow keys and it stops if you hit a wall. :)))) Imagine the possibilities of games people can make with this! This probably sounds funny to most of you since you all are much higher up in skill than I am, but I am really excited. :) Here is:

Code: QB64: [Select]
  1. 'This is an example on how to detect walls from using a picture made by using Ken's Plotter.
  2. 'First make a picture with Ken's Plotter program and then type in the name of it in this program.
  3. 'This example starts you out in the direct center of the screen.
  4. _TITLE "Maze Loader and Wall Detector Example"
  5. start:
  6. 'You will need to DIM these strings and variables first to make memory.
  7. DIM x$(10000), y$(10000), x(10000), y(10000)
  8.  
  9. 'xx and yy are the coordinates to your red square.
  10. xx = 320: yy = 240
  11. SCREEN _NEWIMAGE(640, 480, 32)
  12. PRINT "Maze Loader and Wall Detector Example"
  13. PRINT "By Ken G."
  14. PRINT "This is an example on how to detect walls."
  15. PRINT "First you need to create a picture or maze using 'Ken's Plotter'."
  16. PRINT "Use your arrow keys to move the little red square around and it will"
  17. PRINT "stop at every wall. In this example, you start out in the very center"
  18. PRINT "of the window."
  19. again:
  20. INPUT "Type file name of picture to load (without the .txt ending):", nm$
  21. IF nm$ = "" THEN GOTO again:
  22. nm$ = nm$ + ".txt"
  23. theFileExists = _FILEEXISTS(nm$)
  24. IF theFileExists = 0 THEN
  25.     PRINT "File does not exist, try again."
  26.     GOTO again:
  27. 'First you load the picture and put every coordinate into memory.
  28. OPEN nm$ FOR INPUT AS #1
  29. ggo:
  30. _LIMIT 400
  31. p = p + 1
  32. INPUT #1, x$(p), y$(p)
  33. x(p) = VAL(x$(p)): y(p) = VAL(y$(p))
  34. LINE (x(p), y(p))-(x(p) + 10, y(p) + 10), _RGB(255, 255, 255), BF
  35.     CLOSE #1
  36.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  37.     GOTO go:
  38. GOTO ggo:
  39.  
  40. 'Here is the main loop of the program where you move the square around.
  41. go:
  42. _LIMIT 400
  43. a$ = INKEY$
  44. IF a$ = CHR$(27) THEN END
  45. IF a$ = CHR$(0) + CHR$(72) THEN
  46.     oldyy = yy
  47.     oldxx = xx
  48.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  49.     yy = yy - 5
  50.     GOSUB check:
  51.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  52.  
  53. IF a$ = CHR$(0) + CHR$(80) THEN
  54.     oldyy = yy
  55.     oldxx = xx
  56.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  57.     yy = yy + 5
  58.     GOSUB check:
  59.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  60.  
  61. IF a$ = CHR$(0) + CHR$(75) THEN
  62.     oldxx = xx
  63.     oldyy = yy
  64.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  65.     xx = xx - 5
  66.     GOSUB check:
  67.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  68.  
  69. IF a$ = CHR$(0) + CHR$(77) THEN
  70.     oldxx = xx
  71.     oldyy = yy
  72.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  73.     xx = xx + 5
  74.     GOSUB check:
  75.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  76.  
  77. GOTO go:
  78.  
  79. 'Here is where the computer checks to see if your red square hits a wall.
  80. check:
  81. FOR t = 1 TO p
  82.     IF xx > x(t) - 15 AND xx < x(t) + 15 AND yy > y(t) - 10 AND yy < y(t) + 15 THEN xx = oldxx: yy = oldyy
  83.  
  84.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Simple Maze Designer
« Reply #11 on: June 27, 2019, 09:49:18 pm »
Congratulations Ken,

I think you got a double dose of the Basic bug. :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple Maze Designer
« Reply #12 on: June 27, 2019, 10:25:13 pm »
ROFL Thanks B+! I do! LOL

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple Maze Designer
« Reply #13 on: June 27, 2019, 10:38:11 pm »
I added a couple more lines of code to stop the red square in the Maze Loader and Wall Detector Example, to stop your guy from going outside of the screen. I also decrease 5 numbers from one of the X detection numbers so it goes closer to the wall. 
Here is the newer update:

Code: QB64: [Select]
  1. 'This is an example on how to detect walls from using a picture made by using Ken's Plotter.
  2. 'First make a picture with Ken's Plotter program and then type in the name of it in this program.
  3. 'This example starts you out in the direct center of the screen.
  4. _TITLE "Maze Loader and Wall Detector Example"
  5. start:
  6. 'You will need to DIM these strings and variables first to make memory.
  7. DIM x$(10000), y$(10000), x(10000), y(10000)
  8.  
  9. 'xx and yy are the coordinates to your red square.
  10. xx = 320: yy = 240
  11. SCREEN _NEWIMAGE(640, 480, 32)
  12. PRINT "Maze Loader and Wall Detector Example"
  13. PRINT "By Ken G."
  14. PRINT "This is an example on how to detect walls."
  15. PRINT "First you need to create a picture or maze using 'Ken's Plotter'."
  16. PRINT "Use your arrow keys to move the little red square around and it will"
  17. PRINT "stop at every wall. In this example, you start out in the very center"
  18. PRINT "of the window."
  19. again:
  20. INPUT "Type file name of picture to load (without the .txt ending):", nm$
  21. IF nm$ = "" THEN GOTO again:
  22. nm$ = nm$ + ".txt"
  23. theFileExists = _FILEEXISTS(nm$)
  24. IF theFileExists = 0 THEN
  25.     PRINT "File does not exist, try again."
  26.     GOTO again:
  27. 'First you load the picture and put every coordinate into memory.
  28. OPEN nm$ FOR INPUT AS #1
  29. ggo:
  30. _LIMIT 400
  31. p = p + 1
  32. INPUT #1, x$(p), y$(p)
  33. x(p) = VAL(x$(p)): y(p) = VAL(y$(p))
  34. LINE (x(p), y(p))-(x(p) + 10, y(p) + 10), _RGB32(255, 255, 255), BF
  35.     CLOSE #1
  36.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  37.     GOTO go:
  38. GOTO ggo:
  39.  
  40. 'Here is the main loop of the program where you move the square around.
  41. go:
  42. _LIMIT 400
  43. a$ = INKEY$
  44. IF a$ = CHR$(27) THEN END
  45. IF a$ = CHR$(0) + CHR$(72) THEN
  46.     oldyy = yy
  47.     oldxx = xx
  48.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  49.     yy = yy - 5
  50.     GOSUB check:
  51.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  52.  
  53. IF a$ = CHR$(0) + CHR$(80) THEN
  54.     oldyy = yy
  55.     oldxx = xx
  56.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  57.     yy = yy + 5
  58.     GOSUB check:
  59.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  60.  
  61. IF a$ = CHR$(0) + CHR$(75) THEN
  62.     oldxx = xx
  63.     oldyy = yy
  64.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  65.     xx = xx - 5
  66.     GOSUB check:
  67.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  68.  
  69. IF a$ = CHR$(0) + CHR$(77) THEN
  70.     oldxx = xx
  71.     oldyy = yy
  72.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  73.     xx = xx + 5
  74.     GOSUB check:
  75.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(255, 0, 0), BF
  76.  
  77. GOTO go:
  78.  
  79. 'Here is where the computer checks to see if your red square hits a wall.
  80. check:
  81. IF yy < 0 THEN yy = 0
  82. IF xx < 0 THEN xx = 0
  83. IF yy > 475 THEN yy = 475
  84. IF xx > 635 THEN xx = 635
  85.  
  86. FOR t = 1 TO p
  87.     IF xx > x(t) - 10 AND xx < x(t) + 15 AND yy > y(t) - 10 AND yy < y(t) + 15 THEN xx = oldxx: yy = oldyy
  88.  
« Last Edit: June 28, 2019, 02:32:38 pm by SierraKen »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Simple Maze Designer
« Reply #14 on: June 29, 2019, 05:45:47 am »
"ROFL"?
Logic is the beginning of wisdom.