Author Topic: Is this at all possible in SCREEN 0?  (Read 6509 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Is this at all possible in SCREEN 0?
« Reply #15 on: October 17, 2021, 10:52:57 pm »
Beat me to it!

Yeah, the SUB concept is what I was considering. _PUTIMAGE drives me a bit crazy in that if reverses the row column order of LOCATE. Using the sub to do the thinking is a much more comfortable method of handling things at my age. The simple act of blowing my nose creates brain fog these days. Of course, I'd bet it would help if I stopped inhaling all the CO emissions from the charcoal when I'm barbecuing. I'm only guessing, of course, because I used the CO and smoke detectors for kindling, years ago. I could hear my neighbors say... Dammit, there goes Pete again, having another one of his BEEPING barbecues!

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

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Is this at all possible in SCREEN 0?
« Reply #16 on: October 19, 2021, 03:22:38 am »
So here's as far along as I am as of now. :D

Code: QB64: [Select]
  1. Screen0 = _NEWIMAGE(80, 25, 0)
  2. SCREEN Screen0
  3. swidth = _WIDTH
  4.  
  5. DIM SHARED Overlay
  6. REDIM SHARED hsdata$(5)
  7. hsdata$(1) = " 01  AAA  069000  10-18-21 "
  8. hsdata$(2) = " 01  BBB  053460  10-17-21 "
  9. hsdata$(3) = " 01  CCC  045700  10-17-21 "
  10. hsdata$(4) = " 01  DDD  034780  10-16-21 "
  11. hsdata$(5) = " 01  EEE  025890  10-12-21 "
  12.  
  13. DIM SHARED intro%: intro% = -1
  14.  
  15. skip_intro:
  16. DIM SHARED lmargin%, rmargin%, topmargin%, screenwidth%, level, ibk, ileadingrow
  17. DIM SHARED irow, icol, inextrnd, imaxalienmissiles, alienforce%, ileadingmax, imaxalienforce, ihits, score$
  18.  
  19.  
  20. score$ = "000000"
  21. imaxalienforce = 6
  22. imaxalienmissiles = 3
  23. lmargin% = 2
  24. rmargin% = 79
  25. topmargin% = 3
  26. ialiencolstat = 6
  27. iwin = 3 ' 3 Levels.
  28. screenwidth% = rmargin% - lmargin% + 1
  29. ibk = 0 ' Background color
  30.  
  31. REM Make aliens
  32. a1$ = "^^" + CHR$(79) + "^^  "
  33. a$ = a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$
  34. alt1$ = "--" + CHR$(79) + "--  "
  35. a$ = a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$
  36. alt$ = alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$
  37.  
  38. DIM SHARED a(imaxalienforce) AS STRING * 68
  39.  
  40. CALL qbide
  41.  
  42. COLOR 8, 0
  43. ialiencol = ialiencolstat
  44. LOCATE 4, ialiencol
  45. FOR i = 1 TO imaxalienforce
  46.     IF i MOD 1 = 0 THEN PRINT
  47.     LOCATE , ialiencol
  48.     IF i = imaxalienforce THEN
  49.         ileadingrow = CSRLIN: ileadingmax = ileadingrow
  50.     END IF
  51.     IF i \ 2 = i / 2 THEN a(i) = a$ ELSE a(i) = alt$
  52.     PRINT a(i)
  53.  
  54.  
  55. a = 14
  56. OUT &H3C8, 0
  57. OUT &H3C9, 20 - a
  58. OUT &H3C9, 20 - a
  59. OUT &H3C9, 20 - a
  60.  
  61. OUT &H3C8, 8
  62. OUT &H3C9, 30 - a
  63. OUT &H3C9, 30 - a
  64. OUT &H3C9, 30 - a
  65.  
  66. OUT &H3C8, 7
  67. OUT &H3C9, 30 - a
  68. OUT &H3C9, 30 - a
  69. OUT &H3C9, 30 - a
  70.  
  71. OUT &H3C8, 3
  72. OUT &H3C9, 30 - a
  73. OUT &H3C9, 30 - a
  74. OUT &H3C9, 30 - a
  75.  
  76.  
  77. _DEST Overlay
  78.  
  79. GOSUB pete
  80.  
  81. _FREEIMAGE Overlay
  82. _FONT 16 'select inbuilt 8x16 default font
  83.  
  84.  
  85.  
  86. _DEST 0 'Reset dest back to the normal screen 0.
  87.  
  88. WHILE LEN(INKEY$): WEND ' Clear keyboard buffer in case user pressed a key during program run.
  89. a$ = INPUT$(1)
  90. COLOR 7, 0
  91.  
  92. pete:
  93. font = _LOADFONT("lucon.ttf", 20, "monospace")
  94. IF font <= 0 THEN font = 16
  95. _FONT font
  96.  
  97. bxy% = 3
  98. bxx% = 13 '27
  99. COLOR DarkOrange, 0
  100. text$ = " " + CHR$(218) + STRING$(27, CHR$(196)) + CHR$(191) + " "
  101. PSL bxy%, bxx% - 1, text$
  102. FOR i = 1 TO 11
  103.     text$ = " " + CHR$(179) + STRING$(27, CHR$(32)) + CHR$(179) + " "
  104.     PSL bxy% + i, bxx% - 1, text$
  105. text$ = " " + CHR$(192) + STRING$(27, CHR$(196)) + CHR$(217) + " "
  106. PSL bxy% + i, bxx% - 1, text$
  107.  
  108. COLOR Black, DarkOrange
  109. text$ = "    NAME   SCORE    DATE   "
  110. PSL bxy% + 1, bxx% + 1, text$
  111.  
  112. COLOR DarkOrange, 0
  113. FOR i = 1 TO 5
  114.     text$ = hsdata$(i)
  115.     PSL bxy% + 1 + i * 2, bxx% + 1, text$
  116.  
  117. SUB PSL (y, x, text$)
  118.     _PRINTSTRING ((x - 1) * _FONTWIDTH, (y - 1) * _FONTHEIGHT), text$
  119.     Overlay_Hardware = _COPYIMAGE(Overlay, 33)
  120.  
  121.     _PUTIMAGE (0, 0), Overlay_Hardware
  122.     _DISPLAY
  123.  
  124.  
  125. SUB PSLC (y, x, text$)
  126.     _PRINTSTRING ((x - 1), (y - 1) * _FONTHEIGHT), text$
  127.  
  128. SUB qbide
  129.     PALETTE 2, 59
  130.     COLOR 15, 0
  131.     CLS
  132.  
  133.     COLOR 0, 7
  134.     LOCATE 1, 1
  135.     PRINT SPACE$(80)
  136.     LOCATE 1, 1: PRINT "   File  Edit  View  Search  Run  Debug  Calls  Options                   Help"
  137.  
  138.     COLOR 7, 0 ' Black background.
  139.  
  140.     LOCATE 2, 1: PRINT CHR$(218)
  141.     LOCATE 2, 2: PRINT STRING$(78, CHR$(196))
  142.     LOCATE 2, 80: PRINT CHR$(191)
  143.  
  144.     LOCATE 2, 76: PRINT CHR$(180)
  145.     LOCATE 2, 78: PRINT CHR$(195)
  146.  
  147.     COLOR 0, 7
  148.     LOCATE 2, 77: PRINT CHR$(24)
  149.     LOCATE 2, 36: PRINT " Untitled "
  150.  
  151.     COLOR 7, 0
  152.     FOR Rows = 3 TO 24
  153.         LOCATE Rows, 1: PRINT CHR$(179);
  154.         LOCATE Rows, 80: PRINT CHR$(179);
  155.     NEXT Rows
  156.  
  157.     COLOR 0, 3: LOCATE 25, 1: PRINT " <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step> ";
  158.     LOCATE 25, 59: PRINT SPACE$(4);
  159.     COLOR 0, 3
  160.     LOCATE 25, 63: PRINT CHR$(179);
  161.     LOCATE 25, 64: PRINT SPACE$(6);
  162.     LOCATE 25, 68: PRINT "C  00001:001 ";
  163.  
  164.  

That's right. I've gone completely batty! 🦇🦇🦇🦇🦇

Pete

Edited to remove Error 5 caused by incorrectly named variable in _FREEIMAGE statement. Thanks Jack!
« Last Edit: October 19, 2021, 11:21:51 am by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Is this at all possible in SCREEN 0?
« Reply #17 on: October 19, 2021, 06:39:00 am »
Pete it look good but there's a problem, as soon as I press a key I get
Code: [Select]
---------------------------
Unhandled Error #5 - untitled.exe
---------------------------
Line: 94 (in main module)
Illegal function call
Continue?
---------------------------
Yes   No   
---------------------------

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Is this at all possible in SCREEN 0?
« Reply #18 on: October 19, 2021, 11:17:47 am »
I'll have a look....

Found it, _FREEIMAGE Overlay_Hardware at line 94.

I said this stuff was making me batty...

Ah, I should have coded that as: _FREEIMAGE Overlay

I'll edit that in the code.

Thanks Jack!

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

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Is this at all possible in SCREEN 0?
« Reply #19 on: October 19, 2021, 11:58:09 am »
Pete, no crash but the game won't play
or was this only to show the transparency and not the game itself ?

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Is this at all possible in SCREEN 0?
« Reply #20 on: October 19, 2021, 12:15:21 pm »
You have to put a quarter in, first.

Right, it's just to show the effect, which I haven't substituted into the game yet. I still have to convert using _PRINTSTRING with the alt key input routine to accomplish that.

The game, which does include a SCREEN 0 scoreboard and 5-highest scores database, is here in the "Competition" thread: https://www.qb64.org/forum/index.php?topic=4245.msg137017#msg137017

Pete 

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

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Is this at all possible in SCREEN 0?
« Reply #21 on: October 22, 2021, 02:04:41 pm »
@SMcNeill Hey Steve, thanks again for sharing this technique. I know @Cobalt has a similar overlay method, too. He just augmented Marks Connect 4 project with a replica of the Connect 4 board, used as an overlay.

So I put a centering routine and non-centering routine in subs like you recommened. It helps me see what's going on in my head a lot better. The _FONTWIDTH and _FONTHEIGHT conversions make that easy.

Here's my keeper for the demo...

For versions 1.4 and up.
Code: QB64: [Select]
  1. Screen0 = _NEWIMAGE(80, 25, 0)
  2. SCREEN Screen0
  3.  
  4.  
  5. COLOR 0, 7
  6. FOR x = 1 TO 25
  7.     LOCATE x, 1: PRINT STRING$(80, 176);
  8.  
  9. _DEST overlay
  10. COLOR MidnightBlue, 0
  11.  
  12. REDIM text$(5)
  13. text$(1) = "This is a SCREEN 0 overlay method"
  14. text$(2) = "used by the Amazing Steve and"
  15. text$(3) = "modified by me to create a simple"
  16. text$(4) = "text to screen overlay on a dotted"
  17. text$(5) = "SCREEN 0 background!"
  18.  
  19. font = _LOADFONT("lucon.ttf", 25, "monospace")
  20. IF font <= 0 THEN font = 16
  21. _FONT font
  22.  
  23. startrow = 3
  24. FOR k = 1 TO 5
  25.     t$ = text$(k)
  26.     y = startrow + k * 2 - 1 ' Double space.
  27.  
  28.     pslc y, t$, overlay, Overlay_hardware
  29.  
  30.     _DELAY .5
  31.  
  32. _FONT 16 'select inbuilt 8x16 default font
  33. _FREEFONT font ' Must be placed after the font is changed.
  34.  
  35. COLOR Black, 0
  36. msg$ = "Press space bar to toggle overlay. Press Esc to end."
  37.  
  38. psl 25, 1, msg$, overlay, Overlay_hardware
  39.  
  40.     _LIMIT 30
  41.     b$ = INKEY$
  42.     IF LEN(b$) THEN
  43.         IF b$ = CHR$(27) THEN EXIT DO
  44.         IF Show_Overlay THEN _PUTIMAGE (0, 0), Overlay_hardware
  45.         Show_Overlay = NOT Show_Overlay
  46.         _DISPLAY
  47.     END IF
  48.  
  49. _FREEIMAGE Overlay_hardware
  50. _DEST 0 'Reset dest back to the normal screen 0.
  51. COLOR 0, 7
  52. _DELAY .75
  53. COLOR 1, 7
  54. LOCATE 2, 2
  55. PRINT "Hi, back in SCREEN 0. Bye!"
  56. _DELAY 2.25
  57.  
  58. SUB psl (y, x, t$, overlay, Overlay_hardware)
  59.     _PRINTSTRING ((x - 1) * _FONTWIDTH, (y - 1) * _FONTHEIGHT), t$
  60.     Overlay_hardware = _COPYIMAGE(overlay, 33)
  61.     _PUTIMAGE (0, 0), Overlay_hardware
  62.     _DISPLAY
  63.  
  64. SUB pslc (y, t$, overlay, Overlay_hardware)
  65.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(t$)) \ 2, (y - 1) * _FONTHEIGHT), t$
  66.     Overlay_hardware = _COPYIMAGE(overlay, 33)
  67.     _PUTIMAGE (0, 0), Overlay_hardware
  68.     _DISPLAY


Oh, and this for Version 1.3 (No $COLOR:32)

Code: QB64: [Select]
  1. Screen0 = _NEWIMAGE(80, 25, 0)
  2. SCREEN Screen0
  3.  
  4.  
  5. COLOR 0, 7
  6. FOR x = 1 TO 25
  7.     LOCATE x, 1: PRINT STRING$(80, 176);
  8.  
  9. _DEST overlay
  10. COLOR _RGB(0, 0, 102), 0
  11.  
  12. REDIM text$(5)
  13. text$(1) = "This is a SCREEN 0 overlay method"
  14. text$(2) = "used by the Amazing Steve and"
  15. text$(3) = "modified by me to create a simple"
  16. text$(4) = "text to screen overlay on a dotted"
  17. text$(5) = "SCREEN 0 background!"
  18.  
  19. font = _LOADFONT("lucon.ttf", 25, "monospace")
  20. IF font <= 0 THEN font = 16
  21. _FONT font
  22.  
  23. startrow = 3
  24. FOR k = 1 TO 5
  25.     t$ = text$(k)
  26.     y = startrow + k * 2 - 1 ' Double space.
  27.  
  28.     pslc y, t$, overlay, Overlay_hardware
  29.  
  30.     _DELAY .5
  31.  
  32. _FONT 16 'select inbuilt 8x16 default font
  33. _FREEFONT font ' Must be placed after the font is changed.
  34.  
  35. COLOR _RGB(20, 20, 20), 0
  36. msg$ = "Press space bar to toggle overlay. Press Esc to end."
  37.  
  38. psl 25, 1, msg$, overlay, Overlay_hardware
  39.  
  40.     _LIMIT 30
  41.     b$ = INKEY$
  42.     IF LEN(b$) THEN
  43.         IF b$ = CHR$(27) THEN EXIT DO
  44.         IF Show_Overlay THEN _PUTIMAGE (0, 0), Overlay_hardware
  45.         Show_Overlay = NOT Show_Overlay
  46.         _DISPLAY
  47.     END IF
  48.  
  49. _FREEIMAGE Overlay_hardware
  50. _DEST 0 'Reset dest back to the normal screen 0.
  51. COLOR 0, 7
  52. _DELAY .75
  53. COLOR 1, 7
  54. LOCATE 2, 2
  55. PRINT "Hi, back in SCREEN 0. Bye!"
  56. _DELAY 2.25
  57.  
  58. SUB psl (y, x, t$, overlay, Overlay_hardware)
  59.     _PRINTSTRING ((x - 1) * _FONTWIDTH, (y - 1) * _FONTHEIGHT), t$
  60.     Overlay_hardware = _COPYIMAGE(overlay, 33)
  61.     _PUTIMAGE (0, 0), Overlay_hardware
  62.     _DISPLAY
  63.  
  64. SUB pslc (y, t$, overlay, Overlay_hardware)
  65.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(t$)) \ 2, (y - 1) * _FONTHEIGHT), t$
  66.     Overlay_hardware = _COPYIMAGE(overlay, 33)
  67.     _PUTIMAGE (0, 0), Overlay_hardware
  68.     _DISPLAY
  69.  


Pete
« Last Edit: October 22, 2021, 02:16:27 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/