QB64.org Forum

Active Forums => Programs => Topic started by: bplus on January 16, 2021, 10:37:37 am

Title: Labyrinth Tiles
Post by: bplus on January 16, 2021, 10:37:37 am
Here is something I found interesting Thursday night, Labyrinth Tiles:
Code: QB64: [Select]
  1. _TITLE "Labyrinth Tile, spacebar for random tiling escape for Tile Design" 'b+ 2021-01-15
  2.  
  3. CONST Xmax = 700, Ymax = 700
  4. SCREEN _NEWIMAGE(Xmax, Ymax, 32)
  5. _DELAY .25
  6.  
  7.  
  8. makeTileImageLeft
  9. 'TileLeft 100, 100
  10. 'TileRight 0, 100
  11.  
  12. makeTileImageUp
  13. 'TileUp 100, 0
  14. 'TileDown 100, 99
  15. 'TileDown 100, 199
  16.  
  17.     CLS
  18.     FOR y = 0 TO Ymax STEP 100
  19.         FOR x = 0 TO Xmax STEP 100
  20.             r = RND
  21.             IF r < .25 THEN
  22.                 TileLeft x, y
  23.             ELSEIF r < .5 THEN
  24.                 TileDown x, y
  25.             ELSEIF r < .75 THEN
  26.                 TileRight x, y
  27.             ELSE
  28.                 TileUp x, y
  29.             END IF
  30.         NEXT
  31.     NEXT
  32.     _DISPLAY
  33.     SLEEP
  34.  
  35. ' can we make some designs?
  36. _TITLE "Labyrinth Tile, a Tile Design, Spacebar to Click your own Design"
  37. FOR y = 0 TO 7
  38.     FOR x = 0 TO 7
  39.         IF y MOD 4 = 0 OR y MOD 4 = 2 THEN
  40.             IF x MOD 4 = 0 OR x MOD 4 = 2 THEN
  41.                 TileLeft x * 100, y * 100
  42.             ELSEIF x MOD 4 = 1 OR x MOD 4 = 3 THEN
  43.                 TileRight x * 100, y * 100
  44.             END IF
  45.         ELSEIF y MOD 4 = 1 THEN
  46.             IF x MOD 4 = 0 THEN
  47.                 TileDown x * 100, y * 100
  48.             ELSEIF x MOD 4 = 2 THEN
  49.                 TileUp x * 100, y * 100
  50.             ELSEIF x MOD 4 = 1 THEN
  51.                 TileDown x * 100, y * 100
  52.             ELSEIF x MOD 4 = 3 THEN
  53.                 TileUp x * 100, y * 100
  54.             END IF
  55.         ELSEIF y MOD 4 = 3 THEN
  56.             IF x MOD 4 = 0 THEN
  57.                 TileUp x * 100, y * 100
  58.             ELSEIF x MOD 4 = 2 THEN
  59.                 TileDown x * 100, y * 100
  60.             ELSEIF x MOD 4 = 1 THEN
  61.                 TileUp x * 100, y * 100
  62.             ELSEIF x MOD 4 = 3 THEN
  63.                 TileDown x * 100, y * 100
  64.             END IF
  65.         END IF
  66.     NEXT
  67.  
  68.  
  69. _TITLE "Labyrinth Tile, Click tile to turn it, escape to quit..."
  70. REDIM t(7, 7) AS LONG
  71. FOR y = 0 TO 7
  72.     FOR x = 0 TO 7
  73.         t(x, y) = INT(RND * 4)
  74.     NEXT
  75.     CLS
  76.     FOR y = 0 TO 7
  77.         FOR x = 0 TO 7
  78.             SELECT CASE t(x, y)
  79.                 CASE 0: TileRight x * 100, y * 100
  80.                 CASE 1: TileDown x * 100, y * 100
  81.                 CASE 2: TileLeft x * 100, y * 100
  82.                 CASE 3: TileUp x * 100, y * 100
  83.             END SELECT
  84.         NEXT
  85.     NEXT
  86.     mb = _MOUSEBUTTON(1): mx = INT(_MOUSEX / 100): my = INT(_MOUSEY / 100)
  87.     LINE (mx * 100, my * 100)-STEP(100, 100), , B
  88.     IF mb THEN
  89.         IF mx >= 0 AND mx <= 7 AND my >= 0 AND my <= 7 THEN
  90.             t(mx, my) = (t(mx, my) + 1) MOD 4
  91.             PRINT mx, my
  92.             _DELAY .25
  93.         END IF
  94.     END IF
  95.     _DISPLAY
  96.     _LIMIT 100
  97.  
  98.  
  99. SUB TileLeft (x, y)
  100.     _PUTIMAGE (x, y), TL, 0
  101. SUB TileRight (x, y)
  102.     _PUTIMAGE (x, y), TL, 0, (100, 0)-(0, 100)
  103. SUB TileUp (x, y)
  104.     _PUTIMAGE (x, y), TU, 0
  105. SUB TileDown (x, y)
  106.     _PUTIMAGE (x, y), TU, 0, (0, 100)-(100, 0)
  107.  
  108. SUB makeTileImageLeft ()
  109.     s2 = 50 * SQR(2) + .51
  110.     TL = _NEWIMAGE(100, 100, 32)
  111.     _DEST TL
  112.     FOR x = 10 TO 130 STEP 20
  113.         x1 = x + s2 * COS(_PI(3 / 4))
  114.         y1 = s2 * SIN(_PI(3 / 4))
  115.         x2 = x + s2 * COS(_PI(5 / 4))
  116.         y2 = 100 + s2 * SIN(_PI(5 / 4))
  117.         LINE (x, 0)-(x1, y1)
  118.         LINE (x, 100)-(x2, y2)
  119.     NEXT
  120.     'LINE (0, 0)-STEP(99, 99), , B
  121.     _DEST 0
  122.  
  123. SUB makeTileImageUp ()
  124.     s2 = 50 * SQR(2) + .51
  125.     TU = _NEWIMAGE(100, 100, 32)
  126.     _DEST TU
  127.     FOR y = 10 TO 130 STEP 20
  128.         x1 = s2 * COS(_PI(7 / 4))
  129.         y1 = y + s2 * SIN(_PI(7 / 4))
  130.         x2 = 100 + s2 * COS(_PI(5 / 4))
  131.         y2 = y + s2 * SIN(_PI(5 / 4))
  132.         LINE (0, y)-(x1, y1)
  133.         LINE (100, y)-(x2, y2)
  134.     NEXT
  135.     'LINE (0, 0)-STEP(99, 99), , B
  136.     _DEST 0
  137.  
  138.  
  139.  

Here is design I clicked up today:
 


Couldn't figure out how to get rid of that one pesky pixel hole set. Maybe one last try with Rotozoom...
Title: Re: Labyrinth Tiles
Post by: Pete on January 16, 2021, 10:51:17 am
Is it available in oak or walnut? Reminds me of Parkay floor tiles.

Pete
Title: Re: Labyrinth Tiles
Post by: FellippeHeitor on January 16, 2021, 10:52:59 am
Neat! Kind of like:

Quote from: Commodore 64
10 PRINT CHR$(205.5+RND(1)); : GOTO 10

For the old Commodore.

 
Title: Re: Labyrinth Tiles
Post by: Pete on January 16, 2021, 11:11:13 am
Is that available in 64 and 128? Oh well, lucky for me, I was an Atari guy. We just had plain old black screens. You know... like SCREEN Zero. The way God intended it.

Pete

Title: Re: Labyrinth Tiles
Post by: bplus on January 16, 2021, 11:23:57 am
Is it available in oak or walnut? Reminds me of Parkay floor tiles.

Pete

Actually it was Old Moses Chess board that had me thinking about tiles. :)

I started thinking about mazes that might turn after a player passes so there is no going back.

Yeah @FellippeHeitor  I remember that! Alas, these tiles don't make very good mazes.

Too bad Rotozoom can not translate a straight line! it has the gaps between tiles more than filled:
Code: QB64: [Select]
  1. _TITLE "Labyrinth Tile, spacebar for random tiling escape for Tile Design" 'b+ 2021-01-15
  2.  
  3. CONST Xmax = 700, Ymax = 700
  4. SCREEN _NEWIMAGE(Xmax, Ymax, 32)
  5. _DELAY .25
  6.  
  7.  
  8. makeTileImageUp
  9.  
  10.     CLS
  11.     FOR y = 0 TO Ymax STEP 100
  12.         FOR x = 0 TO Xmax STEP 100
  13.             r = RND
  14.             IF r < .25 THEN
  15.                 TileLeft x, y
  16.             ELSEIF r < .5 THEN
  17.                 TileDown x, y
  18.             ELSEIF r < .75 THEN
  19.                 TileRight x, y
  20.             ELSE
  21.                 TileUp x, y
  22.             END IF
  23.         NEXT
  24.     NEXT
  25.     _DISPLAY
  26.     SLEEP
  27.  
  28. ' can we make some designs?
  29. _TITLE "Labyrinth Tile, a Tile Design, Spacebar to Click your own Design"
  30. FOR y = 0 TO 7
  31.     FOR x = 0 TO 7
  32.         IF y MOD 4 = 0 OR y MOD 4 = 2 THEN
  33.             IF x MOD 4 = 0 OR x MOD 4 = 2 THEN
  34.                 TileLeft x * 100, y * 100
  35.             ELSEIF x MOD 4 = 1 OR x MOD 4 = 3 THEN
  36.                 TileRight x * 100, y * 100
  37.             END IF
  38.         ELSEIF y MOD 4 = 1 THEN
  39.             IF x MOD 4 = 0 THEN
  40.                 TileDown x * 100, y * 100
  41.             ELSEIF x MOD 4 = 2 THEN
  42.                 TileUp x * 100, y * 100
  43.             ELSEIF x MOD 4 = 1 THEN
  44.                 TileDown x * 100, y * 100
  45.             ELSEIF x MOD 4 = 3 THEN
  46.                 TileUp x * 100, y * 100
  47.             END IF
  48.         ELSEIF y MOD 4 = 3 THEN
  49.             IF x MOD 4 = 0 THEN
  50.                 TileUp x * 100, y * 100
  51.             ELSEIF x MOD 4 = 2 THEN
  52.                 TileDown x * 100, y * 100
  53.             ELSEIF x MOD 4 = 1 THEN
  54.                 TileUp x * 100, y * 100
  55.             ELSEIF x MOD 4 = 3 THEN
  56.                 TileDown x * 100, y * 100
  57.             END IF
  58.         END IF
  59.     NEXT
  60.  
  61.  
  62. _TITLE "Labyrinth Tile, Click tile to turn it, escape to quit..."
  63. REDIM t(7, 7) AS LONG
  64. FOR y = 0 TO 7
  65.     FOR x = 0 TO 7
  66.         t(x, y) = INT(RND * 4)
  67.     NEXT
  68.     CLS
  69.     FOR y = 0 TO 7
  70.         FOR x = 0 TO 7
  71.             SELECT CASE t(x, y)
  72.                 CASE 0: TileRight x * 100, y * 100
  73.                 CASE 1: TileDown x * 100, y * 100
  74.                 CASE 2: TileLeft x * 100, y * 100
  75.                 CASE 3: TileUp x * 100, y * 100
  76.             END SELECT
  77.         NEXT
  78.     NEXT
  79.     mb = _MOUSEBUTTON(1): mx = INT(_MOUSEX / 100): my = INT(_MOUSEY / 100)
  80.     LINE (mx * 100, my * 100)-STEP(100, 100), , B
  81.     IF mb THEN
  82.         IF mx >= 0 AND mx <= 7 AND my >= 0 AND my <= 7 THEN
  83.             t(mx, my) = (t(mx, my) + 1) MOD 4
  84.             PRINT mx, my
  85.             _DELAY .25
  86.         END IF
  87.     END IF
  88.     _DISPLAY
  89.     _LIMIT 100
  90.  
  91.  
  92. SUB TileLeft (x, y)
  93.     RotoZoom x + 50, y + 50, TU, 1, 270
  94. SUB TileRight (x, y)
  95.     RotoZoom x + 50, y + 50, TU, 1, 90
  96. SUB TileUp (x, y)
  97.     RotoZoom x + 50, y + 50, TU, 1, 0
  98. SUB TileDown (x, y)
  99.     RotoZoom x + 50, y + 50, TU, 1, 180
  100.  
  101. SUB makeTileImageUp ()
  102.     s2 = 50 * SQR(2)
  103.     TU = _NEWIMAGE(100, 100, 32)
  104.     _DEST TU
  105.     FOR y = 10 TO 130 STEP 20
  106.         x1 = s2 * COS(_PI(7 / 4))
  107.         y1 = y + s2 * SIN(_PI(7 / 4))
  108.         x2 = 100 + s2 * COS(_PI(5 / 4))
  109.         y2 = y + s2 * SIN(_PI(5 / 4))
  110.         LINE (0, y)-(x1, y1)
  111.         LINE (99, y)-(x2, y2)
  112.     NEXT
  113.     'LINE (0, 0)-STEP(99, 99), , B
  114.     _DEST 0
  115.  
  116. SUB RotoZoom (X AS LONG, Y AS LONG, Image AS LONG, Scale AS SINGLE, degreesRotation AS SINGLE)
  117.     DIM px(3) AS SINGLE, py(3) AS SINGLE, W&, H&, sinr!, cosr!, i&, x2&, y2&
  118.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  119.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  120.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  121.     sinr! = SIN(-degreesRotation / 57.2957795131): cosr! = COS(-degreesRotation / 57.2957795131)
  122.     FOR i& = 0 TO 3
  123.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  124.         px(i&) = x2&: py(i&) = y2&
  125.     NEXT
  126.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  127.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  128.  
  129.  
Title: Re: Labyrinth Tiles
Post by: Richard Frost on January 16, 2021, 02:49:47 pm
TILE: Totally Insane Line Excursions

Code: QB64: [Select]
  1. _TITLE "Truchet Tiling, SciAm Jul89 pg 111"
  2. DEFINT A-Z
  3. DIM a(1000)
  4. s = 18: xm = 800 / s: ym = 600 / s: z = (800 - ((xm - 2) * s)) / 2
  5. SCREEN _NEWIMAGE(800, 600, 12)
  6. FOR i = 0 TO 1 '             create tiles (just 2)
  7.     FOR j = 0 TO 1
  8.         FOR a = 0 TO 90
  9.             r! = _D2R(a + j * 180)
  10.             FOR q = -1 TO 1
  11.                 x = j * s + ((s \ 2) + q) * COS(r!)
  12.                 y = j * s + ((s \ 2) + q) * SIN(r!)
  13.                 IF i THEN y = s - y
  14.                 PSET (x, y), 1
  15.             NEXT q
  16.         NEXT a
  17.     NEXT j
  18.     GET (0, 0)-(s, s), a(i * 500)
  19.     CLS
  20.  
  21. DO: _LIMIT 2 '               display tiles
  22.     FOR i = 0 TO xm - 3
  23.         FOR j = 0 TO ym - 3
  24.             xs = i * s + z
  25.             ys = j * s + z
  26.             PUT (xs, ys), a(INT(RND * 2) * 500), PSET
  27.         NEXT j
  28.     NEXT i
  29.     LINE (z, z)-((xm - 2) * s + z, (ym - 2) * s + z), 1, B
  30.     _DISPLAY
Title: Re: Labyrinth Tiles
Post by: bplus on January 16, 2021, 03:57:38 pm
Yeah for 2 Tiler System!

Code: QB64: [Select]
  1. _TITLE "2 Tiler press any for next, esc to quit" 'b+ 2021-01-16
  2.  
  3. CONST Xmax = 700, Ymax = 700, s = 10, sd2 = 5
  4. SCREEN _NEWIMAGE(Xmax, Ymax, 32)
  5. _DELAY .25
  6.     CLS
  7.     FOR y = 0 TO Ymax STEP s
  8.         FOR x = 0 TO Xmax STEP s
  9.             IF RND < .5 THEN t1 x, y ELSE t2 x, y
  10.         NEXT
  11.     NEXT
  12.     FOR x = 1 TO 100
  13.         PAINT (RND * Xmax, RND * Ymax), _RGB32(RND * 255, RND * 255, RND * 254), &HFFFFFFFF
  14.         _LIMIT 30
  15.     NEXT
  16.     ' _DISPLAY
  17.     SLEEP
  18.  
  19. SUB t1 (x, y)
  20.     LINE (x + sd2, y)-(x, y + sd2)
  21.     LINE (x + s, y + sd2)-(x + sd2, y + s)
  22.  
  23. SUB t2 (x, y)
  24.     LINE (x + sd2, y)-(x + s, y + sd2)
  25.     LINE (x, y + sd2)-(x + sd2, y + s)
  26.  
  27.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Labyrinth Tiles
Post by: Richard Frost on January 16, 2021, 08:17:16 pm
What a gem - endless beauty from 26 lines of code, 25 since
the _DELAY should not be required.  I likes de foist one too.
Title: Re: Labyrinth Tiles
Post by: johannhowitzer on January 17, 2021, 07:51:33 am
Got inspired, so I pared this down to 16 lines, 15 if you don't care about the constants and just put their values in-line.  STEP is used to turn the two SUBs into three lines of code... r is set to 1 or -1, and then that's used to flip the result of the STEPs horizontally.  Thanks bplus!  That was really fun.

Code: QB64: [Select]
  1. const w = 700, s = 5
  2. screen _newimage(w, w, 32)
  3.    cls
  4.    for y = 0 to w step s * 2
  5.       for x = 0 to w step s * 2
  6.          r = ((int(rnd * 2)) * 2) - 1
  7.          line(x + s, y)-step(s * r, s)
  8.          line(x + s, y + (s * 2))-step(-s * r, -s)
  9.       next
  10.    next
  11.    for x = 1 to 100
  12.       paint(rnd * w, rnd * w), _rgb32(rnd * 255, rnd * 255, rnd * 254), &HFFFFFFFF
  13.    next
  14.    sleep
Title: Re: Labyrinth Tiles
Post by: bplus on January 17, 2021, 11:04:19 am
Thanks Richard Frost, I am delighted we enjoy simple things.

Nice @johannhowitzer, 2 tile Subs down to 2 lines!
Title: Re: Labyrinth Tiles
Post by: bplus on January 17, 2021, 07:11:36 pm
Take a walk amongst the tiles with keypad, diagonals burn bridges, up, down left right jumps corners and spacebar reverses all your neighbors! Just follow the yellow brick road!

Code: QB64: [Select]
  1. _TITLE "Walk amongst the 2 Tilers: USE KEYPAD  Diagonal keys 7,9,3,1 burns bridges, 8,6,2,4 jumps corners, spacebar reverses neighbors" 'b+ 2021-01-17
  2. CONST Xmax = 1000, Ymax = 700, S = 20, Sd2 = S \ 2, Xcells = Xmax \ S, Ycells = Ymax \ S
  3. SCREEN _NEWIMAGE(Xmax, Ymax, 32): _DELAY .25: _SCREENMOVE _MIDDLE
  4. REDIM TS(Xcells, Ycells) AS LONG
  5. FOR y = 0 TO Ycells
  6.     FOR x = 0 TO Xcells
  7.         TS(x, y) = INT(RND * 2)
  8.     NEXT
  9. bx = Xcells \ 2: by = Ycells \ 2
  10.     CLS
  11.     FOR y = 0 TO Ycells
  12.         FOR x = 0 TO Xcells
  13.             IF TS(x, y) THEN t1 x * S, y * S ELSE t2 x * S, y * S
  14.         NEXT
  15.     NEXT
  16.     drawBplusPath bx, by
  17.     numLock = _KEYDOWN(100300)
  18.     KH& = _KEYHIT
  19.  
  20.     ' go diagonally if the target block is same as current                    and burn bridges as you go!
  21.     IF KH& = 18176 OR (numLock AND (KH& = 55)) THEN 'up, left number 7
  22.         IF bx - 1 >= 0 AND by - 1 >= 0 THEN
  23.             IF TS(bx, by) = TS(bx - 1, by - 1) THEN
  24.                 TS(bx, by) = (TS(bx, by) + 1) MOD 2
  25.                 bx = bx - 1: by = by - 1
  26.             END IF
  27.         END IF
  28.     ELSEIF KH& = 18688 OR (numLock AND (KH& = 57)) THEN ' up, right   number 9
  29.         IF bx + 1 < Xcells AND by - 1 >= 0 THEN
  30.             IF TS(bx, by) = TS(bx + 1, by - 1) THEN
  31.                 TS(bx, by) = (TS(bx, by) + 1) MOD 2
  32.                 bx = bx + 1: by = by - 1
  33.             END IF
  34.         END IF
  35.     ELSEIF KH& = 20736 OR (numLock AND (KH& = 51)) THEN ' down right number 3
  36.         IF bx + 1 < Xcells AND by + 1 < Ycells THEN
  37.             IF TS(bx, by) = TS(bx + 1, by + 1) THEN
  38.                 TS(bx, by) = (TS(bx, by) + 1) MOD 2
  39.                 bx = bx + 1: by = by + 1
  40.             END IF
  41.         END IF
  42.     ELSEIF KH& = 20224 OR (numLock AND (KH& = 49)) THEN ' down left number 1
  43.         IF bx - 1 >= 0 AND by + 1 < Ycells THEN
  44.             IF TS(bx, by) = TS(bx - 1, by + 1) THEN
  45.                 TS(bx, by) = (TS(bx, by) + 1) MOD 2
  46.                 bx = bx - 1: by = by + 1
  47.             END IF
  48.         END IF
  49.  
  50.         '                          ' go up down left right for cornering
  51.     ELSEIF KH& = 18432 OR (numLock AND (KH& = 56)) THEN 'up
  52.         IF by - 1 >= 0 THEN
  53.             IF TS(bx, by) <> TS(bx, by - 1) THEN
  54.                 by = by - 1
  55.             END IF
  56.         END IF
  57.     ELSEIF KH& = 19712 OR (numLock AND (KH& = 54)) THEN 'right
  58.         IF bx + 1 < Xcells THEN
  59.             IF TS(bx, by) <> TS(bx + 1, by) THEN
  60.                 bx = bx + 1
  61.             END IF
  62.         END IF
  63.     ELSEIF KH& = 20480 OR (numLock AND (KH& = 50)) THEN 'down
  64.         IF by + 1 < Ycells THEN
  65.             IF TS(bx, by) <> TS(bx, by + 1) THEN
  66.                 by = by + 1
  67.             END IF
  68.         END IF
  69.  
  70.     ELSEIF KH& = 19200 OR (numLock AND (KH& = 52)) THEN 'left
  71.         IF bx - 1 >= 0 THEN
  72.             IF TS(bx, by) <> TS(bx - 1, by) THEN
  73.                 bx = bx - 1
  74.             END IF
  75.         END IF
  76.     ELSEIF KH& = 32 THEN 'space bar, reverse your neighbors!
  77.         FOR y = -1 TO 1
  78.             FOR x = -1 TO 1
  79.                 IF bx + x >= 0 AND bx + x < Xcells THEN
  80.                     IF by + y >= 0 AND by + y < Ycells THEN
  81.                         IF NOT (x = 0 AND y = 0) THEN
  82.                             TS(bx + x, by + y) = (TS(bx + x, by + y) + 1) MOD 2
  83.                         END IF
  84.                     END IF
  85.                 END IF
  86.             NEXT
  87.         NEXT
  88.     END IF
  89.     _DISPLAY
  90.     _LIMIT 30
  91.  
  92.  
  93. SUB t1 (x, y)
  94.     LINE (x + Sd2, y)-(x, y + Sd2), &HFF006600
  95.     LINE (x + S, y + Sd2)-(x + Sd2, y + S), &HFF006600
  96.     'LINE (x, y)-STEP(S, S), &HFFFFFFFF, B
  97.  
  98. SUB t2 (x, y)
  99.     LINE (x + Sd2, y)-(x + S, y + Sd2), &HFF006600
  100.     LINE (x, y + Sd2)-(x + Sd2, y + S), &HFF006600
  101.     'LINE (x, y)-STEP(S, S), &HFFFFFFFF, B
  102.  
  103. SUB drawBplusPath (x, y)
  104.     'CIRCLE (x * S + Sd2, y * S + Sd2), 2, &HFF006600
  105.     PAINT (x * S + Sd2, y * S + Sd2), &HFFFFFF00, &HFF006600
  106.     FOR r = 0 TO 6 STEP .25
  107.         CIRCLE (x * S + Sd2, y * S + Sd2), r, &HFF0000FF
  108.     NEXT
  109.     COLOR , &H00000000
  110.     _PRINTSTRING (x * S + Sd2 - 4, y * S + Sd2 - 7), "B"
  111.     COLOR , &HFF000000
  112.  
  113.  
  114.  

 






Title: Re: Labyrinth Tiles
Post by: johannhowitzer on January 18, 2021, 03:15:05 am
Thanks Richard Frost, I am delighted we enjoy simple things.

Nice @johannhowitzer, 2 tile Subs down to 2 lines!
[ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 19, 2021, 11:02:43 pm
A variation with 2 lines of code.

How it works I don't know

working on a horizontal code so objects can move around the grid with arrow keys

Code: QB64: [Select]
  1. s = 5
  2. w = 700
  3.  
  4. SCREEN _NEWIMAGE(w, w, 32)
  5.  
  6.  
  7.     CLS
  8.     IF INKEY$ = CHR$(27) THEN END
  9.     FOR y = 0 TO w STEP s * 2
  10.  
  11.         FOR x = 0 TO w STEP s * 2
  12.  
  13.             r = ((INT(RND * 2)) * 2) - 1 'returns  -1, 1
  14.  
  15.             LINE (x - s * r, y)-(x, y + s)
  16.             LINE (x + s * r, y)-(x, y - s)
  17.  
  18.         NEXT x
  19.  
  20.     NEXT y
  21.     SLEEP
  22.  
Title: Re: C Tiles
Post by: NOVARSEG on January 22, 2021, 10:34:09 pm
It is hard to explain how the code generates the labyrinth.

This code will show how the diagonal labyrinth is generated.

press space bar to see how it works.

It should be possible to generate a vertical/horizontal labyrinth in the same way. 

Code: QB64: [Select]
  1. s = 5
  2. w = 1024
  3. h = 768
  4.  
  5. SCREEN _NEWIMAGE(w, h, 32)
  6.  
  7.  
  8.     CLS
  9.     'IF INKEY$ = CHR$(27) THEN END
  10.     FOR y = 10 TO h STEP s * 2
  11.  
  12.         FOR x = 0 TO w STEP s * 2
  13.  
  14.             r = ((INT(RND * 2)) * 2) - 1 'returns  -1, 1
  15.  
  16.             LINE (x - s * r, y)-(x, y + s)
  17.             LINE (x + s * r, y)-(x, y - s)
  18.             DO
  19.                 I$ = INKEY$
  20.                 IF I$ = CHR$(27) THEN END
  21.                 IF I$ = CHR$(32) THEN EXIT DO
  22.             LOOP
  23.  
  24.         NEXT x
  25.  
  26.     NEXT y
  27.     SLEEP
  28.  
  29.  

Shows nice diagonal boxes if alternate 1, -1 are fed into the code

This gives an idea of how to generate a grid of horizontal / vertical boxes.

Code: QB64: [Select]
  1. s = 5
  2. w = 1024
  3. h = 768
  4. r = 1
  5. SCREEN _NEWIMAGE(w, h, 32)
  6.  
  7.  
  8.     CLS
  9.     'IF INKEY$ = CHR$(27) THEN END
  10.     FOR y = 10 TO h STEP s * 2
  11.  
  12.         FOR x = 0 TO w STEP s * 2
  13.  
  14.             'r = ((INT(RND * 2)) * 2) - 1 'returns  -1, 1
  15.  
  16.             IF r = 1 THEN r = -1: GOTO LL
  17.             IF r = -1 THEN r = 1: GOTO LL
  18.             ' r = 1
  19.  
  20.             LL:
  21.  
  22.             LINE (x - s * r, y)-(x, y + s)
  23.             LINE (x + s * r, y)-(x, y - s)
  24.  
  25.  
  26.             DO
  27.                 I$ = INKEY$
  28.                 IF I$ = CHR$(27) THEN END
  29.                 IF I$ = CHR$(32) THEN EXIT DO
  30.             LOOP
  31.  
  32.         NEXT x
  33.  
  34.     NEXT y
  35.     SLEEP
  36.  
  37.  

Title: Re: Labyrinth Tiles
Post by: bplus on January 23, 2021, 10:57:55 am
Quote
This gives an idea of how to generate a grid of horizontal / vertical boxes.

Here is another way to see how 2 simple lines on 2 different tiles can make the "maze" by drawing the tile outlines.
Code: QB64: [Select]
  1. CONST w = 700, s = 20
  2. SCREEN _NEWIMAGE(w, w, 32)
  3.  
  4. FOR y = 0 TO w STEP s * 2
  5.     FOR x = 0 TO w STEP s * 2
  6.         r = ((INT(RND * 2)) * 2) - 1
  7.         LINE (x + s, y)-STEP(s * r, s)
  8.         LINE (x + s, y + (s * 2))-STEP(-s * r, -s)
  9.         LINE (x, y)-STEP(2 * s, 2 * s), , B
  10.     NEXT
  11.  

I did this to figure out how to move inside the "maze" with "arrow keys" on number pad
https://www.qb64.org/forum/index.php?topic=3498.msg128347#msg128347
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 23, 2021, 11:19:52 pm
@bplus


Your square outlines show a pattern .   Was thinking on how to get the maze itself to be up, down, left, right  instead of diagonal. If the squares could be rotated by 45 degrees then the pattern could be applied and the result should be a 45 degree rotated maze. 

Your program shows  that 1, -1   encodes the diagonal components in the squares.

Thanks for the solution to the problem . I'm sure it is doable now

Title: Re: Labyrinth Tiles
Post by: bplus on January 24, 2021, 12:03:04 am
@bplus


Your square outlines show a pattern .   Was thinking on how to get the maze itself to be up, down, left, right  instead of diagonal. If the squares could be rotated by 45 degrees then the pattern could be applied and the result should be a 45 degree rotated maze. 

Your program shows  that 1, -1   encodes the diagonal components in the squares.

Thanks for the solution to the problem . I'm sure it is doable now

I thought it was 0 and -1 but I am using Johann's code :)

Here is the maze turned 45 degrees with the help of some line drawing reinforcement and Rotozoom
Code: QB64: [Select]
  1. CONST sw = 700, s = 10
  2. SCREEN _NEWIMAGE(sw, sw, 32)
  3. _DELAY .25
  4. maze = _NEWIMAGE(sw, sw, 32)
  5. FOR y = 0 TO sw STEP s * 2
  6.     FOR x = 0 TO sw STEP s * 2
  7.         r = ((INT(RND * 2)) * 2) - 1
  8.         LINE (x + s, y)-STEP(s * r, s)
  9.         LINE (x + s + 1, y)-STEP(s * r, s)
  10.         LINE (x + s, y + 1)-STEP(s * r, s)
  11.  
  12.         LINE (x + s, y + (s * 2))-STEP(-s * r, -s)
  13.         LINE (x + s + 1, y + (s * 2))-STEP(-s * r, -s)
  14.         LINE (x + s, y + (s * 2) + 1)-STEP(-s * r, -s)
  15.         'LINE (x, y)-STEP(2 * s, 2 * s), , B
  16.     NEXT
  17. _PUTIMAGE , 0, maze
  18. RotoZoom sw / 2, sw / 2, maze, 1.5, 45
  19.  
  20. SUB RotoZoom (X AS LONG, Y AS LONG, Image AS LONG, Scale AS SINGLE, degreesRotation AS SINGLE)
  21.     DIM px(3) AS SINGLE, py(3) AS SINGLE, W&, H&, sinr!, cosr!, i&, x2&, y2&
  22.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  23.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  24.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  25.     sinr! = SIN(-degreesRotation / 57.2957795131): cosr! = COS(-degreesRotation / 57.2957795131)
  26.     FOR i& = 0 TO 3
  27.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  28.         px(i&) = x2&: py(i&) = y2&
  29.     NEXT
  30.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  31.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  32.  
  33.  

 

Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 24, 2021, 12:26:54 am
@bplus

That looks good.
I'm working on something similar might take a couple days

ROTOZOOM  gotta check that out


Thanks
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 24, 2021, 09:47:24 pm
Here is labyrinth with horizontal / vertical layout.  Moving around the maze with arrow keys will be easier now.

I think the code can be condensed even more. 

Code: QB64: [Select]
  1. CONST w = 700, s = 5
  2. SCREEN _NEWIMAGE(w, w, 32)
  3.  
  4. FOR y = 0 TO w STEP s * 4
  5.  
  6.     FOR x = 0 TO w STEP s * 4
  7.  
  8.         r = ((INT(RND * 2)) * 2) - 1
  9.  
  10.         IF r = -1 THEN
  11.             LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  12.             LINE (x - s, y - s)-(x + s, y - s) 'top line
  13.         END IF
  14.         IF r = 1 THEN
  15.             LINE (x - s, y - s)-(x - s, y + s) 'left line
  16.             LINE (x + s, y - s)-(x + s, y + s) 'right line
  17.         END IF
  18.  
  19.         x = x + 10
  20.         y = y + 10
  21.  
  22.         r = ((INT(RND * 2)) * 2) - 1
  23.  
  24.         IF r = -1 THEN
  25.             LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  26.             LINE (x - s, y - s)-(x + s, y - s) 'top line
  27.         END IF
  28.         IF r = 1 THEN
  29.             LINE (x - s, y - s)-(x - s, y + s) 'left line
  30.             LINE (x + s, y - s)-(x + s, y + s) 'right line
  31.         END IF
  32.  
  33.         x = x - 10
  34.         y = y - 10
  35.  
  36.     NEXT
  37.  
  38.  
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 25, 2021, 01:40:52 am
More features

Code: QB64: [Select]
  1. s = 5
  2. h = 768
  3. w = 1024
  4. SCREEN _NEWIMAGE(w, h, 32)
  5. t = .5
  6.  
  7.  
  8. PRINT "Press z or x to change maze"
  9.  
  10. PRINT "ESC to exit"
  11.     i$ = INKEY$
  12.     IF i$ = CHR$(27) THEN END
  13.     IF i$ <> "" THEN EXIT DO
  14.  
  15.  
  16.     CLS
  17.  
  18.     FOR y = 0 TO h STEP s * 4
  19.  
  20.         FOR x = 0 TO w STEP s * 4
  21.  
  22.             r = RND
  23.  
  24.             IF r <= t THEN
  25.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  26.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  27.             END IF
  28.             IF r > t THEN
  29.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  30.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  31.             END IF
  32.  
  33.             x = x + 10
  34.             y = y + 10
  35.  
  36.             r = RND
  37.  
  38.             IF r <= t THEN
  39.  
  40.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  41.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  42.             END IF
  43.             IF r > t THEN
  44.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  45.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  46.             END IF
  47.  
  48.             x = x - 10
  49.             y = y - 10
  50.  
  51.         NEXT
  52.  
  53.     NEXT
  54.     DO
  55.         i$ = INKEY$
  56.         IF i$ = "z" AND t < 1 THEN t = t + .005: EXIT DO
  57.         IF i$ = "x" AND t > 0 THEN t = t - .005: EXIT DO
  58.         IF i$ = CHR$(27) THEN END
  59.     LOOP
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 25, 2021, 01:59:01 am
Yet more features

Code: QB64: [Select]
  1. s = 10
  2. h = 768
  3. w = 1024
  4. SCREEN _NEWIMAGE(w, h, 32)
  5. t = .5
  6.  
  7.  
  8. PRINT "Press z or x to alter row / column appearance"
  9. PRINT "Press c or v to adjust grid size"
  10. PRINT "ESC to exit"
  11.     i$ = INKEY$
  12.     IF i$ = CHR$(27) THEN END
  13.     IF i$ <> "" THEN EXIT DO
  14.  
  15.  
  16.     CLS
  17.  
  18.     FOR y = 0 TO h STEP s * 4
  19.  
  20.         FOR x = 0 TO w STEP s * 4
  21.  
  22.             r = RND
  23.  
  24.             IF r <= t THEN
  25.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  26.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  27.             END IF
  28.             IF r > t THEN
  29.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  30.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  31.             END IF
  32.  
  33.             x = x + s * 2
  34.             y = y + s * 2
  35.  
  36.             r = RND
  37.  
  38.             IF r <= t THEN
  39.  
  40.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  41.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  42.             END IF
  43.             IF r > t THEN
  44.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  45.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  46.             END IF
  47.  
  48.             x = x - s * 2
  49.             y = y - s * 2
  50.  
  51.         NEXT
  52.  
  53.     NEXT
  54.     DO
  55.         i$ = INKEY$
  56.         IF i$ = "z" AND t < 1 THEN t = t + .005: EXIT DO
  57.         IF i$ = "x" AND t > 0 THEN t = t - .005: EXIT DO
  58.         IF i$ = "c" AND s > 1 THEN s = s - 1: EXIT DO
  59.         IF i$ = "v" AND s < 41 THEN s = s + 1: EXIT DO
  60.         IF i$ = CHR$(27) THEN END
  61.         IF i$ = CHR$(32) THEN EXIT DO
  62.     LOOP
Title: Re: Labyrinth Tiles
Post by: bplus on January 25, 2021, 02:56:17 am
@NOVARSEG

You figured it out! I spent a good part of the day trying to do vertical and horizontal with just drawing. Nice work!

Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 25, 2021, 03:57:57 am
@bplus

You already solved it .   I drew a grid on a piece of paper and figured out the measurements that way.   

It took a few hours. It required making  a checker board pattern, which was tricky.
I can post some details of that later.

Thanks to everyone on this thread.



Title: Re: Labyrinth Tiles
Post by: bplus on January 25, 2021, 12:19:38 pm
Quote
You already solved it .

Not really, I didn't figure out how to draw vertical and horizontal walls without Rotozoom.

I think that is needed to use arrow keys to walk around the tiles because you need to save each cell's random choice.

Eh, if push comes to shove you can arrow around tiles using POINT for collision detection with walls. I don't like collision detection by that method and would prefer going by maze cells content but I am beginning to suspect each pair of walls is actually walls for 3 cells.
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 25, 2021, 07:00:42 pm
Moving around the tiles like a pac man game?



Here is some code that shows the actual x, y positions (small cross hairs) on which everything is measured from.

Maybe that will help the navigation problem.

Code: QB64: [Select]
  1. s = 10
  2. h = 768
  3. w = 1024
  4. SCREEN _NEWIMAGE(w, h, 32)
  5. t = .5
  6.  
  7.  
  8. PRINT "Press z or x to alter row / column appearance"
  9. PRINT "Press c or v to adjust grid size"
  10.  
  11. PRINT "ESC to exit"
  12.     i$ = INKEY$
  13.     IF i$ = CHR$(27) THEN END
  14.     IF i$ <> "" THEN EXIT DO
  15.  
  16.  
  17.     CLS
  18.  
  19.     FOR y = 0 TO h STEP s * 4
  20.  
  21.         FOR x = 0 TO w STEP s * 4
  22.  
  23.             r = RND
  24.  
  25.             IF r <= t THEN
  26.                 LINE (x - 1, y)-(x + 1, y)
  27.                 LINE (x, y - 1)-(x, y + 1)
  28.  
  29.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  30.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  31.             END IF
  32.             IF r > t THEN
  33.                 LINE (x - 1, y)-(x + 1, y)
  34.                 LINE (x, y - 1)-(x, y + 1)
  35.  
  36.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  37.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  38.             END IF
  39.  
  40.             x = x + s * 2
  41.             y = y + s * 2
  42.  
  43.             r = RND
  44.  
  45.             IF r <= t THEN
  46.                 LINE (x - 1, y)-(x + 1, y)
  47.                 LINE (x, y - 1)-(x, y + 1)
  48.  
  49.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  50.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  51.             END IF
  52.             IF r > t THEN
  53.                 LINE (x - 1, y)-(x + 1, y)
  54.                 LINE (x, y - 1)-(x, y + 1)
  55.  
  56.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  57.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  58.             END IF
  59.  
  60.             x = x - s * 2
  61.             y = y - s * 2
  62.  
  63.         NEXT
  64.  
  65.     NEXT
  66.     DO
  67.         IF _MOUSEINPUT = -1 THEN
  68.             IF _MOUSEBUTTON(1) = -1 THEN PAINT (_MOUSEX, _MOUSEY), _RGB(255, 0, 0), &HFFFFFFFF
  69.         END IF
  70.  
  71.  
  72.         i$ = INKEY$
  73.         IF i$ = "z" AND t < 1 THEN t = t + .005: EXIT DO
  74.         IF i$ = "x" AND t > 0 THEN t = t - .005: EXIT DO
  75.         IF i$ = "c" AND s > 1 THEN s = s - 1: EXIT DO
  76.         IF i$ = "v" AND s < 41 THEN s = s + 1: EXIT DO
  77.         IF i$ = CHR$(27) THEN END
  78.         IF i$ = CHR$(32) THEN EXIT DO
  79.     LOOP
  80.  
Title: Re: Labyrinth Tiles
Post by: bplus on January 25, 2021, 07:18:34 pm
@NOVARSEG 

Yeah moving around inside the maze, with only arrows keys, unless walled in. The we apply special elixir to reverse a wall pair from over under to left and right or vice versa ;-))

Yeah marking cell centers might help :)
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 25, 2021, 07:32:03 pm
@bplus


The x, y positions are always in mid travel.   Detect a wall and reverse a wall pair - yep.  That will allow travel through where the wall once was.



Title: Re: Labyrinth Tiles
Post by: bplus on January 25, 2021, 07:51:13 pm
@NOVARSEG I love the mouse painter so much I gave the right button another color!

I moved your instructions to title bar and made them more clear (IMHO) and colored the 2 different cell centers yellow and blue, that was what I couldn't figure out yesterday, nice and clear now... oh pretty colors! ;-))

Code: QB64: [Select]
  1. ' b+ mod NOVARSEG code for 2 tiler 2021-01-25
  2. s = 10
  3. h = 700
  4. w = 1024
  5. SCREEN _NEWIMAGE(w, h, 32)
  6. _DELAY .25
  7. '_FULLSCREEN
  8. t = .5
  9.  
  10. _TITLE "Press z increase over/under,  x increase left/right, c makes smaller cells, v bigger, esc to quit, left mouse paints red, right blue"
  11.  
  12.  
  13.     CLS
  14.  
  15.     FOR y = 0 TO h STEP s * 4
  16.  
  17.         FOR x = 0 TO w STEP s * 4
  18.  
  19.             r = RND
  20.             CIRCLE (x, y), 2, &HFFFFFF00
  21.             IF r <= t THEN
  22.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  23.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  24.             END IF
  25.             IF r > t THEN
  26.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  27.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  28.             END IF
  29.  
  30.             x = x + s * 2
  31.             y = y + s * 2
  32.             CIRCLE (x, y), 2, &HFF0000FF
  33.             r = RND
  34.  
  35.             IF r <= t THEN
  36.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  37.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  38.             END IF
  39.             IF r > t THEN
  40.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  41.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  42.             END IF
  43.  
  44.             x = x - s * 2
  45.             y = y - s * 2
  46.  
  47.         NEXT
  48.  
  49.     NEXT
  50.     DO
  51.         IF _MOUSEINPUT = -1 THEN
  52.             IF _MOUSEBUTTON(1) = -1 THEN PAINT (_MOUSEX, _MOUSEY), _RGB(255, 0, 0), &HFFFFFFFF
  53.             IF _MOUSEBUTTON(2) = -1 THEN PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 255), &HFFFFFFFF
  54.         END IF
  55.  
  56.  
  57.         i$ = INKEY$
  58.         IF i$ = "z" AND t < 1 THEN t = t + .005: EXIT DO
  59.         IF i$ = "x" AND t > 0 THEN t = t - .005: EXIT DO
  60.         IF i$ = "c" AND s > 1 THEN s = s - 1: EXIT DO
  61.         IF i$ = "v" AND s < 41 THEN s = s + 1: EXIT DO
  62.         IF i$ = CHR$(27) THEN END
  63.         IF i$ = CHR$(32) THEN EXIT DO
  64.     LOOP
  65.  
  66.  
  67.  

Title: Re: Labyrinth Tiles
Post by: bplus on January 25, 2021, 07:54:09 pm
Now all we need is an idea to make a game with the different colored mazes, cool!
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 25, 2021, 09:46:17 pm
@bplus
hey my nice DIMs are gone waaaa

I like the small circles to mark the x, y positions. can't see blue ones though so they are all the same now
maybe there was a reason for the way it was?

The small circles are only for testing of navigation etc  but they do look nice.

mouse clicks toggle the color from black to color to black etc

Im trying some crude navigation code.  How do you erase a previous CIRCLE from the screen?

As far as "cell centers" go, there are cell centers generated directly from the FOR NEXT  outputs.  The other centers are  "offset" (both in x and y) from the FOR NEXT outputs.  These "offsets"  were the tricky part.  It look like you had the "offset" centers in blue.  That could be useful, will see.

Code: QB64: [Select]
  1. ' b+ mod NOVARSEG code for 2 tiler 2021-01-25
  2. s = 10
  3. h = 700
  4. w = 1024
  5. SCREEN _NEWIMAGE(w, h, 32)
  6. _DELAY .25
  7. '_FULLSCREEN
  8. t = .5
  9.  
  10. _TITLE "Press z increase over/under,  x increase left/right, c makes smaller cells, v bigger, esc to quit, left mouse paints red, right blue"
  11.  
  12.  
  13.     CLS
  14.  
  15.     FOR y = 0 TO h STEP s * 4
  16.  
  17.         FOR x = 0 TO w STEP s * 4
  18.  
  19.             r = RND
  20.             CIRCLE (x, y), 2, &HFFFFFF00
  21.             IF r <= t THEN
  22.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  23.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  24.             END IF
  25.             IF r > t THEN
  26.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  27.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  28.             END IF
  29.  
  30.             x = x + s * 2
  31.             y = y + s * 2
  32.             CIRCLE (x, y), 2, &HFFFFFF00 ' &HFF0000FF
  33.             r = RND
  34.  
  35.             IF r <= t THEN
  36.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  37.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  38.             END IF
  39.             IF r > t THEN
  40.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  41.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  42.             END IF
  43.  
  44.             x = x - s * 2
  45.             y = y - s * 2
  46.  
  47.         NEXT
  48.  
  49.     NEXT
  50.     DO
  51.         IF _MOUSEINPUT = -1 THEN
  52.  
  53.  
  54.             IF _MOUSEBUTTON(1) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(0, 0, 0) THEN
  55.                 PAINT (_MOUSEX, _MOUSEY), _RGB(255, 0, 0), &HFFFFFFFF
  56.                 GOTO L1
  57.             END IF
  58.             IF _MOUSEBUTTON(1) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(255, 0, 0) THEN
  59.                 PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 0), &HFFFFFFFF
  60.             END IF
  61.  
  62.             L1:
  63.  
  64.             IF _MOUSEBUTTON(2) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(0, 0, 0) THEN
  65.                 PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 255), &HFFFFFFFF
  66.                 GOTO L2
  67.             END IF
  68.             IF _MOUSEBUTTON(2) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(0, 0, 255) THEN
  69.                 PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 0), &HFFFFFFFF
  70.             END IF
  71.  
  72.             L2:
  73.  
  74.  
  75.         END IF
  76.  
  77.  
  78.         i$ = INKEY$
  79.         IF i$ = "z" AND t < 1 THEN t = t + .005: EXIT DO
  80.         IF i$ = "x" AND t > 0 THEN t = t - .005: EXIT DO
  81.         IF i$ = "c" AND s > 1 THEN s = s - 1: EXIT DO
  82.         IF i$ = "v" AND s < 41 THEN s = s + 1: EXIT DO
  83.         IF i$ = CHR$(27) THEN END
  84.         IF i$ = CHR$(32) THEN EXIT DO
  85.     LOOP
  86.  


Title: Re: Labyrinth Tiles
Post by: bplus on January 25, 2021, 10:50:27 pm
@bplus
hey my nice DIMs are gone waaaa

I like the small circles to mark the x, y positions. can't see blue ones though so they are all the same now
maybe there was a reason for the way it was?

The small circles are only for testing of navigation etc  but they do look nice.

mouse clicks toggle the color from black to color to black etc

Im trying some crude navigation code.  How do you erase a previous CIRCLE from the screen?

As far as "cell centers" go, there are cell centers generated directly from the FOR NEXT  outputs.  The other centers are  "offset" (both in x and y) from the FOR NEXT outputs.  These "offsets"  were the tricky part.  It look like you had the "offset" centers in blue.  That could be useful, will see.

Code: QB64: [Select]
  1. ' b+ mod NOVARSEG code for 2 tiler 2021-01-25
  2. s = 10
  3. h = 700
  4. w = 1024
  5. SCREEN _NEWIMAGE(w, h, 32)
  6. _DELAY .25
  7. '_FULLSCREEN
  8. t = .5
  9.  
  10. _TITLE "Press z increase over/under,  x increase left/right, c makes smaller cells, v bigger, esc to quit, left mouse paints red, right blue"
  11.  
  12.  
  13.     CLS
  14.  
  15.     FOR y = 0 TO h STEP s * 4
  16.  
  17.         FOR x = 0 TO w STEP s * 4
  18.  
  19.             r = RND
  20.             CIRCLE (x, y), 2, &HFFFFFF00
  21.             IF r <= t THEN
  22.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  23.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  24.             END IF
  25.             IF r > t THEN
  26.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  27.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  28.             END IF
  29.  
  30.             x = x + s * 2
  31.             y = y + s * 2
  32.             CIRCLE (x, y), 2, &HFFFFFF00 ' &HFF0000FF
  33.             r = RND
  34.  
  35.             IF r <= t THEN
  36.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  37.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  38.             END IF
  39.             IF r > t THEN
  40.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  41.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  42.             END IF
  43.  
  44.             x = x - s * 2
  45.             y = y - s * 2
  46.  
  47.         NEXT
  48.  
  49.     NEXT
  50.     DO
  51.         IF _MOUSEINPUT = -1 THEN
  52.  
  53.  
  54.             IF _MOUSEBUTTON(1) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(0, 0, 0) THEN
  55.                 PAINT (_MOUSEX, _MOUSEY), _RGB(255, 0, 0), &HFFFFFFFF
  56.                 GOTO L1
  57.             END IF
  58.             IF _MOUSEBUTTON(1) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(255, 0, 0) THEN
  59.                 PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 0), &HFFFFFFFF
  60.             END IF
  61.  
  62.             L1:
  63.  
  64.             IF _MOUSEBUTTON(2) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(0, 0, 0) THEN
  65.                 PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 255), &HFFFFFFFF
  66.                 GOTO L2
  67.             END IF
  68.             IF _MOUSEBUTTON(2) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(0, 0, 255) THEN
  69.                 PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 0), &HFFFFFFFF
  70.             END IF
  71.  
  72.             L2:
  73.  
  74.  
  75.         END IF
  76.  
  77.  
  78.         i$ = INKEY$
  79.         IF i$ = "z" AND t < 1 THEN t = t + .005: EXIT DO
  80.         IF i$ = "x" AND t > 0 THEN t = t - .005: EXIT DO
  81.         IF i$ = "c" AND s > 1 THEN s = s - 1: EXIT DO
  82.         IF i$ = "v" AND s < 41 THEN s = s + 1: EXIT DO
  83.         IF i$ = CHR$(27) THEN END
  84.         IF i$ = CHR$(32) THEN EXIT DO
  85.     LOOP
  86.  





Quote
I like the small circles to mark the x, y positions. can't see blue ones though so they are all the same now
maybe there was a reason for the way it was?

Yes, it was to distinguish the first set of x, y positions and the second set.

Quote
Im trying some crude navigation code.  How do you erase a previous CIRCLE from the screen?
After I make the map, I'd save the image, then in main loop, I _PUTIMAGE that image back in as background and then draw in the present location of the hero position then I poll for arrow keypresses and update hero position if he doesn't have to run through a wall, and loop... background image, hero drawn, update next position, loop...

Quote
The other centers are  "offset" (both in x and y) from the FOR NEXT outputs.  These "offsets"  were the tricky part.  It look like you had the "offset" centers in blue.  That could be useful, will see.

And we are back to first comment :) that's why one set blue and the other yellow.
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 26, 2021, 12:48:04 am
@bplus

working on navigation.


With the arrow keys,  i'm trying to navigate from center to any other center.  Any turn must be made from yet another center which is in between the centers shown on the screen.  The moving object is another circle or similar which is somewhat larger (maybe a solid) .  The object moves in S * 2 steps left, right, up or down.

To make it more complex the moving object must stay centered for any cell size.

The action of the moving object is s * 2 pixels at a time for any arrow key pressed.  For a game, a smoothly moving object is wanted, but I have not yet figure that out.

Title: Re: Labyrinth Tiles
Post by: bplus on January 26, 2021, 01:52:09 am
Re: Navigation
Looking over the blue and yellow little circles, I notice every place open to turn, you have to be exactly between the colored circles, can't turn when on a colored circle. So I think the arrow keys should move us an s amount not 2 * s and it will certainly be easier to tell in code where walls are by using POINT to check down the line you want to head.

As for reversing walls you have to be standing on a colored circle and you have to work in offsets depending on if you are standing on a blue circle or a yellow.

The blue circles were the offset group:
Code: QB64: [Select]
  1.             x = x + s * 2
  2.             y = y + s * 2
  3.             CIRCLE (x, y), 2, &HFF0000FF
  4.  

yellow set 0 4 8 12  *s    both x and y
   blue set 2, 6, 10   *s

so all the places you can turn are odd numbers *s
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 26, 2021, 09:02:52 pm
@bplus

Quote
Looking over the blue and yellow little circles, I notice every place open to turn, you have to be exactly between the colored circles, can't turn when on a colored circle.

correct.

 
Quote
FOR y = 0 TO h STEP s * 4

        FOR x = 0 TO w STEP s * 4

The step size is S * 4 from color center to color center (no diagonal moves), so S * 2 should land half way between any color center. 
Title: Re: Labyrinth Tiles
Post by: bplus on January 26, 2021, 11:20:29 pm
Quote
so S * 2 should land half way between any color center.

@NOVARSEG confirmed! I just got the up arrow working. The walls to watch out for are only 1 s away +- 1 pixel, so I am using POINT for wall detection. But when you do move it is 2*S.
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 27, 2021, 12:54:03 am
@bplus

Got some crude navigation code working.  Press space bar to obtain a maze that'll work.

The moving circle stays within the grid lines (walls).  use arrow keys to move around.

c and v keys are disabled for this test.

Code: QB64: [Select]
  1.  
  2. s = 20
  3. h = 768
  4. w = 1024
  5. SCREEN _NEWIMAGE(w, h, 32)
  6. t = .5
  7.  
  8. _TITLE "Press z increase over/under,  x increase left/right, c makes smaller cells, v bigger, esc to quit, left mouse paints red, right blue"
  9.  
  10.  
  11.     CLS
  12.  
  13.     FOR y = 0 TO h STEP s * 4
  14.  
  15.         FOR x = 0 TO w STEP s * 4
  16.  
  17.             r = RND
  18.             CIRCLE (x, y), 2, _RGB(255, 255, 0)
  19.             IF r <= t THEN
  20.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  21.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  22.             END IF
  23.             IF r > t THEN
  24.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  25.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  26.             END IF
  27.  
  28.             x = x + s * 2
  29.             y = y + s * 2
  30.  
  31.             CIRCLE (x, y), 2, _RGB(0, 255, 0)
  32.             r = RND
  33.  
  34.             IF r <= t THEN
  35.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  36.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  37.             END IF
  38.             IF r > t THEN
  39.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  40.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  41.             END IF
  42.  
  43.             x = x - s * 2
  44.             y = y - s * 2
  45.  
  46.         NEXT
  47.  
  48.     NEXT
  49.     'yy = 100
  50.     DO
  51.         IF _MOUSEINPUT = -1 THEN
  52.  
  53.  
  54.             IF _MOUSEBUTTON(1) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(0, 0, 0) THEN
  55.                 PAINT (_MOUSEX, _MOUSEY), _RGB(255, 0, 0), &HFFFFFFFF
  56.                 GOTO L1
  57.             END IF
  58.             IF _MOUSEBUTTON(1) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(255, 0, 0) THEN
  59.                 PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 0), &HFFFFFFFF
  60.             END IF
  61.  
  62.             L1:
  63.  
  64.             IF _MOUSEBUTTON(2) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(0, 0, 0) THEN
  65.                 PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 255), &HFFFFFFFF
  66.                 GOTO L2
  67.             END IF
  68.             IF _MOUSEBUTTON(2) = -1 AND POINT(_MOUSEX, _MOUSEY) = _RGB(0, 0, 255) THEN
  69.                 PAINT (_MOUSEX, _MOUSEY), _RGB(0, 0, 0), &HFFFFFFFF
  70.             END IF
  71.  
  72.             L2:
  73.  
  74.  
  75.         END IF
  76.  
  77.  
  78.  
  79.  
  80.         KH& = _KEYHIT
  81.         IF KH& = 18432 AND yy > s * 2 AND POINT(xx, yy - 20) <> _RGB(255, 255, 255) THEN 'up
  82.             CIRCLE (xx, yy), 6, _RGB(0, 0, 0)
  83.             yy = yy - s * 2
  84.             CIRCLE (xx, yy), 6, &HFF00FF00
  85.  
  86.         END IF
  87.  
  88.         IF KH& = 19712 AND xx < 1024 AND POINT(xx + 20, yy) <> _RGB(255, 255, 255) THEN 'right
  89.             CIRCLE (xx, yy), 6, _RGB(0, 0, 0)
  90.             xx = xx + s * 2
  91.             CIRCLE (xx, yy), 6, &HFF00FF00
  92.             IF POINT(xx + 5, yy) = _RGB(255, 255, 255) THEN SOUND 300, 1
  93.         END IF
  94.  
  95.         IF KH& = 20480 AND yy < 768 AND POINT(xx, yy + 20) <> _RGB(255, 255, 255) THEN 'down
  96.             CIRCLE (xx, yy), 6, _RGB(0, 0, 0)
  97.             yy = yy + s * 2
  98.             CIRCLE (xx, yy), 6, &HFF00FF00
  99.         END IF
  100.  
  101.         IF KH& = 19200 AND xx > s * 2 AND POINT(xx - 20, yy) <> _RGB(255, 255, 255) THEN 'left
  102.             CIRCLE (xx, yy), 6, _RGB(0, 0, 0)
  103.             xx = xx - s * 2
  104.             CIRCLE (xx, yy), 6, &HFF00FF00
  105.         END IF
  106.  
  107.         IF xx MOD s * 4 = 0 AND yy MOD s * 4 = 0 THEN LOCATE 20, 20: PRINT "Yellow circle"
  108.         IF (xx + s * 2) MOD s * 4 = 0 AND (yy + s * 2) MOD s * 4 = 0 THEN LOCATE 20, 20: PRINT "green circle"
  109.  
  110.         IF (xx + s * 4) MOD s * 4 = 0 AND (yy + s * 2) MOD s * 4 = 0 THEN LOCATE 20, 20: PRINT "between      "
  111.         IF (xx + s * 2) MOD s * 4 = 0 AND yy MOD s * 4 = 0 THEN LOCATE 20, 20: PRINT "between      "
  112.  
  113.  
  114.         i$ = INKEY$
  115.  
  116.         IF i$ = "z" AND t < 1 THEN t = t + .005: EXIT DO
  117.         IF i$ = "x" AND t > 0 THEN t = t - .005: EXIT DO
  118.         ' IF i$ = "c" AND s > 1 THEN s = s - 1: xx = 0: yy = 0: EXIT DO
  119.         'IF i$ = "v" AND s < 41 THEN s = s + 1: xx = 0: yy = 0: EXIT DO
  120.         IF i$ = CHR$(27) THEN END
  121.         IF i$ = CHR$(32) THEN EXIT DO
  122.     LOOP
  123.  
Title: Re: Labyrinth Tiles
Post by: bplus on January 27, 2021, 01:27:15 am
Hey good work @NOVARSEG I know this was hard!

I got everything working good including toggling the PAINT jobs that you suggested then went to clean up code a bit and suddenly my guy is walking through walls! Dang WTH happened? After much hair pulling I discovered my White Constant was saying it was -1???
So I had to make White a normal variable and remember to dimension it _UNSIGNED LONG first and everything was working again, yeah! You should be able to resize s now too.

Code: QB64: [Select]
  1. ' b+ mod NOVARSEG code for 2 tiler 2021-01-25
  2. ' 2021-01-27  mod this for navigation and toggle paint jobs red and back or blue and black as per NOVARSEG
  3. CONST W = 1024, H = 700 ' screen width and height and color for lines and border check
  4. SCREEN _NEWIMAGE(W, H, 32)
  5. _DELAY .25 'wait for screen to set
  6. _SCREENMOVE _MIDDLE 'then center it in screen
  7. white = &HFFFFFFFF
  8. s = 10 ' s is the unit for drawing and navigating screen each step is 2*s
  9. t = .5 ' t is splitter between up/down walls and left/right walls
  10. COLOR white
  11. _TITLE "Press z increase over/under,  x increase left/right, c makes smaller cells, v bigger, esc to quit, left mouse paints red/black, right blue/black"
  12.     CLS
  13.     FOR y = 0 TO H STEP s * 4
  14.         FOR x = 0 TO W STEP s * 4
  15.             r = RND
  16.             'CIRCLE (x, y), 2, &HFFFFFF00
  17.             IF r <= t THEN
  18.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  19.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  20.             END IF
  21.             IF r > t THEN
  22.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  23.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  24.             END IF
  25.             x = x + s * 2: y = y + s * 2 ' offset to do the other half of screen
  26.             'CIRCLE (x, y), 2, &HFF0000FF
  27.             r = RND
  28.             IF r <= t THEN
  29.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  30.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  31.             END IF
  32.             IF r > t THEN
  33.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  34.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  35.             END IF
  36.             x = x - s * 2: y = y - s * 2 ' set back to first set
  37.         NEXT
  38.     NEXT
  39.     IF back THEN _FREEIMAGE back ' be careful not to cause a memory leak
  40.     REDIM back AS LONG
  41.     back = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' this uses new memory regardless if back is same old name or not
  42.     _PUTIMAGE , 0, back 'store current maze into image
  43.     xcells = INT(W / s) 'how many cells across
  44.     ycells = INT(H / s) 'how many down
  45.     hx = INT(xcells / 2) 'put our guy smack in middle of screen but he has to be on even number of cells!
  46.     IF hx MOD 2 = 1 THEN hx = hx + 1
  47.     hy = INT(ycells / 2)
  48.     IF hy MOD 2 = 1 THEN hy = hy + 1
  49.     's2 = 2 * s ' this is distance to move for each arrow press edit: did not need
  50.     DO
  51.         _PUTIMAGE , back, 0
  52.         KH& = _KEYHIT
  53.         SELECT CASE KH& '                                       which key was pressed?
  54.             CASE 27 '                                           the ESC key
  55.                 SYSTEM '
  56.             CASE 18432 '  Up Arrow
  57.                 IF hy - 2 > 0 THEN
  58.                     'CIRCLE (hx * s, (hy - 1) * s), 5, &HFFFFFF00
  59.                     '_DELAY .5
  60.                     'PRINT POINT(hx * s, (hy - 1) * s), POINT(hx * s, (hy - 1) * s + 1), POINT(hx * s, (hy - 1) * s - 1), white
  61.                     '_DISPLAY
  62.                     'SLEEP
  63.                     IF POINT(hx * s, (hy - 1) * s) <> white AND POINT(hx * s, (hy - 1) * s + 1) <> white AND POINT(hx * s, (hy - 1) * s - 1) <> white THEN hy = hy - 2
  64.                 END IF
  65.             CASE 19712 'the RIGHT ARROW key
  66.                 IF hx + 2 < xcells THEN
  67.                     'CIRCLE ((hx + 1) * s, hy * s), 5, &HFFFFFF00
  68.                     '_DELAY .5
  69.                     IF POINT((hx + 1) * s, hy * s) <> white AND POINT((hx + 1) * s + 1, hy * s) <> white AND POINT((hx + 1) * s - 1, hy * s) <> white THEN hx = hx + 2
  70.                 END IF
  71.             CASE 20480 ' the DOWN ARROW key
  72.                 IF hy + 2 < ycells THEN
  73.                     'CIRCLE (hx * s, (hy + 1) * s), 5, &HFFFFFF00
  74.                     '_DELAY .5
  75.                     IF POINT(hx * s, (hy + 1) * s) <> white AND POINT(hx * s, (hy + 1) * s + 1) <> white AND POINT(hx * s, (hy + 1) * s - 1) <> white THEN hy = hy + 2
  76.                 END IF
  77.             CASE 19200 'the LEFT ARROW key
  78.                 IF hx - 2 > 0 THEN
  79.                     'CIRCLE ((hx - 1) * s, hy * s), 5, &HFFFFFF00
  80.                     '_DELAY .5
  81.                     IF POINT((hx - 1) * s, hy * s) <> white AND POINT((hx - 1) * s + 1, hy * s) <> white AND POINT((hx - 1) * s - 1, hy * s) <> white THEN hx = hx - 2
  82.                 END IF
  83.         END SELECT
  84.         FOR ra = 0 TO .5 * s STEP .25 ' make a solid filled circle
  85.             CIRCLE (hx * s, hy * s), ra, &HFFFFFF00
  86.         NEXT
  87.         _DISPLAY
  88.         _LIMIT 60
  89.  
  90.         ' the rest of this loop is input from user, the drawing part is over but might PAINT roadways
  91.  
  92.         WHILE _MOUSEINPUT: WEND
  93.         IF _MOUSEBUTTON(1) THEN
  94.             _DELAY .2
  95.             _PUTIMAGE , back, 0 'get rid of hero
  96.             IF POINT(_MOUSEX, _MOUSEY) = _RGB32(0, 0, 0) THEN
  97.                 PAINT (_MOUSEX, _MOUSEY), _RGB32(255, 0, 0), &HFFFFFFFF
  98.             ELSEIF POINT(_MOUSEX, _MOUSEY) = _RGB32(255, 0, 0) THEN
  99.                 PAINT (_MOUSEX, _MOUSEY), _RGB32(0, 0, 0), &HFFFFFFFF
  100.             END IF
  101.             _DISPLAY
  102.             IF back THEN _FREEIMAGE back ' be careful not to cause a memory leak
  103.             back = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' this uses new memory regardless if back is same old name or not
  104.             _PUTIMAGE , 0, back 'store current maze into image
  105.         END IF
  106.         IF _MOUSEBUTTON(2) THEN
  107.             _DELAY .2
  108.             _PUTIMAGE , back, 0 'get rid of hero
  109.             IF POINT(_MOUSEX, _MOUSEY) = _RGB32(0, 0, 255) THEN
  110.                 PAINT (_MOUSEX, _MOUSEY), _RGB32(0, 0, 0), &HFFFFFFFF
  111.             ELSEIF POINT(_MOUSEX, _MOUSEY) = _RGB32(0, 0, 0) THEN
  112.                 PAINT (_MOUSEX, _MOUSEY), _RGB32(0, 0, 255), &HFFFFFFFF
  113.             END IF
  114.             _DISPLAY
  115.             IF back THEN _FREEIMAGE back ' be careful not to cause a memory leak
  116.             back = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' this uses new memory regardless if back is same old name or not
  117.             _PUTIMAGE , 0, back 'store current maze into image
  118.         END IF
  119.         i$ = INKEY$
  120.         IF i$ = "z" AND t < 1 THEN t = t + .005: EXIT DO
  121.         IF i$ = "x" AND t > 0 THEN t = t - .005: EXIT DO
  122.         IF i$ = "c" AND s > 1 THEN s = s - 1: EXIT DO
  123.         IF i$ = "v" AND s < 41 THEN s = s + 1: EXIT DO
  124.         IF i$ = CHR$(27) THEN END
  125.         IF i$ = CHR$(32) THEN EXIT DO
  126.     LOOP
  127.  
  128.  
  129.  

Oh heck, I never used s2!
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 27, 2021, 01:40:16 am
@bplus

Your code is working perfect. The circle moves fast.  I  can scale it way down and it still works . Almost pacman grade!

Works with _FULLSCREEN too. 

Also moving circle scales up or down with cell size.
Title: Re: Labyrinth Tiles
Post by: bplus on January 27, 2021, 01:48:08 am
Hey maybe some sort of Pacman variation that employs red and blue paths and some maze magic to shift the walls around you. I have to confess I never played Pacman.
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 27, 2021, 01:57:45 am
yep pacman is an old game for sure.   

Other  features can be added.     I want to try wall pair reversal for sure.  Might be useful in a game . With wall reversal, the moving circle can make a custom path, so in a game it depends on whether that is allowed or not.

Title: Re: Labyrinth Tiles
Post by: bplus on January 27, 2021, 11:42:22 pm
OK use spacebar to switch a cells walls and if the cell can be switched (you are not in a corner or intersection of walls and every other step on long straight path section), the cell will switch and the color you are standing on will be painted down the new pathway. If the cell is not one with switchable walls a low buzzer will sound, try one step over from where you are.

It's pretty cool!
Code: QB64: [Select]
  1. ' b+ mod NOVARSEG code for 2 tiler 2021-01-25
  2. ' 2021-01-27  mod this for navigation and toggle paint jobs red and back or blue and black as per NOVARSEG
  3. ' 2021-01-27  add spacebar to reverse a cells walls a sound will buzz if not inside a cell with walls
  4. '             The color your standing on will PAINT the new roadway if the walls switch.
  5.  
  6. CONST W = 1024, H = 700 ' screen width and height and color for lines and border check
  7. SCREEN _NEWIMAGE(W, H, 32)
  8. _DELAY .25 'wait for screen to set
  9. _SCREENMOVE _MIDDLE 'then center it in screen
  10. white = &HFFFFFFFF
  11. s = 10 ' s is the unit for drawing and navigating screen each step is 2*s
  12. t = .5 ' t is splitter between up/down walls and left/right walls
  13. COLOR white
  14. _TITLE "Press z increase over/under, x increase left/right, c makes smaller cells, v bigger, esc to quit, left mouse paints red/black, right blue/black, spacebar to reverse cells"
  15.     CLS
  16.     xcells = INT(W / s) 'how many cells across
  17.     ycells = INT(H / s) 'how many down
  18.     REDIM maze(xcells + 2, ycells + 2) AS LONG ' save our wall settings in maze array for wall changing with spacebar
  19.     FOR y = 0 TO H STEP s * 4
  20.         FOR x = 0 TO W STEP s * 4
  21.             r = RND
  22.             'CIRCLE (x, y), 2, &HFFFFFF00
  23.             IF r <= t THEN
  24.                 maze(INT(x / s), INT(y / s)) = -1
  25.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  26.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  27.             END IF
  28.             IF r > t THEN
  29.                 maze(INT(x / s), INT(y / s)) = 1
  30.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  31.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  32.             END IF
  33.             x = x + s * 2: y = y + s * 2 ' offset to do the other half of screen
  34.             'CIRCLE (x, y), 2, &HFF0000FF
  35.             r = RND
  36.             IF r <= t THEN
  37.                 maze(INT(x / s), INT(y / s)) = -1
  38.                 LINE (x - s, y + s)-(x + s, y + s) 'bottom line
  39.                 LINE (x - s, y - s)-(x + s, y - s) 'top line
  40.             END IF
  41.             IF r > t THEN
  42.                 maze(INT(x / s), INT(y / s)) = 1
  43.                 LINE (x - s, y - s)-(x - s, y + s) 'left line
  44.                 LINE (x + s, y - s)-(x + s, y + s) 'right line
  45.             END IF
  46.             x = x - s * 2: y = y - s * 2 ' set back to first set
  47.         NEXT
  48.     NEXT
  49.     IF back THEN _FREEIMAGE back ' be careful not to cause a memory leak
  50.     REDIM back AS LONG
  51.     back = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' this uses new memory regardless if back is same old name or not
  52.     _PUTIMAGE , 0, back 'store current maze into image
  53.     xcells = INT(W / s) 'how many cells across
  54.     ycells = INT(H / s) 'how many down
  55.     hx = INT(xcells / 2) 'put our guy smack in middle of screen but he has to be on even number of cells!
  56.     IF hx MOD 2 = 1 THEN hx = hx + 1
  57.     hy = INT(ycells / 2)
  58.     IF hy MOD 2 = 1 THEN hy = hy + 1
  59.     DO
  60.         _PUTIMAGE , back, 0
  61.         KH& = _KEYHIT
  62.         SELECT CASE KH& '                                       which key was pressed?
  63.             CASE 27 '                                           the ESC key
  64.                 SYSTEM '
  65.             CASE 32
  66.                 IF maze(hx, hy) THEN ' make sure on a cell that has walls
  67.                     IF maze(hx, hy) = 1 THEN
  68.                         maze(hx, hy) = -1
  69.                     ELSEIF maze(hx, hy) = -1 THEN
  70.                         maze(hx, hy) = 1
  71.                     END IF
  72.                     ' now redraw everything!!!!
  73.                     hColr = POINT(hx * s - (s - 1), hy * s - (s - 1)) ' preserve color at hx, hy
  74.                     CLS
  75.                     FOR y = 0 TO ycells STEP 2 'redraw maze
  76.                         FOR x = 0 TO xcells STEP 2
  77.                             IF maze(x, y) = -1 THEN
  78.                                 LINE (x * s - s, y * s + s)-(x * s + s, y * s + s) 'bottom line
  79.                                 LINE (x * s - s, y * s - s)-(x * s + s, y * s - s) 'top line
  80.                             ELSEIF maze(x, y) = 1 THEN
  81.                                 LINE (x * s - s, y * s - s)-(x * s - s, y * s + s) 'left line
  82.                                 LINE (x * s + s, y * s - s)-(x * s + s, y * s + s) 'right line
  83.                             END IF
  84.                         NEXT
  85.                     NEXT
  86.                     IF hColr <> white THEN PAINT (hx * s, hy * s), hColr, white ' paint the new roadway
  87.                     'take a new picture
  88.                     _DISPLAY
  89.                     IF back THEN _FREEIMAGE back ' be careful not to cause a memory leak
  90.                     back = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' this uses new memory regardless if back is same old name or not
  91.                     _PUTIMAGE , 0, back 'store current maze into image
  92.                 ELSE
  93.                     SOUND 100, 4
  94.                 END IF
  95.             CASE 18432 '  Up Arrow
  96.                 IF hy - 2 > 0 THEN
  97.                     'CIRCLE (hx * s, (hy - 1) * s), 5, &HFFFFFF00
  98.                     '_DELAY .5
  99.                     'PRINT POINT(hx * s, (hy - 1) * s), POINT(hx * s, (hy - 1) * s + 1), POINT(hx * s, (hy - 1) * s - 1), white
  100.                     '_DISPLAY
  101.                     'SLEEP
  102.                     IF POINT(hx * s, (hy - 1) * s) <> white AND POINT(hx * s, (hy - 1) * s + 1) <> white AND POINT(hx * s, (hy - 1) * s - 1) <> white THEN hy = hy - 2
  103.                 END IF
  104.             CASE 19712 'the RIGHT ARROW key
  105.                 IF hx + 2 < xcells THEN
  106.                     'CIRCLE ((hx + 1) * s, hy * s), 5, &HFFFFFF00
  107.                     '_DELAY .5
  108.                     IF POINT((hx + 1) * s, hy * s) <> white AND POINT((hx + 1) * s + 1, hy * s) <> white AND POINT((hx + 1) * s - 1, hy * s) <> white THEN hx = hx + 2
  109.                 END IF
  110.             CASE 20480 ' the DOWN ARROW key
  111.                 IF hy + 2 < ycells THEN
  112.                     'CIRCLE (hx * s, (hy + 1) * s), 5, &HFFFFFF00
  113.                     '_DELAY .5
  114.                     IF POINT(hx * s, (hy + 1) * s) <> white AND POINT(hx * s, (hy + 1) * s + 1) <> white AND POINT(hx * s, (hy + 1) * s - 1) <> white THEN hy = hy + 2
  115.                 END IF
  116.             CASE 19200 'the LEFT ARROW key
  117.                 IF hx - 2 > 0 THEN
  118.                     'CIRCLE ((hx - 1) * s, hy * s), 5, &HFFFFFF00
  119.                     '_DELAY .5
  120.                     IF POINT((hx - 1) * s, hy * s) <> white AND POINT((hx - 1) * s + 1, hy * s) <> white AND POINT((hx - 1) * s - 1, hy * s) <> white THEN hx = hx - 2
  121.                 END IF
  122.         END SELECT
  123.         FOR ra = 0 TO .5 * s STEP .25 ' make a solid filled circle
  124.             CIRCLE (hx * s, hy * s), ra, &HFFFFFF00
  125.         NEXT
  126.         _DISPLAY
  127.         _LIMIT 60
  128.  
  129.         ' the rest of this loop is input from user, the drawing part is over but might PAINT roadways
  130.  
  131.         WHILE _MOUSEINPUT: WEND
  132.         IF _MOUSEBUTTON(1) THEN
  133.             _DELAY .2
  134.             _PUTIMAGE , back, 0 'get rid of hero
  135.             IF POINT(_MOUSEX, _MOUSEY) = _RGB32(0, 0, 0) THEN
  136.                 PAINT (_MOUSEX, _MOUSEY), _RGB32(255, 0, 0), &HFFFFFFFF
  137.             ELSEIF POINT(_MOUSEX, _MOUSEY) = _RGB32(255, 0, 0) THEN
  138.                 PAINT (_MOUSEX, _MOUSEY), _RGB32(0, 0, 0), &HFFFFFFFF
  139.             END IF
  140.             _DISPLAY
  141.             IF back THEN _FREEIMAGE back ' be careful not to cause a memory leak
  142.             back = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' this uses new memory regardless if back is same old name or not
  143.             _PUTIMAGE , 0, back 'store current maze into image
  144.         END IF
  145.         IF _MOUSEBUTTON(2) THEN
  146.             _DELAY .2
  147.             _PUTIMAGE , back, 0 'get rid of hero
  148.             IF POINT(_MOUSEX, _MOUSEY) = _RGB32(0, 0, 255) THEN
  149.                 PAINT (_MOUSEX, _MOUSEY), _RGB32(0, 0, 0), &HFFFFFFFF
  150.             ELSEIF POINT(_MOUSEX, _MOUSEY) = _RGB32(0, 0, 0) THEN
  151.                 PAINT (_MOUSEX, _MOUSEY), _RGB32(0, 0, 255), &HFFFFFFFF
  152.             END IF
  153.             _DISPLAY
  154.             IF back THEN _FREEIMAGE back ' be careful not to cause a memory leak
  155.             back = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' this uses new memory regardless if back is same old name or not
  156.             _PUTIMAGE , 0, back 'store current maze into image
  157.         END IF
  158.         i$ = INKEY$
  159.         IF i$ = "z" AND t < 1 THEN t = t + .05: EXIT DO '  changed from .005 because too slow
  160.         IF i$ = "x" AND t > 0 THEN t = t - .05: EXIT DO
  161.         IF i$ = "c" AND s > 3 THEN s = s - 1: EXIT DO
  162.         IF i$ = "v" AND s < 41 THEN s = s + 1: EXIT DO
  163.         IF i$ = CHR$(27) THEN END
  164.     LOOP
  165.  
  166.  
  167.  

Oh I also changed how fast the t ratio gets changed by z or x, 10 times faster, more like s changes, noticeable with each press.
Title: Re: Labyrinth Tiles
Post by: NOVARSEG on January 28, 2021, 02:48:45 am
Nice toggle effect with space bar. Looking at your code to see how the reversal works.


Ya the t ratio was too slow.