Author Topic: QB64 Surabikku-like puzzle.  (Read 5120 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
QB64 Surabikku-like puzzle.
« on: October 20, 2021, 11:40:09 am »
I got stuck waiting at the auto mechanics this morning, luckily I had my laptop with me to play with and threw together this sliding block puzzle.  I was playing something like last night online called Surabikku.  I made to use images for the blocks, just in case I want to switch out real pictures tiles in the future.

You simply slide the blocks using the arrows and try to make the puzzle look like the one on the right.  Not too hard, really.  It's harder to pronounce the puzzle name probably.

- Dav

Code: QB64: [Select]
  1. '=============
  2. 'SURABIKKU.BAS
  3. '=============
  4. 'QB64 version of a SURABIKKU like puzzle.
  5. 'Coded by Dav, OCT/2021
  6.  
  7. SCREEN _NEWIMAGE(1024, 675, 32)
  8.  
  9. 'define deminsions for chessboard
  10. DIM SHARED row, col, size: row = 3: col = 3: size = 175
  11. DIM SHARED boxes: boxes = row * col
  12.  
  13. 'define box value, x/y, values...
  14. DIM SHARED bv&(boxes) 'box values (scrambled)
  15. DIM SHARED slv&(boxes) 'box values (solved)
  16. DIM SHARED bx1(boxes), by1(boxes) 'top x/y cords of box
  17. DIM SHARED bx2(boxes), by2(boxes) ' bottom x/y cords of box
  18.  
  19. DIM SHARED red&, blu&, grn&
  20.  
  21. 'draw color boxes
  22. red& = _NEWIMAGE(size, size, 32): _DEST red&: CLS , _RGB(255, 0, 0)
  23. blu& = _NEWIMAGE(size, size, 32): _DEST blu&: CLS , _RGB(0, 0, 255)
  24. grn& = _NEWIMAGE(size, size, 32): _DEST grn&: CLS , _RGB(0, 255, 0)
  25.  
  26.  
  27. 'init box x.y values
  28. bc = 1 'counter
  29. FOR r = 1 TO row
  30.     FOR c = 1 TO col
  31.         x = 75 + (c * size): y = 75 + (r * size)
  32.         bx1(bc) = x - size: bx2(bc) = x ' generate x/y values
  33.         by1(bc) = y - size: by2(bc) = y
  34.         bc = bc + 1
  35.     NEXT
  36.  
  37. 'assign scramble up box values
  38. bv&(1) = red&: bv&(2) = grn&: bv&(3) = red&
  39. bv&(4) = blu&: bv&(5) = grn&: bv&(6) = blu&
  40. bv&(7) = grn&: bv&(8) = blu&: bv&(9) = red&
  41.  
  42. 'assign solved box values
  43. slv&(1) = red&: slv&(2) = red&: slv&(3) = grn&
  44. slv&(4) = red&: slv&(5) = blu&: slv&(6) = grn&
  45. slv&(7) = blu&: slv&(8) = blu&: slv&(9) = grn&
  46.  
  47. CLS , _RGB(64, 64, 64)
  48.  
  49. 'draw puzzle
  50. FOR b = 1 TO boxes
  51.     _PUTIMAGE (bx1(b), by1(b))-(bx2(b), by2(b)), bv&(b)
  52.     LINE (bx1(b), by1(b))-(bx2(b), by2(b)), _RGB(0, 0, 0), B
  53.  
  54. slidespeed = 300
  55.  
  56. PPRINT 668, 28, 25, _RGB(128, 128, 128), 255, "QB64 SURABIKKU"
  57. PPRINT 665, 25, 25, _RGB(255, 255, 0), 255, "QB64 SURABIKKU"
  58. PPRINT 725, 75, 20, _RGB(128, 128, 128), 255, "Click Arrow."
  59. PPRINT 725, 110, 20, _RGB(128, 128, 128), 255, "Move Blocks."
  60.  
  61. PPRINT 725, 250, 20, _RGB(255, 255, 255), 255, "Make it like:"
  62.  
  63. 'draw solved puzzle on right
  64. _PUTIMAGE (725, 300)-(800, 375), slv&(1)
  65. _PUTIMAGE (800, 300)-(875, 375), slv&(2)
  66. _PUTIMAGE (875, 300)-(950, 375), slv&(3)
  67. _PUTIMAGE (725, 375)-(800, 450), slv&(4)
  68. _PUTIMAGE (800, 375)-(875, 450), slv&(5)
  69. _PUTIMAGE (875, 375)-(950, 450), slv&(6)
  70. _PUTIMAGE (725, 450)-(800, 525), slv&(7)
  71. _PUTIMAGE (800, 450)-(875, 525), slv&(8)
  72. _PUTIMAGE (875, 450)-(950, 525), slv&(9)
  73.  
  74. 'draw top arrows
  75. FOR t = 0 TO 450 STEP 175
  76.     LINE (130 + t, 55)-(160 + t, 25), _RGB(128, 128, 128)
  77.     LINE (160 + t, 25)-(190 + t, 55), _RGB(128, 128, 128)
  78.     LINE (130 + t, 55)-(190 + t, 55), _RGB(128, 128, 128)
  79. 'draw bottom arrows
  80. FOR t = 0 TO 450 STEP 175
  81.     LINE (130 + t, 620)-(160 + t, 650), _RGB(128, 128, 128)
  82.     LINE (160 + t, 650)-(190 + t, 620), _RGB(128, 128, 128)
  83.     LINE (130 + t, 620)-(190 + t, 620), _RGB(128, 128, 128)
  84. 'draw left arrows
  85. FOR t = 0 TO 450 STEP 175
  86.     LINE (20, 160 + t)-(50, 130 + t), _RGB(128, 128, 128)
  87.     LINE (20, 160 + t)-(50, 190 + t), _RGB(128, 128, 128)
  88.     LINE (50, 130 + t)-(50, 190 + t), _RGB(128, 128, 128)
  89. 'draw right arrows
  90. FOR t = 0 TO 450 STEP 175
  91.     LINE (620, 130 + t)-(650, 160 + t), _RGB(128, 128, 128)
  92.     LINE (620, 190 + t)-(650, 160 + t), _RGB(128, 128, 128)
  93.     LINE (620, 130 + t)-(620, 190 + t), _RGB(128, 128, 128)
  94.  
  95.  
  96.  
  97.     IF _MOUSEBUTTON(1) = 0 THEN clicked = 0
  98.  
  99.     mi = _MOUSEINPUT: mx = _MOUSEX: my = _MOUSEY
  100.     'LOCATE 1, 1: PRINT mx, my, _MOUSEBUTTON(1)
  101.     '_DISPLAY
  102.  
  103.     IF _MOUSEBUTTON(1) = -1 AND clicked = 0 THEN
  104.  
  105.         clicked = 1
  106.  
  107.         '===== if top-left button clicked...
  108.         IF mx > 75 AND mx < 250 AND my > 0 AND my < 75 THEN
  109.             'slide column up
  110.             FOR y = 0 TO size
  111.                 'just move bottom two images up
  112.                 _PUTIMAGE (bx1(4), by1(4) - y), bv&(4)
  113.                 _PUTIMAGE (bx1(7), by1(7) - y), bv&(7)
  114.                 'expand bottom location with top image
  115.                 _PUTIMAGE (bx1(7), by2(7) - y)-(bx2(7), by2(7)), bv&(1)
  116.                 'redraw boxes around them, for looks
  117.                 LINE (bx1(1), by1(1))-(bx2(1), by2(1)), _RGB(0, 0, 0), B
  118.                 LINE (bx1(4), by1(4))-(bx2(4), by2(4)), _RGB(0, 0, 0), B
  119.                 LINE (bx1(7), by1(7))-(bx2(7), by2(7)), _RGB(0, 0, 0), B
  120.                 _DISPLAY
  121.                 _LIMIT slidespeed
  122.             NEXT
  123.             'update/assign new values
  124.             t1& = bv&(1): t2& = bv&(4): t3& = bv&(7) 'old values
  125.             bv&(1) = t2&: bv&(4) = t3&: bv&(7) = t1& 'new values
  126.         END IF
  127.  
  128.         '===== if bottom-left button clicked...
  129.         IF mx > 75 AND mx < 250 AND my > 600 AND my < 675 THEN
  130.             'slide column down
  131.             FOR y = 0 TO size
  132.                 'expand top location with bottom image
  133.                 _PUTIMAGE (bx1(1), by1(1))-(bx2(1), by2(1) + y), bv&(7)
  134.                 'just move top two images down
  135.                 _PUTIMAGE (bx1(1), by1(1) + y), bv&(1)
  136.                 _PUTIMAGE (bx1(4), by1(4) + y), bv&(4)
  137.                 'redraw boxes around them, for looks
  138.                 LINE (bx1(1), by1(1))-(bx2(1), by2(1)), _RGB(0, 0, 0), B
  139.                 LINE (bx1(4), by1(4))-(bx2(4), by2(4)), _RGB(0, 0, 0), B
  140.                 LINE (bx1(7), by1(7))-(bx2(7), by2(7)), _RGB(0, 0, 0), B
  141.                 _DISPLAY
  142.                 _LIMIT slidespeed
  143.             NEXT
  144.             'update/assign new values
  145.             t1& = bv&(1): t2& = bv&(4): t3& = bv&(7) 'old values
  146.             bv&(1) = t3&: bv&(4) = t1&: bv&(7) = t2& 'new values
  147.         END IF
  148.  
  149.         '===== if top-middle button clicked...
  150.         IF mx > 250 AND mx < 425 AND my > 0 AND my < 75 THEN
  151.             'slide column up
  152.             FOR y = 0 TO size
  153.                 'just move bottom two images up
  154.                 _PUTIMAGE (bx1(5), by1(5) - y), bv&(5)
  155.                 _PUTIMAGE (bx1(8), by1(8) - y), bv&(8)
  156.                 'expand bottom location with top image
  157.                 _PUTIMAGE (bx1(8), by2(8) - y)-(bx2(8), by2(8)), bv&(2)
  158.                 'redraw boxes around them, for looks
  159.                 LINE (bx1(2), by1(2))-(bx2(2), by2(2)), _RGB(0, 0, 0), B
  160.                 LINE (bx1(5), by1(5))-(bx2(5), by2(5)), _RGB(0, 0, 0), B
  161.                 LINE (bx1(8), by1(8))-(bx2(8), by2(8)), _RGB(0, 0, 0), B
  162.                 _DISPLAY
  163.                 _LIMIT slidespeed
  164.             NEXT
  165.             'update/assign new values
  166.             t1& = bv&(2): t2& = bv&(5): t3& = bv&(8) 'old values
  167.             bv&(2) = t2&: bv&(5) = t3&: bv&(8) = t1& 'new values
  168.         END IF
  169.  
  170.         '===== if bottom-middle button clicked...
  171.         IF mx > 250 AND mx < 425 AND my > 600 AND my < 675 THEN
  172.             'slide column down
  173.             FOR y = 0 TO size
  174.                 'expand top location with bottom image
  175.                 _PUTIMAGE (bx1(2), by1(2))-(bx2(2), by2(2) + y), bv&(8)
  176.                 'just move top two images down
  177.                 _PUTIMAGE (bx1(2), by1(2) + y), bv&(2)
  178.                 _PUTIMAGE (bx1(5), by1(5) + y), bv&(5)
  179.                 'redraw boxes around them, for looks
  180.                 LINE (bx1(2), by1(2))-(bx2(2), by2(2)), _RGB(0, 0, 0), B
  181.                 LINE (bx1(5), by1(5))-(bx2(5), by2(5)), _RGB(0, 0, 0), B
  182.                 LINE (bx1(8), by1(8))-(bx2(8), by2(8)), _RGB(0, 0, 0), B
  183.                 _DISPLAY
  184.                 _LIMIT slidespeed
  185.             NEXT
  186.             'update/assign new values
  187.             t1& = bv&(2): t2& = bv&(5): t3& = bv&(8) 'old values
  188.             bv&(2) = t3&: bv&(5) = t1&: bv&(8) = t2& 'new values
  189.         END IF
  190.  
  191.         '===== if top-right button clicked...
  192.         IF mx > 425 AND mx < 600 AND my > 0 AND my < 75 THEN
  193.             'slide column up
  194.             FOR y = 0 TO size
  195.                 'just move bottom two images up
  196.                 _PUTIMAGE (bx1(6), by1(6) - y), bv&(6)
  197.                 _PUTIMAGE (bx1(9), by1(9) - y), bv&(9)
  198.                 'expand bottom location with top image
  199.                 _PUTIMAGE (bx1(9), by2(9) - y)-(bx2(9), by2(9)), bv&(3)
  200.                 'redraw boxes around them, for looks
  201.                 LINE (bx1(3), by1(3))-(bx2(3), by2(3)), _RGB(0, 0, 0), B
  202.                 LINE (bx1(6), by1(6))-(bx2(6), by2(6)), _RGB(0, 0, 0), B
  203.                 LINE (bx1(9), by1(9))-(bx2(9), by2(9)), _RGB(0, 0, 0), B
  204.                 _DISPLAY
  205.                 _LIMIT slidespeed
  206.             NEXT
  207.             'update/assign new values
  208.             t1& = bv&(3): t2& = bv&(6): t3& = bv&(9) 'old values
  209.             bv&(3) = t2&: bv&(6) = t3&: bv&(9) = t1& 'new values
  210.         END IF
  211.  
  212.         '===== if bottom-right button clicked...
  213.         IF mx > 425 AND mx < 600 AND my > 600 AND my < 675 THEN
  214.             'slide column down
  215.             FOR y = 0 TO size
  216.                 'expand top location with bottom image
  217.                 _PUTIMAGE (bx1(3), by1(3))-(bx2(3), by2(3) + y), bv&(9)
  218.                 'just move top two images down
  219.                 _PUTIMAGE (bx1(3), by1(3) + y), bv&(3)
  220.                 _PUTIMAGE (bx1(6), by1(6) + y), bv&(6)
  221.                 'redraw boxes around them, for looks
  222.                 LINE (bx1(3), by1(3))-(bx2(3), by2(3)), _RGB(0, 0, 0), B
  223.                 LINE (bx1(6), by1(6))-(bx2(6), by2(6)), _RGB(0, 0, 0), B
  224.                 LINE (bx1(9), by1(9))-(bx2(9), by2(9)), _RGB(0, 0, 0), B
  225.                 _DISPLAY
  226.                 _LIMIT slidespeed
  227.             NEXT
  228.             'update/assign new values
  229.             t1& = bv&(3): t2& = bv&(6): t3& = bv&(9) 'old values
  230.             bv&(3) = t3&: bv&(6) = t1&: bv&(9) = t2& 'new values
  231.         END IF
  232.  
  233.         '===== if left-top button clicked...
  234.         IF mx > 0 AND mx < 75 AND my > 75 AND my < 250 THEN
  235.             'slide column left
  236.             FOR x = 0 TO size
  237.                 'just move right two images left
  238.                 _PUTIMAGE (bx1(2) - x, by1(2)), bv&(2)
  239.                 _PUTIMAGE (bx1(3) - x, by1(3)), bv&(3)
  240.                 'and expand far right location with far left image
  241.                 _PUTIMAGE (bx2(3) - x, by1(3))-(bx2(3) - x, by2(3)), bv&(1)
  242.                 'redraw boxes around them, for looks
  243.                 LINE (bx1(1), by1(1))-(bx2(1), by2(1)), _RGB(0, 0, 0), B
  244.                 LINE (bx1(2), by1(2))-(bx2(2), by2(2)), _RGB(0, 0, 0), B
  245.                 LINE (bx1(3), by1(3))-(bx2(3), by2(3)), _RGB(0, 0, 0), B
  246.                 _DISPLAY
  247.                 _LIMIT slidespeed
  248.             NEXT
  249.             'update/assign new values
  250.             t1& = bv&(1): t2& = bv&(2): t3& = bv&(3) 'old values
  251.             bv&(1) = t2&: bv&(2) = t3&: bv&(3) = t1& 'new values
  252.         END IF
  253.  
  254.         '===== if right-top button clicked...
  255.         IF mx > 600 AND mx < 675 AND my > 75 AND my < 250 THEN
  256.             'slide column left
  257.             FOR x = 0 TO size
  258.                 'just move left two images right
  259.                 _PUTIMAGE (bx1(1) + x, by1(1)), bv&(1)
  260.                 _PUTIMAGE (bx1(2) + x, by1(2)), bv&(2)
  261.                 'and expand far left location with far right image
  262.                 _PUTIMAGE (bx1(1), by1(1))-(bx1(1) + x, by2(1)), bv&(3)
  263.                 'redraw boxes around them, for looks
  264.                 LINE (bx1(1), by1(1))-(bx2(1), by2(1)), _RGB(0, 0, 0), B
  265.                 LINE (bx1(2), by1(2))-(bx2(2), by2(2)), _RGB(0, 0, 0), B
  266.                 LINE (bx1(3), by1(3))-(bx2(3), by2(3)), _RGB(0, 0, 0), B
  267.                 _DISPLAY
  268.                 _LIMIT slidespeed
  269.             NEXT
  270.             'update/assign new values
  271.             t1& = bv&(1): t2& = bv&(2): t3& = bv&(3) 'old values
  272.             bv&(1) = t3&: bv&(2) = t1&: bv&(3) = t2& 'new values
  273.         END IF
  274.  
  275.         '===== if left-middle button clicked...
  276.         IF mx > 0 AND mx < 75 AND my > 250 AND my < 425 THEN
  277.             'slide column left
  278.             FOR x = 0 TO size
  279.                 'just move right two images left
  280.                 _PUTIMAGE (bx1(5) - x, by1(5)), bv&(5)
  281.                 _PUTIMAGE (bx1(6) - x, by1(6)), bv&(6)
  282.                 'and expand far right location with far left image
  283.                 _PUTIMAGE (bx2(6) - x, by1(6))-(bx2(6) - x, by2(6)), bv&(4)
  284.                 'redraw boxes around them, for looks
  285.                 LINE (bx1(4), by1(4))-(bx2(4), by2(4)), _RGB(0, 0, 0), B
  286.                 LINE (bx1(5), by1(5))-(bx2(5), by2(5)), _RGB(0, 0, 0), B
  287.                 LINE (bx1(6), by1(6))-(bx2(6), by2(6)), _RGB(0, 0, 0), B
  288.                 _DISPLAY
  289.                 _LIMIT slidespeed
  290.             NEXT
  291.             'update/assign new values
  292.             t1& = bv&(4): t2& = bv&(5): t3& = bv&(6) 'old values
  293.             bv&(4) = t2&: bv&(5) = t3&: bv&(6) = t1& 'new values
  294.         END IF
  295.  
  296.         '===== if right-middle button clicked...
  297.         IF mx > 600 AND mx < 675 AND my > 250 AND my < 425 THEN
  298.             'slide column left
  299.             FOR x = 0 TO size
  300.                 'just move left two images right
  301.                 _PUTIMAGE (bx1(4) + x, by1(4)), bv&(4)
  302.                 _PUTIMAGE (bx1(5) + x, by1(5)), bv&(5)
  303.                 'and expand far left location with far right image
  304.                 _PUTIMAGE (bx1(4), by1(4))-(bx1(4) + x, by2(4)), bv&(6)
  305.                 'redraw boxes around them, for looks
  306.                 LINE (bx1(4), by1(4))-(bx2(4), by2(4)), _RGB(0, 0, 0), B
  307.                 LINE (bx1(5), by1(5))-(bx2(5), by2(5)), _RGB(0, 0, 0), B
  308.                 LINE (bx1(6), by1(6))-(bx2(6), by2(6)), _RGB(0, 0, 0), B
  309.                 _DISPLAY
  310.                 _LIMIT slidespeed
  311.             NEXT
  312.             'update/assign new values
  313.             t1& = bv&(4): t2& = bv&(5): t3& = bv&(6) 'old values
  314.             bv&(4) = t3&: bv&(5) = t1&: bv&(6) = t2& 'new values
  315.         END IF
  316.  
  317.         '===== if left-bottom button clicked...
  318.         IF mx > 0 AND mx < 75 AND my > 425 AND my < 600 THEN
  319.             'slide column left
  320.             FOR x = 0 TO size
  321.                 'just move right two images left
  322.                 _PUTIMAGE (bx1(8) - x, by1(8)), bv&(8)
  323.                 _PUTIMAGE (bx1(9) - x, by1(9)), bv&(9)
  324.                 'and expand far right location with far left image
  325.                 _PUTIMAGE (bx2(9) - x, by1(9))-(bx2(9) - x, by2(9)), bv&(7)
  326.                 'redraw boxes around them, for looks
  327.                 LINE (bx1(7), by1(7))-(bx2(7), by2(7)), _RGB(0, 0, 0), B
  328.                 LINE (bx1(8), by1(8))-(bx2(8), by2(8)), _RGB(0, 0, 0), B
  329.                 LINE (bx1(9), by1(9))-(bx2(9), by2(9)), _RGB(0, 0, 0), B
  330.                 _DISPLAY
  331.                 _LIMIT slidespeed
  332.             NEXT
  333.             'update/assign new values
  334.             t1& = bv&(7): t2& = bv&(8): t3& = bv&(9) 'old values
  335.             bv&(7) = t2&: bv&(8) = t3&: bv&(9) = t1& 'new values
  336.         END IF
  337.  
  338.         '===== if right-bottom button clicked...
  339.         IF mx > 600 AND mx < 675 AND my > 425 AND my < 600 THEN
  340.             'slide column left
  341.             FOR x = 0 TO size
  342.                 'just move left two images right
  343.                 _PUTIMAGE (bx1(7) + x, by1(7)), bv&(7)
  344.                 _PUTIMAGE (bx1(8) + x, by1(8)), bv&(8)
  345.                 'and expand far left location with far right image
  346.                 _PUTIMAGE (bx1(7), by1(7))-(bx1(7) + x, by2(7)), bv&(9)
  347.                 'redraw boxes around them, for looks
  348.                 LINE (bx1(7), by1(7))-(bx2(7), by2(7)), _RGB(0, 0, 0), B
  349.                 LINE (bx1(8), by1(8))-(bx2(8), by2(8)), _RGB(0, 0, 0), B
  350.                 LINE (bx1(9), by1(9))-(bx2(9), by2(9)), _RGB(0, 0, 0), B
  351.                 _DISPLAY
  352.                 _LIMIT slidespeed
  353.             NEXT
  354.             'update/assign new values
  355.             t1& = bv&(7): t2& = bv&(8): t3& = bv&(9) 'old values
  356.             bv&(7) = t3&: bv&(8) = t1&: bv&(9) = t2& 'new values
  357.         END IF
  358.  
  359.         '==== check for solved here....
  360.         solved = 1
  361.         FOR s = 1 TO boxes
  362.             IF bv&(s) <> slv&(s) THEN solved = 0
  363.         NEXT
  364.         IF solved = 1 THEN BEEP: BEEP: END
  365.  
  366.     END IF
  367.  
  368.  
  369.  
  370.  
  371. SUB PPRINT (x, y, size, clr&, trans&, text$)
  372.     'This sub outputs to the current _DEST set
  373.     'It makes trans& the transparent color
  374.  
  375.     'x/y is where to print text
  376.     'size is the font size to use
  377.     'clr& is the color of your text
  378.     'trans& is the background transparent color
  379.     'text$ is the string to print
  380.  
  381.     '=== get users current write screen
  382.     orig& = _DEST
  383.  
  384.     '=== if you are using an 8 or 32 bit screen
  385.     bit = 32: IF _PIXELSIZE(0) = 1 THEN bit = 256
  386.  
  387.     '=== step through your text
  388.     FOR t = 0 TO LEN(text$) - 1
  389.         '=== make a temp screen to use
  390.         pprintimg& = _NEWIMAGE(16, 16, bit)
  391.         _DEST pprintimg&
  392.         '=== set colors and print text
  393.         CLS , trans&: COLOR clr&
  394.         PRINT MID$(text$, t + 1, 1);
  395.         '== make background color the transprent one
  396.         _CLEARCOLOR _RGB(0, 0, 0), pprintimg&
  397.         '=== go back to original screen  to output
  398.         _DEST orig&
  399.         '=== set it and forget it
  400.         x1 = x + (t * size): x2 = x1 + size
  401.         y1 = y: y2 = y + size
  402.         _PUTIMAGE (x1 - (size / 2), y1)-(x2, y2 + (size / 3)), pprintimg&
  403.         _FREEIMAGE pprintimg&
  404.     NEXT
  405.  
« Last Edit: October 20, 2021, 02:13:32 pm by Dav »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #1 on: October 20, 2021, 12:22:54 pm »
Nice, I got it but don't know how? :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #2 on: October 20, 2021, 12:52:45 pm »
@Dav This is begging to do images with difficulty levels of pieces.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #3 on: October 20, 2021, 02:17:25 pm »
Yeah I was thinking along that line.  I need to come up with a way to PUTIMAGE just a portion of an image on screen, for when sliding the edge tiles.  Maybe make a temporary images offscreen using _NEWIMAGE/_DEST for that.

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #4 on: October 20, 2021, 04:31:23 pm »
To avoid _NewImage for each rectangle chunk of image, you could use a formula that takes an image number and converts to a row and col from the image and vice versa. From row, col convert to x, y top left corner of image chunk then Step(width, height) of each chunk.

Image number = row * (nCellsWide -1) + col
EDIT >>>>>>> row * nCellsWide + col    both rows and columns start at 0

row = INT( image number / nCellsWide)   ' rows 0 to nCellsHigh - 1
col = ( image number) mod nCellsWide     ' cols 0 to nCellsWide - 1

x = row * cellWidth   EDIT: x = col * cellWidth
y = col * cellHeight   EDIT: y = row * cellHeight

_putimage (destinationX, destinationY)-step(cellWidth, cellHeight), image, screen, (x, y) -step(cellWidth, cellHeight)
(destinationX, destinationY) or more likely (destRow, destCol) EDIT >>> (destCol, destRow) has to be tracked by the progress of the puzzle.

_Putimage uses 2 line boxes one from source (the image) and one for destination (the screen) just have to track the image number with the game setup and play.

eg image number 0 is top left corner of image, 1 is next cell to right, new row (2nd) starts at image number = nCellsWide

Sorry for EDITs but I hope to get this correct.

EDIT: Row is vertical associated with Y's of graphic,  Col (Column) is horizontal associated with X's of graphic.
I've learned to say Row, Col when it comes to Locate for Text and x, y when it comes to graphics but they are reversed text and graphic.
« Last Edit: October 20, 2021, 08:35:45 pm by bplus »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #5 on: October 20, 2021, 06:53:14 pm »
Oh wow - I haven't used _PUTIMAGE in that way before.  I'll play around with it.  Not sure I fully grasp the formula yet, but will chew on it for awhile.

Thanks!

- Dav

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #6 on: October 20, 2021, 07:43:25 pm »
To avoid _NewImage for each rectangle chunk of image, you could use a formula that takes an image number and converts to a row and col from the image and vice versa. From row, col convert to x, y top left corner of image chunk then Step(width, height) of each chunk.

Image number = row * (nCellsWide -1) + col

row = INT( image number / nCellsWide)   ' rows 0 to nCellsHigh - 1
col = ( image number) mod nCellsWide     ' cols 0 to nCellsWide - 1

x = row * cellWidth
y = col * cellHeight

_putimage (destinationX, destinationY)-step(cellWidth, cellHeight), image, screen, (x, y) -step(cellWidth, cellHeight)
(destinationX, destinationY) or more likely (destRow, destCol) has to be tracked by the progress of the puzzle.

_Putimage uses 2 line boxes one from source (the image) and one for destination (the screen) just have to track the image number with the game setup and play.

eg image number 0 is top left corner of image, 1 is next cell to right, new row (2nd) starts at image number = nCellsWide

🤯🤯🤯
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #7 on: October 20, 2021, 07:56:55 pm »
@Pete kinda' of thought this would be the reaction so as I said before a picture is worth a thousand words.

Here is a demo of using _PutImage. I make an image, divide it into cells, number those cells, and then choose cell numbers randomly to rebuild the original image a cell at a time as far as 100 random choices takes us.

Code: QB64: [Select]
  1. _Title "PutImage test Image Number Sheet" ' b+ 2021-10-20
  2.  
  3. Screen _NewImage(800, 600, 32) '
  4. _Delay .25
  5.  
  6. ' make sample image
  7. snap& = _NewImage(_Width, _Height, 32)
  8. For r = 20 To _Width / 1.5 Step 20
  9.     Circle (_Width / 2, _Height / 2), r
  10. For i = 1 To _Width * _Height * .00035
  11.     Line (Rnd * _Width, Rnd * _Height)-Step(Rnd * 50, Rnd * 50), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255, Rnd * 255), BF
  12. _PutImage , 0, snap&
  13. Print "Here is Image sheet,    zzz."
  14. _PutImage , snap&, 0
  15. cellWidth = _Width / 10
  16. cellHeight = _Height / 10
  17. For i = 0 To _Width Step cellWidth
  18.     Line (i, 0)-(i, _Height - 1)
  19. For i = 0 To _Height Step cellHeight
  20.     Line (0, i)-(_Width - 1, i)
  21. i = 0
  22. For r = 0 To 9
  23.     For c = 0 To 9
  24.         _PrintString (c * cellWidth + 20, r * cellHeight + 20), _Trim$(Str$(i))
  25.         i = i + 1
  26.     Next
  27. Print "Here is sheet divided into image cells with Image Numbers,  zzz"
  28. snapCopy& = _CopyImage(snap&)
  29. _SetAlpha 20, , snapCopy&
  30. _PutImage , snapCopy&, 0
  31. For i = 1 To 100
  32.     rcell = Int(Rnd * 100)
  33.     row = Int(rcell / 10)
  34.     col = rcell Mod 10
  35.     _PutImage (col * cellWidth, row * cellHeight)-Step(cellWidth, cellHeight), snap&, 0, (col * cellWidth, row * cellHeight)-Step(cellWidth, cellHeight)
  36.     Locate 1, 1: Print "Here is 100 randomly chosen image numbers from image. Newest random cell #"; _Trim$(Str$(rcell))
  37.     _Delay 1.5
  38.     _PrintString (col * cellWidth + 20, row * cellHeight + 20), _Trim$(Str$(rcell))
  39.     _Delay 1.5
  40.  




Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #8 on: October 20, 2021, 08:13:09 pm »
Ahh I see.  That will be very useful.  Cool snippet. Thank you!

- Dav

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #9 on: October 20, 2021, 08:23:29 pm »
I get what it does, it's just a lot of parameters to "see" at once. All this stuff gets a lot more intuitive once a person has put several coding projects together. Hell, I'm even getting used to putting up with _PUTSTRING.

Nice demo, but _delay 1.5, RU flocking kidding me. .1. I'm old, but I'm not dead... wait, let me check... yep, there's a pulse, sort of.

Pet^V^V______e
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: QB64 Surabikku-like puzzle.
« Reply #10 on: October 23, 2021, 09:57:08 pm »
Quote
It's harder to pronounce the puzzle name probably.

Soo-rah-beak-oo.  Japanese has similar vowels to Spanish, and when you see a double-consonant, you jump to that consonant quicker.  It's the romaji (english characters) representation of the Japanese small "tsu."

The method bplus describes is pretty much how my sprite sheet slicer routine works.  One big image, and the routine goes through and hunts for detector pixels and stores where each sprite is, then you just store the reference for the sprite in each object, and when you go to draw, you can call up the location of the sprite from the object's data.