QB64.org Forum

Active Forums => Programs => Topic started by: romichess on December 04, 2019, 03:40:55 pm

Title: MOO
Post by: romichess on December 04, 2019, 03:40:55 pm
This is my first graphics project ever. My only meaningful work so far was writing RomiChess which has received praise from a handful of people due to its playing style and unique learning algorithm labeled as "famous" on the chess programming wiki. Okay, enough of that.

Anyway, my fav game of all time is MOO (Master Of Orion) 1. It is a DOS game from 1993. There have been dozens of attempts to emulate and improve upon it, including MOO 2, MOO 3 and MOO 2016. All add complexity and add to the micromanagement necessities of playing the game, successfully. I personally am of the Risk generation. Risk is a great game because it is super simple and easy to play. And yet one can put in as much deep thought and strategic planning as they want. MOO is a lot like that. Except MOO does have some problems that make it problematic to get a fair starting position. Sometimes one enemy or more are right on top of the players starting position while another enemy has a large portion of the map to themselves. Those games are often over before they begin. The micromanagement was rather simple in MOO but it could still be very time consuming.

My dream ever since the 90's was to create my own space conquest game similar to MOO but in the spirit of Risk, i.e., keep the micromanagement under control. It is to be real time instead of turn based and have a modern GUI. And by modern I mean one of my vision. Even though I taught myself to program in C in 2004 so I could write RomiChess anything more than a console based C application was beyond my ability. The reason for that was the complexity of installing and using graphics libraries with myriads of mind boggling function names and cryptic parameters. I spent months with some packages just to determine that they don't really do what I need to be done.

A couple of weeks ago I stumbled upon QB64. I was not immediately impressed. I have no need nor desire to do anything in less than 1080p. And all the examples were in less than 1080p. Then I stumbled upon a YT vid that was in a 1080p window. That got my attention. The presenter in the vid mentioned that _FULLSCREEN could be used but he'd leave that up to the viewer to implement. Okay, so I had to investigate. I downloaded QB64 and entered the YT presenters code and modified it to run _FULLSCREEN. For the first time ever I had in my hands a tool chain that would do what I wanted to do without exhausting myself trying to understand it. So I started a few days ago writing my game Beyond Sol.

My vision of the GUI is no visible GUI until requested. My example code gives the flavor. It displays the game, not the interface. In the example when a star is moused over it displays the name of the Star. Eventually it will display a panel. The panel will appear and disappear as stars (or fleets) are moused over. The panel will stay displayed if the star is clicked. I got a late start today so I have not cleaned up the code or commented it yet. I will do that next. Then I will find a way to display panels and print to them.

There is one thing I need to know. Does this work on 2k and 4k displays and is the scaling okay. Also any suggestions to make the game or code better are welcome. Even really cool star names would be nice. I just copied star names from a list and made a few up along the way. Can you spot the ones I made up, :)? For those following me on my initial thread I added a micro amount of graphical bling and initiated the 6 starting positions.

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

"Does this work on 2k and 4k displays and is the scaling okay?"

I do not know if the following is helpful for you but :-

I ran your program (without any changes what so ever) on my laptop which has 3200 x 1800 display and took a Windows 10 screenshot (attached as 1-3200x1800...)

I then imported this screenshot into Windows Paint and viewed at 800% (maximum), took a screenshot (attached as 2-3200x1800...).

I also imported the original screenshot into Windows Paint3D and viewed at 6400% (maximum), took a screenshot (attached as 3-3200x1800...)

And finally imported the screenshot above (i.e. 3-3200x1800...) into Paint and viewed at 800% (maximum), took a screenshot (attached as 4-3200x1800...)

Windows Paint allowed pixel coordinates of cursor and grid lines - however Windows Paint3D does not (and is a real pain to use because of this).

My display (3200x1800) is classified as 3k (by some) and in every QB64 graphics application I have wrote etc - I DO NOT GET THE FULL DISPLAY RESOLUTION ( I only seem to get 1600x900 - i.e. all pixels instead of being 1x1 become 2x2 - and alternate pixels are not displayed (in x or y positioning).

As far as I can tell (at this stage) the display electronically appears to be working correctly and when I view say File Explorer page with an actual 10x magnifying glass (not the silly Windows 10 magnifier which seems to optically distort the display image) it would seem to be okay - however it is difficult to find anything that is actually only 1 pixel wide (say) so I cannot confirm if pixels are preserved as 1x1 or that they are converted to 2x2 (which kind of defeats the purpose of having a higher resolution display).

Previously (Page 7 of Discussion) I started a post "3200 x 1800 display problem" which you may want to read. I am still trying to sort out my problem.

In summary, I do not get 1x1 pixel resolution (I get 2x2 pixel resolution) and I may be missing 75% of the "pin point stars" (if they are unlucky to be located on the alternate x and y coordinate positions).

I would be happy to re-run your program if you (slightly) rewrite it to directly access 3200 x 1800 display (as fullscreen) and if you cram various possibilities in say the very extreme top left hand corner (the easiest area for me to access using the silly painful Windows 10 Paint3d at 6400%) and throw in some fixed grid references (so actual pixel coordinates can be confirmed).

From all of above I assumed you were interested in the resolution capabilities of the display to your star maps.

Hope this may be of use to you.
Title: Re: MOO
Post by: romichess on December 04, 2019, 10:03:06 pm
Hi Richard,

Thanks for all the work. Much appreciation! While the game is being developed on a 1080p system it does not set up the graphics for anything other than the native resolution of the users system. The only thing the scaling does is decide how big to draw the circles. The x and y coordinates use the full native range of the users system. That means that when the program starts on your 3200 x 1800 system if that really is the true _DESKTOPWIDTH and _DESKTOPHEIGHT of your monitor as it appears to be because it appears to look and scale correctly.

One thing to consider is the graphics adapter in your system. If it is set to 1600 x 900 it will double the pixel x and y dimensions to fill the monitor. I have seen that problem before. A friend had a monitor with a higher resolution than his graphics card would do. Just some thoughts.

Anyway, thanks again!

 
Title: Re: MOO
Post by: romichess on December 04, 2019, 10:22:21 pm
It took a while to wade through all the information and to find the right combination to do exactly what was needed. And of course there was a couple of hours of frustration trying to figure out what I was doing wrong and why it would not work correctly. However, it works now, yay! The panel is up and working and the star name is on the panel. Next I have to figure out fonts and font sizing. And add a bit more functionality to the panel.

Code: QB64: [Select]
  1. TYPE stars
  2.     n AS STRING * 10 '                 Name of star
  3.     x AS INTEGER '                     x-position
  4.     y AS INTEGER '                     y-position
  5.     o AS INTEGER '                     Owner
  6.     c AS INTEGER '                     Color
  7.     s AS INTEGER '                     Size
  8.     t AS INTEGER '                     Type of planetary system; terran, frozen, radiated, toxic, etc.
  9.     p AS INTEGER '                     Population
  10.  
  11. DECLARE SUB NewGame
  12. DECLARE SUB PaintStars
  13. DECLARE SUB StarNames
  14. DECLARE SUB ShowPanel (i)
  15. DECLARE SUB Identify (x, y)
  16. DECLARE SUB PaintBackground
  17.  
  18. ' Global variables shared because they are needed in more than one routine
  19. DIM SHARED sw AS INTEGER '             Screen Width
  20. DIM SHARED sh AS INTEGER '             Screen Height
  21. DIM SHARED sww AS INTEGER '            Screen Width Wide margin
  22. DIM SHARED swn AS INTEGER '            Screen Width Narrow adjustment
  23. DIM SHARED shw AS INTEGER '            Screen Height Wide margine
  24. DIM SHARED shn AS INTEGER '            Screen Height Narrow adjustment
  25. DIM SHARED nw AS INTEGER '             games Natural screen Width
  26. DIM SHARED nh AS INTEGER '             games Natural screen Height
  27. DIM SHARED ratio AS _FLOAT '           the Ratio of the games natural screen width to the actual
  28. DIM SHARED star(100) AS stars '        100 stars - may change
  29. DIM SHARED names(200) AS STRING * 10 ' 200 star names
  30. DIM SHARED seed AS INTEGER '           Seed to prime the Randomizer to display identical background each frame
  31. DIM SHARED home(6) AS INTEGER '        The starting star for each player. The human always has star(0), Sol
  32.  
  33. ' Simple variables
  34. DIM repeat AS INTEGER '                Game loop control variable
  35. DIM ch AS STRING * 1 '                 Game loop key input variable
  36.  
  37. repeat = 1
  38.  
  39. sw = _DESKTOPWIDTH '                   native video with of syatem
  40. sww = sw / 24 '                        margin based on native video width to keep stars away from edge
  41. swn = sw / 48 '                        adjustment that works with sww to keep stars away from left and top of screen
  42. nw = 1920
  43.  
  44. ratio = sw / 1920 '                    Used to adjust distances and sizes for various screen modes
  45.  
  46. shw = sh / 20
  47. shn = sh / 40
  48. nh = 1080
  49.  
  50. SCREEN _NEWIMAGE(sw, sh, 256) '        creates a screen the resolution of the users native system
  51.  
  52.  
  53. StarNames '                            Routine to load star names into string array stars(200)
  54.  
  55. NewGame
  56.  
  57. WHILE repeat
  58.  
  59.     _LIMIT 60 '                        Set to 60 frames per second
  60.  
  61.     CLS
  62.  
  63.     WHILE _MOUSEINPUT: WEND '          Eat all the mice but keep last mouse to toy with
  64.  
  65.     x = _MOUSEX
  66.     y = _MOUSEY
  67.     mb = _MOUSEBUTTON(1)
  68.  
  69.     PaintBackground
  70.  
  71.     PaintStars
  72.  
  73.     Identify x, y '                    Identify star mouse is over if any
  74.  
  75.     _DISPLAY
  76.  
  77.     ch = INKEY$
  78.     IF ch = CHR$(27) THEN repeat = 0
  79.     IF ch = "n" THEN NewGame
  80.     ch = ""
  81.  
  82.  
  83.  
  84. SUB PaintBackground
  85.     x = RND * sw
  86.     y = RND * sh
  87.     c = RND * 14 + 1
  88.     PSET (x, y), c
  89.     RANDOMIZE USING seed
  90.     FOR i = 1 TO 600 * ratio
  91.         x = RND * sw
  92.         y = RND * sh
  93.         c = RND * 14 + 1
  94.         PSET (x, y), c
  95.     NEXT
  96.  
  97. SUB Identify (x, y)
  98.     FOR i = 0 TO 99
  99.         dx = star(i).x - x
  100.         dy = star(i).y - y
  101.         IF ABS(dx) <= star(i).s + 6 AND ABS(dy) <= star(i).s + 6 THEN
  102.             ShowPanel i
  103.         END IF
  104.     NEXT
  105.  
  106. SUB ShowPanel (i)
  107.     DIM ps AS LONG
  108.     DIM x AS INTEGER
  109.     DIM y AS INTEGER
  110.     x = star(i).x - 420 * ratio
  111.     IF star(i).x < sw / 2 THEN x = star(i).x + 20
  112.     y = star(i).y
  113.     IF y > sh - 540 * ratio THEN y = sh - 540 * ratio
  114.     ps = _NEWIMAGE(400 * ratio, 540 * ratio, 256)
  115.     _DEST ps
  116.     CLS 0, 8
  117.     PRINT star(i).n
  118.     _PUTIMAGE (x, y), ps, 0, (0, 0)-(400 * ratio, 540 * ratio)
  119.     _DEST 0
  120.  
  121. SUB PaintStars
  122.     FOR i = 0 TO 99
  123.         c = star(i).c
  124.         x = star(i).x
  125.         y = star(i).y
  126.         CIRCLE (x, y), (star(i).s + 6) * ratio, c
  127.         IF star(i).o > 0 THEN
  128.             PAINT (x, y), star(i).o + 8, c
  129.         END IF
  130.     NEXT
  131.  
  132. SUB NewGame
  133.     DIM k AS INTEGER
  134.     DIM r AS INTEGER
  135.     DIM dx AS INTEGER
  136.     DIM dy AS INTEGER
  137.     DIM n AS STRING * 10
  138.     seed = RND * 1000
  139.     star(0).n = "Sol"
  140.     star(0).x = RND * (sw - sww) + swn
  141.     star(0).y = RND * (sh - shw) + shn
  142.     star(0).c = 14
  143.     star(0).s = 3
  144.     star(0).o = 1
  145.     home(0) = 0
  146.     FOR i = 1 TO 99
  147.         k = 1
  148.         WHILE k
  149.             k = 0
  150.             x = RND * (sw - sww) + swn
  151.             y = RND * (sh - shw) + shn
  152.             r = INT(RND * 200)
  153.             n = names(r)
  154.             FOR j = 0 TO i - 1
  155.                 dx = x - star(j).x
  156.                 dy = y - star(j).y
  157.                 IF ABS(dx) < sww AND ABS(dy) < shw THEN
  158.                     k = 1
  159.                 END IF
  160.                 IF n = star(j).n THEN
  161.                     k = 1
  162.                 END IF
  163.             NEXT
  164.         WEND
  165.         star(i).n = n
  166.         star(i).x = x
  167.         star(i).y = y
  168.         star(i).c = RND * 7 + 9
  169.         star(i).s = RND * 5
  170.         star(i).o = 0
  171.     NEXT
  172.     FOR i = 2 TO 6
  173.         k = 1
  174.         WHILE k
  175.             k = 0
  176.             r = RND * 100
  177.             FOR j = 1 TO i - 1
  178.                 IF r = home(j) THEN k = 1
  179.                 x = star(0).x
  180.                 y = star(0).y
  181.                 dx = ABS(star(r).x - x)
  182.                 dy = ABS(star(r).y - y)
  183.                 IF dx < sw / 4 AND dy < sh / 4 THEN k = 1
  184.             NEXT
  185.         WEND
  186.         home(i) = r
  187.         star(r).o = i
  188.     NEXT
  189.  
  190. ' A lot of star names I made up
  191.  
  192. SUB StarNames
  193.     names(0) = "Acamar"
  194.     names(1) = "Arcab"
  195.     names(2) = "Acrux"
  196.     names(3) = "Adhara"
  197.     names(4) = "Arneb"
  198.     names(5) = "Antares"
  199.     names(6) = "Arcturus"
  200.     names(7) = "Atria"
  201.     names(8) = "Beid"
  202.     names(9) = "Betelgeuse"
  203.     names(10) = "Botein"
  204.     names(11) = "Beemim"
  205.     names(12) = "Bellatrix"
  206.     names(13) = "Bharani"
  207.     names(14) = "Biham"
  208.     names(15) = "Brachium"
  209.     names(16) = "Canopus"
  210.     names(17) = "Capella"
  211.     names(18) = "Castor"
  212.     names(19) = "Chara"
  213.     names(20) = "Cursa"
  214.     names(21) = "Copernicus"
  215.     names(22) = "Chalawan"
  216.     names(23) = "Chertan"
  217.     names(24) = "Dabih"
  218.     names(25) = "Dalim"
  219.     names(26) = "Deneb"
  220.     names(27) = "Denebola"
  221.     names(28) = "Diadem"
  222.     names(29) = "Diphda"
  223.     names(30) = "Dschubba"
  224.     names(31) = "Dziban"
  225.     names(32) = "Edasich"
  226.     names(33) = "Electra"
  227.     names(34) = "Elgafar"
  228.     names(35) = "Elkurud"
  229.     names(36) = "Elnath"
  230.     names(37) = "Eltanin"
  231.     names(38) = "Enif"
  232.     names(39) = "Errai"
  233.     names(40) = "Fafnir"
  234.     names(41) = "Fang"
  235.     names(42) = "Fawaris"
  236.     names(43) = "Felis"
  237.     names(44) = "Fomalhaut"
  238.     names(45) = "Fulu"
  239.     names(46) = "Fumal"
  240.     names(47) = "Furud"
  241.     names(48) = "Garnet"
  242.     names(49) = "Giausar"
  243.     names(50) = "Gienah"
  244.     names(51) = "Ginan"
  245.     names(52) = "Gomeisa"
  246.     names(53) = "Graffias"
  247.     names(54) = "Grumium"
  248.     names(55) = "Gudja"
  249.     names(56) = "Hadar"
  250.     names(57) = "Haedus"
  251.     names(58) = "Hamal"
  252.     names(59) = "Hassaleh"
  253.     names(60) = "Hatysa"
  254.     names(61) = "Helvetios"
  255.     names(62) = "Heze"
  256.     names(63) = "Homan"
  257.     names(64) = "Iklil"
  258.     names(65) = "Imai"
  259.     names(66) = "Intercrus"
  260.     names(67) = "Izar"
  261.     names(68) = "Iccar"
  262.     names(69) = "Inar"
  263.     names(70) = "Iaeth"
  264.     names(71) = "Imaous"
  265.     names(72) = "Jabbah"
  266.     names(73) = "Jishui"
  267.     names(74) = "Jax"
  268.     names(75) = "Jalae"
  269.     names(76) = "Jewel"
  270.     names(77) = "Jumbo"
  271.     names(78) = "Jerue"
  272.     names(79) = "Jabear"
  273.     names(80) = "Kakkab"
  274.     names(81) = "Kang"
  275.     names(82) = "Kekouan"
  276.     names(83) = "Keid"
  277.     names(84) = "Kitalpha"
  278.     names(85) = "Kochab"
  279.     names(86) = "Kolob"
  280.     names(87) = "Kobol"
  281.     names(88) = "Larawag"
  282.     names(89) = "Lesath"
  283.     names(90) = "Libertas"
  284.     names(91) = "Lich"
  285.     names(92) = "Lilly"
  286.     names(93) = "Laddel"
  287.     names(94) = "Luminous"
  288.     names(95) = "Lasacious"
  289.     names(96) = "Mizar"
  290.     names(97) = "Markab"
  291.     names(98) = "Matar"
  292.     names(99) = "Mintaka"
  293.     names(100) = "Meleph"
  294.     names(101) = "Menkar"
  295.     names(102) = "Merga"
  296.     names(103) = "Merope"
  297.     names(104) = "Nahn"
  298.     names(105) = "Naos"
  299.     names(106) = "Nashira"
  300.     names(107) = "Navi"
  301.     names(108) = "Nekkar"
  302.     names(109) = "Nembus"
  303.     names(110) = "Nihal"
  304.     names(111) = "Nunki"
  305.     names(112) = "Ogma"
  306.     names(113) = "Okab"
  307.     names(114) = "Ohmy"
  308.     names(115) = "Oragami"
  309.     names(116) = "Origen"
  310.     names(117) = "Omanii"
  311.     names(118) = "Obytewa"
  312.     names(119) = "Oglok"
  313.     names(120) = "Phact"
  314.     names(121) = "Pherkad"
  315.     names(122) = "Pleione"
  316.     names(122) = "Polaris"
  317.     names(123) = "Pollux"
  318.     names(124) = "Procyon"
  319.     names(125) = "Proxima"
  320.     names(126) = "Polis"
  321.     names(127) = "Quaint"
  322.     names(128) = "Quazzat"
  323.     names(129) = "Quetzal"
  324.     names(130) = "Qussol"
  325.     names(131) = "Quella"
  326.     names(132) = "Quyaeo"
  327.     names(133) = "Ququdas"
  328.     names(134) = "Quekak"
  329.     names(135) = "Rasalas"
  330.     names(136) = "Regor"
  331.     names(137) = "Regulus"
  332.     names(138) = "Rigel"
  333.     names(139) = "Revati"
  334.     names(140) = "Rotenev"
  335.     names(141) = "Rukbat"
  336.     names(142) = "Rastaban"
  337.     names(143) = "Sabik"
  338.     names(144) = "Sadr"
  339.     names(145) = "Saiph"
  340.     names(146) = "Sargas"
  341.     names(147) = "Sarin"
  342.     names(148) = "Syrma"
  343.     names(149) = "Spica"
  344.     names(150) = "Sirius"
  345.     names(151) = "Tarazed"
  346.     names(152) = "Taygeta"
  347.     names(153) = "Tejat"
  348.     names(154) = "Thabit"
  349.     names(155) = "Thuban"
  350.     names(156) = "Tiaki"
  351.     names(157) = "Toliman"
  352.     names(158) = "Torcular"
  353.     names(157) = "Umala"
  354.     names(158) = "Ulatte"
  355.     names(159) = "Ubbessa"
  356.     names(160) = "Unoless"
  357.     names(161) = "Umaddem"
  358.     names(162) = "Ummbra"
  359.     names(162) = "Uniqu"
  360.     names(163) = "Uzzaal"
  361.     names(164) = "Vega"
  362.     names(165) = "Veritate"
  363.     names(166) = "Vindetrix"
  364.     names(167) = "Vedas"
  365.     names(168) = "Vergg"
  366.     names(169) = "Vacant"
  367.     names(170) = "Vucae"
  368.     names(171) = "Vicar"
  369.     names(172) = "Wasat"
  370.     names(173) = "Wazn"
  371.     names(174) = "Wezen"
  372.     names(175) = "Waiten"
  373.     names(176) = "Wachar"
  374.     names(177) = "Wheelz"
  375.     names(178) = "Whatsp"
  376.     names(179) = "Wassand"
  377.     names(180) = "Xenno"
  378.     names(181) = "Xyphod"
  379.     names(182) = "Xu"
  380.     names(183) = "Xaal"
  381.     names(184) = "Xyross"
  382.     names(185) = "Xiggot"
  383.     names(186) = "Xirrks"
  384.     names(187) = "Yed"
  385.     names(188) = "Yildun"
  386.     names(189) = "yundun"
  387.     names(190) = "Yavyo"
  388.     names(191) = "Yotrac"
  389.     names(192) = "Yxzoqu"
  390.     names(193) = "Ynnot"
  391.     names(194) = "Zaniah"
  392.     names(195) = "Zaurak"
  393.     names(196) = "Zhang"
  394.     names(197) = "Zibal"
  395.     names(198) = "Zosma"
  396.     names(199) = "Zuben"
  397.  
Title: Re: MOO
Post by: SierraKen on December 04, 2019, 10:48:50 pm
Interesting start of a space simulator game you got there. I've thought of similar things. Back in the 80's I had a store-bought game that let you fly to different planets on my Apple 2e compatible computer. I see you mention GUI's a bit. I don't know if you know, but QB64 does have a GUI add-on if you want to use it. It's called InForm and it's on the main page or directly here: https://www.qb64.org/inform/ (https://www.qb64.org/inform/) I'm just starting out on that myself and I've used QB64 for almost half a year now. There's also a forum area for that as well here: https://www.qb64.org/forum/index.php?board=13.0 (https://www.qb64.org/forum/index.php?board=13.0) with some examples. There's some examples and info on the download page as well.
That's really awesome you made a Chess game. I've never programmed something that intense, but recently I made a Tic-Tac-Toe game against the computer. My website so far has 33 examples of QB64 programs and games if you want to check it out, here: http://www.KensPrograms.com/ (http://www.KensPrograms.com/) Most of them you copy/paste the .txt files to your own QB64 language. That URL is also below on all my forum posts.
I've been using this forum here since I started QB64 in the Summer and there's a lot of great helpers here if you need anything. I've learned that screen size matters a lot if you make specified window sizes. I have my Brick Smasher game on my website that uses _FULLSCREEN which you can check out too. I've seen that people rarely use FULLSCREEN on this forum though, probably because of the ease to turn off a game by clicking X and also the fact that you can use the _TITLE command anywhere in your program to add and change the name of that window in the bar above. Anyway, I won't talk here forever but if you need help or have any questions, please ask. By the way, since I'm an old school programmer from the 80's, I don't usually do a lot of what everyone else does, like DIM all of the variables and use SUB's. Although I am slowly learning I think. 
Title: Re: MOO
Post by: SierraKen on December 04, 2019, 10:58:49 pm
I just tried your second post with the panels, great job! If you want to add text to any graphic coordinate area, I would use _PRINTSTRING which can be found here: https://qb64.org/wiki/PRINTSTRING (https://qb64.org/wiki/PRINTSTRING)
Title: Re: MOO
Post by: romichess on December 04, 2019, 11:33:23 pm
I just tried your second post with the panels, great job! If you want to add text to any graphic coordinate area, I would use _PRINTSTRING which can be found here: https://qb64.org/wiki/PRINTSTRING (https://qb64.org/wiki/PRINTSTRING)

Oh wow! Thank you for the information, kind words and encouragement. I too am torn about all the DIM's. I find myself getting lazy and not using them everywhere. In C it is mandatory practice. C is strongly type checked which prevents tricky bugs that are hard to find. I think that my philosophy if I were writing a compiler is that INTEGERS never need DIM and everything else does. Thank you for the invite to ask questions. I will surely take advantage of that offer when I get stuck! :))
Title: Re: MOO
Post by: OldMoses on December 05, 2019, 08:45:33 am
For printing text in graphics areas, there is one that Petr made that I use frequently in my projects. It's quite versatile for spacing, both horizontal and vertical, as well as resizing. Thought you might find it interesting.

He posted the code here.
https://www.qb64.org/forum/index.php?topic=498.msg3458#msg3458
Title: Re: MOO
Post by: romichess on December 05, 2019, 10:23:11 am
For printing text in graphics areas, there is one that Petr made that I use frequently in my projects. It's quite versatile for spacing, both horizontal and vertical, as well as resizing. Thought you might find it interesting.

He posted the code here.
https://www.qb64.org/forum/index.php?topic=498.msg3458#msg3458

Yes! Very helpful link. Thank you.
Title: Re: MOO
Post by: bplus on December 05, 2019, 11:18:42 am
I am kind of curious, for a new QB64 program why limit yourself to 256 color system? why not 32 bit color system 16 million colors with Alpha transparencies.
Title: Re: MOO
Post by: romichess on December 05, 2019, 01:26:04 pm
I am kind of curious, for a new QB64 program why limit yourself to 256 color system? why not 32 bit color system 16 million colors with Alpha transparencies.

Fair question! It is because I am a new QB64 programmer and 32 bit color adds a level of complexity. Also this is just a rough draft, proof of concept, build and 256 colors is more than enough. And to be honest I do not see this program ever needing more than 256 colors. And I already know how to do pallette cycling animations.
Title: Re: MOO
Post by: romichess on December 05, 2019, 01:42:04 pm
Some rather nice progress showing better how the GUI will work. Also pressing 't' will toggle the star names on and off underneath the stars. Now when a star is clicked the panel will stay on the screen. Clicking inside the panel will call the ProcessPanel routine. Nothing happens yet except the panel remains on screen. Clicking anywhere else and the panel will close. Next a right click anywhere will be added that brings up a game panel for loading, saving, quitting, etc.
 
Once I get the GUI portion complete to the point that I understand all the necessities of the system I'll being doing a rewrite using longer variable names and a cleaner design. Please let me know what you think of "the feel" of the interface. Suggestions welcomed!

Code: QB64: [Select]
  1. TYPE stars
  2.     n AS STRING * 10 '                 Name of star
  3.     x AS INTEGER '                     x-position
  4.     y AS INTEGER '                     y-position
  5.     o AS INTEGER '                     Owner
  6.     c AS INTEGER '                     Color
  7.     s AS INTEGER '                     Size
  8.     t AS INTEGER '                     Type of planetary system; terran, frozen, radiated, toxic, etc.
  9.     p AS INTEGER '                     Population
  10.  
  11. DECLARE SUB NewGame
  12. DECLARE SUB PaintStars
  13. DECLARE SUB StarNames
  14. DECLARE SUB ShowPanel (i)
  15. DECLARE SUB Identify (x, y)
  16. DECLARE SUB PaintBackground
  17. DECLARE SUB GetInput
  18.  
  19. ' Global variables shared because they are needed in more than one routine
  20. DIM SHARED sw AS INTEGER '             Screen Width
  21. DIM SHARED sh AS INTEGER '             Screen Height
  22. DIM SHARED sww AS INTEGER '            Screen Width Wide margin
  23. DIM SHARED swn AS INTEGER '            Screen Width Narrow adjustment
  24. DIM SHARED shw AS INTEGER '            Screen Height Wide margine
  25. DIM SHARED shn AS INTEGER '            Screen Height Narrow adjustment
  26. DIM SHARED nw AS INTEGER '             games Natural screen Width
  27. DIM SHARED nh AS INTEGER '             games Natural screen Height
  28. DIM SHARED ratio AS _FLOAT '           the Ratio of the games natural screen width to the actual
  29. DIM SHARED star(100) AS stars '        100 stars - may change
  30. DIM SHARED names(200) AS STRING * 10 ' 200 star names
  31. DIM SHARED seed AS INTEGER '           Seed to prime the Randomizer to display identical background each frame
  32. DIM SHARED home(6) AS INTEGER '        The starting star for each player. The human always has star(0), Sol
  33. DIM SHARED f1 AS LONG '                Font 1
  34. DIM SHARED tt AS INTEGER '             tt = 0 star names displayed, tt = 0 star names not didplayed
  35. DIM SHARED ch AS STRING * 1 '                 Game loop key input variable
  36. DIM SHARED repeat AS INTEGER '                Game loop control variable
  37.  
  38. repeat = 1
  39.  
  40.  
  41. sw = _DESKTOPWIDTH '                   native video with of syatem
  42. sww = sw / 24 '                        margin based on native video width to keep stars away from edge
  43. swn = sw / 48 '                        adjustment that works with sww to keep stars away from left and top of screen
  44. nw = 1920
  45.  
  46. ratio = sw / 1920 '                    Used to adjust distances and sizes for various screen modes
  47.  
  48. shw = sh / 20
  49. shn = sh / 40
  50. nh = 1080
  51.  
  52. tt = 0
  53. cx = sw
  54. cp = 100
  55. h = 100
  56. ar = 0
  57.  
  58. SCREEN _NEWIMAGE(sw, sh, 256) '        creates a screen the resolution of the users native system
  59.  
  60.  
  61. f1 = _LOADFONT("C:\Windows\Fonts\Ebrima.ttf", 12, "BOLD")
  62.  
  63. ps = _NEWIMAGE(400 * ratio, 540 * ratio, 256)
  64.  
  65. StarNames '                            Routine to load star names into string array stars(200)
  66.  
  67. NewGame
  68.  
  69. WHILE repeat
  70.  
  71.     _LIMIT 60 '                        Set to 60 frames per second
  72.  
  73.     CLS
  74.  
  75.     PaintBackground
  76.  
  77.     PaintStars
  78.  
  79.     GetInput
  80.  
  81.     Identify x, y '                    Identify star mouse is over if any
  82.  
  83.     _DISPLAY
  84.  
  85.  
  86.  
  87. SUB GetInput
  88.     WHILE _MOUSEINPUT: WEND '          Eat all the mice but keep last mouse to toy with
  89.  
  90.     x = _MOUSEX
  91.     y = _MOUSEY
  92.     mb = _MOUSEBUTTON(1)
  93.     clk = 0
  94.  
  95.     IF mb = -1 AND cx = sw THEN
  96.         cx = x
  97.         cy = y
  98.     END IF
  99.  
  100.     IF mb = 0 AND cx < sw THEN
  101.         IF ABS(x - cx) < 4 AND ABS(y - cy) < 4 THEN
  102.             clk = 1
  103.         END IF
  104.         cx = sw
  105.     END IF
  106.  
  107.     ch = INKEY$
  108.     IF ch = CHR$(27) THEN repeat = 0
  109.     IF ch = "n" THEN NewGame
  110.     IF ch = "t" THEN tt = 1 - tt
  111.     ch = ""
  112.  
  113.  
  114. SUB PaintBackground
  115.     x = RND * sw
  116.     y = RND * sh
  117.     c = RND * 14 + 1
  118.     PSET (x, y), c
  119.     RANDOMIZE USING seed
  120.     FOR i = 1 TO 600 * ratio
  121.         x = RND * sw
  122.         y = RND * sh
  123.         c = RND * 14 + 1
  124.         PSET (x, y), c
  125.     NEXT
  126.  
  127. SUB ProcessPanel
  128.  
  129.  
  130. SUB Identify (x, y)
  131.     IF ar = 1 THEN
  132.         ShowPanel h
  133.         IF clk THEN
  134.             IF x >= x1 AND x <= x2 AND y >= y1 AND y <= y2 THEN
  135.                 ProcessPanel
  136.             ELSE
  137.                 ar = 0
  138.             END IF
  139.         END IF
  140.     END IF
  141.     IF ar = 0 THEN
  142.         FOR i = 0 TO 99
  143.             dx = star(i).x - x
  144.             dy = star(i).y - y
  145.             IF ABS(dx) <= star(i).s + 6 AND ABS(dy) <= star(i).s + 6 THEN
  146.                 ShowPanel i
  147.                 IF clk THEN
  148.                     clk = 0
  149.                     h = i
  150.                     ar = 1
  151.                     ax = x
  152.                 END IF
  153.             END IF
  154.         NEXT
  155.     END IF
  156.  
  157. SUB ShowPanel (i)
  158.     DIM x AS INTEGER
  159.     DIM y AS INTEGER
  160.     x1 = star(i).x - 420 * ratio
  161.     IF star(i).x < sw / 2 THEN x1 = star(i).x + 20
  162.     x2 = x1 + 400 * ratio
  163.     y1 = star(i).y
  164.     IF y1 > sh - 560 * ratio THEN y1 = sh - 560 * ratio
  165.     y2 = y1 + 540 * ratio
  166.     _DEST ps
  167.     CLS 0, 8
  168.     PRINT star(i).n
  169.     _PUTIMAGE (x1, y1), ps, 0, (0, 0)-(400 * ratio, 540 * ratio)
  170.     _DEST 0
  171.  
  172. SUB PaintStars
  173.     FOR i = 0 TO 99
  174.         c = star(i).c
  175.         x = star(i).x
  176.         y = star(i).y
  177.         o = star(i).o
  178.         CIRCLE (x, y), (star(i).s + 6) * ratio, c
  179.         COLOR 15
  180.         IF o > 0 THEN
  181.             PAINT (x, y), o + 8, c
  182.             COLOR o + 8
  183.         END IF
  184.         IF tt THEN
  185.             _FONT f1
  186.             _PRINTSTRING (x - 10, y + 12), star(i).n, 0
  187.         END IF
  188.     NEXT
  189.  
  190. SUB NewGame
  191.     DIM k AS INTEGER
  192.     DIM r AS INTEGER
  193.     DIM dx AS INTEGER
  194.     DIM dy AS INTEGER
  195.     DIM n AS STRING * 10
  196.     seed = RND * 1000
  197.     star(0).n = "Sol"
  198.     star(0).x = RND * (sw - sww) + swn
  199.     star(0).y = RND * (sh - shw) + shn
  200.     star(0).c = 14
  201.     star(0).s = 3
  202.     star(0).o = 1
  203.     home(0) = 0
  204.     FOR i = 1 TO 99
  205.         k = 1
  206.         WHILE k
  207.             k = 0
  208.             x = RND * (sw - sww) + swn
  209.             y = RND * (sh - shw) + shn
  210.             r = INT(RND * 200)
  211.             n = names(r)
  212.             FOR j = 0 TO i - 1
  213.                 dx = x - star(j).x
  214.                 dy = y - star(j).y
  215.                 IF ABS(dx) < sww AND ABS(dy) < shw THEN
  216.                     k = 1
  217.                 END IF
  218.                 IF n = star(j).n THEN
  219.                     k = 1
  220.                 END IF
  221.             NEXT
  222.         WEND
  223.         star(i).n = n
  224.         star(i).x = x
  225.         star(i).y = y
  226.         star(i).c = RND * 6 + 9
  227.         star(i).s = RND * 5
  228.         star(i).o = 0
  229.     NEXT
  230.     FOR i = 2 TO 6
  231.         k = 1
  232.         WHILE k
  233.             k = 0
  234.             r = RND * 100
  235.             FOR j = 1 TO i - 1
  236.                 IF r = home(j) THEN k = 1
  237.                 x = star(0).x
  238.                 y = star(0).y
  239.                 dx = ABS(star(r).x - x)
  240.                 dy = ABS(star(r).y - y)
  241.                 IF dx < sw / 4 AND dy < sh / 4 THEN k = 1
  242.             NEXT
  243.         WEND
  244.         home(i) = r
  245.         star(r).o = i
  246.     NEXT
  247.  
  248. ' A lot of star names I made up
  249.  
  250. SUB StarNames
  251.     names(0) = "Acamar"
  252.     names(1) = "Arcab"
  253.     names(2) = "Acrux"
  254.     names(3) = "Adhara"
  255.     names(4) = "Arneb"
  256.     names(5) = "Antares"
  257.     names(6) = "Arcturus"
  258.     names(7) = "Atria"
  259.     names(8) = "Beid"
  260.     names(9) = "Betelgeuse"
  261.     names(10) = "Botein"
  262.     names(11) = "Beemim"
  263.     names(12) = "Bellatrix"
  264.     names(13) = "Bharani"
  265.     names(14) = "Biham"
  266.     names(15) = "Brachium"
  267.     names(16) = "Canopus"
  268.     names(17) = "Capella"
  269.     names(18) = "Castor"
  270.     names(19) = "Chara"
  271.     names(20) = "Cursa"
  272.     names(21) = "Copernicus"
  273.     names(22) = "Chalawan"
  274.     names(23) = "Chertan"
  275.     names(24) = "Dabih"
  276.     names(25) = "Dalim"
  277.     names(26) = "Deneb"
  278.     names(27) = "Denebola"
  279.     names(28) = "Diadem"
  280.     names(29) = "Diphda"
  281.     names(30) = "Dschubba"
  282.     names(31) = "Dziban"
  283.     names(32) = "Edasich"
  284.     names(33) = "Electra"
  285.     names(34) = "Elgafar"
  286.     names(35) = "Elkurud"
  287.     names(36) = "Elnath"
  288.     names(37) = "Eltanin"
  289.     names(38) = "Enif"
  290.     names(39) = "Errai"
  291.     names(40) = "Fafnir"
  292.     names(41) = "Fang"
  293.     names(42) = "Fawaris"
  294.     names(43) = "Felis"
  295.     names(44) = "Fomalhaut"
  296.     names(45) = "Fulu"
  297.     names(46) = "Fumal"
  298.     names(47) = "Furud"
  299.     names(48) = "Garnet"
  300.     names(49) = "Giausar"
  301.     names(50) = "Gienah"
  302.     names(51) = "Ginan"
  303.     names(52) = "Gomeisa"
  304.     names(53) = "Graffias"
  305.     names(54) = "Grumium"
  306.     names(55) = "Gudja"
  307.     names(56) = "Hadar"
  308.     names(57) = "Haedus"
  309.     names(58) = "Hamal"
  310.     names(59) = "Hassaleh"
  311.     names(60) = "Hatysa"
  312.     names(61) = "Helvetios"
  313.     names(62) = "Heze"
  314.     names(63) = "Homan"
  315.     names(64) = "Iklil"
  316.     names(65) = "Imai"
  317.     names(66) = "Intercrus"
  318.     names(67) = "Izar"
  319.     names(68) = "Iccar"
  320.     names(69) = "Inar"
  321.     names(70) = "Iaeth"
  322.     names(71) = "Imaous"
  323.     names(72) = "Jabbah"
  324.     names(73) = "Jishui"
  325.     names(74) = "Jax"
  326.     names(75) = "Jalae"
  327.     names(76) = "Jewel"
  328.     names(77) = "Jumbo"
  329.     names(78) = "Jerue"
  330.     names(79) = "Jabear"
  331.     names(80) = "Kakkab"
  332.     names(81) = "Kang"
  333.     names(82) = "Kekouan"
  334.     names(83) = "Keid"
  335.     names(84) = "Kitalpha"
  336.     names(85) = "Kochab"
  337.     names(86) = "Kolob"
  338.     names(87) = "Kobol"
  339.     names(88) = "Larawag"
  340.     names(89) = "Lesath"
  341.     names(90) = "Libertas"
  342.     names(91) = "Lich"
  343.     names(92) = "Lilly"
  344.     names(93) = "Laddel"
  345.     names(94) = "Luminous"
  346.     names(95) = "Lasacious"
  347.     names(96) = "Mizar"
  348.     names(97) = "Markab"
  349.     names(98) = "Matar"
  350.     names(99) = "Mintaka"
  351.     names(100) = "Meleph"
  352.     names(101) = "Menkar"
  353.     names(102) = "Merga"
  354.     names(103) = "Merope"
  355.     names(104) = "Nahn"
  356.     names(105) = "Naos"
  357.     names(106) = "Nashira"
  358.     names(107) = "Navi"
  359.     names(108) = "Nekkar"
  360.     names(109) = "Nembus"
  361.     names(110) = "Nihal"
  362.     names(111) = "Nunki"
  363.     names(112) = "Ogma"
  364.     names(113) = "Okab"
  365.     names(114) = "Ohmy"
  366.     names(115) = "Oragami"
  367.     names(116) = "Origen"
  368.     names(117) = "Omanii"
  369.     names(118) = "Obytewa"
  370.     names(119) = "Oglok"
  371.     names(120) = "Phact"
  372.     names(121) = "Pherkad"
  373.     names(122) = "Pleione"
  374.     names(122) = "Polaris"
  375.     names(123) = "Pollux"
  376.     names(124) = "Procyon"
  377.     names(125) = "Proxima"
  378.     names(126) = "Polis"
  379.     names(127) = "Quaint"
  380.     names(128) = "Quazzat"
  381.     names(129) = "Quetzal"
  382.     names(130) = "Qussol"
  383.     names(131) = "Quella"
  384.     names(132) = "Quyaeo"
  385.     names(133) = "Ququdas"
  386.     names(134) = "Quekak"
  387.     names(135) = "Rasalas"
  388.     names(136) = "Regor"
  389.     names(137) = "Regulus"
  390.     names(138) = "Rigel"
  391.     names(139) = "Revati"
  392.     names(140) = "Rotenev"
  393.     names(141) = "Rukbat"
  394.     names(142) = "Rastaban"
  395.     names(143) = "Sabik"
  396.     names(144) = "Sadr"
  397.     names(145) = "Saiph"
  398.     names(146) = "Sargas"
  399.     names(147) = "Sarin"
  400.     names(148) = "Syrma"
  401.     names(149) = "Spica"
  402.     names(150) = "Sirius"
  403.     names(151) = "Tarazed"
  404.     names(152) = "Taygeta"
  405.     names(153) = "Tejat"
  406.     names(154) = "Thabit"
  407.     names(155) = "Thuban"
  408.     names(156) = "Tiaki"
  409.     names(157) = "Toliman"
  410.     names(158) = "Torcular"
  411.     names(157) = "Umala"
  412.     names(158) = "Ulatte"
  413.     names(159) = "Ubbessa"
  414.     names(160) = "Unoless"
  415.     names(161) = "Umaddem"
  416.     names(162) = "Ummbra"
  417.     names(162) = "Uniqu"
  418.     names(163) = "Uzzaal"
  419.     names(164) = "Vega"
  420.     names(165) = "Veritate"
  421.     names(166) = "Vindetrix"
  422.     names(167) = "Vedas"
  423.     names(168) = "Vergg"
  424.     names(169) = "Vacant"
  425.     names(170) = "Vucae"
  426.     names(171) = "Vicar"
  427.     names(172) = "Wasat"
  428.     names(173) = "Wazn"
  429.     names(174) = "Wezen"
  430.     names(175) = "Waiten"
  431.     names(176) = "Wachar"
  432.     names(177) = "Wheelz"
  433.     names(178) = "Whatsp"
  434.     names(179) = "Wassand"
  435.     names(180) = "Xenno"
  436.     names(181) = "Xyphod"
  437.     names(182) = "Xu"
  438.     names(183) = "Xaal"
  439.     names(184) = "Xyross"
  440.     names(185) = "Xiggot"
  441.     names(186) = "Xirrks"
  442.     names(187) = "Yed"
  443.     names(188) = "Yildun"
  444.     names(189) = "yundun"
  445.     names(190) = "Yavyo"
  446.     names(191) = "Yotrac"
  447.     names(192) = "Yxzoqu"
  448.     names(193) = "Ynnot"
  449.     names(194) = "Zaniah"
  450.     names(195) = "Zaurak"
  451.     names(196) = "Zhang"
  452.     names(197) = "Zibal"
  453.     names(198) = "Zosma"
  454.     names(199) = "Zuben"
  455.  
Title: Re: MOO
Post by: romichess on December 05, 2019, 02:35:54 pm
I forgot about the likely font issue. I'm using the Ebrima.ttf bold font because it is very easy to read. So if one does not have that font pressing 't' to toggle the star names won't work. I will fix that problem right now.
Title: Re: MOO
Post by: romichess on December 05, 2019, 03:08:07 pm
For this prototype version I'll just stick to the default font. It's not all that bad. :)
Code: QB64: [Select]
  1. TYPE stars
  2.     n AS STRING * 10 '                 Name of star
  3.     x AS INTEGER '                     x-position
  4.     y AS INTEGER '                     y-position
  5.     o AS INTEGER '                     Owner
  6.     c AS INTEGER '                     Color
  7.     s AS INTEGER '                     Size
  8.     t AS INTEGER '                     Type of planetary system; terran, frozen, radiated, toxic, etc.
  9.     p AS INTEGER '                     Population
  10.  
  11. DECLARE SUB NewGame
  12. DECLARE SUB PaintStars
  13. DECLARE SUB StarNames
  14. DECLARE SUB ShowPanel (i)
  15. DECLARE SUB Identify (x, y)
  16. DECLARE SUB PaintBackground
  17. DECLARE SUB GetInput
  18.  
  19. ' Global variables shared because they are needed in more than one routine
  20. DIM SHARED sw AS INTEGER '             Screen Width
  21. DIM SHARED sh AS INTEGER '             Screen Height
  22. DIM SHARED sww AS INTEGER '            Screen Width Wide margin
  23. DIM SHARED swn AS INTEGER '            Screen Width Narrow adjustment
  24. DIM SHARED shw AS INTEGER '            Screen Height Wide margine
  25. DIM SHARED shn AS INTEGER '            Screen Height Narrow adjustment
  26. DIM SHARED nw AS INTEGER '             games Natural screen Width
  27. DIM SHARED nh AS INTEGER '             games Natural screen Height
  28. DIM SHARED ratio AS _FLOAT '           the Ratio of the games natural screen width to the actual
  29. DIM SHARED star(100) AS stars '        100 stars - may change
  30. DIM SHARED names(200) AS STRING * 10 ' 200 star names
  31. DIM SHARED seed AS INTEGER '           Seed to prime the Randomizer to display identical background each frame
  32. DIM SHARED home(6) AS INTEGER '        The starting star for each player. The human always has star(0), Sol
  33. DIM SHARED tt AS INTEGER '             tt = 0 star names displayed, tt = 0 star names not didplayed
  34. DIM SHARED ch AS STRING * 1 '                 Game loop key input variable
  35. DIM SHARED repeat AS INTEGER '                Game loop control variable
  36.  
  37. repeat = 1
  38.  
  39.  
  40. sw = _DESKTOPWIDTH '                   native video with of syatem
  41. sww = sw / 24 '                        margin based on native video width to keep stars away from edge
  42. swn = sw / 48 '                        adjustment that works with sww to keep stars away from left and top of screen
  43. nw = 1920
  44.  
  45. ratio = sw / 1920 '                    Used to adjust distances and sizes for various screen modes
  46.  
  47. shw = sh / 20
  48. shn = sh / 40
  49. nh = 1080
  50.  
  51. tt = 0
  52. cx = sw
  53. cp = 100
  54. h = 100
  55. ar = 0
  56.  
  57. SCREEN _NEWIMAGE(sw, sh, 256) '        creates a screen the resolution of the users native system
  58.  
  59.  
  60. ps = _NEWIMAGE(400 * ratio, 540 * ratio, 256)
  61.  
  62. StarNames '                            Routine to load star names into string array stars(200)
  63.  
  64. NewGame
  65.  
  66. WHILE repeat
  67.  
  68.     _LIMIT 60 '                        Set to 60 frames per second
  69.  
  70.     CLS
  71.  
  72.     PaintBackground
  73.  
  74.     PaintStars
  75.  
  76.     GetInput
  77.  
  78.     Identify x, y '                    Identify star mouse is over if any
  79.  
  80.     _DISPLAY
  81.  
  82.  
  83.  
  84. SUB GetInput
  85.     WHILE _MOUSEINPUT: WEND '          Eat all the mice but keep last mouse to toy with
  86.  
  87.     x = _MOUSEX
  88.     y = _MOUSEY
  89.     mb = _MOUSEBUTTON(1)
  90.     clk = 0
  91.  
  92.     IF mb = -1 AND cx = sw THEN
  93.         cx = x
  94.         cy = y
  95.     END IF
  96.  
  97.     IF mb = 0 AND cx < sw THEN
  98.         IF ABS(x - cx) < 4 AND ABS(y - cy) < 4 THEN
  99.             clk = 1
  100.         END IF
  101.         cx = sw
  102.     END IF
  103.  
  104.     ch = INKEY$
  105.     IF ch = CHR$(27) THEN repeat = 0
  106.     IF ch = "n" THEN NewGame
  107.     IF ch = "t" THEN tt = 1 - tt
  108.     ch = ""
  109.  
  110.  
  111. SUB PaintBackground
  112.     x = RND * sw
  113.     y = RND * sh
  114.     c = RND * 14 + 1
  115.     PSET (x, y), c
  116.     RANDOMIZE USING seed
  117.     FOR i = 1 TO 600 * ratio
  118.         x = RND * sw
  119.         y = RND * sh
  120.         c = RND * 14 + 1
  121.         PSET (x, y), c
  122.     NEXT
  123.  
  124. SUB ProcessPanel
  125.  
  126.  
  127. SUB Identify (x, y)
  128.     IF ar = 1 THEN
  129.         ShowPanel h
  130.         IF clk THEN
  131.             IF x >= x1 AND x <= x2 AND y >= y1 AND y <= y2 THEN
  132.                 ProcessPanel
  133.             ELSE
  134.                 ar = 0
  135.             END IF
  136.         END IF
  137.     END IF
  138.     IF ar = 0 THEN
  139.         FOR i = 0 TO 99
  140.             dx = star(i).x - x
  141.             dy = star(i).y - y
  142.             IF ABS(dx) <= star(i).s + 6 AND ABS(dy) <= star(i).s + 6 THEN
  143.                 ShowPanel i
  144.                 IF clk THEN
  145.                     clk = 0
  146.                     h = i
  147.                     ar = 1
  148.                     ax = x
  149.                 END IF
  150.             END IF
  151.         NEXT
  152.     END IF
  153.  
  154. SUB ShowPanel (i)
  155.     DIM x AS INTEGER
  156.     DIM y AS INTEGER
  157.     x1 = star(i).x - 420 * ratio
  158.     IF star(i).x < sw / 2 THEN x1 = star(i).x + 20
  159.     x2 = x1 + 400 * ratio
  160.     y1 = star(i).y
  161.     IF y1 > sh - 560 * ratio THEN y1 = sh - 560 * ratio
  162.     y2 = y1 + 540 * ratio
  163.     _DEST ps
  164.     CLS 0, 8
  165.     PRINT star(i).n
  166.     _PUTIMAGE (x1, y1), ps, 0, (0, 0)-(400 * ratio, 540 * ratio)
  167.     _DEST 0
  168.  
  169. SUB PaintStars
  170.     FOR i = 0 TO 99
  171.         c = star(i).c
  172.         x = star(i).x
  173.         y = star(i).y
  174.         o = star(i).o
  175.         CIRCLE (x, y), (star(i).s + 6) * ratio, c
  176.         COLOR 15
  177.         IF o > 0 THEN
  178.             PAINT (x, y), o + 8, c
  179.             COLOR o + 8
  180.         END IF
  181.         IF tt THEN
  182.             _PRINTSTRING (x - 10, y + 12), star(i).n, 0
  183.         END IF
  184.     NEXT
  185.  
  186. SUB NewGame
  187.     DIM k AS INTEGER
  188.     DIM r AS INTEGER
  189.     DIM dx AS INTEGER
  190.     DIM dy AS INTEGER
  191.     DIM n AS STRING * 10
  192.     seed = RND * 1000
  193.     star(0).n = "Sol"
  194.     star(0).x = RND * (sw - sww) + swn
  195.     star(0).y = RND * (sh - shw) + shn
  196.     star(0).c = 14
  197.     star(0).s = 3
  198.     star(0).o = 1
  199.     home(0) = 0
  200.     FOR i = 1 TO 99
  201.         k = 1
  202.         WHILE k
  203.             k = 0
  204.             x = RND * (sw - sww) + swn
  205.             y = RND * (sh - shw) + shn
  206.             r = INT(RND * 200)
  207.             n = names(r)
  208.             FOR j = 0 TO i - 1
  209.                 dx = x - star(j).x
  210.                 dy = y - star(j).y
  211.                 IF ABS(dx) < sww AND ABS(dy) < shw THEN
  212.                     k = 1
  213.                 END IF
  214.                 IF n = star(j).n THEN
  215.                     k = 1
  216.                 END IF
  217.             NEXT
  218.         WEND
  219.         star(i).n = n
  220.         star(i).x = x
  221.         star(i).y = y
  222.         star(i).c = RND * 6 + 9
  223.         star(i).s = RND * 5
  224.         star(i).o = 0
  225.     NEXT
  226.     FOR i = 2 TO 6
  227.         k = 1
  228.         WHILE k
  229.             k = 0
  230.             r = RND * 100
  231.             FOR j = 1 TO i - 1
  232.                 IF r = home(j) THEN k = 1
  233.                 x = star(0).x
  234.                 y = star(0).y
  235.                 dx = ABS(star(r).x - x)
  236.                 dy = ABS(star(r).y - y)
  237.                 IF dx < sw / 4 AND dy < sh / 4 THEN k = 1
  238.             NEXT
  239.         WEND
  240.         home(i) = r
  241.         star(r).o = i
  242.     NEXT
  243.  
  244. ' A lot of star names I made up
  245.  
  246. SUB StarNames
  247.     names(0) = "Acamar"
  248.     names(1) = "Arcab"
  249.     names(2) = "Acrux"
  250.     names(3) = "Adhara"
  251.     names(4) = "Arneb"
  252.     names(5) = "Antares"
  253.     names(6) = "Arcturus"
  254.     names(7) = "Atria"
  255.     names(8) = "Beid"
  256.     names(9) = "Betelgeuse"
  257.     names(10) = "Botein"
  258.     names(11) = "Beemim"
  259.     names(12) = "Bellatrix"
  260.     names(13) = "Bharani"
  261.     names(14) = "Biham"
  262.     names(15) = "Brachium"
  263.     names(16) = "Canopus"
  264.     names(17) = "Capella"
  265.     names(18) = "Castor"
  266.     names(19) = "Chara"
  267.     names(20) = "Cursa"
  268.     names(21) = "Copernicus"
  269.     names(22) = "Chalawan"
  270.     names(23) = "Chertan"
  271.     names(24) = "Dabih"
  272.     names(25) = "Dalim"
  273.     names(26) = "Deneb"
  274.     names(27) = "Denebola"
  275.     names(28) = "Diadem"
  276.     names(29) = "Diphda"
  277.     names(30) = "Dschubba"
  278.     names(31) = "Dziban"
  279.     names(32) = "Edasich"
  280.     names(33) = "Electra"
  281.     names(34) = "Elgafar"
  282.     names(35) = "Elkurud"
  283.     names(36) = "Elnath"
  284.     names(37) = "Eltanin"
  285.     names(38) = "Enif"
  286.     names(39) = "Errai"
  287.     names(40) = "Fafnir"
  288.     names(41) = "Fang"
  289.     names(42) = "Fawaris"
  290.     names(43) = "Felis"
  291.     names(44) = "Fomalhaut"
  292.     names(45) = "Fulu"
  293.     names(46) = "Fumal"
  294.     names(47) = "Furud"
  295.     names(48) = "Garnet"
  296.     names(49) = "Giausar"
  297.     names(50) = "Gienah"
  298.     names(51) = "Ginan"
  299.     names(52) = "Gomeisa"
  300.     names(53) = "Graffias"
  301.     names(54) = "Grumium"
  302.     names(55) = "Gudja"
  303.     names(56) = "Hadar"
  304.     names(57) = "Haedus"
  305.     names(58) = "Hamal"
  306.     names(59) = "Hassaleh"
  307.     names(60) = "Hatysa"
  308.     names(61) = "Helvetios"
  309.     names(62) = "Heze"
  310.     names(63) = "Homan"
  311.     names(64) = "Iklil"
  312.     names(65) = "Imai"
  313.     names(66) = "Intercrus"
  314.     names(67) = "Izar"
  315.     names(68) = "Iccar"
  316.     names(69) = "Inar"
  317.     names(70) = "Iaeth"
  318.     names(71) = "Imaous"
  319.     names(72) = "Jabbah"
  320.     names(73) = "Jishui"
  321.     names(74) = "Jax"
  322.     names(75) = "Jalae"
  323.     names(76) = "Jewel"
  324.     names(77) = "Jumbo"
  325.     names(78) = "Jerue"
  326.     names(79) = "Jabear"
  327.     names(80) = "Kakkab"
  328.     names(81) = "Kang"
  329.     names(82) = "Kekouan"
  330.     names(83) = "Keid"
  331.     names(84) = "Kitalpha"
  332.     names(85) = "Kochab"
  333.     names(86) = "Kolob"
  334.     names(87) = "Kobol"
  335.     names(88) = "Larawag"
  336.     names(89) = "Lesath"
  337.     names(90) = "Libertas"
  338.     names(91) = "Lich"
  339.     names(92) = "Lilly"
  340.     names(93) = "Laddel"
  341.     names(94) = "Luminous"
  342.     names(95) = "Lasacious"
  343.     names(96) = "Mizar"
  344.     names(97) = "Markab"
  345.     names(98) = "Matar"
  346.     names(99) = "Mintaka"
  347.     names(100) = "Meleph"
  348.     names(101) = "Menkar"
  349.     names(102) = "Merga"
  350.     names(103) = "Merope"
  351.     names(104) = "Nahn"
  352.     names(105) = "Naos"
  353.     names(106) = "Nashira"
  354.     names(107) = "Navi"
  355.     names(108) = "Nekkar"
  356.     names(109) = "Nembus"
  357.     names(110) = "Nihal"
  358.     names(111) = "Nunki"
  359.     names(112) = "Ogma"
  360.     names(113) = "Okab"
  361.     names(114) = "Ohmy"
  362.     names(115) = "Oragami"
  363.     names(116) = "Origen"
  364.     names(117) = "Omanii"
  365.     names(118) = "Obytewa"
  366.     names(119) = "Oglok"
  367.     names(120) = "Phact"
  368.     names(121) = "Pherkad"
  369.     names(122) = "Pleione"
  370.     names(122) = "Polaris"
  371.     names(123) = "Pollux"
  372.     names(124) = "Procyon"
  373.     names(125) = "Proxima"
  374.     names(126) = "Polis"
  375.     names(127) = "Quaint"
  376.     names(128) = "Quazzat"
  377.     names(129) = "Quetzal"
  378.     names(130) = "Qussol"
  379.     names(131) = "Quella"
  380.     names(132) = "Quyaeo"
  381.     names(133) = "Ququdas"
  382.     names(134) = "Quekak"
  383.     names(135) = "Rasalas"
  384.     names(136) = "Regor"
  385.     names(137) = "Regulus"
  386.     names(138) = "Rigel"
  387.     names(139) = "Revati"
  388.     names(140) = "Rotenev"
  389.     names(141) = "Rukbat"
  390.     names(142) = "Rastaban"
  391.     names(143) = "Sabik"
  392.     names(144) = "Sadr"
  393.     names(145) = "Saiph"
  394.     names(146) = "Sargas"
  395.     names(147) = "Sarin"
  396.     names(148) = "Syrma"
  397.     names(149) = "Spica"
  398.     names(150) = "Sirius"
  399.     names(151) = "Tarazed"
  400.     names(152) = "Taygeta"
  401.     names(153) = "Tejat"
  402.     names(154) = "Thabit"
  403.     names(155) = "Thuban"
  404.     names(156) = "Tiaki"
  405.     names(157) = "Toliman"
  406.     names(158) = "Torcular"
  407.     names(157) = "Umala"
  408.     names(158) = "Ulatte"
  409.     names(159) = "Ubbessa"
  410.     names(160) = "Unoless"
  411.     names(161) = "Umaddem"
  412.     names(162) = "Ummbra"
  413.     names(162) = "Uniqu"
  414.     names(163) = "Uzzaal"
  415.     names(164) = "Vega"
  416.     names(165) = "Veritate"
  417.     names(166) = "Vindetrix"
  418.     names(167) = "Vedas"
  419.     names(168) = "Vergg"
  420.     names(169) = "Vacant"
  421.     names(170) = "Vucae"
  422.     names(171) = "Vicar"
  423.     names(172) = "Wasat"
  424.     names(173) = "Wazn"
  425.     names(174) = "Wezen"
  426.     names(175) = "Waiten"
  427.     names(176) = "Wachar"
  428.     names(177) = "Wheelz"
  429.     names(178) = "Whatsp"
  430.     names(179) = "Wassand"
  431.     names(180) = "Xenno"
  432.     names(181) = "Xyphod"
  433.     names(182) = "Xu"
  434.     names(183) = "Xaal"
  435.     names(184) = "Xyross"
  436.     names(185) = "Xiggot"
  437.     names(186) = "Xirrks"
  438.     names(187) = "Yed"
  439.     names(188) = "Yildun"
  440.     names(189) = "yundun"
  441.     names(190) = "Yavyo"
  442.     names(191) = "Yotrac"
  443.     names(192) = "Yxzoqu"
  444.     names(193) = "Ynnot"
  445.     names(194) = "Zaniah"
  446.     names(195) = "Zaurak"
  447.     names(196) = "Zhang"
  448.     names(197) = "Zibal"
  449.     names(198) = "Zosma"
  450.     names(199) = "Zuben"
  451.  
  452.  
  453.  
  454.  
Title: Re: MOO
Post by: bplus on December 05, 2019, 04:26:46 pm
Hi Mike,

Quick tip, in Toolbox board there is a really nice circle fill routine you might want to pickup, first entry I think.
Title: Re: MOO
Post by: romichess on December 05, 2019, 05:34:32 pm
Hi Mike,

Quick tip, in Toolbox board there is a really nice circle fill routine you might want to pickup, first entry I think.

Cool!
Title: Re: MOO
Post by: TempodiBasic on December 06, 2019, 08:14:02 am
Fine!
please say me
what is the conceptual difference between star showed as a voide circle and star showed as a full colored circle?

it is not necessary but I must note that
Code: QB64: [Select]
  1. DECLARE SUB NewGame
  2. DECLARE SUB PaintStars
  3. DECLARE SUB StarNames
  4. DECLARE SUB ShowPanel (i)
  5. DECLARE SUB Identify (x, y)
  6. DECLARE SUB PaintBackground
  7. DECLARE SUB GetInput
  8.  
  9.  
are declaration of subprograms need in QB4.5 QBASIC and QB PDS
for QB64 you can  change the code into this one
Code: QB64: [Select]
  1. 'DECLARE SUB NewGame
  2. 'DECLARE SUB PaintStars
  3. 'DECLARE SUB StarNames
  4. 'DECLARE SUB ShowPanel (i)
  5. 'DECLARE SUB Identify (x, y)
  6. 'DECLARE SUB PaintBackground
  7. 'DECLARE SUB GetInput
  8.  
  9.  
as you can read here http://www.qb64.org/wiki/DECLARE (http://www.qb64.org/wiki/DECLARE)

PS Welcome to QB64 forum!
Title: Re: MOO
Post by: romichess on December 06, 2019, 10:15:04 am
Fine!
please say me
what is the conceptual difference between star showed as a voide circle and star showed as a full colored circle?

it is not necessary but I must note that
Code: QB64: [Select]
  1. DECLARE SUB NewGame
  2. DECLARE SUB PaintStars
  3. DECLARE SUB StarNames
  4. DECLARE SUB ShowPanel (i)
  5. DECLARE SUB Identify (x, y)
  6. DECLARE SUB PaintBackground
  7. DECLARE SUB GetInput
  8.  
  9.  
are declaration of subprograms need in QB4.5 QBASIC and QB PDS
for QB64 you can  change the code into this one
Code: QB64: [Select]
  1. 'DECLARE SUB NewGame
  2. 'DECLARE SUB PaintStars
  3. 'DECLARE SUB StarNames
  4. 'DECLARE SUB ShowPanel (i)
  5. 'DECLARE SUB Identify (x, y)
  6. 'DECLARE SUB PaintBackground
  7. 'DECLARE SUB GetInput
  8.  
  9.  
as you can read here http://www.qb64.org/wiki/DECLARE (http://www.qb64.org/wiki/DECLARE)

PS Welcome to QB64 forum!

Thanks, glad to be here. A painted circle is one of the six players. The human player for now always plays from Sol.
Title: Re: MOO
Post by: OldMoses on December 06, 2019, 12:02:10 pm
It looks like there are a few black holes in your star field. ;) Name boxes pop up where I don't see anything.

Welcome to the forum.

Title: Re: MOO
Post by: romichess on December 06, 2019, 02:41:49 pm
It looks like there are a few black holes in your star field. ;) Name boxes pop up where I don't see anything.

Welcome to the forum.

Thanks! That should have been fixed a couple of post ago. I'm about to make a new post and I'll make sure it does not do that anymore. Hmm, maybe a few cloaked planets is not a bad idea. The mouse did detect them by the way as they were there but painted black, lol.
Title: Re: MOO
Post by: romichess on December 06, 2019, 03:19:58 pm
I have decided to code the simplest space game possible just to have a game and not just some example code. Then I was reminded of a game that I used to play on my Atari 800 around 1984. It was a text screen space conquest game that used 40 characters, A thru z and the symbols above the numbers. Each turn every planet produced a number of ships. The players played by the hot seat style and there were no computer players. Each turn a player could send ships to another planet either friendly or hostile. It was a very simple yet fun game. So first I'll aim for something close to that.

I'm old and my eyes are not the greatest. Just a short while ago I noticed the cyberbit.ttf font that comes with QB64. So I switched to that font. It would have saved me a lot of time had I seen it sooner.

Now hitting 't' toggles between the name and the number of ships printed under the star. Trying to print both introduced noticeable lag. Printing must be very expensive. Now I'm wondering if QB64 will be fast enough. I suppose that the frame rate can be reduced to compensate.

Code: QB64: [Select]
  1. TYPE stars
  2.     n AS STRING * 10 '                 Name of star
  3.     x AS INTEGER '                     x-position
  4.     y AS INTEGER '                     y-position
  5.     o AS INTEGER '                     Owner
  6.     c AS INTEGER '                     Color
  7.     s AS INTEGER '                     Size
  8.     t AS INTEGER '                     (Type of planetary system; terran, frozen, radiated, toxic, etc.) Ships
  9.     p AS INTEGER '                     (Population) For now ships produced per turn
  10.  
  11. 'DECLARE SUB NewGame
  12. 'DECLARE SUB PaintStars
  13. 'DECLARE SUB StarNames
  14. 'DECLARE SUB ShowPanel (i)
  15. 'DECLARE SUB Identify (x, y)
  16. 'DECLARE SUB PaintBackground
  17. 'DECLARE SUB GetInput
  18.  
  19. ' Global variables shared because they are needed in more than one routine
  20. DIM SHARED sw AS INTEGER '             Screen Width
  21. DIM SHARED sh AS INTEGER '             Screen Height
  22. DIM SHARED sww AS INTEGER '            Screen Width Wide margin
  23. DIM SHARED swn AS INTEGER '            Screen Width Narrow adjustment
  24. DIM SHARED shw AS INTEGER '            Screen Height Wide margine
  25. DIM SHARED shn AS INTEGER '            Screen Height Narrow adjustment
  26. DIM SHARED nw AS INTEGER '             games Natural screen Width
  27. DIM SHARED nh AS INTEGER '             games Natural screen Height
  28. DIM SHARED ratio AS _FLOAT '           the Ratio of the games natural screen width to the actual
  29. DIM SHARED star(100) AS stars '        100 stars - may change
  30. DIM SHARED names(200) AS STRING * 10 ' 200 star names
  31. DIM SHARED seed AS INTEGER '           Seed to prime the Randomizer to display identical background each frame
  32. DIM SHARED home(6) AS INTEGER '        The starting star for each player. The human always has star(0), Sol
  33. DIM SHARED tt AS INTEGER '             tt = 0 star names displayed, tt = 0 star names not didplayed
  34. DIM SHARED ch AS STRING * 1 '          Game loop key input variable
  35. DIM SHARED repeat AS INTEGER '         Game loop control variable
  36.  
  37. sw = _DESKTOPWIDTH '                   native video with of syatem
  38. sww = sw / 24 '                        margin based on native video width to keep stars away from edge
  39. swn = sw / 48 '                        adjustment that works with sww to keep stars away from left and top of screen
  40. nw = 1920
  41.  
  42. ratio = sw / 1920 '                    Used to adjust distances and sizes for various screen modes
  43.  
  44. shw = sh / 20
  45. shn = sh / 40
  46. nh = 1080
  47.  
  48. tt = 0
  49. cx = sw
  50. cp = 100
  51. h = 100
  52. ar = 0
  53.  
  54. SCREEN _NEWIMAGE(sw, sh, 256) '        creates a screen the resolution of the users native system
  55.  
  56.  
  57. ps = _NEWIMAGE(400 * ratio, 540 * ratio, 256)
  58.  
  59. StarNames '                            Routine to load star names into string array stars(200)
  60.  
  61. NewGame
  62.  
  63. ttf1 = _LOADFONT("cyberbit.ttf", 14, "BOLD")
  64. ttf2 = _LOADFONT("cyberbit.ttf", 72, "BOLD")
  65.  
  66. repeat = 1
  67.  
  68. WHILE repeat
  69.  
  70.     _LIMIT 60 '                        Set to 60 frames per second
  71.  
  72.     CLS
  73.  
  74.     PaintBackground
  75.  
  76.     PaintStars
  77.  
  78.     GetInput
  79.  
  80.     Identify x, y '                    Identify star mouse is over if any
  81.  
  82.     computer
  83.  
  84.     _DISPLAY
  85.  
  86.  
  87.  
  88. SUB computer
  89.     FOR i = 0 TO 99
  90.         r = INT(RND * 120)
  91.         IF r < star(i).p THEN star(i).t = star(i).t + 1
  92.     NEXT
  93.  
  94. SUB GetInput
  95.  
  96.     ch = INKEY$
  97.     IF ch = CHR$(27) THEN repeat = 0
  98.     IF ch = "n" THEN NewGame
  99.     IF ch = "t" THEN tt = 1 - tt
  100.     ch = ""
  101.  
  102.     WHILE _MOUSEINPUT: WEND '          Eat all the mice but keep last mouse to toy with
  103.  
  104.     x = _MOUSEX
  105.     y = _MOUSEY
  106.     mb = _MOUSEBUTTON(1)
  107.     clk = 0
  108.  
  109.     IF mb = -1 AND cx = sw THEN
  110.         cx = x
  111.         cy = y
  112.     END IF
  113.  
  114.     IF mb = 0 AND cx < sw THEN
  115.         IF ABS(x - cx) < 4 AND ABS(y - cy) < 4 THEN
  116.             clk = 1
  117.         END IF
  118.         cx = sw
  119.     END IF
  120.  
  121. SUB PaintBackground
  122.     x = RND * sw
  123.     y = RND * sh
  124.     c = RND * 14 + 1
  125.     PSET (x, y), c
  126.     RANDOMIZE USING seed
  127.     FOR i = 1 TO 600 * ratio
  128.         x = RND * sw
  129.         y = RND * sh
  130.         c = RND * 14 + 1
  131.         PSET (x, y), c
  132.     NEXT
  133.  
  134. SUB ProcessPanel
  135.  
  136.  
  137. SUB Identify (x, y)
  138.     IF ar = 1 THEN
  139.         ShowPanel h
  140.         IF clk THEN
  141.             IF x >= x1 AND x <= x2 AND y >= y1 AND y <= y2 THEN
  142.                 ProcessPanel
  143.             ELSE
  144.                 ar = 0
  145.             END IF
  146.         END IF
  147.     END IF
  148.     IF ar = 0 THEN
  149.         FOR i = 0 TO 99
  150.             dx = star(i).x - x
  151.             dy = star(i).y - y
  152.             IF ABS(dx) <= star(i).s + 6 AND ABS(dy) <= star(i).s + 6 THEN
  153.                 ShowPanel i
  154.                 IF clk THEN
  155.                     clk = 0
  156.                     h = i
  157.                     ar = 1
  158.                     ax = x
  159.                 END IF
  160.             END IF
  161.         NEXT
  162.     END IF
  163.  
  164. SUB ShowPanel (i)
  165.     x1 = star(i).x - 420 * ratio
  166.     IF star(i).x < sw / 2 THEN x1 = star(i).x + 20
  167.     x2 = x1 + 400 * ratio
  168.     y1 = star(i).y
  169.     IF y1 > sh - 560 * ratio THEN y1 = sh - 560 * ratio
  170.     y2 = y1 + 540 * ratio
  171.     _DEST ps
  172.     CLS 0, 8
  173.     COLOR 0, 8
  174.     _FONT ttf2
  175.     n$ = RTRIM$(star(i).n)
  176.     l = _PRINTWIDTH(n$)
  177.     _PRINTSTRING ((400 - l) / 2, 8), n$, ps
  178.     _PUTIMAGE (x1, y1), ps, 0, (0, 0)-(400 * ratio, 540 * ratio)
  179.     _DEST 0
  180.  
  181. SUB PaintStars
  182.     FOR i = 0 TO 99
  183.         c = star(i).c
  184.         x = star(i).x
  185.         y = star(i).y
  186.         o = star(i).o
  187.         CIRCLE (x, y), (star(i).s + 6) * ratio, c
  188.         COLOR 15
  189.         IF o > 0 THEN
  190.             PAINT (x, y), o + 8, c
  191.             COLOR o + 8
  192.         END IF
  193.         _FONT ttf1
  194.         IF tt THEN
  195.             n$ = star(i).n
  196.             n$ = RTRIM$(n$)
  197.             l = _PRINTWIDTH(n$)
  198.         ELSE
  199.             n$ = STR$(star(i).t)
  200.             l = _PRINTWIDTH(n$)
  201.         END IF
  202.         _PRINTSTRING (x - l / 2, y + 12), n$, 0
  203.     NEXT
  204.  
  205. SUB NewGame
  206.     DIM k AS INTEGER
  207.     DIM r AS INTEGER
  208.     DIM dx AS INTEGER
  209.     DIM dy AS INTEGER
  210.     DIM n AS STRING * 10
  211.     seed = RND * 1000
  212.     star(0).n = "Sol"
  213.     star(0).x = RND * (sw - sww) + swn
  214.     star(0).y = RND * (sh - shw) + shn
  215.     star(0).c = 14
  216.     star(0).s = 2
  217.     star(0).o = 1
  218.     star(0).p = 10
  219.     star(0).t = 100
  220.     home(0) = 0
  221.     FOR i = 1 TO 99
  222.         k = 1
  223.         WHILE k
  224.             k = 0
  225.             x = RND * (sw - sww) + swn
  226.             y = RND * (sh - shw) + shn
  227.             r = INT(RND * 200)
  228.             n = names(r)
  229.             FOR j = 0 TO i - 1
  230.                 dx = x - star(j).x
  231.                 dy = y - star(j).y
  232.                 IF ABS(dx) < sww AND ABS(dy) < shw THEN
  233.                     k = 1
  234.                 END IF
  235.                 IF n = star(j).n THEN
  236.                     k = 1
  237.                 END IF
  238.             NEXT
  239.         WEND
  240.         star(i).n = n
  241.         star(i).x = x
  242.         star(i).y = y
  243.         star(i).c = RND * 6 + 9
  244.         star(i).s = RND * 5
  245.         star(i).o = 0
  246.         star(i).p = star(i).s + (RND * 8) + 1
  247.         star(i).t = 0
  248.     NEXT
  249.     FOR i = 2 TO 6
  250.         k = 1
  251.         WHILE k
  252.             k = 0
  253.             r = RND * 100
  254.             FOR j = 1 TO i - 1
  255.                 IF r = home(j) THEN k = 1
  256.                 x = star(0).x
  257.                 y = star(0).y
  258.                 dx = ABS(star(r).x - x)
  259.                 dy = ABS(star(r).y - y)
  260.                 IF dx < sw / 4 AND dy < sh / 4 THEN k = 1
  261.             NEXT
  262.         WEND
  263.         home(i) = r
  264.         star(r).o = i
  265.         star(r).p = 10
  266.         star(r).t = 100
  267.     NEXT
  268.  
  269. ' A lot of star names I made up
  270.  
  271. SUB StarNames
  272.     names(0) = "Acamar"
  273.     names(1) = "Arcab"
  274.     names(2) = "Acrux"
  275.     names(3) = "Adhara"
  276.     names(4) = "Arneb"
  277.     names(5) = "Antares"
  278.     names(6) = "Arcturus"
  279.     names(7) = "Atria"
  280.     names(8) = "Beid"
  281.     names(9) = "Betelgeuse"
  282.     names(10) = "Botein"
  283.     names(11) = "Beemim"
  284.     names(12) = "Bellatrix"
  285.     names(13) = "Bharani"
  286.     names(14) = "Biham"
  287.     names(15) = "Brachium"
  288.     names(16) = "Canopus"
  289.     names(17) = "Capella"
  290.     names(18) = "Castor"
  291.     names(19) = "Chara"
  292.     names(20) = "Cursa"
  293.     names(21) = "Copernicus"
  294.     names(22) = "Chalawan"
  295.     names(23) = "Chertan"
  296.     names(24) = "Dabih"
  297.     names(25) = "Dalim"
  298.     names(26) = "Deneb"
  299.     names(27) = "Denebola"
  300.     names(28) = "Diadem"
  301.     names(29) = "Diphda"
  302.     names(30) = "Dschubba"
  303.     names(31) = "Dziban"
  304.     names(32) = "Edasich"
  305.     names(33) = "Electra"
  306.     names(34) = "Elgafar"
  307.     names(35) = "Elkurud"
  308.     names(36) = "Elnath"
  309.     names(37) = "Eltanin"
  310.     names(38) = "Enif"
  311.     names(39) = "Errai"
  312.     names(40) = "Fafnir"
  313.     names(41) = "Fang"
  314.     names(42) = "Fawaris"
  315.     names(43) = "Felis"
  316.     names(44) = "Fomalhaut"
  317.     names(45) = "Fulu"
  318.     names(46) = "Fumal"
  319.     names(47) = "Furud"
  320.     names(48) = "Garnet"
  321.     names(49) = "Giausar"
  322.     names(50) = "Gienah"
  323.     names(51) = "Ginan"
  324.     names(52) = "Gomeisa"
  325.     names(53) = "Graffias"
  326.     names(54) = "Grumium"
  327.     names(55) = "Gudja"
  328.     names(56) = "Hadar"
  329.     names(57) = "Haedus"
  330.     names(58) = "Hamal"
  331.     names(59) = "Hassaleh"
  332.     names(60) = "Hatysa"
  333.     names(61) = "Helvetios"
  334.     names(62) = "Heze"
  335.     names(63) = "Homan"
  336.     names(64) = "Iklil"
  337.     names(65) = "Imai"
  338.     names(66) = "Intercrus"
  339.     names(67) = "Izar"
  340.     names(68) = "Iccar"
  341.     names(69) = "Inar"
  342.     names(70) = "Iaeth"
  343.     names(71) = "Imaous"
  344.     names(72) = "Jabbah"
  345.     names(73) = "Jishui"
  346.     names(74) = "Jax"
  347.     names(75) = "Jalae"
  348.     names(76) = "Jewel"
  349.     names(77) = "Jumbo"
  350.     names(78) = "Jerue"
  351.     names(79) = "Jabear"
  352.     names(80) = "Kakkab"
  353.     names(81) = "Kang"
  354.     names(82) = "Kekouan"
  355.     names(83) = "Keid"
  356.     names(84) = "Kitalpha"
  357.     names(85) = "Kochab"
  358.     names(86) = "Kolob"
  359.     names(87) = "Kobol"
  360.     names(88) = "Larawag"
  361.     names(89) = "Lesath"
  362.     names(90) = "Libertas"
  363.     names(91) = "Lich"
  364.     names(92) = "Lilly"
  365.     names(93) = "Laddel"
  366.     names(94) = "Luminous"
  367.     names(95) = "Lasacious"
  368.     names(96) = "Mizar"
  369.     names(97) = "Markab"
  370.     names(98) = "Matar"
  371.     names(99) = "Mintaka"
  372.     names(100) = "Meleph"
  373.     names(101) = "Menkar"
  374.     names(102) = "Merga"
  375.     names(103) = "Merope"
  376.     names(104) = "Nahn"
  377.     names(105) = "Naos"
  378.     names(106) = "Nashira"
  379.     names(107) = "Navi"
  380.     names(108) = "Nekkar"
  381.     names(109) = "Nembus"
  382.     names(110) = "Nihal"
  383.     names(111) = "Nunki"
  384.     names(112) = "Ogma"
  385.     names(113) = "Okab"
  386.     names(114) = "Ohmy"
  387.     names(115) = "Oragami"
  388.     names(116) = "Origen"
  389.     names(117) = "Omanii"
  390.     names(118) = "Obytewa"
  391.     names(119) = "Oglok"
  392.     names(120) = "Phact"
  393.     names(121) = "Pherkad"
  394.     names(122) = "Pleione"
  395.     names(122) = "Polaris"
  396.     names(123) = "Pollux"
  397.     names(124) = "Procyon"
  398.     names(125) = "Proxima"
  399.     names(126) = "Polis"
  400.     names(127) = "Quaint"
  401.     names(128) = "Quazzat"
  402.     names(129) = "Quetzal"
  403.     names(130) = "Qussol"
  404.     names(131) = "Quella"
  405.     names(132) = "Quyaeo"
  406.     names(133) = "Ququdas"
  407.     names(134) = "Quekak"
  408.     names(135) = "Rasalas"
  409.     names(136) = "Regor"
  410.     names(137) = "Regulus"
  411.     names(138) = "Rigel"
  412.     names(139) = "Revati"
  413.     names(140) = "Rotenev"
  414.     names(141) = "Rukbat"
  415.     names(142) = "Rastaban"
  416.     names(143) = "Sabik"
  417.     names(144) = "Sadr"
  418.     names(145) = "Saiph"
  419.     names(146) = "Sargas"
  420.     names(147) = "Sarin"
  421.     names(148) = "Syrma"
  422.     names(149) = "Spica"
  423.     names(150) = "Sirius"
  424.     names(151) = "Tarazed"
  425.     names(152) = "Taygeta"
  426.     names(153) = "Tejat"
  427.     names(154) = "Thabit"
  428.     names(155) = "Thuban"
  429.     names(156) = "Tiaki"
  430.     names(157) = "Toliman"
  431.     names(158) = "Torcular"
  432.     names(157) = "Umala"
  433.     names(158) = "Ulatte"
  434.     names(159) = "Ubbessa"
  435.     names(160) = "Unoless"
  436.     names(161) = "Umaddem"
  437.     names(162) = "Ummbra"
  438.     names(162) = "Uniqu"
  439.     names(163) = "Uzzaal"
  440.     names(164) = "Vega"
  441.     names(165) = "Veritate"
  442.     names(166) = "Vindetrix"
  443.     names(167) = "Vedas"
  444.     names(168) = "Vergg"
  445.     names(169) = "Vacant"
  446.     names(170) = "Vucae"
  447.     names(171) = "Vicar"
  448.     names(172) = "Wasat"
  449.     names(173) = "Wazn"
  450.     names(174) = "Wezen"
  451.     names(175) = "Waiten"
  452.     names(176) = "Wachar"
  453.     names(177) = "Wheelz"
  454.     names(178) = "Whatsp"
  455.     names(179) = "Wassand"
  456.     names(180) = "Xenno"
  457.     names(181) = "Xyphod"
  458.     names(182) = "Xu"
  459.     names(183) = "Xaal"
  460.     names(184) = "Xyross"
  461.     names(185) = "Xiggot"
  462.     names(186) = "Xirrks"
  463.     names(187) = "Yed"
  464.     names(188) = "Yildun"
  465.     names(189) = "Yundun"
  466.     names(190) = "Yavyo"
  467.     names(191) = "Yotrac"
  468.     names(192) = "Yxzoqu"
  469.     names(193) = "Ynnot"
  470.     names(194) = "Zaniah"
  471.     names(195) = "Zaurak"
  472.     names(196) = "Zhang"
  473.     names(197) = "Zibal"
  474.     names(198) = "Zosma"
  475.     names(199) = "Zuben"
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
Title: Re: MOO
Post by: romichess on December 06, 2019, 11:58:31 pm
I did not get to work on my game today as much as I would have liked. But I id get it to the level of demo, :), at least. It is not a game yet or even a simulation as the A.I. if one wants to call it that is way too rudimentary. My goal for today was just to verify the mechanics and that seems to have been a success.

Code: QB64: [Select]
  1. TYPE stars
  2.     n AS STRING * 10 '                 Name of star
  3.     x AS INTEGER '                     x-position
  4.     y AS INTEGER '                     y-position
  5.     o AS INTEGER '                     Owner
  6.     c AS INTEGER '                     Color
  7.     s AS INTEGER '                     Size
  8.     t AS INTEGER '                     (Type of planetary system; terran, frozen, radiated, toxic, etc.) Ships
  9.     p AS INTEGER '                     (Population) For now ships produced per turn
  10.  
  11. TYPE FLEETS
  12.     n AS INTEGER
  13.     x1 AS INTEGER
  14.     y1 AS INTEGER
  15.     x2 AS INTEGER
  16.     y2 AS INTEGER
  17.     o AS INTEGER
  18.     d AS INTEGER
  19.  
  20. 'DECLARE SUB NewGame
  21. 'DECLARE SUB PaintStars
  22. 'DECLARE SUB StarNames
  23. 'DECLARE SUB ShowPanel (i)
  24. 'DECLARE SUB Identify (x, y)
  25. 'DECLARE SUB PaintBackground
  26. 'DECLARE SUB GetInput
  27.  
  28. ' Global variables shared because they are needed in more than one routine
  29. DIM SHARED sw AS INTEGER '             Screen Width
  30. DIM SHARED sh AS INTEGER '             Screen Height
  31. DIM SHARED sww AS INTEGER '            Screen Width Wide margin
  32. DIM SHARED swn AS INTEGER '            Screen Width Narrow adjustment
  33. DIM SHARED shw AS INTEGER '            Screen Height Wide margine
  34. DIM SHARED shn AS INTEGER '            Screen Height Narrow adjustment
  35. DIM SHARED nw AS INTEGER '             games Natural screen Width
  36. DIM SHARED nh AS INTEGER '             games Natural screen Height
  37. DIM SHARED ratio AS _FLOAT '           the Ratio of the games natural screen width to the actual
  38. DIM SHARED star(100) AS stars '        100 stars - may change
  39. DIM SHARED names(200) AS STRING * 10 ' 200 star names
  40. DIM SHARED seed AS INTEGER '           Seed to prime the Randomizer to display identical background each frame
  41. DIM SHARED home(6) AS INTEGER '        The starting star for each player. The human always has star(0), Sol
  42. DIM SHARED tt AS INTEGER '             tt = 0 star names displayed, tt = 0 star names not didplayed
  43. DIM SHARED ch AS STRING * 1 '          Game loop key input variable
  44. DIM SHARED repeat AS INTEGER '         Game loop control variable
  45. DIM SHARED fleet(1000) AS FLEETS
  46.  
  47. sw = _DESKTOPWIDTH '                   native video with of syatem
  48. sww = sw / 24 '                        margin based on native video width to keep stars away from edge
  49. swn = sw / 48 '                        adjustment that works with sww to keep stars away from left and top of screen
  50. nw = 1920
  51.  
  52. ratio = sw / 1920 '                    Used to adjust distances and sizes for various screen modes
  53.  
  54. shw = sh / 20
  55. shn = sh / 40
  56. nh = 1080
  57.  
  58. tt = 0
  59. cx = sw
  60. cp = 100
  61. h = 100
  62. ar = 0
  63.  
  64. SCREEN _NEWIMAGE(sw, sh, 256) '        creates a screen the resolution of the users native system
  65.  
  66.  
  67. ps = _NEWIMAGE(400 * ratio, 540 * ratio, 256)
  68.  
  69. StarNames '                            Routine to load star names into string array stars(200)
  70.  
  71. NewGame
  72.  
  73. ttf1 = _LOADFONT("cyberbit.ttf", 14, "BOLD")
  74. ttf2 = _LOADFONT("cyberbit.ttf", 72, "BOLD")
  75.  
  76. repeat = 1
  77.  
  78. WHILE repeat
  79.  
  80.     _LIMIT 30 '                        Set to 60 frames per second
  81.  
  82.     CLS
  83.  
  84.     PaintBackground
  85.  
  86.     PaintStars
  87.  
  88.     PaintFleet
  89.  
  90.     GetInput
  91.  
  92.     Identify x, y '                    Identify star mouse is over if any
  93.  
  94.     computer
  95.  
  96.     _DISPLAY
  97.  
  98.  
  99.  
  100. SUB PaintFleet
  101.     count = fltcnt
  102.     i = 0
  103.     WHILE count
  104.         IF fleet(i).o <> 0 THEN
  105.             CIRCLE (fleet(i).x1, fleet(i).y1), 3, fleet(i).o + 8
  106.             count = count - 1
  107.         END IF
  108.         i = i + 1
  109.     WEND
  110.  
  111. SUB SendFleet (org, dst)
  112.     FOR i = 0 TO 999
  113.         IF fleet(i).o = 0 THEN
  114.             fleet(i).o = star(org).o
  115.             fleet(i).d = dst
  116.             fleet(i).x1 = star(org).x
  117.             fleet(i).y1 = star(org).y
  118.             fleet(i).x2 = star(dst).x
  119.             fleet(i).y2 = star(dst).y
  120.             fleet(i).n = star(org).t / 2
  121.             star(org).t = star(org).t / 2
  122.             fltcnt = fltcnt + 1
  123.             EXIT FOR
  124.         END IF
  125.     NEXT
  126.  
  127. SUB computer
  128.     FOR i = 0 TO 99
  129.         r = INT(RND * 120)
  130.         IF r < star(i).p THEN
  131.             IF star(i).o > 0 THEN
  132.                 star(i).t = star(i).t + 1
  133.             ELSE
  134.                 IF INT(RND * 10) = 0 AND star(i).t < 40 THEN
  135.                     star(i).t = star(i).t + 1
  136.                 END IF
  137.             END IF
  138.         END IF
  139.     NEXT
  140.     num = 0
  141.     FOR i = 1 TO 6
  142.         FOR j = 0 TO 99
  143.             IF star(j).o = i THEN
  144.                 IF star(j).t > num THEN
  145.                     num = star(j).t
  146.                     idx = j
  147.                 END IF
  148.             END IF
  149.         NEXT
  150.         org = idx
  151.         num = 10000
  152.         FOR j = 0 TO 99
  153.             IF star(j).o <> i THEN
  154.                 IF star(j).t < num THEN
  155.                     num = star(j).t
  156.                     idx = j
  157.                 END IF
  158.             END IF
  159.         NEXT
  160.         dst = idx
  161.         IF star(org).t > 100 AND star(org).t > star(dst).t * 2 THEN
  162.             SendFleet org, dst
  163.         END IF
  164.     NEXT
  165.     count = fltcnt
  166.     PRINT fltcnt
  167.     i = 0
  168.     WHILE count
  169.         IF fleet(i).o <> 0 THEN
  170.             count = count - 1
  171.             IF fleet(i).x2 > fleet(i).x1 THEN
  172.                 fleet(i).x1 = fleet(i).x1 + 1
  173.             END IF
  174.             IF fleet(i).x2 < fleet(i).x1 THEN
  175.                 fleet(i).x1 = fleet(i).x1 - 1
  176.             END IF
  177.             IF fleet(i).y2 > fleet(i).y1 THEN
  178.                 fleet(i).y1 = fleet(i).y1 + 1
  179.             END IF
  180.             IF fleet(i).y2 < fleet(i).y1 THEN
  181.                 fleet(i).y1 = fleet(i).y1 - 1
  182.             END IF
  183.             IF fleet(i).x1 = fleet(i).x2 AND fleet(i).y1 = fleet(i).y2 THEN
  184.                 dst = fleet(i).d
  185.                 IF star(dst).o = fleet(i).o THEN
  186.                     star(dst).t = star(dst).t + fleet(i).n
  187.                     fleet(i).o = 0
  188.                     fltcnt = fltcnt - 1
  189.                 ELSE
  190.                     star(dst).t = star(dst).t - fleet(i).n
  191.                     IF star(dst).t < 0 THEN
  192.                         star(dst).t = fleet(i).n / 2
  193.                         star(dst).o = fleet(i).o
  194.                     END IF
  195.                     fleet(i).o = 0
  196.                     fltcnt = fltcnt - 1
  197.                 END IF
  198.             END IF
  199.         END IF
  200.         i = i + 1
  201.     WEND
  202.  
  203. SUB GetInput
  204.  
  205.     ch = INKEY$
  206.     IF ch = CHR$(27) THEN repeat = 0
  207.     IF ch = "n" THEN NewGame
  208.     IF ch = "t" THEN tt = 1 - tt
  209.     ch = ""
  210.  
  211.     WHILE _MOUSEINPUT: WEND '          Eat all the mice but keep last mouse to toy with
  212.  
  213.     x = _MOUSEX
  214.     y = _MOUSEY
  215.     mb = _MOUSEBUTTON(1)
  216.     clk = 0
  217.  
  218.     IF mb = -1 AND cx = sw THEN
  219.         cx = x
  220.         cy = y
  221.     END IF
  222.  
  223.     IF mb = 0 AND cx < sw THEN
  224.         IF ABS(x - cx) < 4 AND ABS(y - cy) < 4 THEN
  225.             clk = 1
  226.         END IF
  227.         cx = sw
  228.     END IF
  229.  
  230. SUB PaintBackground
  231.     x = RND * sw
  232.     y = RND * sh
  233.     c = RND * 14 + 1
  234.     PSET (x, y), c
  235.     RANDOMIZE USING seed
  236.     FOR i = 1 TO 600 * ratio
  237.         x = RND * sw
  238.         y = RND * sh
  239.         c = RND * 14 + 1
  240.         PSET (x, y), c
  241.     NEXT
  242.  
  243. SUB ProcessPanel
  244.  
  245.  
  246. SUB Identify (x, y)
  247.     IF ar = 1 THEN
  248.         ShowPanel h
  249.         IF clk THEN
  250.             IF x >= x1 AND x <= x2 AND y >= y1 AND y <= y2 THEN
  251.                 ProcessPanel
  252.             ELSE
  253.                 ar = 0
  254.             END IF
  255.         END IF
  256.     END IF
  257.     IF ar = 0 THEN
  258.         FOR i = 0 TO 99
  259.             dx = star(i).x - x
  260.             dy = star(i).y - y
  261.             IF ABS(dx) <= star(i).s + 6 AND ABS(dy) <= star(i).s + 6 THEN
  262.                 ShowPanel i
  263.                 IF clk THEN
  264.                     clk = 0
  265.                     h = i
  266.                     ar = 1
  267.                     ax = x
  268.                 END IF
  269.             END IF
  270.         NEXT
  271.     END IF
  272.  
  273. SUB ShowPanel (i)
  274.     x1 = star(i).x - 420 * ratio
  275.     IF star(i).x < sw / 2 THEN x1 = star(i).x + 20
  276.     x2 = x1 + 400 * ratio
  277.     y1 = star(i).y
  278.     IF y1 > sh - 560 * ratio THEN y1 = sh - 560 * ratio
  279.     y2 = y1 + 540 * ratio
  280.     _DEST ps
  281.     CLS 0, 8
  282.     COLOR 0, 8
  283.     _FONT ttf2
  284.     n$ = RTRIM$(star(i).n)
  285.     l = _PRINTWIDTH(n$)
  286.     _PRINTSTRING ((400 - l) / 2, 8), n$, ps
  287.     _PUTIMAGE (x1, y1), ps, 0, (0, 0)-(400 * ratio, 540 * ratio)
  288.     _DEST 0
  289.  
  290. SUB PaintStars
  291.     FOR i = 0 TO 99
  292.         c = star(i).c
  293.         x = star(i).x
  294.         y = star(i).y
  295.         o = star(i).o
  296.         CIRCLE (x, y), (star(i).s + 6) * ratio, c
  297.         COLOR 15
  298.         IF o > 0 THEN
  299.             PAINT (x, y), o + 8, c
  300.             COLOR o + 8
  301.         END IF
  302.         _FONT ttf1
  303.         IF tt THEN
  304.             n$ = star(i).n
  305.             n$ = RTRIM$(n$)
  306.             l = _PRINTWIDTH(n$)
  307.         ELSE
  308.             n$ = STR$(star(i).t)
  309.             l = _PRINTWIDTH(n$)
  310.         END IF
  311.         _PRINTSTRING (x - l / 2, y + 12), n$, 0
  312.     NEXT
  313.  
  314. SUB NewGame
  315.     DIM k AS INTEGER
  316.     DIM r AS INTEGER
  317.     DIM dx AS INTEGER
  318.     DIM dy AS INTEGER
  319.     DIM n AS STRING * 10
  320.     FOR i = 0 TO 999
  321.         fleet(i).o = 0
  322.     NEXT
  323.     fltcnt = 0
  324.     seed = RND * 1000
  325.     star(0).n = "Sol"
  326.     star(0).x = RND * (sw - sww) + swn
  327.     star(0).y = RND * (sh - shw) + shn
  328.     star(0).c = 14
  329.     star(0).s = 2
  330.     star(0).o = 1
  331.     star(0).p = 10
  332.     star(0).t = 100
  333.     home(0) = 0
  334.     FOR i = 1 TO 99
  335.         k = 1
  336.         WHILE k
  337.             k = 0
  338.             x = RND * (sw - sww) + swn
  339.             y = RND * (sh - shw) + shn
  340.             r = INT(RND * 200)
  341.             n = names(r)
  342.             FOR j = 0 TO i - 1
  343.                 dx = x - star(j).x
  344.                 dy = y - star(j).y
  345.                 IF ABS(dx) < sww AND ABS(dy) < shw THEN
  346.                     k = 1
  347.                 END IF
  348.                 IF n = star(j).n THEN
  349.                     k = 1
  350.                 END IF
  351.             NEXT
  352.         WEND
  353.         star(i).n = n
  354.         star(i).x = x
  355.         star(i).y = y
  356.         star(i).c = RND * 6 + 9
  357.         star(i).s = RND * 5
  358.         star(i).o = 0
  359.         star(i).p = star(i).s + (RND * 8) + 1
  360.         star(i).t = 0
  361.     NEXT
  362.     FOR i = 2 TO 6
  363.         k = 1
  364.         WHILE k
  365.             k = 0
  366.             r = RND * 100
  367.             FOR j = 1 TO i - 1
  368.                 IF r = home(j) THEN k = 1
  369.                 x = star(0).x
  370.                 y = star(0).y
  371.                 dx = ABS(star(r).x - x)
  372.                 dy = ABS(star(r).y - y)
  373.                 IF dx < sw / 4 AND dy < sh / 4 THEN k = 1
  374.             NEXT
  375.         WEND
  376.         home(i) = r
  377.         star(r).o = i
  378.         star(r).p = 10
  379.         star(r).t = 100
  380.     NEXT
  381.  
  382. ' A lot of star names I made up
  383.  
  384. SUB StarNames
  385.     names(0) = "Acamar"
  386.     names(1) = "Arcab"
  387.     names(2) = "Acrux"
  388.     names(3) = "Adhara"
  389.     names(4) = "Arneb"
  390.     names(5) = "Antares"
  391.     names(6) = "Arcturus"
  392.     names(7) = "Atria"
  393.     names(8) = "Beid"
  394.     names(9) = "Betelgeuse"
  395.     names(10) = "Botein"
  396.     names(11) = "Beemim"
  397.     names(12) = "Bellatrix"
  398.     names(13) = "Bharani"
  399.     names(14) = "Biham"
  400.     names(15) = "Brachium"
  401.     names(16) = "Canopus"
  402.     names(17) = "Capella"
  403.     names(18) = "Castor"
  404.     names(19) = "Chara"
  405.     names(20) = "Cursa"
  406.     names(21) = "Copernicus"
  407.     names(22) = "Chalawan"
  408.     names(23) = "Chertan"
  409.     names(24) = "Dabih"
  410.     names(25) = "Dalim"
  411.     names(26) = "Deneb"
  412.     names(27) = "Denebola"
  413.     names(28) = "Diadem"
  414.     names(29) = "Diphda"
  415.     names(30) = "Dschubba"
  416.     names(31) = "Dziban"
  417.     names(32) = "Edasich"
  418.     names(33) = "Electra"
  419.     names(34) = "Elgafar"
  420.     names(35) = "Elkurud"
  421.     names(36) = "Elnath"
  422.     names(37) = "Eltanin"
  423.     names(38) = "Enif"
  424.     names(39) = "Errai"
  425.     names(40) = "Fafnir"
  426.     names(41) = "Fang"
  427.     names(42) = "Fawaris"
  428.     names(43) = "Felis"
  429.     names(44) = "Fomalhaut"
  430.     names(45) = "Fulu"
  431.     names(46) = "Fumal"
  432.     names(47) = "Furud"
  433.     names(48) = "Garnet"
  434.     names(49) = "Giausar"
  435.     names(50) = "Gienah"
  436.     names(51) = "Ginan"
  437.     names(52) = "Gomeisa"
  438.     names(53) = "Graffias"
  439.     names(54) = "Grumium"
  440.     names(55) = "Gudja"
  441.     names(56) = "Hadar"
  442.     names(57) = "Haedus"
  443.     names(58) = "Hamal"
  444.     names(59) = "Hassaleh"
  445.     names(60) = "Hatysa"
  446.     names(61) = "Helvetios"
  447.     names(62) = "Heze"
  448.     names(63) = "Homan"
  449.     names(64) = "Iklil"
  450.     names(65) = "Imai"
  451.     names(66) = "Intercrus"
  452.     names(67) = "Izar"
  453.     names(68) = "Iccar"
  454.     names(69) = "Inar"
  455.     names(70) = "Iaeth"
  456.     names(71) = "Imaous"
  457.     names(72) = "Jabbah"
  458.     names(73) = "Jishui"
  459.     names(74) = "Jax"
  460.     names(75) = "Jalae"
  461.     names(76) = "Jewel"
  462.     names(77) = "Jumbo"
  463.     names(78) = "Jerue"
  464.     names(79) = "Jabear"
  465.     names(80) = "Kakkab"
  466.     names(81) = "Kang"
  467.     names(82) = "Kekouan"
  468.     names(83) = "Keid"
  469.     names(84) = "Kitalpha"
  470.     names(85) = "Kochab"
  471.     names(86) = "Kolob"
  472.     names(87) = "Kobol"
  473.     names(88) = "Larawag"
  474.     names(89) = "Lesath"
  475.     names(90) = "Libertas"
  476.     names(91) = "Lich"
  477.     names(92) = "Lilly"
  478.     names(93) = "Laddel"
  479.     names(94) = "Luminous"
  480.     names(95) = "Lasacious"
  481.     names(96) = "Mizar"
  482.     names(97) = "Markab"
  483.     names(98) = "Matar"
  484.     names(99) = "Mintaka"
  485.     names(100) = "Meleph"
  486.     names(101) = "Menkar"
  487.     names(102) = "Merga"
  488.     names(103) = "Merope"
  489.     names(104) = "Nahn"
  490.     names(105) = "Naos"
  491.     names(106) = "Nashira"
  492.     names(107) = "Navi"
  493.     names(108) = "Nekkar"
  494.     names(109) = "Nembus"
  495.     names(110) = "Nihal"
  496.     names(111) = "Nunki"
  497.     names(112) = "Ogma"
  498.     names(113) = "Okab"
  499.     names(114) = "Ohmy"
  500.     names(115) = "Oragami"
  501.     names(116) = "Origen"
  502.     names(117) = "Omanii"
  503.     names(118) = "Obytewa"
  504.     names(119) = "Oglok"
  505.     names(120) = "Phact"
  506.     names(121) = "Pherkad"
  507.     names(122) = "Pleione"
  508.     names(122) = "Polaris"
  509.     names(123) = "Pollux"
  510.     names(124) = "Procyon"
  511.     names(125) = "Proxima"
  512.     names(126) = "Polis"
  513.     names(127) = "Quaint"
  514.     names(128) = "Quazzat"
  515.     names(129) = "Quetzal"
  516.     names(130) = "Qussol"
  517.     names(131) = "Quella"
  518.     names(132) = "Quyaeo"
  519.     names(133) = "Ququdas"
  520.     names(134) = "Quekak"
  521.     names(135) = "Rasalas"
  522.     names(136) = "Regor"
  523.     names(137) = "Regulus"
  524.     names(138) = "Rigel"
  525.     names(139) = "Revati"
  526.     names(140) = "Rotenev"
  527.     names(141) = "Rukbat"
  528.     names(142) = "Rastaban"
  529.     names(143) = "Sabik"
  530.     names(144) = "Sadr"
  531.     names(145) = "Saiph"
  532.     names(146) = "Sargas"
  533.     names(147) = "Sarin"
  534.     names(148) = "Syrma"
  535.     names(149) = "Spica"
  536.     names(150) = "Sirius"
  537.     names(151) = "Tarazed"
  538.     names(152) = "Taygeta"
  539.     names(153) = "Tejat"
  540.     names(154) = "Thabit"
  541.     names(155) = "Thuban"
  542.     names(156) = "Tiaki"
  543.     names(157) = "Toliman"
  544.     names(158) = "Torcular"
  545.     names(157) = "Umala"
  546.     names(158) = "Ulatte"
  547.     names(159) = "Ubbessa"
  548.     names(160) = "Unoless"
  549.     names(161) = "Umaddem"
  550.     names(162) = "Ummbra"
  551.     names(162) = "Uniqu"
  552.     names(163) = "Uzzaal"
  553.     names(164) = "Vega"
  554.     names(165) = "Veritate"
  555.     names(166) = "Vindetrix"
  556.     names(167) = "Vedas"
  557.     names(168) = "Vergg"
  558.     names(169) = "Vacant"
  559.     names(170) = "Vucae"
  560.     names(171) = "Vicar"
  561.     names(172) = "Wasat"
  562.     names(173) = "Wazn"
  563.     names(174) = "Wezen"
  564.     names(175) = "Waiten"
  565.     names(176) = "Wachar"
  566.     names(177) = "Wheelz"
  567.     names(178) = "Whatsp"
  568.     names(179) = "Wassand"
  569.     names(180) = "Xenno"
  570.     names(181) = "Xyphod"
  571.     names(182) = "Xu"
  572.     names(183) = "Xaal"
  573.     names(184) = "Xyross"
  574.     names(185) = "Xiggot"
  575.     names(186) = "Xirrks"
  576.     names(187) = "Yed"
  577.     names(188) = "Yildun"
  578.     names(189) = "Yundun"
  579.     names(190) = "Yavyo"
  580.     names(191) = "Yotrac"
  581.     names(192) = "Yxzoqu"
  582.     names(193) = "Ynnot"
  583.     names(194) = "Zaniah"
  584.     names(195) = "Zaurak"
  585.     names(196) = "Zhang"
  586.     names(197) = "Zibal"
  587.     names(198) = "Zosma"
  588.     names(199) = "Zuben"
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
Title: Re: MOO
Post by: romichess on December 07, 2019, 05:13:32 am
The A.I. looks good enough now to add a human player.
Code: QB64: [Select]
  1. TYPE stars
  2.     n AS STRING * 10 '                 Name of star
  3.     x AS INTEGER '                     x-position
  4.     y AS INTEGER '                     y-position
  5.     o AS INTEGER '                     Owner
  6.     c AS INTEGER '                     Color
  7.     s AS INTEGER '                     Size
  8.     t AS INTEGER '                     (Type of planetary system; terran, frozen, radiated, toxic, etc.) Ships
  9.     p AS INTEGER '                     (Population) For now ships produced per turn
  10.  
  11. TYPE FLEETS
  12.     n AS INTEGER
  13.     x1 AS INTEGER
  14.     y1 AS INTEGER
  15.     x2 AS INTEGER
  16.     y2 AS INTEGER
  17.     o AS INTEGER
  18.     d AS INTEGER
  19.  
  20. 'DECLARE SUB NewGame
  21. 'DECLARE SUB PaintStars
  22. 'DECLARE SUB StarNames
  23. 'DECLARE SUB ShowPanel (i)
  24. 'DECLARE SUB Identify (x, y)
  25. 'DECLARE SUB PaintBackground
  26. 'DECLARE SUB GetInput
  27.  
  28. ' Global variables shared because they are needed in more than one routine
  29. DIM SHARED sw AS INTEGER '             Screen Width
  30. DIM SHARED sh AS INTEGER '             Screen Height
  31. DIM SHARED sww AS INTEGER '            Screen Width Wide margin
  32. DIM SHARED swn AS INTEGER '            Screen Width Narrow adjustment
  33. DIM SHARED shw AS INTEGER '            Screen Height Wide margine
  34. DIM SHARED shn AS INTEGER '            Screen Height Narrow adjustment
  35. DIM SHARED nw AS INTEGER '             games Natural screen Width
  36. DIM SHARED nh AS INTEGER '             games Natural screen Height
  37. DIM SHARED ratio AS _FLOAT '           the Ratio of the games natural screen width to the actual
  38. DIM SHARED star(100) AS stars '        100 stars - may change
  39. DIM SHARED names(200) AS STRING * 10 ' 200 star names
  40. DIM SHARED seed AS INTEGER '           Seed to prime the Randomizer to display identical background each frame
  41. DIM SHARED home(6) AS INTEGER '        The starting star for each player. The human always has star(0), Sol
  42. DIM SHARED tt AS INTEGER '             tt = 0 star names displayed, tt = 0 star names not didplayed
  43. DIM SHARED ch AS STRING * 1 '          Game loop key input variable
  44. DIM SHARED repeat AS INTEGER '         Game loop control variable
  45. DIM SHARED fleet(1000) AS FLEETS
  46.  
  47. sw = _DESKTOPWIDTH '                   native video with of syatem
  48. sww = sw / 24 '                        margin based on native video width to keep stars away from edge
  49. swn = sw / 48 '                        adjustment that works with sww to keep stars away from left and top of screen
  50. nw = 1920
  51.  
  52. ratio = sw / 1920 '                    Used to adjust distances and sizes for various screen modes
  53.  
  54. shw = sh / 20
  55. shn = sh / 40
  56. nh = 1080
  57.  
  58. tt = 0
  59. cx = sw
  60. cp = 100
  61. h = 100
  62. ar = 0
  63.  
  64. SCREEN _NEWIMAGE(sw, sh, 256) '        creates a screen the resolution of the users native system
  65.  
  66.  
  67. ps = _NEWIMAGE(400 * ratio, 540 * ratio, 256)
  68.  
  69. StarNames '                            Routine to load star names into string array stars(200)
  70.  
  71. NewGame
  72.  
  73. ttf1 = _LOADFONT("cyberbit.ttf", 14, "BOLD")
  74. ttf2 = _LOADFONT("cyberbit.ttf", 72, "BOLD")
  75.  
  76. repeat = 1
  77.  
  78. WHILE repeat
  79.  
  80.     _LIMIT 60 '                        Set to 60 frames per second
  81.  
  82.     CLS
  83.  
  84.     PaintBackground
  85.  
  86.     PaintStars
  87.  
  88.     PaintFleet
  89.  
  90.     GetInput
  91.  
  92.     Identify x, y '                    Identify star mouse is over if any
  93.  
  94.     computer
  95.  
  96.     _DISPLAY
  97.  
  98.  
  99.  
  100. SUB PaintFleet
  101.     count = fltcnt
  102.     i = 0
  103.     WHILE count
  104.         IF fleet(i).o <> 0 THEN
  105.             CIRCLE (fleet(i).x1, fleet(i).y1), 3, fleet(i).o + 8
  106.             count = count - 1
  107.         END IF
  108.         i = i + 1
  109.     WEND
  110.  
  111. SUB SendFleet (org, dst)
  112.     FOR i = 0 TO 999
  113.         IF fleet(i).o = 0 THEN
  114.             fleet(i).o = star(org).o
  115.             fleet(i).d = dst
  116.             fleet(i).x1 = star(org).x
  117.             fleet(i).y1 = star(org).y
  118.             fleet(i).x2 = star(dst).x
  119.             fleet(i).y2 = star(dst).y
  120.             fleet(i).n = star(org).t / 2
  121.             star(org).t = star(org).t / 2
  122.             fltcnt = fltcnt + 1
  123.             EXIT FOR
  124.         END IF
  125.     NEXT
  126.     LL = LL + 1
  127.  
  128. SUB computer
  129.     FOR i = 0 TO 99
  130.         r = INT(RND * 120)
  131.         IF r < star(i).p THEN
  132.             IF star(i).o > 0 THEN
  133.                 star(i).t = star(i).t + 1
  134.             ELSE
  135.                 IF INT(RND * 10) = 0 AND star(i).t < 40 THEN
  136.                     star(i).t = star(i).t + 1
  137.                 END IF
  138.             END IF
  139.         END IF
  140.     NEXT
  141.     num = 0
  142.     FOR i = 1 TO 6
  143.         FOR j = 0 TO 99
  144.             IF star(j).o = i THEN
  145.                 IF star(j).t > num THEN
  146.                     num = star(j).t
  147.                     idx = j
  148.                 END IF
  149.             END IF
  150.         NEXT
  151.         org = idx
  152.         num = 10000
  153.         FOR j = 0 TO 99
  154.             IF star(j).o <> i THEN
  155.                 sway = ABS(star(org).x - star(j).x) + ABS(star(org).y - star(j).y)
  156.                 sway = sway / 16
  157.                 IF star(j).t + sway < num THEN
  158.                     num = star(j).t
  159.                     idx = j
  160.                 END IF
  161.             END IF
  162.         NEXT
  163.         dst = idx
  164.         IF star(org).t > 100 AND star(org).t > star(dst).t * 2 AND star(org).t > LL THEN
  165.             SendFleet org, dst
  166.         END IF
  167.     NEXT
  168.     count = fltcnt
  169.     PRINT fltcnt
  170.     i = 0
  171.     WHILE count
  172.         IF fleet(i).o <> 0 THEN
  173.             count = count - 1
  174.             IF fleet(i).x2 > fleet(i).x1 THEN
  175.                 fleet(i).x1 = fleet(i).x1 + 1
  176.             END IF
  177.             IF fleet(i).x2 < fleet(i).x1 THEN
  178.                 fleet(i).x1 = fleet(i).x1 - 1
  179.             END IF
  180.             IF fleet(i).y2 > fleet(i).y1 THEN
  181.                 fleet(i).y1 = fleet(i).y1 + 1
  182.             END IF
  183.             IF fleet(i).y2 < fleet(i).y1 THEN
  184.                 fleet(i).y1 = fleet(i).y1 - 1
  185.             END IF
  186.             IF fleet(i).x1 = fleet(i).x2 AND fleet(i).y1 = fleet(i).y2 THEN
  187.                 dst = fleet(i).d
  188.                 IF star(dst).o = fleet(i).o THEN
  189.                     star(dst).t = star(dst).t + fleet(i).n
  190.                     fleet(i).o = 0
  191.                     fltcnt = fltcnt - 1
  192.                 ELSE
  193.                     star(dst).t = star(dst).t - fleet(i).n
  194.                     IF star(dst).t < 0 THEN
  195.                         star(dst).t = fleet(i).n / 2
  196.                         star(dst).o = fleet(i).o
  197.                     END IF
  198.                     fleet(i).o = 0
  199.                     fltcnt = fltcnt - 1
  200.                 END IF
  201.             END IF
  202.         END IF
  203.         i = i + 1
  204.     WEND
  205.  
  206. SUB GetInput
  207.  
  208.     ch = INKEY$
  209.     IF ch = CHR$(27) THEN repeat = 0
  210.     IF ch = "n" THEN NewGame
  211.     IF ch = "t" THEN tt = 1 - tt
  212.     ch = ""
  213.  
  214.     WHILE _MOUSEINPUT: WEND '          Eat all the mice but keep last mouse to toy with
  215.  
  216.     x = _MOUSEX
  217.     y = _MOUSEY
  218.     mb = _MOUSEBUTTON(1)
  219.     clk = 0
  220.  
  221.     IF mb = -1 AND cx = sw THEN
  222.         cx = x
  223.         cy = y
  224.     END IF
  225.  
  226.     IF mb = 0 AND cx < sw THEN
  227.         IF ABS(x - cx) < 4 AND ABS(y - cy) < 4 THEN
  228.             clk = 1
  229.         END IF
  230.         cx = sw
  231.     END IF
  232.  
  233. SUB PaintBackground
  234.     x = RND * sw
  235.     y = RND * sh
  236.     c = RND * 14 + 1
  237.     PSET (x, y), c
  238.     RANDOMIZE USING seed
  239.     FOR i = 1 TO 600 * ratio
  240.         x = RND * sw
  241.         y = RND * sh
  242.         c = RND * 14 + 1
  243.         PSET (x, y), c
  244.     NEXT
  245.  
  246. SUB ProcessPanel
  247.  
  248.  
  249. SUB Identify (x, y)
  250.     IF ar = 1 THEN
  251.         ShowPanel h
  252.         IF clk THEN
  253.             IF x >= x1 AND x <= x2 AND y >= y1 AND y <= y2 THEN
  254.                 ProcessPanel
  255.             ELSE
  256.                 ar = 0
  257.             END IF
  258.         END IF
  259.     END IF
  260.     IF ar = 0 THEN
  261.         FOR i = 0 TO 99
  262.             dx = star(i).x - x
  263.             dy = star(i).y - y
  264.             IF ABS(dx) <= star(i).s + 6 AND ABS(dy) <= star(i).s + 6 THEN
  265.                 ShowPanel i
  266.                 IF clk THEN
  267.                     clk = 0
  268.                     h = i
  269.                     ar = 1
  270.                     ax = x
  271.                 END IF
  272.             END IF
  273.         NEXT
  274.     END IF
  275.  
  276. SUB ShowPanel (i)
  277.     x1 = star(i).x - 420 * ratio
  278.     IF star(i).x < sw / 2 THEN x1 = star(i).x + 20
  279.     x2 = x1 + 400 * ratio
  280.     y1 = star(i).y
  281.     IF y1 > sh - 560 * ratio THEN y1 = sh - 560 * ratio
  282.     y2 = y1 + 540 * ratio
  283.     _DEST ps
  284.     CLS 0, 8
  285.     COLOR 0, 8
  286.     _FONT ttf2
  287.     n$ = RTRIM$(star(i).n)
  288.     L = _PRINTWIDTH(n$)
  289.     _PRINTSTRING ((400 - L) / 2, 8), n$, ps
  290.     _PUTIMAGE (x1, y1), ps, 0, (0, 0)-(400 * ratio, 540 * ratio)
  291.     _DEST 0
  292.  
  293. SUB PaintStars
  294.     FOR i = 0 TO 99
  295.         c = star(i).c
  296.         x = star(i).x
  297.         y = star(i).y
  298.         o = star(i).o
  299.         CIRCLE (x, y), (star(i).s + 6) * ratio, c
  300.         COLOR 15
  301.         IF o > 0 THEN
  302.             PAINT (x, y), o + 8, c
  303.             COLOR o + 8
  304.         END IF
  305.         _FONT ttf1
  306.         IF tt THEN
  307.             n$ = star(i).n
  308.             n$ = RTRIM$(n$)
  309.             L = _PRINTWIDTH(n$)
  310.         ELSE
  311.             n$ = STR$(star(i).t)
  312.             L = _PRINTWIDTH(n$)
  313.         END IF
  314.         _PRINTSTRING (x - L / 2, y + 12), n$, 0
  315.     NEXT
  316.  
  317. SUB NewGame
  318.     DIM k AS INTEGER
  319.     DIM r AS INTEGER
  320.     DIM dx AS INTEGER
  321.     DIM dy AS INTEGER
  322.     DIM n AS STRING * 10
  323.     FOR i = 0 TO 999
  324.         fleet(i).o = 0
  325.     NEXT
  326.     fltcnt = 0
  327.     seed = RND * 1000
  328.     star(0).n = "Sol"
  329.     star(0).x = RND * (sw - sww) + swn
  330.     star(0).y = RND * (sh - shw) + shn
  331.     star(0).c = 14
  332.     star(0).s = 2
  333.     star(0).o = 1
  334.     star(0).p = 10
  335.     star(0).t = 100
  336.     home(0) = 0
  337.     FOR i = 1 TO 99
  338.         k = 1
  339.         WHILE k
  340.             k = 0
  341.             x = RND * (sw - sww) + swn
  342.             y = RND * (sh - shw) + shn
  343.             r = INT(RND * 200)
  344.             n = names(r)
  345.             FOR j = 0 TO i - 1
  346.                 dx = x - star(j).x
  347.                 dy = y - star(j).y
  348.                 IF ABS(dx) < sww AND ABS(dy) < shw THEN
  349.                     k = 1
  350.                 END IF
  351.                 IF n = star(j).n THEN
  352.                     k = 1
  353.                 END IF
  354.             NEXT
  355.         WEND
  356.         star(i).n = n
  357.         star(i).x = x
  358.         star(i).y = y
  359.         star(i).c = RND * 6 + 9
  360.         star(i).s = RND * 5
  361.         star(i).o = 0
  362.         star(i).p = star(i).s + (RND * 8) + 1
  363.         star(i).t = 0
  364.     NEXT
  365.     FOR i = 2 TO 6
  366.         k = 1
  367.         WHILE k
  368.             k = 0
  369.             r = RND * 100
  370.             FOR j = 1 TO i - 1
  371.                 IF r = home(j) THEN k = 1
  372.                 x = star(0).x
  373.                 y = star(0).y
  374.                 dx = ABS(star(r).x - x)
  375.                 dy = ABS(star(r).y - y)
  376.                 IF dx < sw / 4 AND dy < sh / 4 THEN k = 1
  377.             NEXT
  378.         WEND
  379.         home(i) = r
  380.         star(r).o = i
  381.         star(r).p = 10
  382.         star(r).t = 100
  383.     NEXT
  384.  
  385. ' A lot of star names I made up
  386.  
  387. SUB StarNames
  388.     names(0) = "Acamar"
  389.     names(1) = "Arcab"
  390.     names(2) = "Acrux"
  391.     names(3) = "Adhara"
  392.     names(4) = "Arneb"
  393.     names(5) = "Antares"
  394.     names(6) = "Arcturus"
  395.     names(7) = "Atria"
  396.     names(8) = "Beid"
  397.     names(9) = "Betelgeuse"
  398.     names(10) = "Botein"
  399.     names(11) = "Beemim"
  400.     names(12) = "Bellatrix"
  401.     names(13) = "Bharani"
  402.     names(14) = "Biham"
  403.     names(15) = "Brachium"
  404.     names(16) = "Canopus"
  405.     names(17) = "Capella"
  406.     names(18) = "Castor"
  407.     names(19) = "Chara"
  408.     names(20) = "Cursa"
  409.     names(21) = "Copernicus"
  410.     names(22) = "Chalawan"
  411.     names(23) = "Chertan"
  412.     names(24) = "Dabih"
  413.     names(25) = "Dalim"
  414.     names(26) = "Deneb"
  415.     names(27) = "Denebola"
  416.     names(28) = "Diadem"
  417.     names(29) = "Diphda"
  418.     names(30) = "Dschubba"
  419.     names(31) = "Dziban"
  420.     names(32) = "Edasich"
  421.     names(33) = "Electra"
  422.     names(34) = "Elgafar"
  423.     names(35) = "Elkurud"
  424.     names(36) = "Elnath"
  425.     names(37) = "Eltanin"
  426.     names(38) = "Enif"
  427.     names(39) = "Errai"
  428.     names(40) = "Fafnir"
  429.     names(41) = "Fang"
  430.     names(42) = "Fawaris"
  431.     names(43) = "Felis"
  432.     names(44) = "Fomalhaut"
  433.     names(45) = "Fulu"
  434.     names(46) = "Fumal"
  435.     names(47) = "Furud"
  436.     names(48) = "Garnet"
  437.     names(49) = "Giausar"
  438.     names(50) = "Gienah"
  439.     names(51) = "Ginan"
  440.     names(52) = "Gomeisa"
  441.     names(53) = "Graffias"
  442.     names(54) = "Grumium"
  443.     names(55) = "Gudja"
  444.     names(56) = "Hadar"
  445.     names(57) = "Haedus"
  446.     names(58) = "Hamal"
  447.     names(59) = "Hassaleh"
  448.     names(60) = "Hatysa"
  449.     names(61) = "Helvetios"
  450.     names(62) = "Heze"
  451.     names(63) = "Homan"
  452.     names(64) = "Iklil"
  453.     names(65) = "Imai"
  454.     names(66) = "Intercrus"
  455.     names(67) = "Izar"
  456.     names(68) = "Iccar"
  457.     names(69) = "Inar"
  458.     names(70) = "Iaeth"
  459.     names(71) = "Imaous"
  460.     names(72) = "Jabbah"
  461.     names(73) = "Jishui"
  462.     names(74) = "Jax"
  463.     names(75) = "Jalae"
  464.     names(76) = "Jewel"
  465.     names(77) = "Jumbo"
  466.     names(78) = "Jerue"
  467.     names(79) = "Jabear"
  468.     names(80) = "Kakkab"
  469.     names(81) = "Kang"
  470.     names(82) = "Kekouan"
  471.     names(83) = "Keid"
  472.     names(84) = "Kitalpha"
  473.     names(85) = "Kochab"
  474.     names(86) = "Kolob"
  475.     names(87) = "Kobol"
  476.     names(88) = "Larawag"
  477.     names(89) = "Lesath"
  478.     names(90) = "Libertas"
  479.     names(91) = "Lich"
  480.     names(92) = "Lilly"
  481.     names(93) = "Laddel"
  482.     names(94) = "Luminous"
  483.     names(95) = "Lasacious"
  484.     names(96) = "Mizar"
  485.     names(97) = "Markab"
  486.     names(98) = "Matar"
  487.     names(99) = "Mintaka"
  488.     names(100) = "Meleph"
  489.     names(101) = "Menkar"
  490.     names(102) = "Merga"
  491.     names(103) = "Merope"
  492.     names(104) = "Nahn"
  493.     names(105) = "Naos"
  494.     names(106) = "Nashira"
  495.     names(107) = "Navi"
  496.     names(108) = "Nekkar"
  497.     names(109) = "Nembus"
  498.     names(110) = "Nihal"
  499.     names(111) = "Nunki"
  500.     names(112) = "Ogma"
  501.     names(113) = "Okab"
  502.     names(114) = "Ohmy"
  503.     names(115) = "Oragami"
  504.     names(116) = "Origen"
  505.     names(117) = "Omanii"
  506.     names(118) = "Obytewa"
  507.     names(119) = "Oglok"
  508.     names(120) = "Phact"
  509.     names(121) = "Pherkad"
  510.     names(122) = "Pleione"
  511.     names(122) = "Polaris"
  512.     names(123) = "Pollux"
  513.     names(124) = "Procyon"
  514.     names(125) = "Proxima"
  515.     names(126) = "Polis"
  516.     names(127) = "Quaint"
  517.     names(128) = "Quazzat"
  518.     names(129) = "Quetzal"
  519.     names(130) = "Qussol"
  520.     names(131) = "Quella"
  521.     names(132) = "Quyaeo"
  522.     names(133) = "Ququdas"
  523.     names(134) = "Quekak"
  524.     names(135) = "Rasalas"
  525.     names(136) = "Regor"
  526.     names(137) = "Regulus"
  527.     names(138) = "Rigel"
  528.     names(139) = "Revati"
  529.     names(140) = "Rotenev"
  530.     names(141) = "Rukbat"
  531.     names(142) = "Rastaban"
  532.     names(143) = "Sabik"
  533.     names(144) = "Sadr"
  534.     names(145) = "Saiph"
  535.     names(146) = "Sargas"
  536.     names(147) = "Sarin"
  537.     names(148) = "Syrma"
  538.     names(149) = "Spica"
  539.     names(150) = "Sirius"
  540.     names(151) = "Tarazed"
  541.     names(152) = "Taygeta"
  542.     names(153) = "Tejat"
  543.     names(154) = "Thabit"
  544.     names(155) = "Thuban"
  545.     names(156) = "Tiaki"
  546.     names(157) = "Toliman"
  547.     names(158) = "Torcular"
  548.     names(157) = "Umala"
  549.     names(158) = "Ulatte"
  550.     names(159) = "Ubbessa"
  551.     names(160) = "Unoless"
  552.     names(161) = "Umaddem"
  553.     names(162) = "Ummbra"
  554.     names(162) = "Uniqu"
  555.     names(163) = "Uzzaal"
  556.     names(164) = "Vega"
  557.     names(165) = "Veritate"
  558.     names(166) = "Vindetrix"
  559.     names(167) = "Vedas"
  560.     names(168) = "Vergg"
  561.     names(169) = "Vacant"
  562.     names(170) = "Vucae"
  563.     names(171) = "Vicar"
  564.     names(172) = "Wasat"
  565.     names(173) = "Wazn"
  566.     names(174) = "Wezen"
  567.     names(175) = "Waiten"
  568.     names(176) = "Wachar"
  569.     names(177) = "Wheelz"
  570.     names(178) = "Whatsp"
  571.     names(179) = "Wassand"
  572.     names(180) = "Xenno"
  573.     names(181) = "Xyphod"
  574.     names(182) = "Xu"
  575.     names(183) = "Xaal"
  576.     names(184) = "Xyross"
  577.     names(185) = "Xiggot"
  578.     names(186) = "Xirrks"
  579.     names(187) = "Yed"
  580.     names(188) = "Yildun"
  581.     names(189) = "Yundun"
  582.     names(190) = "Yavyo"
  583.     names(191) = "Yotrac"
  584.     names(192) = "Yxzoqu"
  585.     names(193) = "Ynnot"
  586.     names(194) = "Zaniah"
  587.     names(195) = "Zaurak"
  588.     names(196) = "Zhang"
  589.     names(197) = "Zibal"
  590.     names(198) = "Zosma"
  591.     names(199) = "Zuben"
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
Title: Re: MOO
Post by: SierraKen on December 07, 2019, 01:04:18 pm
Pretty cool so far! It reminds me of the population simulators that people make sometimes. Like the ones scientists use for showing that ants can produce only so much then they all die eventually. I also like the way you show the circle spacecraft going to each one. Pretty clever.
Title: Re: MOO
Post by: romichess on December 07, 2019, 01:14:01 pm
Thanks! I have replaced the combat "hack" with a more realistic combat resolution. After that is tested I'll start the work of adding a player. :)
Title: Re: MOO
Post by: romichess on December 07, 2019, 03:35:23 pm
The AI is much better now balancing territory with far away jucy targets a little better. The battle resolution is better. The defence has a slight bonus which helps it maintain its territory better. If that causes a total standoff condition then that will have to be changed. I won't be posting source after today until the human player is working.

Code: QB64: [Select]
  1. TYPE stars
  2.     n AS STRING * 10 '                 Name of star
  3.     x AS INTEGER '                     x-position
  4.     y AS INTEGER '                     y-position
  5.     o AS INTEGER '                     Owner
  6.     c AS INTEGER '                     Color
  7.     s AS INTEGER '                     Size
  8.     t AS INTEGER '                     (Type of planetary system; terran, frozen, radiated, toxic, etc.) Ships
  9.     p AS INTEGER '                     (Population) For now ships produced per turn
  10.  
  11. TYPE FLEETS
  12.     n AS INTEGER
  13.     x1 AS INTEGER
  14.     y1 AS INTEGER
  15.     x2 AS INTEGER
  16.     y2 AS INTEGER
  17.     o AS INTEGER
  18.     d AS INTEGER
  19.  
  20. 'DECLARE SUB NewGame
  21. 'DECLARE SUB PaintStars
  22. 'DECLARE SUB StarNames
  23. 'DECLARE SUB ShowPanel (i)
  24. 'DECLARE SUB Identify (x, y)
  25. 'DECLARE SUB PaintBackground
  26. 'DECLARE SUB GetInput
  27.  
  28. ' Global variables shared because they are needed in more than one routine
  29. DIM SHARED sw AS INTEGER '             Screen Width
  30. DIM SHARED sh AS INTEGER '             Screen Height
  31. DIM SHARED sww AS INTEGER '            Screen Width Wide margin
  32. DIM SHARED swn AS INTEGER '            Screen Width Narrow adjustment
  33. DIM SHARED shw AS INTEGER '            Screen Height Wide margine
  34. DIM SHARED shn AS INTEGER '            Screen Height Narrow adjustment
  35. DIM SHARED nw AS INTEGER '             games Natural screen Width
  36. DIM SHARED nh AS INTEGER '             games Natural screen Height
  37. DIM SHARED ratio AS _FLOAT '           the Ratio of the games natural screen width to the actual
  38. DIM SHARED star(100) AS stars '        100 stars - may change
  39. DIM SHARED names(200) AS STRING * 10 ' 200 star names
  40. DIM SHARED seed AS INTEGER '           Seed to prime the Randomizer to display identical background each frame
  41. DIM SHARED home(6) AS INTEGER '        The starting star for each player. The human always has star(0), Sol
  42. DIM SHARED tt AS INTEGER '             tt = 0 star names displayed, tt = 0 star names not didplayed
  43. DIM SHARED ch AS STRING * 1 '          Game loop key input variable
  44. DIM SHARED repeat AS INTEGER '         Game loop control variable
  45. DIM SHARED fleet(1000) AS FLEETS
  46.  
  47. sw = _DESKTOPWIDTH '                   native video with of syatem
  48. sww = sw / 24 '                        margin based on native video width to keep stars away from edge
  49. swn = sw / 48 '                        adjustment that works with sww to keep stars away from left and top of screen
  50. nw = 1920
  51.  
  52. ratio = sw / 1920 '                    Used to adjust distances and sizes for various screen modes
  53.  
  54. shw = sh / 20
  55. shn = sh / 40
  56. nh = 1080
  57.  
  58. tt = 0
  59. cx = sw
  60. cp = 100
  61. h = 100
  62. ar = 0
  63. rng = 200
  64.  
  65. SCREEN _NEWIMAGE(sw, sh, 256) '        creates a screen the resolution of the users native system
  66.  
  67.  
  68. ps = _NEWIMAGE(400 * ratio, 540 * ratio, 256)
  69.  
  70. StarNames '                            Routine to load star names into string array stars(200)
  71.  
  72. NewGame
  73.  
  74. ttf1 = _LOADFONT("cyberbit.ttf", 14, "BOLD")
  75. ttf2 = _LOADFONT("cyberbit.ttf", 72, "BOLD")
  76.  
  77. repeat = 1
  78.  
  79. WHILE repeat
  80.  
  81.     _LIMIT 60 '                        Set to 60 frames per second
  82.  
  83.     CLS
  84.  
  85.     PaintBackground
  86.  
  87.     PaintStars
  88.  
  89.     PaintFleet
  90.  
  91.     GetInput
  92.  
  93.     Identify x, y '                    Identify star mouse is over if any
  94.  
  95.     computer
  96.  
  97.     _DISPLAY
  98.  
  99.  
  100.  
  101. SUB PaintFleet
  102.     count = fltcnt
  103.     i = 0
  104.     WHILE count
  105.         IF fleet(i).o <> 0 THEN
  106.             CIRCLE (fleet(i).x1, fleet(i).y1), 3, fleet(i).o + 8
  107.             count = count - 1
  108.         END IF
  109.         i = i + 1
  110.     WEND
  111.  
  112. SUB SendFleet (org, dst)
  113.     FOR i = 0 TO 999
  114.         IF fleet(i).o = 0 THEN
  115.             fleet(i).o = star(org).o
  116.             fleet(i).d = dst
  117.             fleet(i).x1 = star(org).x
  118.             fleet(i).y1 = star(org).y
  119.             fleet(i).x2 = star(dst).x
  120.             fleet(i).y2 = star(dst).y
  121.             fleet(i).n = star(org).t / 2
  122.             star(org).t = star(org).t / 2
  123.             fltcnt = fltcnt + 1
  124.             IF rng < 4000 THEN rng = rng + 4
  125.             EXIT FOR
  126.         END IF
  127.     NEXT
  128.     LL = LL + 1
  129.  
  130. SUB computer
  131.     FOR i = 0 TO 99
  132.         r = INT(RND * 120)
  133.         IF r < star(i).p THEN
  134.             IF star(i).o > 0 THEN
  135.                 star(i).t = star(i).t + 1
  136.             ELSE
  137.                 IF INT(RND * 10) = 0 AND star(i).t < 40 THEN
  138.                     star(i).t = star(i).t + 1
  139.                 END IF
  140.             END IF
  141.         END IF
  142.     NEXT
  143.     num = 0
  144.     FOR i = 1 TO 6
  145.         FOR j = 0 TO 99
  146.             IF star(j).o = i THEN
  147.                 IF star(j).t > num THEN
  148.                     num = star(j).t
  149.                     idx = j
  150.                 END IF
  151.             END IF
  152.         NEXT
  153.         org = idx
  154.         num = 10000
  155.         FOR j = 0 TO 99
  156.             IF star(j).o <> i THEN
  157.                 sway = ABS(star(org).x - star(j).x) + ABS(star(org).y - star(j).y)
  158.                 IF sway < rng AND star(j).t < num THEN
  159.                     num = star(j).t
  160.                     idx = j
  161.                 END IF
  162.             END IF
  163.         NEXT
  164.         dst = idx
  165.         IF star(org).t > 100 AND star(org).t > star(dst).t * 2 AND star(org).t > LL THEN
  166.             SendFleet org, dst
  167.         END IF
  168.     NEXT
  169.     count = fltcnt
  170.     PRINT fltcnt
  171.     i = 0
  172.     WHILE count
  173.         IF fleet(i).o <> 0 THEN
  174.             count = count - 1
  175.             IF fleet(i).x2 > fleet(i).x1 THEN
  176.                 fleet(i).x1 = fleet(i).x1 + 1
  177.             END IF
  178.             IF fleet(i).x2 < fleet(i).x1 THEN
  179.                 fleet(i).x1 = fleet(i).x1 - 1
  180.             END IF
  181.             IF fleet(i).y2 > fleet(i).y1 THEN
  182.                 fleet(i).y1 = fleet(i).y1 + 1
  183.             END IF
  184.             IF fleet(i).y2 < fleet(i).y1 THEN
  185.                 fleet(i).y1 = fleet(i).y1 - 1
  186.             END IF
  187.             IF fleet(i).x1 = fleet(i).x2 AND fleet(i).y1 = fleet(i).y2 THEN
  188.                 dst = fleet(i).d
  189.                 IF star(dst).o = fleet(i).o THEN
  190.                     star(dst).t = star(dst).t + fleet(i).n
  191.                     fleet(i).o = 0
  192.                     fltcnt = fltcnt - 1
  193.                 ELSE
  194.                     alive = 1
  195.                     WHILE alive
  196.                         alive = 0
  197.                         damorg = fleet(i).n / 11 + 1
  198.                         damdst = star(dst).t / 10 + 1
  199.                         fleet(i).n = fleet(i).n - damdst
  200.                         star(dst).t = star(dst).t - damorg
  201.                         IF fleet(i).n > 0 AND star(dst).t > 0 THEN
  202.                             alive = 1
  203.                         END IF
  204.                     WEND
  205.                     IF star(dst).t < 1 THEN
  206.                         star(dst).t = fleet(i).n
  207.                         star(dst).o = fleet(i).o
  208.                     END IF
  209.                     fleet(i).o = 0
  210.                     fltcnt = fltcnt - 1
  211.                 END IF
  212.             END IF
  213.         END IF
  214.         i = i + 1
  215.     WEND
  216.  
  217. SUB GetInput
  218.  
  219.     ch = INKEY$
  220.     IF ch = CHR$(27) THEN repeat = 0
  221.     IF ch = "n" THEN NewGame
  222.     IF ch = "t" THEN tt = 1 - tt
  223.     ch = ""
  224.  
  225.     WHILE _MOUSEINPUT: WEND '          Eat all the mice but keep last mouse to toy with
  226.  
  227.     x = _MOUSEX
  228.     y = _MOUSEY
  229.     mb = _MOUSEBUTTON(1)
  230.     clk = 0
  231.  
  232.     IF mb = -1 AND cx = sw THEN
  233.         cx = x
  234.         cy = y
  235.     END IF
  236.  
  237.     IF mb = 0 AND cx < sw THEN
  238.         IF ABS(x - cx) < 4 AND ABS(y - cy) < 4 THEN
  239.             clk = 1
  240.         END IF
  241.         cx = sw
  242.     END IF
  243.  
  244. SUB PaintBackground
  245.     x = RND * sw
  246.     y = RND * sh
  247.     c = RND * 14 + 1
  248.     PSET (x, y), c
  249.     RANDOMIZE USING seed
  250.     FOR i = 1 TO 600 * ratio
  251.         x = RND * sw
  252.         y = RND * sh
  253.         c = RND * 14 + 1
  254.         PSET (x, y), c
  255.     NEXT
  256.  
  257. SUB ProcessPanel
  258.  
  259.  
  260. SUB Identify (x, y)
  261.     IF ar = 1 THEN
  262.         ShowPanel h
  263.         IF clk THEN
  264.             IF x >= x1 AND x <= x2 AND y >= y1 AND y <= y2 THEN
  265.                 ProcessPanel
  266.             ELSE
  267.                 ar = 0
  268.             END IF
  269.         END IF
  270.     END IF
  271.     IF ar = 0 THEN
  272.         FOR i = 0 TO 99
  273.             dx = star(i).x - x
  274.             dy = star(i).y - y
  275.             IF ABS(dx) <= star(i).s + 6 AND ABS(dy) <= star(i).s + 6 THEN
  276.                 ShowPanel i
  277.                 IF clk THEN
  278.                     clk = 0
  279.                     h = i
  280.                     ar = 1
  281.                     ax = x
  282.                 END IF
  283.             END IF
  284.         NEXT
  285.     END IF
  286.  
  287. SUB ShowPanel (i)
  288.     x1 = star(i).x - 420 * ratio
  289.     IF star(i).x < sw / 2 THEN x1 = star(i).x + 20
  290.     x2 = x1 + 400 * ratio
  291.     y1 = star(i).y
  292.     IF y1 > sh - 560 * ratio THEN y1 = sh - 560 * ratio
  293.     y2 = y1 + 540 * ratio
  294.     _DEST ps
  295.     CLS 0, 8
  296.     COLOR 0, 8
  297.     _FONT ttf2
  298.     n$ = RTRIM$(star(i).n)
  299.     L = _PRINTWIDTH(n$)
  300.     _PRINTSTRING ((400 - L) / 2, 8), n$, ps
  301.     _PUTIMAGE (x1, y1), ps, 0, (0, 0)-(400 * ratio, 540 * ratio)
  302.     _DEST 0
  303.  
  304. SUB PaintStars
  305.     FOR i = 0 TO 99
  306.         c = star(i).c
  307.         x = star(i).x
  308.         y = star(i).y
  309.         o = star(i).o
  310.         CIRCLE (x, y), (star(i).s + 6) * ratio, c
  311.         COLOR 15
  312.         IF o > 0 THEN
  313.             PAINT (x, y), o + 8, c
  314.             COLOR o + 8
  315.         END IF
  316.         _FONT ttf1
  317.         IF tt THEN
  318.             n$ = star(i).n
  319.             n$ = RTRIM$(n$)
  320.             L = _PRINTWIDTH(n$)
  321.         ELSE
  322.             n$ = STR$(star(i).t)
  323.             L = _PRINTWIDTH(n$)
  324.         END IF
  325.         _PRINTSTRING (x - L / 2, y + 12), n$, 0
  326.     NEXT
  327.  
  328. SUB NewGame
  329.     DIM k AS INTEGER
  330.     DIM r AS INTEGER
  331.     DIM dx AS INTEGER
  332.     DIM dy AS INTEGER
  333.     DIM n AS STRING * 10
  334.     FOR i = 0 TO 999
  335.         fleet(i).o = 0
  336.     NEXT
  337.     fltcnt = 0
  338.     LL = 50
  339.     seed = RND * 1000
  340.     star(0).n = "Sol"
  341.     star(0).x = RND * (sw - sww) + swn
  342.     star(0).y = RND * (sh - shw) + shn
  343.     star(0).c = 14
  344.     star(0).s = 2
  345.     star(0).o = 1
  346.     star(0).p = 10
  347.     star(0).t = 100
  348.     home(0) = 0
  349.     FOR i = 1 TO 99
  350.         k = 1
  351.         WHILE k
  352.             k = 0
  353.             x = RND * (sw - sww) + swn
  354.             y = RND * (sh - shw) + shn
  355.             r = INT(RND * 200)
  356.             n = names(r)
  357.             FOR j = 0 TO i - 1
  358.                 dx = x - star(j).x
  359.                 dy = y - star(j).y
  360.                 IF ABS(dx) < sww AND ABS(dy) < shw THEN
  361.                     k = 1
  362.                 END IF
  363.                 IF n = star(j).n THEN
  364.                     k = 1
  365.                 END IF
  366.             NEXT
  367.         WEND
  368.         star(i).n = n
  369.         star(i).x = x
  370.         star(i).y = y
  371.         star(i).c = RND * 6 + 9
  372.         star(i).s = RND * 5
  373.         star(i).o = 0
  374.         star(i).p = star(i).s + (RND * 8) + 1
  375.         star(i).t = 0
  376.     NEXT
  377.     FOR i = 2 TO 6
  378.         k = 1
  379.         WHILE k
  380.             k = 0
  381.             r = RND * 100
  382.             FOR j = 1 TO i - 1
  383.                 IF r = home(j) THEN k = 1
  384.                 x = star(0).x
  385.                 y = star(0).y
  386.                 dx = ABS(star(r).x - x)
  387.                 dy = ABS(star(r).y - y)
  388.                 IF dx < sw / 4 AND dy < sh / 4 THEN k = 1
  389.             NEXT
  390.         WEND
  391.         home(i) = r
  392.         star(r).o = i
  393.         star(r).p = 10
  394.         star(r).t = 100
  395.     NEXT
  396.  
  397. ' A lot of star names I made up
  398.  
  399. SUB StarNames
  400.     names(0) = "Acamar"
  401.     names(1) = "Arcab"
  402.     names(2) = "Acrux"
  403.     names(3) = "Adhara"
  404.     names(4) = "Arneb"
  405.     names(5) = "Antares"
  406.     names(6) = "Arcturus"
  407.     names(7) = "Atria"
  408.     names(8) = "Beid"
  409.     names(9) = "Betelgeuse"
  410.     names(10) = "Botein"
  411.     names(11) = "Beemim"
  412.     names(12) = "Bellatrix"
  413.     names(13) = "Bharani"
  414.     names(14) = "Biham"
  415.     names(15) = "Brachium"
  416.     names(16) = "Canopus"
  417.     names(17) = "Capella"
  418.     names(18) = "Castor"
  419.     names(19) = "Chara"
  420.     names(20) = "Cursa"
  421.     names(21) = "Copernicus"
  422.     names(22) = "Chalawan"
  423.     names(23) = "Chertan"
  424.     names(24) = "Dabih"
  425.     names(25) = "Dalim"
  426.     names(26) = "Deneb"
  427.     names(27) = "Denebola"
  428.     names(28) = "Diadem"
  429.     names(29) = "Diphda"
  430.     names(30) = "Dschubba"
  431.     names(31) = "Dziban"
  432.     names(32) = "Edasich"
  433.     names(33) = "Electra"
  434.     names(34) = "Elgafar"
  435.     names(35) = "Elkurud"
  436.     names(36) = "Elnath"
  437.     names(37) = "Eltanin"
  438.     names(38) = "Enif"
  439.     names(39) = "Errai"
  440.     names(40) = "Fafnir"
  441.     names(41) = "Fang"
  442.     names(42) = "Fawaris"
  443.     names(43) = "Felis"
  444.     names(44) = "Fomalhaut"
  445.     names(45) = "Fulu"
  446.     names(46) = "Fumal"
  447.     names(47) = "Furud"
  448.     names(48) = "Garnet"
  449.     names(49) = "Giausar"
  450.     names(50) = "Gienah"
  451.     names(51) = "Ginan"
  452.     names(52) = "Gomeisa"
  453.     names(53) = "Graffias"
  454.     names(54) = "Grumium"
  455.     names(55) = "Gudja"
  456.     names(56) = "Hadar"
  457.     names(57) = "Haedus"
  458.     names(58) = "Hamal"
  459.     names(59) = "Hassaleh"
  460.     names(60) = "Hatysa"
  461.     names(61) = "Helvetios"
  462.     names(62) = "Heze"
  463.     names(63) = "Homan"
  464.     names(64) = "Iklil"
  465.     names(65) = "Imai"
  466.     names(66) = "Intercrus"
  467.     names(67) = "Izar"
  468.     names(68) = "Iccar"
  469.     names(69) = "Inar"
  470.     names(70) = "Iaeth"
  471.     names(71) = "Imaous"
  472.     names(72) = "Jabbah"
  473.     names(73) = "Jishui"
  474.     names(74) = "Jax"
  475.     names(75) = "Jalae"
  476.     names(76) = "Jewel"
  477.     names(77) = "Jumbo"
  478.     names(78) = "Jerue"
  479.     names(79) = "Jabear"
  480.     names(80) = "Kakkab"
  481.     names(81) = "Kang"
  482.     names(82) = "Kekouan"
  483.     names(83) = "Keid"
  484.     names(84) = "Kitalpha"
  485.     names(85) = "Kochab"
  486.     names(86) = "Kolob"
  487.     names(87) = "Kobol"
  488.     names(88) = "Larawag"
  489.     names(89) = "Lesath"
  490.     names(90) = "Libertas"
  491.     names(91) = "Lich"
  492.     names(92) = "Lilly"
  493.     names(93) = "Laddel"
  494.     names(94) = "Luminous"
  495.     names(95) = "Lasacious"
  496.     names(96) = "Mizar"
  497.     names(97) = "Markab"
  498.     names(98) = "Matar"
  499.     names(99) = "Mintaka"
  500.     names(100) = "Meleph"
  501.     names(101) = "Menkar"
  502.     names(102) = "Merga"
  503.     names(103) = "Merope"
  504.     names(104) = "Nahn"
  505.     names(105) = "Naos"
  506.     names(106) = "Nashira"
  507.     names(107) = "Navi"
  508.     names(108) = "Nekkar"
  509.     names(109) = "Nembus"
  510.     names(110) = "Nihal"
  511.     names(111) = "Nunki"
  512.     names(112) = "Ogma"
  513.     names(113) = "Okab"
  514.     names(114) = "Ohmy"
  515.     names(115) = "Oragami"
  516.     names(116) = "Origen"
  517.     names(117) = "Omanii"
  518.     names(118) = "Obytewa"
  519.     names(119) = "Oglok"
  520.     names(120) = "Phact"
  521.     names(121) = "Pherkad"
  522.     names(122) = "Pleione"
  523.     names(122) = "Polaris"
  524.     names(123) = "Pollux"
  525.     names(124) = "Procyon"
  526.     names(125) = "Proxima"
  527.     names(126) = "Polis"
  528.     names(127) = "Quaint"
  529.     names(128) = "Quazzat"
  530.     names(129) = "Quetzal"
  531.     names(130) = "Qussol"
  532.     names(131) = "Quella"
  533.     names(132) = "Quyaeo"
  534.     names(133) = "Ququdas"
  535.     names(134) = "Quekak"
  536.     names(135) = "Rasalas"
  537.     names(136) = "Regor"
  538.     names(137) = "Regulus"
  539.     names(138) = "Rigel"
  540.     names(139) = "Revati"
  541.     names(140) = "Rotenev"
  542.     names(141) = "Rukbat"
  543.     names(142) = "Rastaban"
  544.     names(143) = "Sabik"
  545.     names(144) = "Sadr"
  546.     names(145) = "Saiph"
  547.     names(146) = "Sargas"
  548.     names(147) = "Sarin"
  549.     names(148) = "Syrma"
  550.     names(149) = "Spica"
  551.     names(150) = "Sirius"
  552.     names(151) = "Tarazed"
  553.     names(152) = "Taygeta"
  554.     names(153) = "Tejat"
  555.     names(154) = "Thabit"
  556.     names(155) = "Thuban"
  557.     names(156) = "Tiaki"
  558.     names(157) = "Toliman"
  559.     names(158) = "Torcular"
  560.     names(157) = "Umala"
  561.     names(158) = "Ulatte"
  562.     names(159) = "Ubbessa"
  563.     names(160) = "Unoless"
  564.     names(161) = "Umaddem"
  565.     names(162) = "Ummbra"
  566.     names(162) = "Uniqu"
  567.     names(163) = "Uzzaal"
  568.     names(164) = "Vega"
  569.     names(165) = "Veritate"
  570.     names(166) = "Vindetrix"
  571.     names(167) = "Vedas"
  572.     names(168) = "Vergg"
  573.     names(169) = "Vacant"
  574.     names(170) = "Vucae"
  575.     names(171) = "Vicar"
  576.     names(172) = "Wasat"
  577.     names(173) = "Wazn"
  578.     names(174) = "Wezen"
  579.     names(175) = "Waiten"
  580.     names(176) = "Wachar"
  581.     names(177) = "Wheelz"
  582.     names(178) = "Whatsp"
  583.     names(179) = "Wassand"
  584.     names(180) = "Xenno"
  585.     names(181) = "Xyphod"
  586.     names(182) = "Xu"
  587.     names(183) = "Xaal"
  588.     names(184) = "Xyross"
  589.     names(185) = "Xiggot"
  590.     names(186) = "Xirrks"
  591.     names(187) = "Yed"
  592.     names(188) = "Yildun"
  593.     names(189) = "Yundun"
  594.     names(190) = "Yavyo"
  595.     names(191) = "Yotrac"
  596.     names(192) = "Yxzoqu"
  597.     names(193) = "Ynnot"
  598.     names(194) = "Zaniah"
  599.     names(195) = "Zaurak"
  600.     names(196) = "Zhang"
  601.     names(197) = "Zibal"
  602.     names(198) = "Zosma"
  603.     names(199) = "Zuben"
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.