Author Topic: Labyrinth Tiles  (Read 8129 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #30 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.
« Last Edit: January 25, 2021, 10:56:08 pm by bplus »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Labyrinth Tiles
« Reply #31 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.


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #32 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
« Last Edit: January 26, 2021, 01:54:30 am by bplus »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Labyrinth Tiles
« Reply #33 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. 

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #34 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.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Labyrinth Tiles
« Reply #35 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.  
« Last Edit: January 27, 2021, 01:24:12 am by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #36 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!
« Last Edit: January 27, 2021, 01:32:47 am by bplus »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Labyrinth Tiles
« Reply #37 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.
« Last Edit: January 27, 2021, 01:48:48 am by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #38 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.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Labyrinth Tiles
« Reply #39 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.


Marked as best answer by bplus on January 27, 2021, 06:44:50 pm

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #40 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.
« Last Edit: January 27, 2021, 11:52:48 pm by bplus »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Labyrinth Tiles
« Reply #41 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.




« Last Edit: January 28, 2021, 02:50:48 am by NOVARSEG »