Author Topic: Re: Hellish Nightmare  (Read 1209 times)

0 Members and 1 Guest are viewing this topic.

FellippeHeitor

  • Guest
Re: Hellish Nightmare
« on: April 26, 2018, 09:03:15 am »
Code: QB64: [Select]
  1. Canvas& = _NEWIMAGE(640, 480, 32)
  2. SCREEN Canvas&
  3.  
  4. Bait = _LOADIMAGE("Crypto.png", 32)
  5. _CLEARCOLOR _RGB(255, 255, 255), Bait
  6.  
  7. _PUTIMAGE (142, 2), Bait, 0, (1, 1)-(356, 52)
  8.  
  9. CONST False = 0
  10. CONST True = -1
  11. DIM SHARED MouseDown AS INTEGER
  12.  
  13. Font1 = _NEWIMAGE(576, 68)
  14. Font2 = _NEWIMAGE(576, 68)
  15. LoadFont 1
  16.  
  17. DIM SHARED Buttons
  18. Buttons = 42
  19.  
  20. TYPE RatBait
  21.     x AS INTEGER
  22.     y AS INTEGER
  23.  
  24.     click AS INTEGER
  25.     size AS INTEGER
  26.     style AS INTEGER
  27.  
  28. DIM SHARED Button(Buttons) AS RatBait
  29. DIM SHARED ButtonText(Buttons) AS STRING
  30.  
  31. FOR b = 1 TO Buttons
  32.     READ ButtonText(b)
  33.     READ Button(b).x, Button(b).y
  34.  
  35.     Button(b).size = 23
  36.     IF b > 36 THEN Button(b).size = 47
  37.  
  38.     Button(b).style = 1
  39.     IF b > 36 THEN Button(b).style = 5
  40.  
  41. DATA "A",95,430,"B",120,430,"C",145,430,"D",170,430
  42. DATA "E",195,430,"F",220,430,"G",245,430,"H",270,430
  43. DATA "I",295,430,"J",320,430,"K",345,430,"L",370,430
  44. DATA "M",395,430,"N",420,430,"O",445,430,"P",470,430
  45. DATA "Q",495,430,"R",520,430,"S",95,455,"T",120,455
  46. DATA "U",145,455,"V",170,455,"W",195,455,"X",220,455
  47. DATA "Y",245,455,"Z",270,455,"0",295,455,"1",320,455
  48. DATA "2",345,455,"3",370,455,"4",395,455,"5",420,455
  49. DATA "6",445,455,"7",470,455,"8",495,455,"9",520,455
  50. DATA "New",2,2,"Setup",2,52,"Help",590,2,"About",590,52
  51. DATA "Reset",2,430
  52. DATA "Exit",590,430
  53.  
  54. DIM SHARED Label(80) AS RatBait
  55. DIM SHARED LabelText(Buttons) AS STRING
  56.  
  57. DIM SHARED BeepText AS STRING
  58. BeepText = "YOU SHOULD BE ABLE TO CLICK ON THESE LETTERS AND HEAR A BEEP"
  59. ShowText 320 - 9 * (LEN(BeepText) - 1) \ 2, 248, BeepText, 0
  60.  
  61. a = 320 - 9 * (LEN(BeepText) - 1) \ 2
  62. FOR i = 0 TO LEN(BeepText) - 1
  63.     Label(i + 1).x = 9 * i + a: Label(i + 1).y = 248
  64.  
  65.  
  66.         IF NOT MouseDown THEN
  67.             MouseDown = True
  68.         END IF
  69.     ELSE
  70.         IF MouseDown THEN
  71.             MouseDown = False
  72.             checkClick
  73.         END IF
  74.     END IF
  75.  
  76.     CLS
  77.     GUI
  78.     _DISPLAY
  79.     _LIMIT 30
  80.  
  81. SUB checkClick
  82.     DIM ID AS INTEGER
  83.     DIM Size AS INTEGER
  84.     DIM x AS INTEGER, y AS INTEGER
  85.  
  86.     x = _MOUSEX
  87.     y = _MOUSEY
  88.  
  89.     FOR ID = 1 TO Buttons
  90.         Size = 23: IF ID > 36 THEN Size = 47
  91.  
  92.         IF x > Button(ID).x AND x < Button(ID).x + Size THEN
  93.             IF y > Button(ID).y AND y < Button(ID).y + Size THEN
  94.                 BEEP
  95.                 EXIT FOR
  96.             END IF
  97.         END IF
  98.     NEXT
  99.  
  100. SUB GUI
  101.     DIM Text AS STRING
  102.  
  103.     FOR B = 1 TO Buttons
  104.         Style = Button(B).style
  105.  
  106.         IF x > Button(ID).x AND x < Button(ID).x + Size THEN
  107.             IF y > Button(ID).y AND y < Button(ID).y + Size THEN
  108.                 IF MouseDown THEN
  109.                     Style = Style + 2
  110.                 ELSE
  111.                     Style = Style + 1
  112.                 END IF
  113.                 EXIT FOR
  114.             END IF
  115.         END IF
  116.  
  117.         SELECT CASE Style
  118.             CASE 1: h = 1
  119.             CASE 2: h = 26
  120.             CASE 3: h = 51
  121.             CASE 4: h = 76
  122.             CASE 5: h = 101
  123.             CASE 6: h = 150
  124.             CASE 7: h = 199
  125.             CASE 8: h = 248
  126.         END SELECT
  127.  
  128.         Size = Button(B).size
  129.         x = Button(B).x: y = Button(B).y
  130.         _PUTIMAGE (x, y), Bait, 0, (h, 107)-(h + Size, 107 + Size)
  131.  
  132.         IF Style < 5 THEN
  133.             cx = x + 8: cy = y + 4
  134.         ELSE
  135.             cx = x + (24 - (LEN(Text) * 9) \ 2): cy = y + 20
  136.         END IF
  137.  
  138.         Text = ButtonText(B)
  139.         FOR c = 1 TO LEN(Text)
  140.             char = ASC(MID$(Text, c, 1))
  141.  
  142.             t = char \ 64
  143.             h = 9 * (char - 64 * t) + 1: v = 17 * t + 1
  144.  
  145.             _PUTIMAGE (cx + 9 * (c - 1), cy), Font1, 0, (h, v)-(h + 7, v + 15)
  146.         NEXT
  147.     NEXT
  148.  
  149. SUB LoadFont (Flag AS INTEGER)
  150.     DIM h AS INTEGER
  151.     DIM v AS INTEGER
  152.     DIM x AS INTEGER
  153.     DIM y AS INTEGER
  154.     DIM char AS INTEGER
  155.  
  156.     DIM Temp AS STRING
  157.     DIM FontChar AS STRING
  158.     DIM FontFile AS STRING
  159.  
  160.     DIM Colour0 AS _UNSIGNED LONG
  161.     DIM Colour1 AS _UNSIGNED LONG
  162.  
  163.     Temp = RIGHT$("0" + LTRIM$(STR$(Flag)), 2)
  164.     FontFile = ".\BinFonts\BinFnt" + Temp + ".dat"
  165.  
  166.     OPEN FontFile FOR INPUT AS #1
  167.  
  168.     _DEST Font1
  169.     LINE (0, 0)-(576, 68), _RGB32(255, 255, 255), BF
  170.  
  171.     _DEST Font2
  172.     LINE (0, 0)-(576, 68), _RGB32(255, 255, 255), BF
  173.  
  174.     x = 1: y = 1
  175.     FOR char = 1 TO 256
  176.         INPUT #1, FontChar
  177.  
  178.         _DEST Font1
  179.         Colour0 = _RGB32(255, 255, 255)
  180.         Colour1 = _RGB32(0, 0, 0)
  181.  
  182.         FOR v = 0 TO 15
  183.             Temp = MID$(FontChar, 8 * v + 1, 8)
  184.  
  185.             FOR h = 0 TO 7
  186.                 IF VAL(MID$(Temp, h + 1, 1)) THEN
  187.                     PSET (x + h, y + v), Colour1
  188.                 ELSE
  189.                     PSET (x + h, y + v), Colour0
  190.                 END IF
  191.             NEXT
  192.         NEXT
  193.  
  194.         _DEST Font2
  195.         Colour0 = _RGB32(0, 0, 0)
  196.         Colour1 = _RGB32(255, 215, 0)
  197.  
  198.         FOR v = 0 TO 15
  199.             Temp = MID$(FontChar, 8 * v + 1, 8)
  200.  
  201.             FOR h = 0 TO 7
  202.                 IF VAL(MID$(Temp, h + 1, 1)) THEN
  203.                     PSET (x + h, y + v), Colour1
  204.                 ELSE
  205.                     PSET (x + h, y + v), Colour0
  206.                 END IF
  207.             NEXT
  208.         NEXT
  209.  
  210.         x = x + 9
  211.         IF char MOD 64 = 0 THEN x = 1: y = y + 17
  212.     NEXT
  213.  
  214.     CLOSE #1
  215.  
  216.     _CLEARCOLOR _RGB(255, 255, 255), Font1
  217.     _CLEARCOLOR _RGB(0, 0, 0), Font2
  218.  
  219.     _DEST 0
  220.  
  221. SUB ShowText (x AS INTEGER, y AS INTEGER, Text AS STRING, flag AS INTEGER)
  222.     FOR i = 1 TO LEN(Text)
  223.         char = ASC(MID$(Text, i, 1))
  224.         t = char \ 64: h = 9 * (char - 64 * t) + 1: v = 17 * t + 1
  225.  
  226.         _PUTIMAGE (x + 9 * (i - 1), y), Font2, 0, (h, v)-(h + 7, v + 15)
  227.     NEXT
  228.  

Simplify it, man.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Hellish Nightmare
« Reply #1 on: April 26, 2018, 10:24:08 am »
  • Best Answer
  • Ha! I just saw this at NET and said to myself, oh something to do this afternoon.

    Well Fellippe strikes again! ;-))

    Hey [banned user], did he get it righted?


    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: Hellish Nightmare
    « Reply #2 on: April 26, 2018, 09:13:23 pm »
  • Best Answer
  • Hi [banned user],

    Eh, I was betting Fellippe nailed it again.

    Can you say where you intend to go with this? (It's OK if you don't want to.)

    I might be of little help! ;-))

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: Hellish Nightmare
    « Reply #3 on: April 27, 2018, 12:18:49 am »
  • Best Answer
  • Hi [banned user],

    Looks like it is coming along nicely!

    You know those keys at the bottom for some reason remind me of old juke boxes. :-)