Author Topic: I'm new to QB64 and I'm having a conniption  (Read 3338 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I'm new to QB64 and I'm having a conniption
« Reply #15 on: December 03, 2019, 10:37:52 pm »
Interesting project, not familiar with game but it looks like you can put up real star data and teach star gazing, ID stars.

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: I'm new to QB64 and I'm having a conniption
« Reply #16 on: December 03, 2019, 11:01:31 pm »
Yes! Maybe on a phone or tablet that people can take outside with them.
My name is Michael, but you can call me Mike :)

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: I'm new to QB64 and I'm having a conniption
« Reply #17 on: December 03, 2019, 11:34:48 pm »
Scaling for different resolutions turned out to be rather trivial. It took about 5 minutes. Here is the new code. My monitors are only 1920 x 1080p. If anyone has 1440p or 4k please check it out and let me know if it scales ok. Thanks. Or maybe QB64 does not work at those resolutions? I forget. It's bedtime! gn :)

P.S. I will comment the code before doing much more.

Code: QB64: [Select]
  1. TYPE stars
  2.     n AS STRING * 10
  3.     x AS INTEGER
  4.     y AS INTEGER
  5.     o AS INTEGER
  6.     c AS INTEGER
  7.     s AS INTEGER
  8.     t AS INTEGER
  9.     p AS INTEGER
  10.  
  11. DECLARE SUB NewGame
  12. DECLARE SUB PutStars
  13. DECLARE SUB GiveName
  14. DECLARE SUB ShowPanel (i)
  15.  
  16. DIM repeat AS INTEGER
  17. DIM SHARED star(100) AS stars
  18. DIM ch AS STRING * 1
  19. DIM SHARED names(200) AS STRING * 10
  20.  
  21. repeat = 1
  22.  
  23. sww = sw / 24
  24. swn = sw / 48
  25. nw = 1920
  26.  
  27. ratio = sw / 1920
  28.  
  29. shw = sh / 20
  30. shn = sh / 40
  31. nh = 1080
  32.  
  33. SCREEN _NEWIMAGE(sw, sh, 256)
  34.  
  35.  
  36. GiveName
  37.  
  38. NewGame
  39.  
  40. WHILE repeat
  41.  
  42.     _LIMIT 60
  43.  
  44.     CLS
  45.  
  46.     PutStars
  47.  
  48.  
  49.     x = _MOUSEX
  50.     y = _MOUSEY
  51.     mb = _MOUSEBUTTON(1)
  52.  
  53.     FOR i = 0 TO 99
  54.         dx = star(i).x - x
  55.         dy = star(i).y - y
  56.         IF ABS(dx) <= star(i).s + 6 AND ABS(dy) <= star(i).s + 6 THEN
  57.             ShowPanel (i)
  58.         END IF
  59.     NEXT
  60.  
  61.     _DISPLAY
  62.  
  63.     ch = INKEY$
  64.     IF ch = CHR$(27) THEN repeat = 0
  65.     IF ch = "n" THEN NewGame
  66.     ch = ""
  67.  
  68.  
  69.  
  70. SUB ShowPanel (i)
  71.     PRINT star(i).n
  72.  
  73. SUB PutStars
  74.     FOR i = 0 TO 99
  75.         CIRCLE (star(i).x, star(i).y), (star(i).s + 6) * ratio, star(i).c
  76.     NEXT
  77.  
  78. SUB NewGame
  79.     DIM k AS INTEGER
  80.     DIM r AS INTEGER
  81.     DIM dx AS INTEGER
  82.     DIM dy AS INTEGER
  83.     DIM n AS STRING * 10
  84.     star(0).n = "Sol"
  85.     star(0).x = RND * (sw - sww) + swn
  86.     star(0).y = RND * (sh - shw) + shn
  87.     star(0).c = 14
  88.     star(0).s = 3
  89.     FOR i = 1 TO 99
  90.         k = 1
  91.         WHILE k
  92.             k = 0
  93.             x = RND * (sw - sww) + swn
  94.             y = RND * (sh - shw) + shn
  95.             r = INT(RND * 200)
  96.             n = names(r)
  97.             FOR j = 0 TO i - 1
  98.                 dx = x - star(j).x
  99.                 dy = y - star(j).y
  100.                 IF ABS(dx) < sww AND ABS(dy) < shw THEN
  101.                     k = 1
  102.                 END IF
  103.                 IF n = star(j).n THEN
  104.                     k = 1
  105.                 END IF
  106.             NEXT
  107.         WEND
  108.         star(i).n = n
  109.         star(i).x = x
  110.         star(i).y = y
  111.         star(i).c = RND * 7 + 9
  112.         star(i).s = RND * 5
  113.     NEXT
  114.  
  115. ' A lot of star names I made up
  116.  
  117. SUB GiveName
  118.     names(0) = "Acamar"
  119.     names(1) = "Arcab"
  120.     names(2) = "Acrux"
  121.     names(3) = "Adhara"
  122.     names(4) = "Arneb"
  123.     names(5) = "Antares"
  124.     names(6) = "Arcturus"
  125.     names(7) = "Atria"
  126.     names(8) = "Beid"
  127.     names(9) = "Betelgeuse"
  128.     names(10) = "Botein"
  129.     names(11) = "Beemim"
  130.     names(12) = "Bellatrix"
  131.     names(13) = "Bharani"
  132.     names(14) = "Biham"
  133.     names(15) = "Brachium"
  134.     names(16) = "Canopus"
  135.     names(17) = "Capella"
  136.     names(18) = "Castor"
  137.     names(19) = "Chara"
  138.     names(20) = "Cursa"
  139.     names(21) = "Copernicus"
  140.     names(22) = "Chalawan"
  141.     names(23) = "Chertan"
  142.     names(24) = "Dabih"
  143.     names(25) = "Dalim"
  144.     names(26) = "Deneb"
  145.     names(27) = "Denebola"
  146.     names(28) = "Diadem"
  147.     names(29) = "Diphda"
  148.     names(30) = "Dschubba"
  149.     names(31) = "Dziban"
  150.     names(32) = "Edasich"
  151.     names(33) = "Electra"
  152.     names(34) = "Elgafar"
  153.     names(35) = "Elkurud"
  154.     names(36) = "Elnath"
  155.     names(37) = "Eltanin"
  156.     names(38) = "Enif"
  157.     names(39) = "Errai"
  158.     names(40) = "Fafnir"
  159.     names(41) = "Fang"
  160.     names(42) = "Fawaris"
  161.     names(43) = "Felis"
  162.     names(44) = "Fomalhaut"
  163.     names(45) = "Fulu"
  164.     names(46) = "Fumal"
  165.     names(47) = "Furud"
  166.     names(48) = "Garnet"
  167.     names(49) = "Giausar"
  168.     names(50) = "Gienah"
  169.     names(51) = "Ginan"
  170.     names(52) = "Gomeisa"
  171.     names(53) = "Graffias"
  172.     names(54) = "Grumium"
  173.     names(55) = "Gudja"
  174.     names(56) = "Hadar"
  175.     names(57) = "Haedus"
  176.     names(58) = "Hamal"
  177.     names(59) = "Hassaleh"
  178.     names(60) = "Hatysa"
  179.     names(61) = "Helvetios"
  180.     names(62) = "Heze"
  181.     names(63) = "Homan"
  182.     names(64) = "Iklil"
  183.     names(65) = "Imai"
  184.     names(66) = "Intercrus"
  185.     names(67) = "Izar"
  186.     names(68) = "Iccar"
  187.     names(69) = "Inar"
  188.     names(70) = "Iaeth"
  189.     names(71) = "Imaous"
  190.     names(72) = "Jabbah"
  191.     names(73) = "Jishui"
  192.     names(74) = "Jax"
  193.     names(75) = "Jalae"
  194.     names(76) = "Jewel"
  195.     names(77) = "Jumbo"
  196.     names(78) = "Jerue"
  197.     names(79) = "Jabear"
  198.     names(80) = "Kakkab"
  199.     names(81) = "Kang"
  200.     names(82) = "Kekouan"
  201.     names(83) = "Keid"
  202.     names(84) = "Kitalpha"
  203.     names(85) = "Kochab"
  204.     names(86) = "Kolob"
  205.     names(87) = "Kobol"
  206.     names(88) = "Larawag"
  207.     names(89) = "Lesath"
  208.     names(90) = "Libertas"
  209.     names(91) = "Lich"
  210.     names(92) = "Lilly"
  211.     names(93) = "Laddel"
  212.     names(94) = "Luminous"
  213.     names(95) = "Lasacious"
  214.     names(96) = "Mizar"
  215.     names(97) = "Markab"
  216.     names(98) = "Matar"
  217.     names(99) = "Mintaka"
  218.     names(100) = "Meleph"
  219.     names(101) = "Menkar"
  220.     names(102) = "Merga"
  221.     names(103) = "Merope"
  222.     names(104) = "Nahn"
  223.     names(105) = "Naos"
  224.     names(106) = "Nashira"
  225.     names(107) = "Navi"
  226.     names(108) = "Nekkar"
  227.     names(109) = "Nembus"
  228.     names(110) = "Nihal"
  229.     names(111) = "Nunki"
  230.     names(112) = "Ogma"
  231.     names(113) = "Okab"
  232.     names(114) = "Ohmy"
  233.     names(115) = "Oragami"
  234.     names(116) = "Origen"
  235.     names(117) = "Omanii"
  236.     names(118) = "Obytewa"
  237.     names(119) = "Oglok"
  238.     names(120) = "Phact"
  239.     names(121) = "Pherkad"
  240.     names(122) = "Pleione"
  241.     names(122) = "Polaris"
  242.     names(123) = "Pollux"
  243.     names(124) = "Procyon"
  244.     names(125) = "Proxima"
  245.     names(126) = "Polis"
  246.     names(127) = "Quaint"
  247.     names(128) = "Quazzat"
  248.     names(129) = "Quetzal"
  249.     names(130) = "Qussol"
  250.     names(131) = "Quella"
  251.     names(132) = "Quyaeo"
  252.     names(133) = "Ququdas"
  253.     names(134) = "Quekak"
  254.     names(135) = "Rasalas"
  255.     names(136) = "Regor"
  256.     names(137) = "Regulus"
  257.     names(138) = "Rigel"
  258.     names(139) = "Revati"
  259.     names(140) = "Rotenev"
  260.     names(141) = "Rukbat"
  261.     names(142) = "Rastaban"
  262.     names(143) = "Sabik"
  263.     names(144) = "Sadr"
  264.     names(145) = "Saiph"
  265.     names(146) = "Sargas"
  266.     names(147) = "Sarin"
  267.     names(148) = "Syrma"
  268.     names(149) = "Spica"
  269.     names(150) = "Sirius"
  270.     names(151) = "Tarazed"
  271.     names(152) = "Taygeta"
  272.     names(153) = "Tejat"
  273.     names(154) = "Thabit"
  274.     names(155) = "Thuban"
  275.     names(156) = "Tiaki"
  276.     names(157) = "Toliman"
  277.     names(158) = "Torcular"
  278.     names(157) = "Umala"
  279.     names(158) = "Ulatte"
  280.     names(159) = "Ubbessa"
  281.     names(160) = "Unoless"
  282.     names(161) = "Umaddem"
  283.     names(162) = "Ummbra"
  284.     names(162) = "Uniqu"
  285.     names(163) = "Uzzaal"
  286.     names(164) = "Vega"
  287.     names(165) = "Veritate"
  288.     names(166) = "Vindetrix"
  289.     names(167) = "Vedas"
  290.     names(168) = "Vergg"
  291.     names(169) = "Vacant"
  292.     names(170) = "Vucae"
  293.     names(171) = "Vicar"
  294.     names(172) = "Wasat"
  295.     names(173) = "Wazn"
  296.     names(174) = "Wezen"
  297.     names(175) = "Waiten"
  298.     names(176) = "Wachar"
  299.     names(177) = "Wheelz"
  300.     names(178) = "Whatsp"
  301.     names(179) = "Wassand"
  302.     names(180) = "Xenno"
  303.     names(181) = "Xyphod"
  304.     names(182) = "Xu"
  305.     names(183) = "Xaal"
  306.     names(184) = "Xyross"
  307.     names(185) = "Xiggot"
  308.     names(186) = "Xirrks"
  309.     names(187) = "Yed"
  310.     names(188) = "Yildun"
  311.     names(189) = "yundun"
  312.     names(190) = "Yavyo"
  313.     names(191) = "Yotrac"
  314.     names(192) = "Yxzoqu"
  315.     names(193) = "Ynnot"
  316.     names(194) = "Zaniah"
  317.     names(195) = "Zaurak"
  318.     names(196) = "Zhang"
  319.     names(197) = "Zibal"
  320.     names(198) = "Zosma"
  321.     names(199) = "Zuben"
  322.  
  323.  
My name is Michael, but you can call me Mike :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I'm new to QB64 and I'm having a conniption
« Reply #18 on: December 04, 2019, 10:42:05 am »
Oh wouldn't that be something! to match users latitude and longitude and time and show them their night sky. :)

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: I'm new to QB64 and I'm having a conniption
« Reply #19 on: December 04, 2019, 01:35:47 pm »
Oh wouldn't that be something! to match users latitude and longitude and time and show them their night sky. :)

Hi bplus,

I am not going in that direction. But if you want to go in that direction and my code will help then by all means proceed! :)
My name is Michael, but you can call me Mike :)

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: I'm new to QB64 and I'm having a conniption
« Reply #20 on: December 05, 2019, 04:21:43 pm »
Hi romichess,

There is another conniption causing issue with the mouse you might want to be prepared for that TempodiBasic has alluded to.

This involves executing some code when the mouse is clicked.

The _MOUSEBUUTON(1) reading only tells you when the mouse button is being pressed and if you execute a block of code at that time, you are likely to execute it several times if the user is slow to release or the code is slow to read the mouse clear update, _Mousebutton(1) = 0.

I have only recently seen a best solution by Steve to be clear of mouse button down condition before executing a "Mouse Click Event" block of code.

I have only tested this in newly revised cSleep but looks good to me and you know Steve came up with it so it's got to be good (if it is bug free).

A demo of the technique:
Code: QB64: [Select]
  1. OPTION _EXPLICIT 'B+ actually this might be better than old version of cSleep because handles time also
  2.  
  3. PRINT "Hello World, press key, click mouse or wait 5 secs for goodbye."
  4. cSleep 5
  5. PRINT "goodbye world"
  6.  
  7. 'c for click + SLEEP, this does force you to commit to a max time to wait
  8. SUB cSleep (secsWait AS DOUBLE) 'wait for keypress or mouseclick, solves midnight problem nicely I think
  9.     DIM wayt AS INTEGER, oldMouse AS INTEGER, k AS LONG, startTime AS DOUBLE
  10.  
  11.     startTime = TIMER
  12.     wayt = 1
  13.     _KEYCLEAR
  14.     WHILE wayt
  15.         WHILE _MOUSEINPUT: WEND
  16.         IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN wayt = 0 ' <<<<<<<<<< execute Mouse Click Event
  17.         oldMouse = _MOUSEBUTTON(1) ' <<< this is Steve's cool way to get clear of mouse click
  18.         k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: wayt = 0  
  19.         IF TIMER - startTime < 0 THEN 'past midnight
  20.             IF TIMER + 24 * 60 * 60 - startTime > secsWait THEN wayt = 0
  21.         ELSE
  22.             IF TIMER - startTime >= secsWait THEN wayt = 0
  23.         END IF
  24.         _LIMIT 30
  25.     WEND
  26.  
  27. 'here is steve's   with midnight problem but really nice clear of mouse (and keypresses?)
  28. SUB Pause (time AS _FLOAT)
  29.     DIM ExitTime AS _FLOAT, k AS LONG, oldMouse AS INTEGER
  30.     _KEYCLEAR 'clear the keyboard buffer so we don't automatically exit the routine
  31.     IF time <= 0 THEN ExitTime = 1.18E+1000 ELSE ExitTime = time + TIMER
  32.     DO
  33.         WHILE _MOUSEINPUT: WEND
  34.         IF _MOUSEBUTTON(1) AND NOT oldMouse THEN EXIT SUB
  35.         k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: EXIT SUB 'clear any stray key events so they don't mess with code outside the Pause.
  36.         oldMouse = _MOUSEBUTTON(1)
  37.         _LIMIT 10
  38.     LOOP UNTIL ExitTime < TIMER
  39.  
  40.  

The oldMouse variable helps us get clear of the mouse down condition before we execute our mouse click code.

The solution I had imagined works really well.

Code: QB64: [Select]
  1.     WHILE _MOUSEINPUT: WEND '          Eat all the mice but keep last mouse to toy with
  2.  
  3.     x = _MOUSEX
  4.     y = _MOUSEY
  5.     mb = _MOUSEBUTTON(1)
  6.     clk = 0 ' click, is just a one frame signal
  7.  
  8.     IF mb = -1 AND cx = sw THEN ' if clicked_x is off screen there is no clicked_x
  9.         cx = x 'now we have a clicked_x
  10.         cy = y 'and a clicked_y
  11.     END IF
  12.  
  13.     IF mb = 0 AND cx < sw THEN ' and since we have a clicked_x
  14.         IF ABS(x - cx) < 4 AND ABS(y - cy) < 4 THEN ' mouse jiggle tolerance
  15.             clk = 1 ' we send a click signal for one frame
  16.         END IF
  17.         cx = sw ' and since the click signal is for x, y we move clicked_x off screen
  18.     END IF
  19.  
My name is Michael, but you can call me Mike :)