Author Topic: hangman64  (Read 6626 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
hangman64
« on: October 06, 2020, 08:12:25 pm »
This is a conversion of Hangman, that I wrote back in 2016, with sdlbasic. I spent the better part of yesterday converting it. (A day, you may ask. My... keyboard is very slow... lol )

Thanks to the guys here, the 'problems' that I experienced, have been solved.

It is far from finished; the coding is a bit sloppy... ok. a lot...; there maybe a few bugs but it's playable.

The sdlbasic version used the mouse for input. Converting to QB64 caused the 'cursor' to be drawn as the mouse moved. Still working on that... Just use the keyboard... As "Scotty" in Star Trev 4: The Journey home, replied when instructed to use the keyboard, "The keyboard. How quaint."

Any constructive criticism or modifications would be highly appreciated...

J
* hangman64.zip (Filesize: 6.94 MB, Downloads: 271)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: hangman64
« Reply #1 on: October 06, 2020, 08:41:44 pm »
Very nice @johnno56 love that opening scene!

Mouse should be easy to work in.

poll it in main loop:
Code: QB64: [Select]
  1. mx = _MOUSEX : my = _MOUSEY : mb = _MOUSEBUTTON(1) 'left click

Then you know routine to check for mb (click) and translate mx, my to see if on a letter box.

Once you have a letter box just call the keyhit routine you have written already just translate letter clicked to a keyhit number.
« Last Edit: October 06, 2020, 09:23:26 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: hangman64
« Reply #2 on: October 06, 2020, 10:17:28 pm »
Thanks.

Mouse: Yep. Tried that before using the keyboard. Mouse functioned perfectly. But, when I "put" the cursor (gun) at mx and my, the gun was placed on the screen like a "mouse trail". The "do...loop" that contains the "letter section" routine, does not clear the screen, hence the "trail". No big deal... I will keep working on it...

Sdlbasic uses "mousezone()" to 'create' a box around the letter. Much like an AABB routine. Which can be used in conjunction with a _hitkey() and as you said, everything else is there...

The "word" list is quite limited (testing) at the moment. The "dashes" and "font" kind of limit the number of letters for each word. Adding more is quite easy. I have a much bigger list that I can use once the game is working properly.

Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: hangman64
« Reply #3 on: October 06, 2020, 10:50:33 pm »
This sets up snap which we will use to store image of the screen while game progresses
Code: QB64: [Select]
  1. DIM snap AS LONG
  2. snap = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' take pictures of game as it progresses
  3.  

This takes a snap shot of screen before start of main loop and before each re-loop around right after _DISPLAY:
Code: QB64: [Select]
  1.     _PUTIMAGE , 0, snap  'screen to snapshot
  2.  

This will "CLS" screen with snap shot right after first DO of inner loop
Code: QB64: [Select]
  1.         _PUTIMAGE , snap, 0  ' snap shot to screen
  2.         _MOUSESHOW
  3.  


Now you can move mouse around without making a mess.

All your letters are evenly spaced between two y heights.

Just take mouse x subtract off where letters start x, divide by letter box width see that click isn't past z = 26

Code: QB64: [Select]
  1.             '   Mouse "cursor"?
  2.             WHILE _MOUSEINPUT: WEND
  3.             mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  4.             'LOCATE 10, 5: PRINT mx, my
  5.             '_DISPLAY
  6.             IF mb THEN
  7.                 IF my >= 700 AND my <= 736 THEN
  8.                     'BEEP
  9.                     test = INT((mx - 44) / 36) + 1
  10.                     'LOCATE 11, 5: PRINT test
  11.                     '_DISPLAY
  12.                     IF test > 0 AND test < 27 THEN 'good click
  13.                         choose = 96 + test
  14.                     END IF
  15.                 END IF
  16.             END IF

That's better than 26 zone tests!

Code: QB64: [Select]
  1. '       HANGMAN
  2. '
  3. '   Johnno56 15-Dec-16
  4. '   (sdlbasic version)
  5. '
  6. '   07-Oct-20 QB64   w/mouse bplus
  7. '
  8. xmax = 1024
  9. ymax = 768
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _DELAY .25
  12.  
  13.  
  14. words = 295
  15.  
  16. DIM SHARED wordlist$(words)
  17. DIM SHARED letter(26)
  18. DIM SHARED chosen(26)
  19. DIM SHARED font50
  20. 'DIM SHARED choose AS INTEGER
  21.  
  22. a$ = ""
  23.  
  24. '
  25. '   Load graphics
  26. '
  27. intro = _LOADIMAGE("assets/title.png")
  28. gallowsbase = _LOADIMAGE("assets/base-closed.png")
  29. upright = _LOADIMAGE("assets/upright.png")
  30. support1 = _LOADIMAGE("assets/support1.png")
  31. support2 = _LOADIMAGE("assets/support2.png")
  32. support3 = _LOADIMAGE("assets/support3.png")
  33. beam = _LOADIMAGE("assets/beam.png")
  34. bolts = _LOADIMAGE("assets/bolts.png")
  35. rope = _LOADIMAGE("assets/ropesupport.png")
  36. victim1 = _LOADIMAGE("assets/victim1.png")
  37. victim2 = _LOADIMAGE("assets/victim2.png")
  38. hole = _LOADIMAGE("assets/hole.png")
  39. bground = _LOADIMAGE("assets/bground.png")
  40. grid = _LOADIMAGE("assets/grid.png")
  41. gameover = _LOADIMAGE("assets/gameover.png")
  42. welldone = _LOADIMAGE("assets/welldone.png")
  43. guessed = _LOADIMAGE("assets/x.png")
  44. cursor = _LOADIMAGE("assets/gun.png")
  45. yes = _LOADIMAGE("assets/y.png")
  46. no = _LOADIMAGE("assets/n.png")
  47.  
  48. '
  49. '   Load audio
  50. '
  51. ropestretch = _SNDOPEN("assets/rope.wav")
  52. choke = _SNDOPEN("assets/choke.wav")
  53. shot = _SNDOPEN("assets/shot.wav")
  54. click = _SNDOPEN("assets/click.wav")
  55. clunk = _SNDOPEN("assets/clunk.wav")
  56.  
  57. music = _SNDOPEN("assets/goodbadugly.wav")
  58.  
  59. '
  60. '   Load Fonts
  61. '
  62. font35 = _LOADFONT("assets/rubicmono.ttf", 35)
  63. font50 = _LOADFONT("assets/rubicmono.ttf", 50)
  64.  
  65. count = 0
  66.  
  67.  
  68. ' select word from array (or external file?)
  69.  
  70. filename$ = "assets/words.txt"
  71.  
  72. OPEN filename$ FOR INPUT AS #1
  73. count = 1
  74.     INPUT #1, wordlist$(count)
  75.     count = count + 1
  76.  
  77. yellow = _RGB32(255, 255, 0)
  78. blue = _RGB32(0, 0, 255)
  79. green = _RGB32(0, 255, 0)
  80. red = _RGB32(255, 0, 0)
  81. white = _RGB32(255, 255, 255)
  82. black = _RGB32(0, 0, 0)
  83.  
  84. again = 1
  85. i = 0.1
  86.  
  87. '
  88. '   Title screen - here
  89. '
  90. _PUTIMAGE (0, 0), intro
  91. _SNDPLAY (shot)
  92. _PUTIMAGE (627, 9), hole
  93.  
  94. '
  95. '   Start game loop here
  96. '
  97. DIM snap AS LONG
  98. snap = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' take pictures of game as it progresses
  99.  
  100. WHILE 0 = 0
  101.     CLS
  102.     _PUTIMAGE (0, 0), bground
  103.  
  104.     wordtoguess$ = wordlist$(INT(RND * (count - 1)))
  105.     'print wordtoguess$
  106.     numberoftries = 0
  107.     FOR x = 1 TO 26
  108.         letter(x) = 0
  109.     NEXT
  110.  
  111.     '
  112.     '   Display empty word and letter grid
  113.     '
  114.     FOR dash = 1 TO LEN(wordtoguess$)
  115.         LINE (460 + (dash * 50), 380)-STEP(40, 4), black, BF
  116.     NEXT
  117.  
  118.     _PUTIMAGE (44, 700), grid
  119.     _DISPLAY
  120.  
  121.     counter = 0
  122.  
  123.     '
  124.     '   Letter guess routine - try for mouse input?
  125.     '
  126.  
  127.     '   Clear "chosen" array
  128.     '
  129.     FOR x = 1 TO 26
  130.         chosen(x) = 0
  131.     NEXT
  132.     choose = 0
  133.     '   wait(100)
  134.  
  135.     _SNDVOL music, i
  136.     _SNDLOOP (music)
  137.  
  138.  
  139.     _PUTIMAGE , 0, snap
  140.  
  141.     DO
  142.         foundletter = 0
  143.  
  144.         '
  145.         '   Keyboard (or mouse) selection of letters to guess
  146.         '
  147.  
  148.         DO
  149.             _PUTIMAGE , snap, 0
  150.             _MOUSESHOW
  151.  
  152.  
  153.             choose = 0
  154.             '
  155.             '   Mouse "cursor"?
  156.             WHILE _MOUSEINPUT: WEND
  157.             mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  158.             'LOCATE 10, 5: PRINT mx, my
  159.             '_DISPLAY
  160.             IF mb THEN
  161.                 IF my >= 700 AND my <= 736 THEN
  162.                     'BEEP
  163.                     test = INT((mx - 44) / 36) + 1
  164.                     'LOCATE 11, 5: PRINT test
  165.                     '_DISPLAY
  166.                     IF test > 0 AND test < 27 THEN 'good click
  167.                         choose = 96 + test
  168.                     END IF
  169.                 END IF
  170.             END IF
  171.  
  172.             '
  173.  
  174.             IF choose = 0 THEN choose = _KEYHIT
  175.  
  176.             IF choose = 97 AND chosen(1) = 0 THEN
  177.                 _SNDPLAY (click)
  178.                 a$ = "A"
  179.                 chosen(1) = 1
  180.                 _PUTIMAGE (44, 700), guessed
  181.                 EXIT DO
  182.             END IF
  183.             IF choose = 98 AND chosen(2) = 0 THEN
  184.                 _SNDPLAY (click)
  185.                 a$ = "B"
  186.                 chosen(2) = 1
  187.                 _PUTIMAGE (80, 700), guessed
  188.                 EXIT DO
  189.             END IF
  190.             IF choose = 99 AND chosen(3) = 0 THEN
  191.                 _SNDPLAY (click)
  192.                 a$ = "C"
  193.                 chosen(3) = 1
  194.                 _PUTIMAGE (116, 700), guessed
  195.                 EXIT DO
  196.             END IF
  197.             IF choose = 100 AND chosen(4) = 0 THEN
  198.                 _SNDPLAY (click)
  199.                 a$ = "D"
  200.                 chosen(4) = 1
  201.                 _PUTIMAGE (152, 700), guessed
  202.                 EXIT DO
  203.             END IF
  204.             IF choose = 101 AND chosen(5) = 0 THEN
  205.                 _SNDPLAY (click)
  206.                 a$ = "E"
  207.                 chosen(5) = 1
  208.                 _PUTIMAGE (188, 700), guessed
  209.                 EXIT DO
  210.             END IF
  211.             IF choose = 102 AND chosen(6) = 0 THEN
  212.                 _SNDPLAY (click)
  213.                 a$ = "F"
  214.                 chosen(6) = 1
  215.                 _PUTIMAGE (224, 700), guessed
  216.                 EXIT DO
  217.             END IF
  218.             IF choose = 103 AND chosen(7) = 0 THEN
  219.                 _SNDPLAY (click)
  220.                 a$ = "G"
  221.                 chosen(7) = 1
  222.                 _PUTIMAGE (260, 700), guessed
  223.                 EXIT DO
  224.             END IF
  225.             IF choose = 104 AND chosen(8) = 0 THEN
  226.                 _SNDPLAY (click)
  227.                 a$ = "H"
  228.                 chosen(8) = 1
  229.                 _PUTIMAGE (296, 700), guessed
  230.                 EXIT DO
  231.             END IF
  232.             IF choose = 105 AND chosen(9) = 0 THEN
  233.                 _SNDPLAY (click)
  234.                 a$ = "I"
  235.                 chosen(9) = 1
  236.                 _PUTIMAGE (332, 700), guessed
  237.                 EXIT DO
  238.             END IF
  239.             IF choose = 106 AND chosen(10) = 0 THEN
  240.                 _SNDPLAY (click)
  241.                 a$ = "J"
  242.                 chosen(10) = 1
  243.                 _PUTIMAGE (368, 700), guessed
  244.                 EXIT DO
  245.             END IF
  246.             IF choose = 107 AND chosen(11) = 0 THEN
  247.                 _SNDPLAY (click)
  248.                 a$ = "K"
  249.                 chosen(11) = 1
  250.                 _PUTIMAGE (404, 700), guessed
  251.                 EXIT DO
  252.             END IF
  253.             IF choose = 108 AND chosen(12) = 0 THEN
  254.                 _SNDPLAY (click)
  255.                 a$ = "L"
  256.                 chosen(12) = 1
  257.                 _PUTIMAGE (440, 700), guessed
  258.                 EXIT DO
  259.             END IF
  260.             IF choose = 109 AND chosen(13) = 0 THEN
  261.                 _SNDPLAY (click)
  262.                 a$ = "M"
  263.                 chosen(13) = 1
  264.                 _PUTIMAGE (476, 700), guessed
  265.                 EXIT DO
  266.             END IF
  267.             IF choose = 110 AND chosen(14) = 0 THEN
  268.                 _SNDPLAY (click)
  269.                 a$ = "N"
  270.                 chosen(14) = 1
  271.                 _PUTIMAGE (512, 700), guessed
  272.                 EXIT DO
  273.             END IF
  274.             IF choose = 111 AND chosen(15) = 0 THEN
  275.                 _SNDPLAY (click)
  276.                 a$ = "O"
  277.                 chosen(15) = 1
  278.                 _PUTIMAGE (548, 700), guessed
  279.                 EXIT DO
  280.             END IF
  281.             IF choose = 112 AND chosen(16) = 0 THEN
  282.                 _SNDPLAY (click)
  283.                 a$ = "P"
  284.                 chosen(16) = 1
  285.                 _PUTIMAGE (584, 700), guessed
  286.                 EXIT DO
  287.             END IF
  288.             IF choose = 113 AND chosen(17) = 0 THEN
  289.                 _SNDPLAY (click)
  290.                 a$ = "Q"
  291.                 chosen(17) = 1
  292.                 _PUTIMAGE (620, 700), guessed
  293.                 EXIT DO
  294.             END IF
  295.             IF choose = 114 AND chosen(18) = 0 THEN
  296.                 _SNDPLAY (click)
  297.                 a$ = "R"
  298.                 chosen(18) = 1
  299.                 _PUTIMAGE (656, 700), guessed
  300.                 EXIT DO
  301.             END IF
  302.             IF choose = 115 AND chosen(19) = 0 THEN
  303.                 _SNDPLAY (click)
  304.                 a$ = "S"
  305.                 chosen(19) = 1
  306.                 _PUTIMAGE (692, 700), guessed
  307.                 EXIT DO
  308.             END IF
  309.             IF choose = 116 AND chosen(20) = 0 THEN
  310.                 _SNDPLAY (click)
  311.                 a$ = "T"
  312.                 chosen(20) = 1
  313.                 _PUTIMAGE (728, 700), guessed
  314.                 EXIT DO
  315.             END IF
  316.             IF choose = 117 AND chosen(21) = 0 THEN
  317.                 _SNDPLAY (click)
  318.                 a$ = "U"
  319.                 chosen(21) = 1
  320.                 _PUTIMAGE (764, 700), guessed
  321.                 EXIT DO
  322.             END IF
  323.             IF choose = 118 AND chosen(22) = 0 THEN
  324.                 _SNDPLAY (click)
  325.                 a$ = "V"
  326.                 chosen(22) = 1
  327.                 _PUTIMAGE (800, 700), guessed
  328.                 EXIT DO
  329.             END IF
  330.             IF choose = 119 AND chosen(23) = 0 THEN
  331.                 _SNDPLAY (click)
  332.                 a$ = "W"
  333.                 chosen(23) = 1
  334.                 _PUTIMAGE (836, 700), guessed
  335.                 EXIT DO
  336.             END IF
  337.             IF choose = 120 AND chosen(24) = 0 THEN
  338.                 _SNDPLAY (click)
  339.                 a$ = "X"
  340.                 chosen(24) = 1
  341.                 _PUTIMAGE (872, 700), guessed
  342.                 EXIT DO
  343.             END IF
  344.             IF choose = 121 AND chosen(25) = 0 THEN
  345.                 _SNDPLAY (click)
  346.                 a$ = "Y"
  347.                 chosen(25) = 1
  348.                 _PUTIMAGE (908, 700), guessed
  349.                 EXIT DO
  350.             END IF
  351.             IF choose = 122 AND chosen(26) = 0 THEN
  352.                 _SNDPLAY (click)
  353.                 a$ = "Z"
  354.                 chosen(26) = 1
  355.                 _PUTIMAGE (944, 700), guessed
  356.                 EXIT DO
  357.             END IF
  358.  
  359.             IF ky = 27 THEN
  360.                 _DELAY 2
  361.                 CLS
  362.                 END
  363.             END IF
  364.  
  365.             _DISPLAY
  366.             _LIMIT 100
  367.         LOOP
  368.         _SNDPLAY (click)
  369.  
  370.         SELECT CASE UCASE$(a$)
  371.             CASE "A" TO "Z"
  372.                 '
  373.                 '   Correct letter routine
  374.                 '
  375.                 IF letter(ASC(a$) - 64) = 0 THEN
  376.                     COLOR blue
  377.                     _FONT (font35)
  378.                     FOR x = 1 TO LEN(wordtoguess$)
  379.                         IF UCASE$(MID$(wordtoguess$, x, 1)) = a$ THEN
  380.                             _PRINTSTRING (465 + (x * 50), 330), a$
  381.                             counter = counter + 1
  382.                             foundletter = 1
  383.                         END IF
  384.                     NEXT
  385.                     '
  386.                     '   Not so correct letter routine
  387.                     '
  388.                     IF foundletter = 0 THEN
  389.                         numberoftries = numberoftries + 1
  390.                         '
  391.                         '   Build gallows routine?
  392.                         '
  393.                         IF numberoftries = 1 THEN
  394.                             _PUTIMAGE (70, 505), gallowsbase
  395.                         END IF
  396.                         IF numberoftries = 2 THEN
  397.                             _PUTIMAGE (146, 154), upright
  398.                         END IF
  399.                         IF numberoftries = 3 THEN
  400.                             _PUTIMAGE (125, 461), support1
  401.                         END IF
  402.                         IF numberoftries = 4 THEN
  403.                             _PUTIMAGE (184, 523), support2
  404.                         END IF
  405.                         IF numberoftries = 5 THEN
  406.                             _PUTIMAGE (229, 501), support3
  407.                         END IF
  408.                         IF numberoftries = 6 THEN
  409.                             _PUTIMAGE (116, 134), beam
  410.                         END IF
  411.                         IF numberoftries = 7 THEN
  412.                             _PUTIMAGE (155, 170), bolts
  413.                         END IF
  414.                         IF numberoftries = 8 THEN
  415.                             _PUTIMAGE (209, 140), rope
  416.                         END IF
  417.                         IF numberoftries = 9 THEN
  418.                             _PUTIMAGE (331, 269), victim1
  419.                         END IF
  420.                         IF numberoftries = 10 THEN
  421.                             _SNDPLAY (ropestretch)
  422.                             _SNDPLAY (choke)
  423.                             _PUTIMAGE (331, 269), victim2
  424.                         END IF
  425.                     END IF
  426.                     letter(ASC(a$) - 64) = -1
  427.                 END IF
  428.  
  429.                 _DISPLAY
  430.         END SELECT
  431.         '
  432.         '   Check for finished game?
  433.         '
  434.         IF counter = LEN(wordtoguess$) OR numberoftries = 10 THEN
  435.             EXIT DO
  436.         END IF
  437.  
  438.         _DISPLAY
  439.         _MOUSEHIDE
  440.         _PUTIMAGE , 0, snap
  441.  
  442.         _LIMIT 100
  443.     LOOP
  444.  
  445.     _DELAY 3
  446.  
  447.     '
  448.     '   Winner routine
  449.     '
  450.     IF counter = LEN(wordtoguess$) THEN
  451.         _PUTIMAGE (170, 200), welldone
  452.         _DISPLAY
  453.         _DELAY 3
  454.         CLS
  455.         _DISPLAY
  456.         playagain
  457.         IF a$ = "N" THEN
  458.             _SNDPLAY (click)
  459.             a$ = ""
  460.             _DELAY 1
  461.             CLS
  462.             _PUTIMAGE (0, 0), gameover
  463.             _DISPLAY
  464.             _DELAY 4
  465.             SYSTEM
  466.         END IF
  467.         IF a$ = "Y" THEN
  468.             _SNDPLAY (click)
  469.             a$ = ""
  470.             _DELAY 0.2
  471.             CLS
  472.             _PUTIMAGE (0, 0), bground
  473.             _DISPLAY
  474.         END IF
  475.     ELSE
  476.         '
  477.         '   Loser routine
  478.         '
  479.         FOR x = 1 TO LEN(wordtoguess$)
  480.             a$ = UCASE$(MID$(wordtoguess$, x, 1))
  481.             COLOR red
  482.             _FONT (font35)
  483.             _PRINTSTRING (465 + (x * 50), 330), a$
  484.             _DISPLAY
  485.         NEXT
  486.         _DELAY 4
  487.         CLS
  488.         playagain
  489.         IF a$ = "Y" THEN
  490.             _SNDPLAY (click)
  491.             a$ = ""
  492.             CLS
  493.             _PUTIMAGE (0, 0), bground
  494.             _DISPLAY
  495.         END IF
  496.         IF a$ = "N" THEN
  497.             _SNDPLAY (click)
  498.             a$ = ""
  499.             CLS
  500.             _PUTIMAGE (0, 0), gameover
  501.             _DISPLAY
  502.             _DELAY 3
  503.             CLS
  504.             _DISPLAY
  505.             _DELAY 1
  506.             SYSTEM
  507.         END IF
  508.     END IF
  509.  
  510.     IF INKEY$ = CHR$(27) THEN
  511.         END
  512.     END IF
  513.  
  514.     _DISPLAY
  515.     _LIMIT 100
  516.  
  517. '====================================================
  518. SUB playagain
  519.     a$ = ""
  520.     yn = 0
  521.     CLS
  522.     _PUTIMAGE (0, 0), bground
  523.     _DISPLAY
  524.     COLOR blue
  525.     _FONT (font50)
  526.     WHILE yn <> 121 AND yn <> 110
  527.         yn = _KEYHIT
  528.         _PRINTSTRING (250, 650), "Again Y or N"
  529.         IF yn = 121 THEN
  530.             a$ = "Y"
  531.             FOR x = 1 TO 26
  532.                 chosen(x) = 0
  533.             NEXT
  534.             choose = 0
  535.             _DELAY 1
  536.         ELSEIF yn = 110 THEN
  537.             a$ = "N"
  538.         END IF
  539.         _DISPLAY
  540.     WEND
  541.  
  542.  

Need to find the loop that is making the CPU run hot, I have tried 2 _LIMITs of 100 and still the fan is running.

Update: found it, 3's a charm :) running quiet now.
« Last Edit: October 07, 2020, 01:02:45 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: hangman64
« Reply #4 on: October 07, 2020, 12:51:45 am »
Put the code on a diet:
Code: QB64: [Select]
  1. '       HANGMAN
  2. '
  3. '   Johnno56 15-Dec-16
  4. '   (sdlbasic version)
  5. '
  6. '   07-Oct-20 QB64   w/mouse bplus  cut some lines of code
  7. '
  8. xmax = 1024
  9. ymax = 768
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _DELAY .25
  12.  
  13.  
  14. words = 295
  15.  
  16. DIM SHARED wordlist$(words)
  17. DIM SHARED letter(26)
  18. DIM SHARED chosen(26)
  19. DIM SHARED font50
  20. 'DIM SHARED choose AS INTEGER
  21.  
  22. a$ = ""
  23.  
  24. '
  25. '   Load graphics
  26. '
  27. intro = _LOADIMAGE("assets/title.png")
  28. gallowsbase = _LOADIMAGE("assets/base-closed.png")
  29. upright = _LOADIMAGE("assets/upright.png")
  30. support1 = _LOADIMAGE("assets/support1.png")
  31. support2 = _LOADIMAGE("assets/support2.png")
  32. support3 = _LOADIMAGE("assets/support3.png")
  33. beam = _LOADIMAGE("assets/beam.png")
  34. bolts = _LOADIMAGE("assets/bolts.png")
  35. rope = _LOADIMAGE("assets/ropesupport.png")
  36. victim1 = _LOADIMAGE("assets/victim1.png")
  37. victim2 = _LOADIMAGE("assets/victim2.png")
  38. hole = _LOADIMAGE("assets/hole.png")
  39. bground = _LOADIMAGE("assets/bground.png")
  40. grid = _LOADIMAGE("assets/grid.png")
  41. gameover = _LOADIMAGE("assets/gameover.png")
  42. welldone = _LOADIMAGE("assets/welldone.png")
  43. guessed = _LOADIMAGE("assets/x.png")
  44. cursor = _LOADIMAGE("assets/gun.png")
  45. yes = _LOADIMAGE("assets/y.png")
  46. no = _LOADIMAGE("assets/n.png")
  47.  
  48. '
  49. '   Load audio
  50. '
  51. ropestretch = _SNDOPEN("assets/rope.wav")
  52. choke = _SNDOPEN("assets/choke.wav")
  53. shot = _SNDOPEN("assets/shot.wav")
  54. click = _SNDOPEN("assets/click.wav")
  55. clunk = _SNDOPEN("assets/clunk.wav")
  56.  
  57. music = _SNDOPEN("assets/goodbadugly.wav")
  58.  
  59. '
  60. '   Load Fonts
  61. '
  62. font35 = _LOADFONT("assets/rubicmono.ttf", 35)
  63. font50 = _LOADFONT("assets/rubicmono.ttf", 50)
  64.  
  65. ' select word from array (or external file?)
  66.  
  67. filename$ = "assets/words.txt"
  68.  
  69. OPEN filename$ FOR INPUT AS #1
  70. count = 1
  71.     INPUT #1, wordlist$(count)
  72.     count = count + 1
  73.  
  74. blue = _RGB32(0, 0, 255)
  75. red = _RGB32(255, 0, 0)
  76. black = _RGB32(0, 0, 0)
  77.  
  78. again = 1
  79. i = 0.1
  80.  
  81. '
  82. '   Title screen - here
  83. '
  84. _PUTIMAGE (0, 0), intro
  85. _SNDPLAY (shot)
  86. _PUTIMAGE (627, 9), hole
  87.  
  88. '
  89. '   Start game loop here
  90. '
  91. DIM snap AS LONG
  92. snap = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' take pictures of game as it progresses
  93.  
  94. WHILE 0 = 0
  95.     CLS
  96.     _PUTIMAGE (0, 0), bground
  97.  
  98.     wordtoguess$ = wordlist$(INT(RND * (count - 1)))
  99.     'print wordtoguess$
  100.     numberoftries = 0
  101.     FOR x = 1 TO 26
  102.         letter(x) = 0
  103.     NEXT
  104.  
  105.     '
  106.     '   Display empty word and letter grid
  107.     '
  108.     FOR dash = 1 TO LEN(wordtoguess$)
  109.         LINE (460 + (dash * 50), 380)-STEP(40, 4), black, BF
  110.     NEXT
  111.  
  112.     _PUTIMAGE (44, 700), grid
  113.     _DISPLAY
  114.  
  115.     counter = 0
  116.  
  117.     '
  118.     '   Letter guess routine - try for mouse input?
  119.     '
  120.  
  121.     '   Clear "chosen" array
  122.     '
  123.     FOR x = 1 TO 26
  124.         chosen(x) = 0
  125.     NEXT
  126.     _SNDVOL music, i
  127.     _SNDLOOP (music)
  128.     _PUTIMAGE , 0, snap
  129.     DO
  130.         foundletter = 0
  131.  
  132.         '
  133.         '   Keyboard (or mouse) selection of letters to guess
  134.         '
  135.  
  136.         DO
  137.             _PUTIMAGE , snap, 0
  138.             _MOUSESHOW
  139.             choose = 0
  140.             '
  141.             '   Mouse "cursor"?
  142.             WHILE _MOUSEINPUT: WEND
  143.             mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  144.             'LOCATE 10, 5: PRINT mx, my
  145.             '_DISPLAY
  146.             IF mb THEN
  147.                 IF my >= 700 AND my <= 736 THEN
  148.                     'BEEP
  149.                     test = INT((mx - 44) / 36) + 1
  150.                     'LOCATE 11, 5: PRINT test
  151.                     '_DISPLAY
  152.                     IF test > 0 AND test < 27 THEN 'good click
  153.                         choose = 96 + test
  154.                     END IF
  155.                 END IF
  156.             END IF
  157.  
  158.             ' Check Keypress if not mouse
  159.             IF choose = 0 THEN choose = _KEYHIT
  160.  
  161.             ' Handle choose
  162.             IF choose > 96 AND choose < 123 THEN
  163.                 IF chosen(choose - 96) = 0 THEN
  164.                     a$ = UCASE$(CHR$(choose))
  165.                     chosen(choose - 96) = 1
  166.                     _PUTIMAGE ((choose - 96) * 36 + 8, 700), guessed
  167.                     EXIT DO
  168.                 END IF
  169.             END IF
  170.  
  171.             ' Escape to quit?
  172.             IF ky = 27 THEN
  173.                 _DELAY 2
  174.                 CLS
  175.                 END
  176.             END IF
  177.  
  178.             _DISPLAY
  179.             _LIMIT 100
  180.         LOOP
  181.         _SNDPLAY (click)
  182.  
  183.         '
  184.         '   Correct letter routine
  185.         '
  186.         IF letter(ASC(a$) - 64) = 0 THEN
  187.             COLOR blue
  188.             _FONT (font35)
  189.             FOR x = 1 TO LEN(wordtoguess$)
  190.                 IF UCASE$(MID$(wordtoguess$, x, 1)) = a$ THEN
  191.                     _PRINTSTRING (465 + (x * 50), 330), a$
  192.                     counter = counter + 1
  193.                     foundletter = 1
  194.                 END IF
  195.             NEXT
  196.             '
  197.             '   Not so correct letter routine
  198.             '
  199.             IF foundletter = 0 THEN
  200.                 numberoftries = numberoftries + 1
  201.                 '
  202.                 '   Build gallows routine?
  203.                 '
  204.  
  205.                 SELECT CASE numberoftries
  206.                     CASE 1: _PUTIMAGE (70, 505), gallowsbase
  207.                     CASE 2: _PUTIMAGE (146, 154), upright
  208.                     CASE 3: _PUTIMAGE (125, 461), support1
  209.                     CASE 4: _PUTIMAGE (184, 523), support2
  210.                     CASE 5: _PUTIMAGE (229, 501), support3
  211.                     CASE 6: _PUTIMAGE (116, 134), beam
  212.                     CASE 7: _PUTIMAGE (155, 170), bolts
  213.                     CASE 8: _PUTIMAGE (209, 140), rope
  214.                     CASE 9: _PUTIMAGE (331, 269), victim1
  215.                     CASE 10: _SNDPLAY (ropestretch)
  216.                         _SNDPLAY (choke)
  217.                         _PUTIMAGE (331, 269), victim2
  218.                 END SELECT
  219.             END IF
  220.             letter(ASC(a$) - 64) = -1
  221.         END IF
  222.         _DISPLAY
  223.  
  224.         '
  225.         '   Check for finished game?
  226.         '
  227.         IF counter = LEN(wordtoguess$) OR numberoftries = 10 THEN
  228.             EXIT DO
  229.         END IF
  230.         _DISPLAY
  231.         _MOUSEHIDE
  232.         _PUTIMAGE , 0, snap
  233.         _LIMIT 100
  234.     LOOP
  235.  
  236.     _DELAY 3
  237.  
  238.     '
  239.     '   Winner routine
  240.     '
  241.     IF counter = LEN(wordtoguess$) THEN
  242.         _PUTIMAGE (170, 200), welldone
  243.         _DISPLAY
  244.         _DELAY 3
  245.         CLS
  246.         _DISPLAY
  247.         playagain
  248.         IF a$ = "N" THEN
  249.             _SNDPLAY (click)
  250.             a$ = ""
  251.             _DELAY 1
  252.             CLS
  253.             _PUTIMAGE (0, 0), gameover
  254.             _DISPLAY
  255.             _DELAY 4
  256.             SYSTEM
  257.         END IF
  258.         IF a$ = "Y" THEN
  259.             _SNDPLAY (click)
  260.             a$ = ""
  261.             _DELAY 0.2
  262.             CLS
  263.             _PUTIMAGE (0, 0), bground
  264.             _DISPLAY
  265.         END IF
  266.     ELSE
  267.         '
  268.         '   Loser routine
  269.         '
  270.         FOR x = 1 TO LEN(wordtoguess$)
  271.             a$ = UCASE$(MID$(wordtoguess$, x, 1))
  272.             COLOR red
  273.             _FONT (font35)
  274.             _PRINTSTRING (465 + (x * 50), 330), a$
  275.             _DISPLAY
  276.         NEXT
  277.         _DELAY 4
  278.         CLS
  279.         playagain
  280.         IF a$ = "Y" THEN
  281.             _SNDPLAY (click)
  282.             a$ = ""
  283.             CLS
  284.             _PUTIMAGE (0, 0), bground
  285.             _DISPLAY
  286.         END IF
  287.         IF a$ = "N" THEN
  288.             _SNDPLAY (click)
  289.             a$ = ""
  290.             CLS
  291.             _PUTIMAGE (0, 0), gameover
  292.             _DISPLAY
  293.             _DELAY 3
  294.             CLS
  295.             _DISPLAY
  296.             _DELAY 1
  297.             SYSTEM
  298.         END IF
  299.     END IF
  300.     IF INKEY$ = CHR$(27) THEN END
  301.     _DISPLAY
  302.     _LIMIT 100
  303.  
  304. SUB playagain
  305.     a$ = ""
  306.     yn = 0
  307.     CLS
  308.     _PUTIMAGE (0, 0), bground
  309.     _DISPLAY
  310.     COLOR blue
  311.     _FONT (font50)
  312.     WHILE yn <> 121 AND yn <> 110
  313.         yn = _KEYHIT
  314.         _PRINTSTRING (250, 650), "Again Y or N"
  315.         IF yn = 121 THEN
  316.             a$ = "Y"
  317.             FOR x = 1 TO 26
  318.                 chosen(x) = 0
  319.             NEXT
  320.             choose = 0
  321.             _DELAY 1
  322.         ELSEIF yn = 110 THEN
  323.             a$ = "N"
  324.         END IF
  325.         _DISPLAY
  326.     WEND
  327.  
  328.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: hangman64
« Reply #5 on: October 07, 2020, 06:35:42 am »
Did you manage to complete playing the game (either win or lose)?

I might get about 3 to 6 letter selections and the mouse no longer clicks. But, a couple of times, the program aborts - no errors - just ends. On a rare occasion the mouse will move but will not click.

I did attempt to add the gun "_putimage(mx,my),cursor" and the gun indeed moved with the mouse... But, clicking on a letter, left a copy of the gun when clicked... So I removed it... Well, it worked better than how I coded it... lol

It's not all 'gloom and doom'. After all... You did get the mouse working and reduced the size of program...

I have attached the original sdlbasic version. There's not a lot of difference. (No 'play again' if you lose) Only translated to QB64 where needed... But you might want to check just in case I didn't do it right... lol

But a huge thanks for your efforts so far!!
* hangman.sdlbas (Filesize: 9.76 KB, Downloads: 147)
« Last Edit: October 07, 2020, 06:38:07 am by johnno56 »
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: hangman64
« Reply #6 on: October 07, 2020, 11:31:20 am »
Quote
Did you manage to complete playing the game (either win or lose)?

Yeah the code worked fine for me? I've played game after game, do have to use y or n for play again because that is not mouse supported yet.

I will check a copy / paste of code to see if works from forum. Yep, fine! I even checked for memory leaks last night.

So you want to use the gun for a pointer, sounds good!

Could try a _delay of .1 to .25 after a MB (click) detection, in case mouse click is not clearing?? (I doubt, but have no idea what else it could be, obviously some weird thing with mouse detection.)
« Last Edit: October 07, 2020, 11:41:22 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: hangman64
« Reply #7 on: October 07, 2020, 12:23:27 pm »
OK use the top left gun barrel as mouse point of the pointer when you click a letter:
Code: QB64: [Select]
  1. '       HANGMAN
  2. '
  3. '   Johnno56 15-Dec-16
  4. '   (sdlbasic version)
  5. '
  6. '   07-Oct-20 QB64   w/mouse bplus  cut some lines of code
  7. '
  8. xmax = 1024
  9. ymax = 768
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _DELAY .25
  12.  
  13.  
  14. words = 295
  15.  
  16. DIM SHARED wordlist$(words)
  17. DIM SHARED letter(26)
  18. DIM SHARED chosen(26)
  19. DIM SHARED font50
  20. 'DIM SHARED choose AS INTEGER
  21.  
  22. a$ = ""
  23.  
  24. '
  25. '   Load graphics
  26. '
  27. intro = _LOADIMAGE("assets/title.png")
  28. gallowsbase = _LOADIMAGE("assets/base-closed.png")
  29. upright = _LOADIMAGE("assets/upright.png")
  30. support1 = _LOADIMAGE("assets/support1.png")
  31. support2 = _LOADIMAGE("assets/support2.png")
  32. support3 = _LOADIMAGE("assets/support3.png")
  33. beam = _LOADIMAGE("assets/beam.png")
  34. bolts = _LOADIMAGE("assets/bolts.png")
  35. rope = _LOADIMAGE("assets/ropesupport.png")
  36. victim1 = _LOADIMAGE("assets/victim1.png")
  37. victim2 = _LOADIMAGE("assets/victim2.png")
  38. hole = _LOADIMAGE("assets/hole.png")
  39. bground = _LOADIMAGE("assets/bground.png")
  40. grid = _LOADIMAGE("assets/grid.png")
  41. gameover = _LOADIMAGE("assets/gameover.png")
  42. welldone = _LOADIMAGE("assets/welldone.png")
  43. guessed = _LOADIMAGE("assets/x.png")
  44. gun = _LOADIMAGE("assets/gun.png")
  45. yes = _LOADIMAGE("assets/y.png")
  46. no = _LOADIMAGE("assets/n.png")
  47.  
  48. '
  49. '   Load audio
  50. '
  51. ropestretch = _SNDOPEN("assets/rope.wav")
  52. choke = _SNDOPEN("assets/choke.wav")
  53. shot = _SNDOPEN("assets/shot.wav")
  54. click = _SNDOPEN("assets/click.wav")
  55. clunk = _SNDOPEN("assets/clunk.wav")
  56.  
  57. music = _SNDOPEN("assets/goodbadugly.wav")
  58.  
  59. '
  60. '   Load Fonts
  61. '
  62. font35 = _LOADFONT("assets/rubicmono.ttf", 35)
  63. font50 = _LOADFONT("assets/rubicmono.ttf", 50)
  64.  
  65. ' select word from array (or external file?)
  66.  
  67. filename$ = "assets/words.txt"
  68.  
  69. OPEN filename$ FOR INPUT AS #1
  70. count = 1
  71.     INPUT #1, wordlist$(count)
  72.     count = count + 1
  73.  
  74. blue = _RGB32(0, 0, 255)
  75. red = _RGB32(255, 0, 0)
  76. black = _RGB32(0, 0, 0)
  77.  
  78. again = 1
  79. i = 0.1
  80.  
  81. '
  82. '   Title screen - here
  83. '
  84. _PUTIMAGE (0, 0), intro
  85. _SNDPLAY (shot)
  86. _PUTIMAGE (627, 9), hole
  87.  
  88. '
  89. '   Start game loop here
  90. '
  91. DIM snap AS LONG
  92. snap = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' take pictures of game as it progresses
  93.  
  94. WHILE 0 = 0
  95.     CLS
  96.     _PUTIMAGE (0, 0), bground
  97.  
  98.     wordtoguess$ = wordlist$(INT(RND * (count - 1)))
  99.     'print wordtoguess$
  100.     numberoftries = 0
  101.     FOR x = 1 TO 26
  102.         letter(x) = 0
  103.     NEXT
  104.  
  105.     '
  106.     '   Display empty word and letter grid
  107.     '
  108.     FOR dash = 1 TO LEN(wordtoguess$)
  109.         LINE (460 + (dash * 50), 380)-STEP(40, 4), black, BF
  110.     NEXT
  111.  
  112.     _PUTIMAGE (44, 700), grid
  113.     _DISPLAY
  114.  
  115.     counter = 0
  116.  
  117.     '
  118.     '   Letter guess routine - try for mouse input?
  119.     '
  120.  
  121.     '   Clear "chosen" array
  122.     '
  123.     FOR x = 1 TO 26
  124.         chosen(x) = 0
  125.     NEXT
  126.     _SNDVOL music, i
  127.     _SNDLOOP (music)
  128.     _PUTIMAGE , 0, snap
  129.     DO
  130.         foundletter = 0
  131.  
  132.         '
  133.         '   Keyboard (or mouse) selection of letters to guess
  134.         '
  135.  
  136.         DO
  137.             _PUTIMAGE , snap, 0
  138.             '_MOUSESHOW
  139.             choose = 0
  140.             '
  141.             '   Mouse "cursor"?
  142.             WHILE _MOUSEINPUT: WEND
  143.             mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  144.             _PUTIMAGE (mx, my), gun, 0
  145.             IF mb THEN
  146.                 IF my >= 700 AND my <= 736 THEN
  147.                     'BEEP
  148.                     test = INT((mx - 44) / 36) + 1
  149.                     'LOCATE 11, 5: PRINT test
  150.                     '_DISPLAY
  151.                     IF test > 0 AND test < 27 THEN 'good click
  152.                         choose = 96 + test
  153.                     END IF
  154.                 END IF
  155.             END IF
  156.  
  157.             ' Check Keypress if not mouse
  158.             IF choose = 0 THEN choose = _KEYHIT
  159.  
  160.             ' Handle choose
  161.             IF choose > 96 AND choose < 123 THEN
  162.                 IF chosen(choose - 96) = 0 THEN
  163.                     a$ = UCASE$(CHR$(choose))
  164.                     chosen(choose - 96) = 1
  165.                     _PUTIMAGE , snap, 0 'hide gun
  166.                     _PUTIMAGE ((choose - 96) * 36 + 8, 700), guessed
  167.                     EXIT DO
  168.                 END IF
  169.             END IF
  170.  
  171.             ' Escape to quit?
  172.             IF ky = 27 THEN
  173.                 _DELAY 2
  174.                 CLS
  175.                 END
  176.             END IF
  177.  
  178.             _DISPLAY
  179.             _LIMIT 100
  180.         LOOP
  181.         _SNDPLAY (click)
  182.  
  183.         '
  184.         '   Correct letter routine
  185.         '
  186.         IF letter(ASC(a$) - 64) = 0 THEN
  187.             COLOR blue
  188.             _FONT (font35)
  189.             FOR x = 1 TO LEN(wordtoguess$)
  190.                 IF UCASE$(MID$(wordtoguess$, x, 1)) = a$ THEN
  191.                     _PRINTSTRING (465 + (x * 50), 330), a$
  192.                     counter = counter + 1
  193.                     foundletter = 1
  194.                 END IF
  195.             NEXT
  196.             '
  197.             '   Not so correct letter routine
  198.             '
  199.             IF foundletter = 0 THEN
  200.                 numberoftries = numberoftries + 1
  201.                 '
  202.                 '   Build gallows routine?
  203.                 '
  204.  
  205.                 SELECT CASE numberoftries
  206.                     CASE 1: _PUTIMAGE (70, 505), gallowsbase
  207.                     CASE 2: _PUTIMAGE (146, 154), upright
  208.                     CASE 3: _PUTIMAGE (125, 461), support1
  209.                     CASE 4: _PUTIMAGE (184, 523), support2
  210.                     CASE 5: _PUTIMAGE (229, 501), support3
  211.                     CASE 6: _PUTIMAGE (116, 134), beam
  212.                     CASE 7: _PUTIMAGE (155, 170), bolts
  213.                     CASE 8: _PUTIMAGE (209, 140), rope
  214.                     CASE 9: _PUTIMAGE (331, 269), victim1
  215.                     CASE 10: _SNDPLAY (ropestretch)
  216.                         _SNDPLAY (choke)
  217.                         _PUTIMAGE (331, 269), victim2
  218.                 END SELECT
  219.             END IF
  220.             letter(ASC(a$) - 64) = -1
  221.         END IF
  222.         _DISPLAY
  223.  
  224.         '
  225.         '   Check for finished game?
  226.         '
  227.         IF counter = LEN(wordtoguess$) OR numberoftries = 10 THEN
  228.             EXIT DO
  229.         END IF
  230.         _DISPLAY
  231.  
  232.         _PUTIMAGE , 0, snap
  233.         _LIMIT 100
  234.     LOOP
  235.  
  236.     _DELAY 3
  237.  
  238.     '
  239.     '   Winner routine
  240.     '
  241.     IF counter = LEN(wordtoguess$) THEN
  242.         _PUTIMAGE (170, 200), welldone
  243.         _DISPLAY
  244.         _DELAY 3
  245.         CLS
  246.         _DISPLAY
  247.         playagain
  248.         IF a$ = "N" THEN
  249.             _SNDPLAY (click)
  250.             a$ = ""
  251.             _DELAY 1
  252.             CLS
  253.             _PUTIMAGE (0, 0), gameover
  254.             _DISPLAY
  255.             _DELAY 4
  256.             SYSTEM
  257.         END IF
  258.         IF a$ = "Y" THEN
  259.             _SNDPLAY (click)
  260.             a$ = ""
  261.             _DELAY 0.2
  262.             CLS
  263.             _PUTIMAGE (0, 0), bground
  264.             _DISPLAY
  265.         END IF
  266.     ELSE
  267.         '
  268.         '   Loser routine
  269.         '
  270.         FOR x = 1 TO LEN(wordtoguess$)
  271.             a$ = UCASE$(MID$(wordtoguess$, x, 1))
  272.             COLOR red
  273.             _FONT (font35)
  274.             _PRINTSTRING (465 + (x * 50), 330), a$
  275.             _DISPLAY
  276.         NEXT
  277.         _DELAY 4
  278.         CLS
  279.         playagain
  280.         IF a$ = "Y" THEN
  281.             _SNDPLAY (click)
  282.             a$ = ""
  283.             CLS
  284.             _PUTIMAGE (0, 0), bground
  285.             _DISPLAY
  286.         END IF
  287.         IF a$ = "N" THEN
  288.             _SNDPLAY (click)
  289.             a$ = ""
  290.             CLS
  291.             _PUTIMAGE (0, 0), gameover
  292.             _DISPLAY
  293.             _DELAY 3
  294.             CLS
  295.             _DISPLAY
  296.             _DELAY 1
  297.             SYSTEM
  298.         END IF
  299.     END IF
  300.     IF INKEY$ = CHR$(27) THEN END
  301.     _DISPLAY
  302.     _LIMIT 100
  303.  
  304. SUB playagain
  305.     a$ = ""
  306.     yn = 0
  307.     CLS
  308.     _PUTIMAGE (0, 0), bground
  309.     _DISPLAY
  310.     COLOR blue
  311.     _FONT (font50)
  312.     WHILE yn <> 121 AND yn <> 110
  313.         yn = _KEYHIT
  314.         _PRINTSTRING (250, 650), "Again Y or N"
  315.         IF yn = 121 THEN
  316.             a$ = "Y"
  317.             FOR x = 1 TO 26
  318.                 chosen(x) = 0
  319.             NEXT
  320.             choose = 0
  321.             _DELAY 1
  322.         ELSEIF yn = 110 THEN
  323.             a$ = "N"
  324.         END IF
  325.         _DISPLAY
  326.     WEND
  327.  


"Have gun will travel."
« Last Edit: October 07, 2020, 12:34:25 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: hangman64
« Reply #8 on: October 07, 2020, 06:01:31 pm »
Ok. Where do I begin?

Ha. I know 'exactly' where... The game (including the gun cursor) worked flawlessly!! I'm going over that code with a 'fine-toothed comb' to see what I did wrong.... lol

The Y and N... The sprites are in the assets folder but hadn't got around to coding it... lol It does make it a little awkward switching to keyboard at the end of the game... I can fix that... I promise not to muck things up... lol

Many thanks for the fix... Just think... When this game tops #1 on the 'Best Game' sales list... You will be in line for a serious percentage!!  How do you think the market will handle a 'Snake' remake?  At least we couldn't do any worse than Atari's ET... lol

Well... I'm going to make our coffee's then I'm going to fix the Y/N issue...

Have a great day!

Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: hangman64
« Reply #9 on: October 07, 2020, 06:06:53 pm »
Quote
The game (including the gun cursor) worked flawlessly!!

Ah! good to hear :)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: hangman64
« Reply #10 on: October 07, 2020, 08:25:16 pm »
"Again" now works with both mouse and keyboard. Slightly modified the 'playagain' routine to display the 'gun' without 'trails'. There is probably a better way to do it... lol

I will attach the code and the extra sprite (Again? Y or N)

Code: QB64: [Select]
  1. '       HANGMAN
  2. '
  3. '   Johnno56 15-Dec-16
  4. '   (sdlbasic version)
  5. '
  6. '   07-Oct-20 QB64   w/mouse bplus  cut some lines of code
  7. '
  8. xmax = 1024
  9. ymax = 768
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _DELAY .25
  12.  
  13.  
  14. words = 295
  15.  
  16. DIM SHARED wordlist$(words)
  17. DIM SHARED letter(26)
  18. DIM SHARED chosen(26)
  19. DIM SHARED font50
  20. 'DIM SHARED choose AS INTEGER
  21. DIM SHARED click
  22.  
  23. a$ = ""
  24.  
  25. '
  26. '   Load graphics
  27. '
  28. intro = _LOADIMAGE("assets/title.png")
  29. gallowsbase = _LOADIMAGE("assets/base-closed.png")
  30. upright = _LOADIMAGE("assets/upright.png")
  31. support1 = _LOADIMAGE("assets/support1.png")
  32. support2 = _LOADIMAGE("assets/support2.png")
  33. support3 = _LOADIMAGE("assets/support3.png")
  34. beam = _LOADIMAGE("assets/beam.png")
  35. bolts = _LOADIMAGE("assets/bolts.png")
  36. rope = _LOADIMAGE("assets/ropesupport.png")
  37. victim1 = _LOADIMAGE("assets/victim1.png")
  38. victim2 = _LOADIMAGE("assets/victim2.png")
  39. hole = _LOADIMAGE("assets/hole.png")
  40. bground = _LOADIMAGE("assets/bground.png")
  41. grid = _LOADIMAGE("assets/grid.png")
  42. gameover = _LOADIMAGE("assets/gameover.png")
  43. welldone = _LOADIMAGE("assets/welldone.png")
  44. guessed = _LOADIMAGE("assets/x.png")
  45. gun = _LOADIMAGE("assets/gun.png")
  46. yesno = _LOADIMAGE("assets/yesno.png")
  47.  
  48. '
  49. '   Load audio
  50. '
  51. ropestretch = _SNDOPEN("assets/rope.wav")
  52. choke = _SNDOPEN("assets/choke.wav")
  53. shot = _SNDOPEN("assets/shot.wav")
  54. click = _SNDOPEN("assets/click.wav")
  55. clunk = _SNDOPEN("assets/clunk.wav")
  56.  
  57. music = _SNDOPEN("assets/goodbadugly.wav")
  58.  
  59. '
  60. '   Load Fonts
  61. '
  62. font35 = _LOADFONT("assets/rubicmono.ttf", 35)
  63. font50 = _LOADFONT("assets/rubicmono.ttf", 50)
  64.  
  65. ' select word from array (or external file?)
  66.  
  67. filename$ = "assets/words.txt"
  68.  
  69. OPEN filename$ FOR INPUT AS #1
  70. count = 1
  71.     INPUT #1, wordlist$(count)
  72.     count = count + 1
  73.  
  74. blue = _RGB32(0, 0, 255)
  75. red = _RGB32(255, 0, 0)
  76. black = _RGB32(0, 0, 0)
  77.  
  78. again = 1
  79. i = 0.1
  80.  
  81. '
  82. '   Title screen - here
  83. '
  84. _PUTIMAGE (0, 0), intro
  85. _SNDPLAY (shot)
  86. _PUTIMAGE (627, 9), hole
  87.  
  88. '
  89. '   Start game loop here
  90. '
  91. DIM snap AS LONG
  92. snap = _NEWIMAGE(_WIDTH, _HEIGHT, 32) ' take pictures of game as it progresses
  93.  
  94. WHILE 0 = 0
  95.     CLS
  96.     _PUTIMAGE (0, 0), bground
  97.  
  98.     wordtoguess$ = wordlist$(INT(RND * (count - 1)))
  99.     'print wordtoguess$
  100.     numberoftries = 0
  101.     FOR x = 1 TO 26
  102.         letter(x) = 0
  103.     NEXT
  104.  
  105.     '
  106.     '   Display empty word and letter grid
  107.     '
  108.     FOR dash = 1 TO LEN(wordtoguess$)
  109.         LINE (460 + (dash * 50), 380)-STEP(40, 4), black, BF
  110.     NEXT
  111.  
  112.     _PUTIMAGE (44, 700), grid
  113.     _DISPLAY
  114.  
  115.     counter = 0
  116.  
  117.     '
  118.     '   Letter guess routine - try for mouse input?
  119.     '
  120.  
  121.     '   Clear "chosen" array
  122.     '
  123.     FOR x = 1 TO 26
  124.         chosen(x) = 0
  125.     NEXT
  126.     _SNDVOL music, i
  127.     _SNDLOOP (music)
  128.     _PUTIMAGE , 0, snap
  129.     DO
  130.         foundletter = 0
  131.  
  132.         '
  133.         '   Keyboard (or mouse) selection of letters to guess
  134.         '
  135.  
  136.         DO
  137.             _PUTIMAGE , snap, 0
  138.             '_MOUSESHOW
  139.             choose = 0
  140.             '
  141.             '   Mouse "cursor"?
  142.             WHILE _MOUSEINPUT: WEND
  143.             mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  144.             _PUTIMAGE (mx, my), gun, 0
  145.             IF mb THEN
  146.                 IF my >= 700 AND my <= 736 THEN
  147.                     'BEEP
  148.                     test = INT((mx - 44) / 36) + 1
  149.                     'LOCATE 11, 5: PRINT test
  150.                     '_DISPLAY
  151.                     IF test > 0 AND test < 27 THEN 'good click
  152.                         choose = 96 + test
  153.                     END IF
  154.                 END IF
  155.             END IF
  156.  
  157.             ' Check Keypress if not mouse
  158.             IF choose = 0 THEN choose = _KEYHIT
  159.  
  160.             ' Handle choose
  161.             IF choose > 96 AND choose < 123 THEN
  162.                 IF chosen(choose - 96) = 0 THEN
  163.                     a$ = UCASE$(CHR$(choose))
  164.                     chosen(choose - 96) = 1
  165.                     _PUTIMAGE , snap, 0 'hide gun
  166.                     _PUTIMAGE ((choose - 96) * 36 + 8, 700), guessed
  167.                     EXIT DO
  168.                 END IF
  169.             END IF
  170.  
  171.             ' Escape to quit?
  172.             IF ky = 27 THEN
  173.                 _DELAY 2
  174.                 CLS
  175.                 END
  176.             END IF
  177.  
  178.             _DISPLAY
  179.             _LIMIT 100
  180.         LOOP
  181.         _SNDPLAY (click)
  182.  
  183.         '
  184.         '   Correct letter routine
  185.         '
  186.         IF letter(ASC(a$) - 64) = 0 THEN
  187.             COLOR blue
  188.             _FONT (font35)
  189.             FOR x = 1 TO LEN(wordtoguess$)
  190.                 IF UCASE$(MID$(wordtoguess$, x, 1)) = a$ THEN
  191.                     _PRINTSTRING (465 + (x * 50), 330), a$
  192.                     counter = counter + 1
  193.                     foundletter = 1
  194.                 END IF
  195.             NEXT
  196.             '
  197.             '   Not so correct letter routine
  198.             '
  199.             IF foundletter = 0 THEN
  200.                 numberoftries = numberoftries + 1
  201.                 '
  202.                 '   Build gallows routine?
  203.                 '
  204.  
  205.                 SELECT CASE numberoftries
  206.                     CASE 1: _PUTIMAGE (70, 505), gallowsbase
  207.                     CASE 2: _PUTIMAGE (146, 154), upright
  208.                     CASE 3: _PUTIMAGE (125, 461), support1
  209.                     CASE 4: _PUTIMAGE (184, 523), support2
  210.                     CASE 5: _PUTIMAGE (229, 501), support3
  211.                     CASE 6: _PUTIMAGE (116, 134), beam
  212.                     CASE 7: _PUTIMAGE (155, 170), bolts
  213.                     CASE 8: _PUTIMAGE (209, 140), rope
  214.                     CASE 9: _PUTIMAGE (331, 269), victim1
  215.                     CASE 10: _SNDPLAY (ropestretch)
  216.                         _SNDPLAY (choke)
  217.                         _PUTIMAGE (331, 269), victim2
  218.                 END SELECT
  219.             END IF
  220.             letter(ASC(a$) - 64) = -1
  221.         END IF
  222.         _DISPLAY
  223.  
  224.         '
  225.         '   Check for finished game?
  226.         '
  227.         IF counter = LEN(wordtoguess$) OR numberoftries = 10 THEN
  228.             EXIT DO
  229.         END IF
  230.         _DISPLAY
  231.  
  232.         _PUTIMAGE , 0, snap
  233.         _LIMIT 100
  234.     LOOP
  235.  
  236.     _DELAY 3
  237.  
  238.     '
  239.     '   Winner routine
  240.     '
  241.     IF counter = LEN(wordtoguess$) THEN
  242.         _PUTIMAGE (170, 200), welldone
  243.         _DISPLAY
  244.         _DELAY 3
  245.         CLS
  246.         _DISPLAY
  247.         playagain
  248.         IF a$ = "N" THEN
  249.             a$ = ""
  250.             _DELAY 1
  251.             CLS
  252.             _PUTIMAGE (0, 0), gameover
  253.             _DISPLAY
  254.             _DELAY 4
  255.             SYSTEM
  256.         END IF
  257.         IF a$ = "Y" THEN
  258.             a$ = ""
  259.             _DELAY 0.2
  260.             CLS
  261.             _PUTIMAGE (0, 0), bground
  262.             _DISPLAY
  263.         END IF
  264.     ELSE
  265.         '
  266.         '   Loser routine
  267.         '
  268.         FOR x = 1 TO LEN(wordtoguess$)
  269.             a$ = UCASE$(MID$(wordtoguess$, x, 1))
  270.             COLOR red
  271.             _FONT (font35)
  272.             _PRINTSTRING (465 + (x * 50), 330), a$
  273.             _DISPLAY
  274.         NEXT
  275.         _DELAY 4
  276.         CLS
  277.         playagain
  278.         IF a$ = "Y" THEN
  279.             a$ = ""
  280.             CLS
  281.             _PUTIMAGE (0, 0), bground
  282.             _DISPLAY
  283.         END IF
  284.         IF a$ = "N" THEN
  285.             _SNDPLAY (click)
  286.             a$ = ""
  287.             CLS
  288.             _PUTIMAGE (0, 0), gameover
  289.             _DISPLAY
  290.             _DELAY 3
  291.             CLS
  292.             _DISPLAY
  293.             _DELAY 1
  294.             SYSTEM
  295.         END IF
  296.     END IF
  297.     IF INKEY$ = CHR$(27) THEN END
  298.     _DISPLAY
  299.     _LIMIT 100
  300.  
  301. SUB playagain
  302.     a$ = ""
  303.     yn = 0
  304.     WHILE (yn <> 121 AND yn <> 110) AND (a$ <> "Y" AND a$ <> "N")
  305.         CLS
  306.         _PUTIMAGE (0, 0), bground
  307.         yn = _KEYHIT
  308.         WHILE _MOUSEINPUT = 0: WEND
  309.         mx = _MOUSEX
  310.         my = _MOUSEY
  311.         mb = _MOUSEBUTTON(1)
  312.         '        LOCATE 1, 1: PRINT mx
  313.         '        LOCATE 2, 1: PRINT my
  314.         '        LOCATE 3, 1: PRINT mb
  315.         _PUTIMAGE (250, 650), yesno
  316.         _PUTIMAGE (mx, my), gun
  317.         '_PRINTSTRING (250, 650), "Again Y or N"
  318.         IF yn = 121 OR (mx > 548 AND mx < 583 AND my > 650 AND my < 685 AND mb = -1) THEN
  319.             _SNDPLAY (click)
  320.             a$ = "Y"
  321.             FOR x = 1 TO 26
  322.                 chosen(x) = 0
  323.             NEXT
  324.             choose = 0
  325.             _DELAY 1
  326.         ELSEIF yn = 110 OR (mx > 725 AND mx < 760 AND my > 650 AND my < 685 AND mb = -1) THEN
  327.             _SNDPLAY (click)
  328.             a$ = "N"
  329.         END IF
  330.         _DISPLAY
  331.     WEND
  332.  
yesno.png
* yesno.png (Filesize: 4.9 KB, Dimensions: 508x35, Views: 130)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: hangman64
« Reply #11 on: October 07, 2020, 10:52:53 pm »
Hey Johnno,

I tried out the new code and got a very weird response from the mouse, it kept moving with a mind of it's own when I got to the new Y or N part. Made 2 changes and it works solid as a rock now:

Code: QB64: [Select]
  1. SUB playagain
  2.     a$ = ""
  3.     yn = 0
  4.     WHILE (yn <> 121 AND yn <> 110) AND (a$ <> "Y" AND a$ <> "N")
  5.         CLS
  6.         _PUTIMAGE (0, 0), bground
  7.         yn = _KEYHIT
  8.         WHILE _MOUSEINPUT: WEND ' <<<<<<<<<<<<<<<<<<  not while _mouseinput = 0
  9.         mx = _MOUSEX
  10.         my = _MOUSEY
  11.         mb = _MOUSEBUTTON(1)
  12.         '        LOCATE 1, 1: PRINT mx
  13.         '        LOCATE 2, 1: PRINT my
  14.         '        LOCATE 3, 1: PRINT mb
  15.         _PUTIMAGE (250, 650), yesno
  16.         _PUTIMAGE (mx, my), gun
  17.         '_PRINTSTRING (250, 650), "Again Y or N"
  18.         IF yn = 121 OR (mx > 548 AND mx < 583 AND my > 650 AND my < 685 AND mb = -1) THEN
  19.             _SNDPLAY (click)
  20.             a$ = "Y"
  21.             FOR x = 1 TO 26
  22.                 chosen(x) = 0
  23.             NEXT
  24.             choose = 0
  25.             _DELAY 1
  26.         ELSEIF yn = 110 OR (mx > 725 AND mx < 760 AND my > 650 AND my < 685 AND mb = -1) THEN
  27.             _SNDPLAY (click)
  28.             a$ = "N"
  29.         END IF
  30.         _DISPLAY
  31.         _LIMIT 100 '<  save the fan!
  32.     WEND
  33.  

It's nice to have the mouse working here now too!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: hangman64
« Reply #12 on: October 08, 2020, 02:37:28 am »
As you said, "Solid as a rock."  Very cool indeed...

The one thing I didn't do was to code the title... Don't forget to put your name in there... wink, wink...

Many thanks for the assist... Time to play some mind numbing shootem ups... Before thinking about another 'classic'. I'm thinking of tackling 1945... Done one for sdlbasic and rcbasic... Maybe it's QB's turn?
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: hangman64
« Reply #13 on: October 08, 2020, 10:58:27 am »
I was thinking you might throw in a word list with a Western Theme or offer an assortment of lists.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: hangman64
« Reply #14 on: October 08, 2020, 04:41:20 pm »
Good reminder. I did say that I would add a larger list. The 'Vocabulary' game I made has a word list of over 15,000 words. Of course not all the words can be used... Length limit. A western theme you say... I wonder how many types of cactii and tumbleweeds there are? lol
Logic is the beginning of wisdom.