Author Topic: Game board/ crosscut and flip SUB  (Read 130 times)

0 Members and 1 Guest are viewing this topic.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 411
Game board/ crosscut and flip SUB
« on: January 13, 2021, 10:43:41 PM »
Back when I was a young lad endeavoring to put an eye out with sharp tools, I made a chessboard in wood shop. It was a disaster, given that I didn't make sufficient allowance for saw kerfs. However, it did show me how it was done.

So I reasoned that I could do it the same way with QB64. Start with two desired images. Saw out 8 alternating strips, glue them together, crosscut them and flip every other crosscut strip. It gives a somewhat natural variation in the board, such as might be expected by the manufacturing process. Best of all, no saw kerf allowances. You can substitute black marble and strawberry tapioca if you have a mind to. Try that on a table saw...

Code: QB64: [Select]
  1. 'Make Chess/Checker Board Demo
  2. DIM SHARED scr&
  3. lite& = _LOADIMAGE("litewood.jpg", 32)
  4. dark& = _LOADIMAGE("darkwood.jpg", 32)
  5. scr& = _NEWIMAGE(640, 640, 32)
  6. SCREEN scr&
  7. x = 0
  8.     x = x + 1
  9.     IF x MOD 2 = 0 THEN
  10.         Make_Board lite&, dark&
  11.     ELSE
  12.         Make_Board dark&, lite&
  13.     END IF
  14.     SLEEP
  15.  
  16. SUB Make_Board (im1 AS LONG, im2 AS LONG)
  17.  
  18.     DIM b(3) AS LONG
  19.     DIM w(3) AS LONG
  20.     DIM crs(3) AS LONG
  21.     DIM tmp AS LONG
  22.     tmp = _COPYIMAGE(scr&) '                                    or make an _newimage of desired size
  23.     widb% = _HEIGHT(im2) / 8: widw% = _HEIGHT(im1) / 8
  24.     IF widb% >= widw% THEN strip% = widw% ELSE strip% = widb%
  25.  
  26.     FOR x = 0 TO 3 '                                            cut and join the vertical strips
  27.         b(x) = _NEWIMAGE(strip%, strip% * 8, 32)
  28.         w(x) = _NEWIMAGE(strip%, strip% * 8, 32)
  29.         _PUTIMAGE , im2, b(x), (x * widb%, 0)-(x * widb% + widb% - 1, _HEIGHT(b(x)) - 1)
  30.         _PUTIMAGE , im1, w(x), (x * widw%, 0)-(x * widw% + widw% - 1, _HEIGHT(w(x)) - 1)
  31.         _PUTIMAGE (x * (_WIDTH(tmp) / 4), 0)-(x * (_WIDTH(tmp) / 4) + _WIDTH(tmp) / 8 - 1, _HEIGHT(tmp) - 1), b(x), tmp
  32.         _PUTIMAGE (x * (_WIDTH(tmp) / 4) + _WIDTH(tmp) / 8, 0)-((x + 1) * (_WIDTH(tmp) / 4) - 1, _HEIGHT(tmp) - 1), w(x), tmp
  33.         _FREEIMAGE b(x): _FREEIMAGE w(x)
  34.     NEXT x
  35.     FOR x = 0 TO 3 '                                            crosscut, flip and join alternating horizontal strips
  36.         crs(x) = _NEWIMAGE(_WIDTH(tmp), _WIDTH(tmp) / 8, 32)
  37.         _PUTIMAGE , tmp, crs(x), (_WIDTH(tmp) - 1, x * (_HEIGHT(tmp) / 4) + (_HEIGHT(tmp) / 8))-(0, x * (_HEIGHT(tmp) / 4))
  38.         _PUTIMAGE (0, x * (_HEIGHT(tmp) / 4)), crs(x), tmp
  39.         _FREEIMAGE crs(x)
  40.     NEXT x
  41.     _PUTIMAGE , tmp, 0
  42.     _FREEIMAGE tmp
  43.  
  44. END SUB 'Make_Board
  45.  

 
 
Andy

Offline SierraKen

  • Forum Resident
  • Posts: 1300
Re: Game board/ crosscut and flip SUB
« Reply #1 on: January 14, 2021, 12:01:58 AM »
WOW!!!! That is so cool OldMoses! Someone could either add a chess or checkers game to it (even a 2 player would be really cool). Or they could print it out and play right on the paper. :D
This reminds me of the chess board I made when I was staying at a head injury rehab center in 1992. Except I didn't make one like this, instead I glued square ceramic tiles to a piece of plywood. I didn't have it for long though, it took up a lot of room and I didn't use it much. I really hope someone makes a game out of yours.

Offline SierraKen

  • Forum Resident
  • Posts: 1300
Re: Game board/ crosscut and flip SUB
« Reply #2 on: January 14, 2021, 12:04:13 AM »
I see yours switches dark to light and light to dark when you press a key. :)

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 980
  • Savage
    • WFBarnes
Re: Game board/ crosscut and flip SUB
« Reply #3 on: January 14, 2021, 02:41:04 AM »
Nice work. All diced up like that, I can barely see the watermark on the images anymore!
1) Get it to work.
2) Make the code beautiful.
3) Optimize.

Offline Pete

  • Forum Resident
  • Posts: 2313
  • Cuz I sez so, varmint!
Re: Game board/ crosscut and flip SUB
« Reply #4 on: January 14, 2021, 02:49:24 AM »
Sure, it's all fun and games until for FOR loop loses an i.

Pete

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 411
Re: Game board/ crosscut and flip SUB
« Reply #5 on: January 14, 2021, 07:15:17 AM »
Nice work. All diced up like that, I can barely see the watermark on the images anymore!

My old peepers didn't see them until you pointed them out. I could have put an i out... LOL

Another thing I didn't catch;--- until I was singing in the shower about a half hour after posting, --- since I am freeing the images within the loop, the arrays are completely extraneous. Revised code works the same.

Code: QB64: [Select]
  1. 'Make Chess/Checker Board Demo
  2. DIM SHARED scr&
  3. lite& = _LOADIMAGE("litewood.jpg", 32)
  4. dark& = _LOADIMAGE("darkwood.jpg", 32)
  5. scr& = _NEWIMAGE(640, 640, 32)
  6. SCREEN scr&
  7. x = 0
  8.     x = x + 1
  9.     IF x MOD 2 = 0 THEN
  10.         Make_Board lite&, dark&
  11.     ELSE
  12.         Make_Board dark&, lite&
  13.     END IF
  14.     SLEEP
  15.  
  16. SUB Make_Board (im1 AS LONG, im2 AS LONG)
  17.  
  18.     DIM b, w, crs, tmp AS LONG
  19.     tmp = _COPYIMAGE(scr&) '                                    or make an _newimage of desired size
  20.     widb% = _HEIGHT(im2) / 8: widw% = _HEIGHT(im1) / 8
  21.     IF widb% >= widw% THEN strip% = widw% ELSE strip% = widb%
  22.  
  23.     FOR x = 0 TO 3 '                                            cut and join the vertical strips
  24.         b = _NEWIMAGE(strip%, strip% * 8, 32)
  25.         w = _NEWIMAGE(strip%, strip% * 8, 32)
  26.         _PUTIMAGE , im2, b, (x * widb%, 0)-(x * widb% + widb% - 1, _HEIGHT(b) - 1)
  27.         _PUTIMAGE , im1, w, (x * widw%, 0)-(x * widw% + widw% - 1, _HEIGHT(w) - 1)
  28.         _PUTIMAGE (x * (_WIDTH(tmp) / 4), 0)-(x * (_WIDTH(tmp) / 4) + _WIDTH(tmp) / 8 - 1, _HEIGHT(tmp) - 1), b, tmp
  29.         _PUTIMAGE (x * (_WIDTH(tmp) / 4) + _WIDTH(tmp) / 8, 0)-((x + 1) * (_WIDTH(tmp) / 4) - 1, _HEIGHT(tmp) - 1), w, tmp
  30.         _FREEIMAGE b: _FREEIMAGE w
  31.     NEXT x
  32.     FOR x = 0 TO 3 '                                            crosscut, flip and join alternating horizontal strips
  33.         crs = _NEWIMAGE(_WIDTH(tmp), _WIDTH(tmp) / 8, 32)
  34.         _PUTIMAGE , tmp, crs, (_WIDTH(tmp) - 1, x * (_HEIGHT(tmp) / 4) + (_HEIGHT(tmp) / 8))-(0, x * (_HEIGHT(tmp) / 4))
  35.         _PUTIMAGE (0, x * (_HEIGHT(tmp) / 4)), crs, tmp
  36.         _FREEIMAGE crs
  37.     NEXT x
  38.     _PUTIMAGE , tmp, 0
  39.     _FREEIMAGE tmp
  40.  
  41. END SUB 'Make_Board
Andy