Author Topic: b+ Asteroids makeover  (Read 19227 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #75 on: November 05, 2020, 05:52:12 pm »
WHEW! I just played and got 230,962 on the default speed and rocks. I got to where 3 saucers were coming at me at once. LOL My hand was starting to wear out. Here is a picture I took with my camera.

IMG_2700-2.jpg
* IMG_2700-2.jpg (Filesize: 174.33 KB, Dimensions: 800x600, Views: 257)
« Last Edit: November 05, 2020, 05:54:05 pm by SierraKen »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: b+ Asteroids makeover
« Reply #76 on: November 05, 2020, 06:07:02 pm »
Aw man! I was just about to post my new high score, that topped BPlus's 84,000, with my 85,932... When I saw Ken's posting... Ouch! Well done, Ken... (grumble.. grumble..)
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #77 on: November 05, 2020, 06:52:30 pm »
LOL Thanks Johno. I guess I've always been good at Asteroids. LOL

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #78 on: November 05, 2020, 07:47:27 pm »
Holy cow, Ken! Wow, and that's after I put more start rocks back in and increased speeds a bit!

How long did that take? Do you use thrust much? Isn't Hyperspace jump a life saver? ;-)


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #79 on: November 05, 2020, 10:54:58 pm »
The long awaited p button (98,000+):
Code: QB64: [Select]
  1. _TITLE "b+QB64 Asteroids M10" 'started 2018-07-13
  2. '2020 - Oct and Nov: Special thanks to SierraKen who has been helpful with suggestions, ideas and fixes.
  3.  
  4. ' Far far away in a universe where Newton's 1st Law of Motion is not obeyed...    ;-))
  5.  
  6.  
  7. '                                            New Controls
  8. ' key a or left arrow = turn left
  9. ' key s or right arrow = turn right
  10. ' enter or spacebar =  "hyperspace" show up somewhere else  better or worse use when collision is imminent
  11. ' key k or up arrow = thrust  just a burst in direction you are pointed but doesn't last
  12. ' fire! owwha, owha, owha...  is now continuous
  13.  
  14. '=================================================================================================================
  15.  
  16. ' 2020-10-27 remove the alternate subs and get down below 200 LOC almost there now! new shooter action font and background
  17. ' 2020-10-28 another makeover explosions and split asteroids
  18. ' 2020-10-29 fix baby rock management, break between lives
  19. ' 2020-10-29 fix left/right gun, fix explosions over many frames to eliminate pause in action, speed up 60 fps
  20. ' 2020-10-30 m3 SierraKen's idea to angle shooter with mousewheel also finish WASD options, more rocks, points system
  21. ' points:
  22. ' The higher the speed the better    speed range .5 to 2.5, diff = 2 * 50 = 100          s - .5 * 50
  23. ' DELETE The lower the color the better   color range 10 to 60, diff =      50 * 2 = 100  50 - (c - 10) * 2
  24. ' The smaller the size the better  size range 10 to 100, diff = 90 * 1.1111 = 100  90 - (sz -10) * 1.1111
  25. '        ((speed - .5) * 50 + (90 - (r - 10)) * 1.1111) / 2 = 100 best score per hit
  26. ' 2020-10-30 increase level of difficulty, fix double lives lost, add an ending after all lives spent.
  27. ' 2020-10-31 M4 They are Here - the aliens have accepted my invitaion for war games don't get caught in their beam.
  28. ' rework ending and variable LONG suffix. Aliens on the attack 100 points before or after transformed into the Bolder of Death.
  29. ' 2020-11-01 M5 FX Moving through space, Oh yeah, more aliens!
  30. ' 2020-11-01 M6 add play again and save high game , continuous shoot
  31. ' 2020-11-01 M7 fix hits count when hit alien ship or Bolder of Death. Fix lights on aliens ship. I want to see collsions with ship.
  32. ' Ken recommends removing text in middle of screen, yeah, distracting. Makeover ship as with mouse x, y it's center. Add Splash screen.
  33. ' Show mouse in between lives so can be in screen center when press key to start next run.
  34.  
  35. ' 2020-11-03 M9 watching videos on Asteroids, I found a view and description of the control panel, it is:
  36. ' 2 buttons on left and lower button in middle and 2 buttons on right level with 2 on left.
  37. ' 2 buttons on left are left and right turns they will be Keys A and S
  38. ' The middle will be spacebar for Hypespace or these days we might call it worm hole, jump to another location better or worse!
  39. ' 2 buttons on right K and L: K will be a thruster of sorts you eventually come to a stop (not what Newton would like) L is the fire button.
  40. ' So let's try that. I am impressed by hitting thruster and shooting all around as you dift in direction gun was pointed when hit thruster.
  41. ' Lighten rocks and change points, based now only on size and speed of Asteroids.
  42. ' 2020-11-04 M9 Install new update to thrust control. Thanks to SierraKen for finding out what happened to Hyperspace jump when press
  43. ' spacebar a 2nd time in a life. Oh also Boulders of Death are now more like smooth colored spheres. Ahhhh Fixed the crashing at the borders
  44. ' now fly out one side and come back in on the other! This is getting good! Adding some sound effects.
  45. ' 2020-11-05 M10 set some constants for starting game so can just change them to level of play desired.
  46. ' speed points =  50 * (rockSpeed - minRockSpeed)/rockSpeedRange > fastest rock gets 50 points
  47. ' size points = 50 * (rockSizeRange - (rockSize - minRockSize))/rockSizeRange  > smallest rock gets 50 points
  48. ' points = points +  50 * ( (rockSpeed - minRockSpeed)/rockSpeedRange +  (rockSizeRange - (rockSize - minRockSize))/rockSizeRange )
  49. ' Dav's comments: Add arrow keys for left right turns and up for thrust, continuous fire now! A little score board in top left corner.
  50. ' Dav I am keeping spacebar for Hyperspace but also Enter, don't need fire button now.
  51. ' Try the A for left and the right arrow for right turns.
  52. ' 2020-11-05 p is for pause
  53.  
  54. '================================================================================================================
  55.  
  56. '    NOTE: !!!!!!!!!!!!!!!   When there is a pause in action, just press enter,  as in enter a new life!
  57.  
  58. '================================================================================================================
  59.  
  60. CONST xmax = 1200, ymax = 700, pi = _PI, polyAngle = _PI / 6, nRocks = 300, nBullets = 2000, bSpeed = 15
  61. CONST startRocks = 2, minRockSpeed = 0.5000, maxRockSpeed = 2.5000, minRockSize = 10, maxRockSize = 100
  62. CONST rockSpeedRange = maxRockSpeed - minRockSpeed, rockSizeRange = maxRockSize - minRockSize
  63. CONST alienSpeed = rockSpeedRange / 2 + minRockSpeed ' average rock speed
  64.  
  65. TYPE alienType
  66.     x AS SINGLE
  67.     y AS SINGLE
  68.     dx AS SINGLE
  69.     dy AS SINGLE
  70.     ls AS LONG ' lights offset and gray scale
  71.     c AS _UNSIGNED LONG ' color
  72.     live AS LONG
  73.     attackFrame AS LONG
  74.     fireX AS SINGLE
  75.     fireY AS SINGLE
  76.     transform AS LONG
  77.  
  78. TYPE particle
  79.     x AS SINGLE
  80.     y AS SINGLE
  81.     dx AS SINGLE
  82.     dy AS SINGLE
  83.     size AS SINGLE
  84.     kolor AS _UNSIGNED LONG
  85.  
  86. TYPE bullet
  87.     x AS SINGLE
  88.     y AS SINGLE
  89.     dx AS SINGLE
  90.     dy AS SINGLE
  91.     live AS LONG
  92.  
  93. TYPE shipType
  94.     x AS SINGLE
  95.     y AS SINGLE
  96.     live AS LONG
  97.     speed AS SINGLE '       just a constant now when Thrust is applied
  98.     thrustAngle AS SINGLE ' ship/gun angle at moment Thrust is pressed
  99.     angle AS SINGLE '       rotated position ship/gun now A or S keypress or hold down
  100.     thrust AS LONG '        this now tracks how many frames ship will move at speed and thrustAngle
  101.  
  102. TYPE rock
  103.     x AS SINGLE
  104.     y AS SINGLE
  105.     r AS LONG '            radius
  106.     ra AS SINGLE '         rotation position   a = a + spin
  107.     heading AS SINGLE '    heading from which dx, dy are calc with speed
  108.     speed AS SINGLE '      speed
  109.     spin AS SINGLE '       rotation direction and amount
  110.     seed AS LONG '         for drawing rocks with RND USING
  111.     c AS LONG '            color   rgb(c, c, c)
  112.     live AS LONG '         need this to track rocks still active like bullets
  113.     explodeFrame AS LONG ' after a rock is hit by bullet, it explodes and in more than one frame
  114.  
  115. REDIM SHARED aliens(1 TO 5) AS alienType
  116. DIM SHARED dots(2000) AS particle ' explosions
  117. DIM SHARED b(nBullets) AS bullet
  118. DIM SHARED ship AS shipType
  119. DIM SHARED r(nRocks) AS rock
  120. DIM SHARED points AS LONG
  121. DIM SHARED rocks AS LONG 'rocks is the minimum number of parent rocks to have on screen  automatic replace when hit or out of bounds
  122.  
  123. DIM HS AS LONG, fnt AS LONG, fnt2 AS LONG ' file LOAD handles
  124. DIM i AS LONG, bullets AS LONG, fire AS LONG ' index and bullets
  125. DIM r AS LONG, newRockN AS LONG, maxBabyRocks AS LONG, br AS LONG, hits AS LONG ' rock stuff
  126. DIM ai AS LONG, alienN AS LONG ' alien index and number
  127. DIM kh AS LONG 'key hit for ship thrust k or up arrow or hyperspace jump spacebar
  128. DIM hs$, s$, k$, t, lastt 'high score, general string and times for bullets
  129. DIM rockPoints AS LONG, roundPoints AS LONG ' various points scores
  130. ship.speed = 3.5 'this would be a constant but ship has to declared as Ship Type first, Hyperspace jump
  131.  
  132. SCREEN _NEWIMAGE(xmax, ymax, 32)
  133. _SCREENMOVE 100, 20
  134.  
  135. fnt = _LOADFONT("ARLRDBD.ttf", 16, "MONOSPACE")
  136. fnt2 = _LOADFONT("ARLRDBD.ttf", 40, "MONOSPACE")
  137. _FONT fnt2
  138. COLOR &HFF00FFFF, &H00000000
  139.  
  140. IF _FILEEXISTS("Asteroids High Score.txt") THEN
  141.     OPEN "Asteroids High Score.txt" FOR INPUT AS #1
  142.     INPUT #1, HS
  143.     CLOSE #1
  144. hs$ = "High Score:" + STR$(HS)
  145.  
  146. 'a little splash screen
  147. rocks = 7: alienN = 3
  148. FOR i = 1 TO nRocks
  149.     newRock i
  150.     IF i > rocks THEN r(i).live = 0
  151. FOR i = 1 TO alienN
  152.     newAlien i
  153. i = 0
  154.     drawStars 0
  155.     i = i + 1
  156.     IF i MOD 30 = 29 AND rocks < nRocks THEN rocks = rocks + 1: r(rocks).live = 1
  157.     FOR r = 1 TO nRocks
  158.         IF r(r).live THEN drawRock r
  159.     NEXT
  160.     FOR i = 1 TO alienN
  161.         drawAliens i
  162.     NEXT
  163.     _FONT fnt2
  164.     s$ = "*** b+QB64 Asteroids ***"
  165.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 60), s$
  166.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(hs$)) / 2, 140), hs$
  167.     s$ = "A or arrow = Left spin"
  168.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 220), s$
  169.     s$ = "S or arrow = Right Spin"
  170.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 300), s$
  171.     s$ = "Space or Enter = Hyper jump"
  172.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 380), s$
  173.     s$ = "K or up arrow = Thrust"
  174.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 460), s$
  175.     s$ = "Escape quit, any plays"
  176.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 540), s$
  177.     _FONT fnt
  178.     k$ = INKEY$
  179.     _DISPLAY
  180.     _LIMIT 60
  181.  
  182. restart:
  183. IF _FILEEXISTS("Asteroids High Score.txt") THEN
  184.     OPEN "Asteroids High Score.txt" FOR INPUT AS #1
  185.     INPUT #1, HS
  186.     CLOSE #1
  187. hs$ = "  High Score:" + STR$(HS)
  188. lives = 10: alienN = 1: rocks = startRocks: ' always active rocks
  189. points = 0: hits = 0: bullets = 0
  190. WHILE lives > 0 AND _KEYDOWN(27) = 0 ' init start restart
  191.     REDIM aliens(1 TO alienN) AS alienType
  192.     FOR ai = 1 TO alienN
  193.         newAlien ai
  194.     NEXT
  195.     FOR i = 1 TO nRocks 'reset rocks mainly clear baby rocks
  196.         newRock (i)
  197.         IF i > rocks THEN r(i).live = 0
  198.     NEXT
  199.     ship.x = xmax / 2 'avoids explosions top left corner at start, dang still get some!
  200.     ship.y = ymax / 2
  201.     ship.angle = 0
  202.     ship.thrustAngle = 0
  203.     ship.thrust = 0
  204.     ship.live = 1
  205.     rockPoints = 0
  206.     roundPoints = 0
  207.     WHILE ship.live AND _KEYDOWN(27) = 0
  208.  
  209.         _KEYCLEAR 'clear all previous INKEY$ or _KEYHIT and variables  so ship should always start in middle of sceen pointed east
  210.         kh = 0
  211.  
  212.         'draw everything then process bullets
  213.         drawStars 1
  214.         LOCATE 1, 1: PRINT "Lives:"; lives
  215.         LOCATE 2, 1: PRINT "Last Rock:"; STR$(rockPoints)
  216.         LOCATE 3, 1: PRINT "Round:;"; STR$(roundPoints)
  217.         LOCATE 4, 1: PRINT "Points:"; STR$(points)
  218.         LOCATE 5, 1: PRINT "High Score:"; STR$(HS)
  219.         FOR ai = 1 TO alienN
  220.             drawAliens ai
  221.         NEXT
  222.         FOR i = 1 TO nRocks
  223.             IF r(i).live THEN 'make sure if we crash into a ship it is a live rock, not one sitting on side waiting to be called up
  224.                 drawRock i ' while drawing rocks the ship could be blown up
  225.                 IF ((r(i).x - ship.x) ^ 2 + (r(i).y - ship.y) ^ 2) ^ .5 < r(i).r + 25 THEN 'rock collides with ship?
  226.                     FOR br = 1 TO 200 STEP 5
  227.                         CIRCLE ((ship.x + r(i).x) / 2, (ship.y + r(i).y) / 2), br, _RGB32(255 - br, 255 - 2 * br, 0)
  228.                     NEXT
  229.                     drawRock i
  230.                     drawship
  231.                     ship.live = 0
  232.                     IF i <= rocks THEN newRock i ELSE r(i).live = 0
  233.                 END IF
  234.             END IF
  235.         NEXT
  236.         FOR i = 1 TO nRocks 'smoke up the place with rock debris fields still flying out from hit frames ago
  237.             IF r(i).explodeFrame THEN
  238.                 r(i).explodeFrame = r(i).explodeFrame + 1
  239.                 IF r(i).explodeFrame > .25 * r(i).r THEN
  240.                     r(i).explodeFrame = 0
  241.                     IF i <= rocks THEN newRock i ' now replace the rock
  242.                 ELSE
  243.                     explode r(i).x, r(i).y, r(i).r, r(i).explodeFrame
  244.                 END IF
  245.             END IF
  246.         NEXT
  247.         IF ship.live THEN
  248.             FOR ai = 1 TO alienN
  249.                 IF SQR((aliens(ai).x - ship.x) ^ 2 + (aliens(ai).y - ship.y) ^ 2) < 60 THEN 'aliens and ship collisde boom boom
  250.                     FOR br = 1 TO 200 STEP 5
  251.                         CIRCLE ((ship.x + aliens(ai).x) / 2, (ship.y + aliens(ai).y) / 2), br, _RGB32(255 - br, 255 - 2 * br, 0)
  252.                     NEXT
  253.                     drawship
  254.                     ship.live = 0
  255.                     _CONTINUE
  256.                 ELSE
  257.                     drawship
  258.                 END IF
  259.             NEXT
  260.  
  261.             '                                                                   ship controls update
  262.             'a key or left arrow = left spin
  263.             IF _KEYDOWN(97) OR _KEYDOWN(19200) THEN ship.angle = ship.angle - pi / 48
  264.  
  265.             's key or right arrow = right spin
  266.             IF _KEYDOWN(115) OR _KEYDOWN(19712) THEN ship.angle = ship.angle + pi / 48
  267.  
  268.             'l is Fire!  JUST CONTINUOUS FIRE
  269.             fire = 0
  270.             'IF _KEYDOWN(108) THEN
  271.             t = TIMER(.01)
  272.             IF lastt = 0 OR t - lastt > .15 THEN fire = 1: SOUND 2088, .01: lastt = t
  273.             'END IF
  274.  
  275.             kh = _KEYHIT
  276.             SELECT CASE kh
  277.                 CASE 112
  278.                     kh = 0
  279.                     WHILE _KEYHIT <> 112: _LIMIT 60: WEND
  280.                 CASE 107, 18432 'thrust  k key or up arrow
  281.                     SOUND 488, .01
  282.                     ship.thrustAngle = ship.angle: ship.thrust = 120
  283.                 CASE 13, 32 ' space = hyperspace jump
  284.                     RANDOMIZE TIMER
  285.                     ship.x = (xmax - 300) * RND + 150: ship.y = (ymax - 300) * RND + 150: ship.thrust = 0
  286.             END SELECT
  287.  
  288.             '                                                                   locate ship
  289.             IF ship.thrust > 0 THEN
  290.                 'relocate ship position
  291.                 ship.x = ship.x + ship.speed * COS(ship.thrustAngle)
  292.                 ship.y = ship.y + ship.speed * SIN(ship.thrustAngle)
  293.             END IF
  294.             '                                                                    jump borders
  295.             IF ship.x < 0 THEN ship.x = xmax - ABS(ship.x)
  296.             IF ship.x > xmax THEN ship.x = ship.x - xmax
  297.             IF ship.y < 0 THEN ship.y = ymax - ABS(ship.y)
  298.             IF ship.y > ymax THEN ship.y = ship.y - ymax
  299.  
  300.  
  301.             FOR i = 0 TO nBullets '                                               handle bullets
  302.                 IF b(i).live = 0 AND fire = 1 THEN 'have inactive bullet to use
  303.                     b(i).x = ship.x + bSpeed * COS(ship.angle)
  304.                     b(i).y = ship.y + bSpeed * SIN(ship.angle)
  305.                     b(i).dx = bSpeed * COS(ship.angle)
  306.                     b(i).dy = bSpeed * SIN(ship.angle)
  307.                     b(i).live = -1
  308.                     bullets = bullets + 1
  309.                     fire = 0
  310.                 END IF
  311.                 IF b(i).live THEN 'new location
  312.                     b(i).x = b(i).x + b(i).dx
  313.                     b(i).y = b(i).y + b(i).dy
  314.                     IF b(i).x > 0 AND b(i).x < xmax AND b(i).y > 0 AND b(i).y < ymax THEN 'in bounds draw it
  315.  
  316.                         'bullet hit aliens?
  317.                         FOR ai = 1 TO alienN
  318.                             IF SQR((aliens(ai).x - b(i).x) ^ 2 + (aliens(ai).y - b(i).y) ^ 2) < 30 THEN
  319.                                 FOR br = 1 TO 120
  320.                                     CIRCLE (aliens(ai).x, aliens(ai).y), br / 3, plasma~&(0)
  321.                                 NEXT
  322.                                 _DISPLAY
  323.                                 _DELAY .05
  324.                                 hits = hits + 1
  325.                                 roundPoints = roundPoints + 100
  326.                                 points = points + 100
  327.                                 aliens(ai).live = 0
  328.                                 newAlien ai
  329.                                 b(i).live = 0
  330.                                 _CONTINUE
  331.                             END IF
  332.                         NEXT
  333.                         FOR r = 1 TO nRocks 'check for collision with rock
  334.                             IF r(r).live THEN
  335.                                 IF SQR((r(r).x - b(i).x) ^ 2 + (r(r).y - b(i).y) ^ 2) < r(r).r THEN 'its a hit!
  336.                                     r(r).explodeFrame = 1 'linger with explosion
  337.                                     r(r).live = 0
  338.                                     hits = hits + 1
  339.                                     rockPoints = 50 * ((r(r).speed - minRockSpeed) / rockSpeedRange + (rockSizeRange - (r(r).r - minRockSize)) / rockSizeRange)
  340.                                     roundPoints = roundPoints + rockPoints
  341.                                     points = points + rockPoints
  342.                                     IF r(r).r > 30 THEN '       split rock  into ? new ones
  343.                                         maxBabyRocks = INT((r(r).r - 10) / 10)
  344.                                         maxBabyRocks = irnd&(2, maxBabyRocks) ' pick a number of baby Rocks
  345.                                         FOR br = 1 TO maxBabyRocks
  346.                                             '                        new rock
  347.                                             newRockN = freeRock& '                          get inactive rock number
  348.                                             newRock newRockN '                              new identity and activate
  349.                                             r(newRockN).r = (r(r).r - 10) / maxBabyRocks '  split in equal parts minus 20% mass
  350.                                             r(newRockN).x = r(r).x + irnd&(-30, 30) '       thrown from parent
  351.                                             r(newRockN).y = r(r).y + irnd&(-30, 30)
  352.                                             r(newRockN).c = r(r).c '                   same color as parent
  353.                                             r(newRockN).heading = rrnd(ship.angle - .75 * pi, ship.angle + .75 * pi)
  354.                                         NEXT
  355.                                     END IF ' big enough to split
  356.                                     b(i).live = 0 'kill bullet
  357.                                 END IF ' hit rock
  358.                             END IF 'rock is there
  359.                         NEXT ' rock
  360.                         IF b(i).live THEN fcirc b(i).x, b(i).y, 3, _RGB32(255, 255, 0) 'draws bullet
  361.                     ELSE
  362.                         b(i).live = 0 'out of bounds
  363.                     END IF ' bullet is in bounds
  364.                 END IF ' bullet live
  365.             NEXT ' bullet
  366.         END IF ' if ship still live
  367.         _DISPLAY
  368.         IF ship.live = 0 THEN
  369.             lives = lives - 1
  370.             IF lives MOD 4 = 0 THEN rocks = rocks + 1
  371.             IF lives MOD 4 = 2 THEN alienN = alienN + 1
  372.             s$ = "Lives:" + STR$(lives) + "  Hits:" + STR$(hits) + "  Bullets:" + STR$(bullets) + "  Shooting:" + STR$(INT(hits * 100 / bullets)) + "%"
  373.             _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2 - 80), s$
  374.             _FONT fnt2
  375.             s$ = STR$(points) + hs$
  376.             _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2), s$
  377.             _FONT fnt
  378.             s$ = "Press enter to enter next life."
  379.             _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2 + 120), s$
  380.             _DISPLAY
  381.             kh = 0
  382.             WHILE kh <> 13
  383.                 kh = _KEYHIT
  384.             WEND 'wait for enter key
  385.         ELSE
  386.             _LIMIT 60 ' if ship dies let's rest and regroup  before restart next life
  387.         END IF
  388.     WEND
  389.     _DISPLAY
  390. IF points > HS THEN
  391.     OPEN "Asteroids High Score.txt" FOR OUTPUT AS #1
  392.     PRINT #1, points
  393.     CLOSE #1
  394. ship.x = -200: ship.y = -200 'get it out of the way
  395. i = 0
  396.     drawStars 0
  397.     i = i + 1
  398.     IF i MOD 30 = 29 AND rocks < nRocks THEN rocks = rocks + 1: r(rocks).live = 1
  399.     FOR r = 1 TO nRocks
  400.         IF r(r).live THEN drawRock r
  401.     NEXT
  402.     s$ = "Lives:" + STR$(lives) + "  Hits:" + STR$(hits) + "  Bullets:" + STR$(bullets) + "  Shooting:" + STR$(INT(hits * 100 / bullets)) + "%"
  403.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2 - 80), s$
  404.     _FONT fnt2
  405.     s$ = STR$(points)
  406.     IF points > HS THEN s$ = s$ + " a New Record!" ELSE s$ = STR$(points) + hs$
  407.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2), s$
  408.     _FONT fnt
  409.     s$ = "Press q to quit, p or a to Play Again..."
  410.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2 + 120), s$
  411.     IF _KEYDOWN(ASC("a")) OR _KEYDOWN(ASC("p")) THEN GOTO restart
  412.     _DISPLAY
  413.     _LIMIT 60
  414.  
  415. SUB drawStars (moving)
  416.     TYPE starType
  417.         x AS SINGLE
  418.         y AS SINGLE
  419.         size AS SINGLE
  420.         c AS INTEGER
  421.     END TYPE
  422.     STATIC beenHere, stars(600) AS starType, cy AS LONG
  423.     DIM i AS LONG
  424.     IF beenHere = 0 THEN 'static part
  425.         FOR i = 0 TO 200
  426.             stars(i).x = RND * xmax: stars(i).y = RND * ymax: stars(i).size = 0
  427.             stars(i).c = irnd&(80, 140)
  428.         NEXT
  429.         FOR i = 0 TO 200
  430.             stars(i).x = RND * xmax: stars(i).y = RND * ymax: stars(i).size = .3
  431.             stars(i).c = irnd&(80, 140)
  432.         NEXT
  433.  
  434.         FOR i = 1 TO 140
  435.             stars(i + 400).x = RND * xmax: stars(i + 400).y = RND * ymax: stars(i + 100).size = .6
  436.             stars(i).c = irnd&(110, 170)
  437.         NEXT
  438.         FOR i = 1 TO 50
  439.             stars(i + 540).x = RND * xmax: stars(i + 540).y = RND * ymax: stars(i + 170).size = 1.2
  440.             stars(i).c = irnd&(140, 200)
  441.         NEXT
  442.         FOR i = 1 TO 10
  443.             stars(i + 590).x = RND * xmax: stars(i + 590).y = RND * ymax: stars(i + 195).size = 2.4
  444.             stars(i).c = irnd&(170, 235)
  445.         NEXT
  446.         cy = ymax / 2
  447.         beenHere = 1
  448.     END IF
  449.     FOR i = 0 TO cy
  450.         LINE (0, i)-(xmax, i), _RGB32(0, 0, .1 * i + 4)
  451.         LINE (0, ymax - i)-(xmax, ymax - i), _RGB(0, 0, .1 * i + 4)
  452.     NEXT
  453.     FOR i = 0 TO 200
  454.         IF moving THEN
  455.             stars(i).x = stars(i).x + .2 * stars(i).size ^ stars(i).size
  456.             IF stars(i).x > xmax THEN stars(i).x = -1 * RND * 20
  457.         END IF
  458.         fcirc stars(i).x, stars(i).y, stars(i).size, _RGB32(stars(i).c - 10, stars(i).c, stars(i).c + 10)
  459.     NEXT
  460.  
  461. SUB newAlien (i AS LONG)
  462.     DIM side AS LONG, heading
  463.     RANDOMIZE TIMER * RND 'to avoid making twins
  464.     side = irnd&(1, 4) 'bring rock in from one side, need to set heading according to side
  465.     aliens(i).fireX = irnd(10, xmax - 10)
  466.     aliens(i).fireY = irnd(10, ymax - 10)
  467.     aliens(i).attackFrame = irnd(30, 400) ' EDIT a tweak to survive a little long before getting murdered with low lives over and over...
  468.     SELECT CASE side
  469.         CASE 1
  470.             aliens(i).x = -10
  471.             aliens(i).y = rrnd(20, ymax - 20)
  472.         CASE 2
  473.             aliens(i).x = xmax + 10
  474.             aliens(i).y = rrnd(20, ymax - 20)
  475.         CASE 3
  476.             aliens(i).x = rrnd(20, xmax - 20)
  477.             aliens(i).y = -10
  478.         CASE 4
  479.             aliens(i).x = rrnd(20, xmax - 20)
  480.             aliens(i).y = ymax + 10
  481.     END SELECT
  482.     heading = _ATAN2(aliens(i).fireY - aliens(i).y, aliens(i).fireX - aliens(i).x)
  483.     aliens(i).dx = alienSpeed * COS(heading)
  484.     aliens(i).dy = alienSpeed * SIN(heading)
  485.     aliens(i).live = 0
  486.     aliens(i).transform = 0
  487.     aliens(i).c = _RGB32(irnd(128, 255), irnd(0, 255), irnd(0, 255))
  488.  
  489. FUNCTION plasma~& (new AS LONG)
  490.     STATIC r, g, b, cnt, beenHere
  491.     IF beenHere = 0 OR new THEN
  492.         r = RND: g = RND: b = RND: beenHere = 1: cnt = 0
  493.     END IF
  494.     cnt = cnt + .2
  495.     plasma~& = _RGB32(127 + 127 * SIN(r * cnt), 127 + 127 * SIN(g * cnt), 127 + 127 * SIN(b * cnt))
  496.  
  497. SUB drawAliens (i AS LONG) 'shipType
  498.     DIM light AS LONG, heading, r AS LONG, g AS LONG, b AS LONG
  499.     IF aliens(i).live THEN
  500.         SOUND 6000 + i * 200, .07
  501.         IF aliens(i).transform = 0 THEN
  502.             r = _RED32(aliens(i).c): g = _GREEN32(aliens(i).c): b = _BLUE32(aliens(i).c)
  503.             fellipse aliens(i).x, aliens(i).y, 6, 15, _RGB32(r, g - 120, b - 100)
  504.             fellipse aliens(i).x, aliens(i).y, 18, 11, _RGB32(r, g - 60, b - 50)
  505.             fellipse aliens(i).x, aliens(i).y, 30, 7, _RGB32(r, g, b)
  506.             FOR light = 0 TO 5
  507.                 fcirc aliens(i).x - 30 + 11 * light + aliens(i).ls, aliens(i).y, 1, _RGB32(aliens(i).ls * 50, aliens(i).ls * 50, aliens(i).ls * 50)
  508.             NEXT
  509.             aliens(i).ls = aliens(i).ls + 1
  510.             IF aliens(i).ls > 5 THEN aliens(i).ls = 0
  511.         ELSE
  512.             drawBall aliens(i).x, aliens(i).y, 30, aliens(i).c
  513.         END IF
  514.         'time to shoot?
  515.         aliens(i).x = aliens(i).x + aliens(i).dx
  516.         aliens(i).y = aliens(i).y + aliens(i).dy
  517.         IF SQR((aliens(i).fireX - aliens(i).x) ^ 2 + (aliens(i).fireY - aliens(i).y) ^ 2) < 5 THEN 'transform into the bolder of death
  518.             aliens(i).transform = 1
  519.             heading = _ATAN2(ship.y - aliens(i).y, ship.x - aliens(i).x)
  520.             aliens(i).dx = 2.5 * COS(heading)
  521.             aliens(i).dy = 2.5 * SIN(heading)
  522.         END IF
  523.         IF aliens(i).x < -10 OR aliens(i).x > xmax + 10 THEN
  524.             IF aliens(i).y < -10 OR aliens(i).y > ymax + 10 THEN '  out of bounds goodbye bolder of death!
  525.                 aliens(i).live = 0 'man we dodged a bullet here!!!!
  526.                 newAlien i 'reset the trap
  527.             END IF
  528.         END IF
  529.     ELSE
  530.         IF aliens(i).attackFrame THEN
  531.             aliens(i).attackFrame = aliens(i).attackFrame - 1
  532.             IF aliens(i).attackFrame = 0 THEN
  533.                 aliens(i).live = 1
  534.             END IF
  535.         END IF
  536.     END IF
  537.  
  538. FUNCTION freeRock&
  539.     DIM i AS LONG
  540.     FOR i = rocks + 1 TO nRocks ' look for inactive rock number
  541.         IF r(i).live = 0 AND r(i).explodeFrame = 0 THEN freeRock& = i: EXIT FUNCTION
  542.     NEXT
  543.  
  544. SUB explode (x AS LONG, y AS LONG, r AS LONG, frm AS LONG)
  545.     DIM maxParticles AS LONG, i AS LONG, rounds AS LONG, loopCount AS LONG
  546.     maxParticles = r * 4
  547.     FOR i = 1 TO r
  548.         NewDot i, x, y, r
  549.     NEXT
  550.     rounds = r
  551.     FOR loopCount = 0 TO frm
  552.         IF _KEYDOWN(27) THEN END
  553.         FOR i = 1 TO rounds
  554.             dots(i).x = dots(i).x + dots(i).dx
  555.             dots(i).y = dots(i).y + dots(i).dy
  556.             fcirc dots(i).x, dots(i).y, dots(i).size, dots(i).kolor
  557.         NEXT
  558.         IF rounds < maxParticles THEN
  559.             FOR i = 1 TO r
  560.                 NewDot (rounds + i), x, y, r
  561.             NEXT
  562.             rounds = rounds + r
  563.         END IF
  564.     NEXT
  565.  
  566. SUB NewDot (i AS LONG, x AS LONG, y AS LONG, r AS LONG)
  567.     DIM angle, rd
  568.     angle = pi * 2 * RND
  569.     rd = RND * 30
  570.     dots(i).x = x + rd * COS(angle)
  571.     dots(i).y = y + rd * SIN(angle)
  572.     dots(i).size = RND * r * .05
  573.     rd = RND 'STxAxTIC recommended for rounder spreads
  574.     dots(i).dx = rd * 10 * (10 - 2 * dots(i).size) * COS(angle)
  575.     dots(i).dy = rd * 10 * (10 - 2 * dots(i).size) * SIN(angle)
  576.     rd = 20 + RND * 70
  577.     dots(i).kolor = _RGBA32(rd, rd, rd, 80)
  578.  
  579. SUB drawship 'simple red iso triangle pointed towards radianAngle
  580.     DIM x1 AS LONG, y1 AS LONG, x2 AS LONG, y2 AS LONG, x3 AS LONG, y3 AS LONG
  581.     DIM x4 AS LONG, y4 AS LONG, x5 AS LONG, y5 AS LONG
  582.     IF ship.thrust > 0 THEN
  583.         'burn out flame as thruster dies out
  584.         x4 = ship.x + .5 * ship.thrust * COS(ship.angle - 17 / 18 * pi)
  585.         y4 = ship.y + .5 * ship.thrust * SIN(ship.angle - 17 / 18 * pi)
  586.         x5 = ship.x + .5 * ship.thrust * COS(ship.angle - 19 / 18 * pi)
  587.         y5 = ship.y + .5 * ship.thrust * SIN(ship.angle - 19 / 18 * pi)
  588.         ftri ship.x, ship.y, x4, y4, x5, y5, &H99FFFF88
  589.         ship.thrust = ship.thrust - 1
  590.     END IF
  591.     'draw ship dead or alive thrust or not, calculate 3 points of triangle ship
  592.     fcirc ship.x, ship.y, 30, &H05FFFFFF
  593.     x1 = ship.x + 30 * COS(ship.angle) ' front point
  594.     y1 = ship.y + 30 * SIN(ship.angle) '
  595.     x2 = ship.x + 30 * COS(ship.angle + .6666 * pi) ' wing
  596.     y2 = ship.y + 30 * SIN(ship.angle + .6666 * pi)
  597.     x3 = ship.x + 30 * COS(ship.angle - .6666 * pi) ' other wing
  598.     y3 = ship.y + 30 * SIN(ship.angle - .6666 * pi)
  599.     ftri ship.x, ship.y, x1, y1, x2, y2, _RGB32(80, 120, 80, 80)
  600.     ftri ship.x, ship.y, x1, y1, x3, y3, _RGB32(60, 100, 60, 80)
  601.     LINE (x1, y1)-(ship.x, ship.y), _RGB32(255, 255, 128)
  602.     LINE (x1, y1)-(x2, y2), _RGB32(255, 180, 40)
  603.     LINE (x1, y1)-(x3, y3), _RGB32(255, 180, 40)
  604.  
  605. SUB drawRock (iRock)
  606.     RANDOMIZE USING r(iRock).seed 'this prevents having to save a particular sequence of random number
  607.     DIM dx, dy, j AS LONG, rRad AS SINGLE, leg AS SINGLE, x0 AS LONG, y0 AS LONG, rc AS LONG, c~&, x1 AS LONG, y1 AS LONG, xoff, yoff, i AS LONG
  608.     DIM x2 AS LONG, y2 AS LONG
  609.     dx = r(iRock).speed * COS(r(iRock).heading)
  610.     dy = r(iRock).speed * SIN(r(iRock).heading) 'update location
  611.     r(iRock).ra = r(iRock).ra + r(iRock).spin
  612.     IF r(iRock).x + dx + r(iRock).r < 0 OR r(iRock).x + dx - r(iRock).r > xmax OR r(iRock).y + dy + r(iRock).r < 0 OR r(iRock).y + dy - r(iRock).r > ymax THEN
  613.         IF iRock <= rocks THEN newRock iRock ELSE r(iRock).live = 0
  614.         EXIT SUB ' reassigned get out of here
  615.     ELSE
  616.         r(iRock).x = r(iRock).x + dx
  617.         r(iRock).y = r(iRock).y + dy
  618.     END IF
  619.     FOR j = 10 TO 3 STEP -1 '                  rock drawing (see demo program where developed code)
  620.         rRad = .1 * j * r(iRock).r
  621.         leg = rRad * (RND * .7 + .3)
  622.         x0 = r(iRock).x + leg * COS(r(iRock).ra)
  623.         y0 = r(iRock).y + leg * SIN(r(iRock).ra)
  624.         rc = r(iRock).c + 30 * RND - 15
  625.         c~& = _RGB32(rc + 5, rc - 10, rc + 5)
  626.         x1 = x0
  627.         y1 = y0
  628.         xoff = RND * 20 - 10 + r(iRock).x
  629.         yoff = RND * 20 - 10 + r(iRock).y
  630.         FOR i = 1 TO 12
  631.             leg = rRad * (RND * .35 + .65)
  632.             IF i = 12 THEN
  633.                 x2 = x0: y2 = y0
  634.             ELSE
  635.                 x2 = xoff + leg * COS(i * polyAngle + r(iRock).ra)
  636.                 y2 = yoff + leg * SIN(i * polyAngle + r(iRock).ra)
  637.             END IF
  638.             ftri r(iRock).x, r(iRock).y, x1, y1, x2, y2, c~&
  639.             x1 = x2: y1 = y2
  640.         NEXT
  641.     NEXT
  642.  
  643. SUB newRock (iRock)
  644.     DIM side AS LONG
  645.     RANDOMIZE TIMER * RND 'to avoid making twins
  646.     side = irnd&(1, 4) 'bring rock in from one side, need to set heading according to side
  647.     SELECT CASE side
  648.         CASE 1
  649.             r(iRock).x = -100
  650.             r(iRock).y = rrnd(20, ymax - 20)
  651.             r(iRock).heading = 3 * pi / 2 + RND * pi
  652.         CASE 2
  653.             r(iRock).x = xmax + 100
  654.             r(iRock).y = rrnd(20, ymax - 20)
  655.             r(iRock).heading = pi / 2 + RND * pi
  656.         CASE 3
  657.             r(iRock).x = rrnd(20, xmax - 20)
  658.             r(iRock).y = -100
  659.             r(iRock).heading = RND * pi
  660.         CASE 4
  661.             r(iRock).x = rrnd(20, xmax - 20)
  662.             r(iRock).y = ymax + 100
  663.             r(iRock).heading = pi + RND * pi
  664.     END SELECT
  665.     r(iRock).speed = rrnd(minRockSpeed, maxRockSpeed) 'speed, rotation angle, radius, gray coloring, spin, seed, hit for explosion
  666.     r(iRock).ra = RND * 2 * pi
  667.     r(iRock).r = irnd&(minRockSize * 3, maxRockSize) 'every parent rock can be split up into at least 2 - 10 size rocks
  668.     r(iRock).c = irnd&(60, 110) ' Ken request increase in rock color
  669.     r(iRock).spin = rrnd(-pi / 20, pi / 20)
  670.     r(iRock).seed = INT(RND * 64000) - 32000
  671.     r(iRock).explodeFrame = 0
  672.     r(iRock).live = 1
  673.  
  674. FUNCTION irnd& (n1, n2) 'return an integer between 2 numbers
  675.     DIM l%, h%
  676.     IF n1 > n2 THEN l% = n2: h% = n1 ELSE l% = n1: h% = n2
  677.     irnd& = INT(RND * (h% - l% + 1)) + l%
  678.  
  679. FUNCTION rrnd (n1, n2) ' return number (expecting reals =_single, double, _float depending on default / define setup)
  680.     rrnd = (n2 - n1) * RND + n1
  681.  
  682. SUB drawBall (x, y, r, c AS _UNSIGNED LONG)
  683.     DIM red AS LONG, grn AS LONG, blu AS LONG, rr AS LONG, f
  684.     red = _RED32(c): grn = _GREEN32(c): blu = _BLUE32(c)
  685.     FOR rr = r TO 0 STEP -1
  686.         f = 1 - rr / r
  687.         fcirc x, y, rr, _RGB32(red * f, grn * f, blu * f)
  688.     NEXT
  689.  
  690. SUB fellipse (CX AS LONG, CY AS LONG, xr AS LONG, yr AS LONG, C AS _UNSIGNED LONG)
  691.     IF xr = 0 OR yr = 0 THEN EXIT SUB
  692.     DIM x AS LONG, y AS LONG
  693.     w2 = xr * xr: h2 = yr * yr: h2w2 = h2 * w2
  694.     LINE (CX - xr, CY)-(CX + xr, CY), C, BF
  695.     DO WHILE y < yr
  696.         y = y + 1
  697.         x = SQR((h2w2 - y * y * w2) \ h2)
  698.         LINE (CX - x, CY + y)-(CX + x, CY + y), C, BF
  699.         LINE (CX - x, CY - y)-(CX + x, CY - y), C, BF
  700.     LOOP
  701.  
  702. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  703.     DIM D AS LONG
  704.     STATIC a&
  705.     D = _DEST
  706.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  707.     _DEST a&
  708.     _DONTBLEND a& '  '<<<< new 2019-12-16 fix
  709.     PSET (0, 0), K
  710.     _BLEND a& '<<<< new 2019-12-16 fix
  711.     _DEST D
  712.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  713.  
  714. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG) 'vince version
  715.     DIM x0 AS LONG, y0 AS LONG, e AS LONG
  716.     x0 = R: y0 = 0: e = 0
  717.     DO WHILE y0 < x0
  718.         IF e <= 0 THEN
  719.             y0 = y0 + 1
  720.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  721.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  722.             e = e + 2 * y0
  723.         ELSE
  724.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  725.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  726.             x0 = x0 - 1: e = e - 2 * x0
  727.         END IF
  728.     LOOP
  729.     LINE (x - R, y)-(x + R, y), C, BF
  730.  
« Last Edit: November 05, 2020, 10:56:13 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #80 on: November 05, 2020, 11:41:31 pm »
To be honest B+, I didn't use thrust until it was almost over because I was getting tired. I'm not sure how long that game was, maybe 30 minutes or so. I also didn't use Hyperspace because I was just doing the same thing pretty much the whole time, turning to each rock and saucer and shooting, that was all I did. lol
« Last Edit: November 05, 2020, 11:42:34 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #81 on: November 05, 2020, 11:46:12 pm »
Ah, (P)ause! Very nice! :))

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #82 on: November 05, 2020, 11:48:33 pm »
To be honest B+, I didn't use thrust until it was almost over because I was getting tired. I'm not sure how long that game was, maybe 30 minutes or so. I also didn't use Hyperspace because I was just doing the same thing pretty much the whole time, turning to each rock and saucer and shooting, that was all I did. lol

That's funny! My first version here was just turning! (though we were using mouse to point the way) Then someone said we should be able to move the ship, who was that? ;-))  Well I for one am glad we tried more things.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: b+ Asteroids makeover
« Reply #83 on: November 06, 2020, 07:04:20 am »
Since it fires automaticaly now, I thought I'd sit my flashlight on the arrow key a while and see how well it could play.  It played a pretty good game - without batteries even...

- Dav

 
AsteroidsFlashLight.jpg

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: b+ Asteroids makeover
« Reply #84 on: November 06, 2020, 07:41:23 am »
Cool... Now you know how to set it for 'auto-pilot' if you need to take a toilet or coffee break....
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #85 on: November 06, 2020, 11:37:55 am »
Since it fires automaticaly now, I thought I'd sit my flashlight on the arrow key a while and see how well it could play.  It played a pretty good game - without batteries even...

- Dav

 
AsteroidsFlashLight.jpg


Well something tells me this game is too easy ;-))


Cool... Now you know how to set it for 'auto-pilot' if you need to take a toilet or coffee break....

Speaking of auto-pilot, I made one for Snake Game and one for Lunar Lander in JB, hmm....

Well first, we need to make the game a little more challanging hee, hee...

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: b+ Asteroids makeover
« Reply #86 on: November 06, 2020, 01:09:19 pm »
It's playing really well.   For more challenge, how about make the ufo shoot back, or when some rocks explode, a few small pieces head towards the ship?

- Dav
« Last Edit: November 06, 2020, 01:14:01 pm by Dav »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #87 on: November 06, 2020, 02:23:37 pm »
Yeah more little rocks heading toward the ship would be good. Then people might have to dodge them. :) I would also speed the game up a little faster than it does, maybe cut the time in half on how often it speeds up.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #88 on: November 06, 2020, 05:04:49 pm »
Does this fix your wagon? ;-))

A little faster rocks and therefore aliens and more rock fragments heading your way along with alien ship paths and they are all starting a little closer to the center, if you like to hang out there be warned...

I also tweaked some other things like tightened the gap between ship and collision object, sort of like to see rock or alien touching ship during collision, closer but not perfect. The flashlight strategy still is a pretty good survival technique.

Code: QB64: [Select]
  1. _TITLE "b+QB64 Asteroids M10" 'started 2018-07-13
  2. '2020 - Oct and Nov: Special thanks to SierraKen who has been helpful with suggestions, ideas and fixes.
  3.  
  4. ' Far far away in a universe where Newton's 1st Law of Motion is not obeyed...    ;-))
  5.  
  6.  
  7. '                                            New Controls
  8. ' key a or left arrow = turn left
  9. ' key s or right arrow = turn right
  10. ' enter or spacebar =  "hyperspace" show up somewhere else  better or worse use when collision is imminent
  11. ' key k or up arrow = thrust  just a burst in direction you are pointed but doesn't last
  12. ' fire! owwha, owha, owha...  is now continuous
  13.  
  14. '=================================================================================================================
  15.  
  16. ' 2020-10-27 remove the alternate subs and get down below 200 LOC almost there now! new shooter action font and background
  17. ' 2020-10-28 another makeover explosions and split asteroids
  18. ' 2020-10-29 fix baby rock management, break between lives
  19. ' 2020-10-29 fix left/right gun, fix explosions over many frames to eliminate pause in action, speed up 60 fps
  20. ' 2020-10-30 m3 SierraKen's idea to angle shooter with mousewheel also finish WASD options, more rocks, points system
  21. ' points:
  22. ' The higher the speed the better    speed range .5 to 2.5, diff = 2 * 50 = 100          s - .5 * 50
  23. ' DELETE The lower the color the better   color range 10 to 60, diff =      50 * 2 = 100  50 - (c - 10) * 2
  24. ' The smaller the size the better  size range 10 to 100, diff = 90 * 1.1111 = 100  90 - (sz -10) * 1.1111
  25. '        ((speed - .5) * 50 + (90 - (r - 10)) * 1.1111) / 2 = 100 best score per hit
  26. ' 2020-10-30 increase level of difficulty, fix double lives lost, add an ending after all lives spent.
  27. ' 2020-10-31 M4 They are Here - the aliens have accepted my invitaion for war games don't get caught in their beam.
  28. ' rework ending and variable LONG suffix. Aliens on the attack 100 points before or after transformed into the Bolder of Death.
  29. ' 2020-11-01 M5 FX Moving through space, Oh yeah, more aliens!
  30. ' 2020-11-01 M6 add play again and save high game , continuous shoot
  31. ' 2020-11-01 M7 fix hits count when hit alien ship or Bolder of Death. Fix lights on aliens ship. I want to see collsions with ship.
  32. ' Ken recommends removing text in middle of screen, yeah, distracting. Makeover ship as with mouse x, y it's center. Add Splash screen.
  33. ' Show mouse in between lives so can be in screen center when press key to start next run.
  34.  
  35. ' 2020-11-03 M9 watching videos on Asteroids, I found a view and description of the control panel, it is:
  36. ' 2 buttons on left and lower button in middle and 2 buttons on right level with 2 on left.
  37. ' 2 buttons on left are left and right turns they will be Keys A and S
  38. ' The middle will be spacebar for Hypespace or these days we might call it worm hole, jump to another location better or worse!
  39. ' 2 buttons on right K and L: K will be a thruster of sorts you eventually come to a stop (not what Newton would like) L is the fire button.
  40. ' So let's try that. I am impressed by hitting thruster and shooting all around as you dift in direction gun was pointed when hit thruster.
  41. ' Lighten rocks and change points, based now only on size and speed of Asteroids.
  42. ' 2020-11-04 M9 Install new update to thrust control. Thanks to SierraKen for finding out what happened to Hyperspace jump when press
  43. ' spacebar a 2nd time in a life. Oh also Boulders of Death are now more like smooth colored spheres. Ahhhh Fixed the crashing at the borders
  44. ' now fly out one side and come back in on the other! This is getting good! Adding some sound effects.
  45. ' 2020-11-05 M10 set some constants for starting game so can just change them to level of play desired.
  46. ' speed points =  50 * (rockSpeed - minRockSpeed)/rockSpeedRange > fastest rock gets 50 points
  47. ' size points = 50 * (rockSizeRange - (rockSize - minRockSize))/rockSizeRange  > smallest rock gets 50 points
  48. ' points = points +  50 * ( (rockSpeed - minRockSpeed)/rockSpeedRange +  (rockSizeRange - (rockSize - minRockSize))/rockSizeRange )
  49. ' Dav's comments: Add arrow keys for left right turns and up for thrust, continuous fire now! A little score board in top left corner.
  50. ' Dav I am keeping spacebar for Hyperspace but also Enter, don't need fire button now.
  51. ' Try the A for left and the right arrow for right turns.
  52. ' 2020-11-05 p is for pause
  53. ' 2020-11-06 Move it or lose it!
  54.  
  55. '================================================================================================================
  56.  
  57. '    NOTE: !!!!!!!!!!!!!!!   When there is a pause in action, just press enter,  as in enter a new life!
  58.  
  59. '================================================================================================================
  60.  
  61. CONST xmax = 1200, ymax = 700, pi = _PI, polyAngle = _PI / 6, nRocks = 300, nBullets = 2000, bSpeed = 15
  62. CONST startRocks = 2, minRockSpeed = 0.7500, maxRockSpeed = 3.2500, minRockSize = 10, maxRockSize = 100
  63. CONST rockSpeedRange = maxRockSpeed - minRockSpeed, rockSizeRange = maxRockSize - minRockSize
  64. CONST alienSpeed = rockSpeedRange / 2 + minRockSpeed ' average rock speed
  65.  
  66. TYPE alienType
  67.     x AS SINGLE
  68.     y AS SINGLE
  69.     dx AS SINGLE
  70.     dy AS SINGLE
  71.     ls AS LONG ' lights offset and gray scale
  72.     c AS _UNSIGNED LONG ' color
  73.     live AS LONG
  74.     attackFrame AS LONG
  75.     fireX AS SINGLE
  76.     fireY AS SINGLE
  77.     transform AS LONG
  78.  
  79. TYPE particle
  80.     x AS SINGLE
  81.     y AS SINGLE
  82.     dx AS SINGLE
  83.     dy AS SINGLE
  84.     size AS SINGLE
  85.     kolor AS _UNSIGNED LONG
  86.  
  87. TYPE bullet
  88.     x AS SINGLE
  89.     y AS SINGLE
  90.     dx AS SINGLE
  91.     dy AS SINGLE
  92.     live AS LONG
  93.  
  94. TYPE shipType
  95.     x AS SINGLE
  96.     y AS SINGLE
  97.     live AS LONG
  98.     speed AS SINGLE '       just a constant now when Thrust is applied
  99.     thrustAngle AS SINGLE ' ship/gun angle at moment Thrust is pressed
  100.     angle AS SINGLE '       rotated position ship/gun now A or S keypress or hold down
  101.     thrust AS LONG '        this now tracks how many frames ship will move at speed and thrustAngle
  102.  
  103. TYPE rock
  104.     x AS SINGLE
  105.     y AS SINGLE
  106.     r AS LONG '            radius
  107.     ra AS SINGLE '         rotation position   a = a + spin
  108.     heading AS SINGLE '    heading from which dx, dy are calc with speed
  109.     speed AS SINGLE '      speed
  110.     spin AS SINGLE '       rotation direction and amount
  111.     seed AS LONG '         for drawing rocks with RND USING
  112.     c AS LONG '            color   rgb(c, c, c)
  113.     live AS LONG '         need this to track rocks still active like bullets
  114.     explodeFrame AS LONG ' after a rock is hit by bullet, it explodes and in more than one frame
  115.  
  116. REDIM SHARED aliens(1 TO 5) AS alienType
  117. DIM SHARED dots(2000) AS particle ' explosions
  118. DIM SHARED b(nBullets) AS bullet
  119. DIM SHARED ship AS shipType
  120. DIM SHARED r(nRocks) AS rock
  121. DIM SHARED points AS LONG
  122. DIM SHARED rocks AS LONG 'rocks is the minimum number of parent rocks to have on screen  automatic replace when hit or out of bounds
  123.  
  124. DIM HS AS LONG, fnt AS LONG, fnt2 AS LONG ' file LOAD handles
  125. DIM i AS LONG, bullets AS LONG, fire AS LONG ' index and bullets
  126. DIM r AS LONG, newRockN AS LONG, maxBabyRocks AS LONG, br AS LONG, hits AS LONG ' rock stuff
  127. DIM ai AS LONG, alienN AS LONG ' alien index and number
  128. DIM kh AS LONG 'key hit for ship thrust k or up arrow or hyperspace jump spacebar
  129. DIM hs$, s$, k$, t, lastt 'high score, general string and times for bullets
  130. DIM rockPoints AS LONG, roundPoints AS LONG ' various points scores
  131. ship.speed = 3.5 'this would be a constant but ship has to declared as Ship Type first, Hyperspace jump
  132.  
  133. SCREEN _NEWIMAGE(xmax, ymax, 32)
  134. _SCREENMOVE 100, 20
  135.  
  136. fnt = _LOADFONT("ARLRDBD.ttf", 16, "MONOSPACE")
  137. fnt2 = _LOADFONT("ARLRDBD.ttf", 40, "MONOSPACE")
  138. _FONT fnt2
  139. COLOR &HFF00FFFF, &H00000000
  140.  
  141. IF _FILEEXISTS("Asteroids High Score.txt") THEN
  142.     OPEN "Asteroids High Score.txt" FOR INPUT AS #1
  143.     INPUT #1, HS
  144.     CLOSE #1
  145. hs$ = "High Score:" + STR$(HS)
  146.  
  147. 'a little splash screen
  148. rocks = 7: alienN = 3
  149. FOR i = 1 TO nRocks
  150.     newRock i
  151.     IF i > rocks THEN r(i).live = 0
  152. FOR i = 1 TO alienN
  153.     newAlien i
  154. i = 0
  155.     drawStars 0
  156.     i = i + 1
  157.     IF i MOD 30 = 29 AND rocks < nRocks THEN rocks = rocks + 1: r(rocks).live = 1
  158.     FOR r = 1 TO nRocks
  159.         IF r(r).live THEN drawRock r
  160.     NEXT
  161.     FOR i = 1 TO alienN
  162.         drawAliens i
  163.     NEXT
  164.     _FONT fnt2
  165.     s$ = "*** b+QB64 Asteroids ***"
  166.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 60), s$
  167.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(hs$)) / 2, 140), hs$
  168.     s$ = "A or arrow = Left spin"
  169.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 220), s$
  170.     s$ = "S or arrow = Right Spin"
  171.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 300), s$
  172.     s$ = "Space or Enter = Hyper jump"
  173.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 380), s$
  174.     s$ = "K or up arrow = Thrust"
  175.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 460), s$
  176.     s$ = "Escape quit, any plays"
  177.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, 540), s$
  178.     _FONT fnt
  179.     k$ = INKEY$
  180.     _DISPLAY
  181.     _LIMIT 60
  182.  
  183. restart:
  184. IF _FILEEXISTS("Asteroids High Score.txt") THEN
  185.     OPEN "Asteroids High Score.txt" FOR INPUT AS #1
  186.     INPUT #1, HS
  187.     CLOSE #1
  188. hs$ = "  High Score:" + STR$(HS)
  189. lives = 10: alienN = 1: rocks = startRocks: ' always active rocks
  190. points = 0: hits = 0: bullets = 0
  191. WHILE lives > 0 AND _KEYDOWN(27) = 0 ' init start restart
  192.     REDIM aliens(1 TO alienN) AS alienType
  193.     FOR ai = 1 TO alienN
  194.         newAlien ai
  195.     NEXT
  196.     FOR i = 1 TO nRocks 'reset rocks mainly clear baby rocks
  197.         newRock (i)
  198.         IF i > rocks THEN r(i).live = 0
  199.     NEXT
  200.     ship.x = xmax / 2 'avoids explosions top left corner at start, dang still get some!
  201.     ship.y = ymax / 2
  202.     ship.angle = 0
  203.     ship.thrustAngle = 0
  204.     ship.thrust = 0
  205.     ship.live = 1
  206.     rockPoints = 0
  207.     roundPoints = 0
  208.     WHILE ship.live AND _KEYDOWN(27) = 0
  209.  
  210.         _KEYCLEAR 'clear all previous INKEY$ or _KEYHIT and variables  so ship should always start in middle of sceen pointed east
  211.         kh = 0
  212.  
  213.         'draw everything then process bullets
  214.         drawStars 1
  215.         LOCATE 1, 1: PRINT "Lives:"; lives
  216.         LOCATE 2, 1: PRINT "Last Rock:"; STR$(rockPoints)
  217.         LOCATE 3, 1: PRINT "Round:;"; STR$(roundPoints)
  218.         LOCATE 4, 1: PRINT "Points:"; STR$(points)
  219.         LOCATE 5, 1: PRINT "High Score:"; STR$(HS)
  220.         FOR ai = 1 TO alienN
  221.             drawAliens ai
  222.         NEXT
  223.         FOR i = 1 TO nRocks
  224.             IF r(i).live THEN 'make sure if we crash into a ship it is a live rock, not one sitting on side waiting to be called up
  225.                 drawRock i ' while drawing rocks the ship could be blown up
  226.                 IF ((r(i).x - ship.x) ^ 2 + (r(i).y - ship.y) ^ 2) ^ .5 < r(i).r + 20 THEN 'rock collides with ship?
  227.                     FOR br = 1 TO 200 STEP 5
  228.                         CIRCLE ((ship.x + r(i).x) / 2, (ship.y + r(i).y) / 2), br, _RGB32(255 - br, 255 - 2 * br, 0)
  229.                     NEXT
  230.                     drawRock i
  231.                     drawship
  232.                     ship.live = 0
  233.                     IF i <= rocks THEN newRock i ELSE r(i).live = 0
  234.                 END IF
  235.             END IF
  236.         NEXT
  237.         FOR i = 1 TO nRocks 'smoke up the place with rock debris fields still flying out from hit frames ago
  238.             IF r(i).explodeFrame THEN
  239.                 r(i).explodeFrame = r(i).explodeFrame + 1
  240.                 IF r(i).explodeFrame > .25 * r(i).r THEN
  241.                     r(i).explodeFrame = 0
  242.                     IF i <= rocks THEN newRock i ' now replace the rock
  243.                 ELSE
  244.                     explode r(i).x, r(i).y, r(i).r, r(i).explodeFrame
  245.                 END IF
  246.             END IF
  247.         NEXT
  248.         IF ship.live THEN
  249.             FOR ai = 1 TO alienN
  250.                 IF SQR((aliens(ai).x - ship.x) ^ 2 + (aliens(ai).y - ship.y) ^ 2) < 55 THEN 'aliens and ship collisde boom boom
  251.                     FOR br = 1 TO 200 STEP 5
  252.                         CIRCLE ((ship.x + aliens(ai).x) / 2, (ship.y + aliens(ai).y) / 2), br, _RGB32(255 - br, 255 - 2 * br, 0)
  253.                     NEXT
  254.                     drawship
  255.                     ship.live = 0
  256.                     _CONTINUE
  257.                 ELSE
  258.                     drawship
  259.                 END IF
  260.             NEXT
  261.  
  262.             '                                                                   ship controls update
  263.             'a key or left arrow = left spin
  264.             IF _KEYDOWN(97) OR _KEYDOWN(19200) THEN ship.angle = ship.angle - pi / 48
  265.  
  266.             's key or right arrow = right spin
  267.             IF _KEYDOWN(115) OR _KEYDOWN(19712) THEN ship.angle = ship.angle + pi / 48
  268.  
  269.             'l is Fire!  JUST CONTINUOUS FIRE
  270.             fire = 0
  271.             'IF _KEYDOWN(108) THEN
  272.             t = TIMER(.01)
  273.             IF lastt = 0 OR t - lastt > .15 THEN fire = 1: SOUND 2088, .01: lastt = t
  274.             'END IF
  275.  
  276.             kh = _KEYHIT
  277.             SELECT CASE kh
  278.                 CASE 112
  279.                     kh = 0
  280.                     WHILE _KEYHIT <> 112: _LIMIT 60: WEND
  281.                 CASE 107, 18432 'thrust  k key or up arrow
  282.                     SOUND 488, .01
  283.                     ship.thrustAngle = ship.angle: ship.thrust = 120
  284.                 CASE 13, 32 ' space = hyperspace jump
  285.                     RANDOMIZE TIMER
  286.                     ship.x = (xmax - 300) * RND + 150: ship.y = (ymax - 300) * RND + 150: ship.thrust = 0
  287.             END SELECT
  288.  
  289.             '                                                                   locate ship
  290.             IF ship.thrust > 0 THEN
  291.                 'relocate ship position
  292.                 ship.x = ship.x + ship.speed * COS(ship.thrustAngle)
  293.                 ship.y = ship.y + ship.speed * SIN(ship.thrustAngle)
  294.             END IF
  295.             '                                                                    jump borders
  296.             IF ship.x < 0 THEN ship.x = xmax - ABS(ship.x)
  297.             IF ship.x > xmax THEN ship.x = ship.x - xmax
  298.             IF ship.y < 0 THEN ship.y = ymax - ABS(ship.y)
  299.             IF ship.y > ymax THEN ship.y = ship.y - ymax
  300.  
  301.  
  302.             FOR i = 0 TO nBullets '                                               handle bullets
  303.                 IF b(i).live = 0 AND fire = 1 THEN 'have inactive bullet to use
  304.                     b(i).x = ship.x + 2 * bSpeed * COS(ship.angle)
  305.                     b(i).y = ship.y + 2 * bSpeed * SIN(ship.angle)
  306.                     b(i).dx = bSpeed * COS(ship.angle)
  307.                     b(i).dy = bSpeed * SIN(ship.angle)
  308.                     b(i).live = -1
  309.                     bullets = bullets + 1
  310.                     fire = 0
  311.                 END IF
  312.                 IF b(i).live THEN 'new location
  313.                     b(i).x = b(i).x + b(i).dx
  314.                     b(i).y = b(i).y + b(i).dy
  315.                     IF b(i).x > 0 AND b(i).x < xmax AND b(i).y > 0 AND b(i).y < ymax THEN 'in bounds draw it
  316.  
  317.                         'bullet hit aliens?
  318.                         FOR ai = 1 TO alienN
  319.                             IF SQR((aliens(ai).x - b(i).x) ^ 2 + (aliens(ai).y - b(i).y) ^ 2) < 30 THEN
  320.                                 FOR br = 1 TO 120
  321.                                     CIRCLE (aliens(ai).x, aliens(ai).y), br / 3, plasma~&(0)
  322.                                 NEXT
  323.                                 _DISPLAY
  324.                                 _DELAY .05
  325.                                 hits = hits + 1
  326.                                 roundPoints = roundPoints + 100
  327.                                 points = points + 100
  328.                                 aliens(ai).live = 0
  329.                                 newAlien ai
  330.                                 b(i).live = 0
  331.                                 _CONTINUE
  332.                             END IF
  333.                         NEXT
  334.                         FOR r = 1 TO nRocks 'check for collision with rock
  335.                             IF r(r).live THEN
  336.                                 IF SQR((r(r).x - b(i).x) ^ 2 + (r(r).y - b(i).y) ^ 2) < r(r).r THEN 'its a hit!
  337.                                     r(r).explodeFrame = 1 'linger with explosion
  338.                                     r(r).live = 0
  339.                                     hits = hits + 1
  340.                                     rockPoints = 50 * ((r(r).speed - minRockSpeed) / rockSpeedRange + (rockSizeRange - (r(r).r - minRockSize)) / rockSizeRange)
  341.                                     roundPoints = roundPoints + rockPoints
  342.                                     points = points + rockPoints
  343.                                     IF r(r).r > 30 THEN '       split rock  into ? new ones
  344.                                         maxBabyRocks = INT((r(r).r - 10) / 10)
  345.                                         maxBabyRocks = irnd&(2, maxBabyRocks) ' pick a number of baby Rocks
  346.                                         FOR br = 1 TO maxBabyRocks
  347.                                             '                        new rock
  348.                                             newRockN = freeRock& '                          get inactive rock number
  349.                                             newRock newRockN '                              new identity and activate
  350.                                             r(newRockN).r = (r(r).r - 10) / maxBabyRocks '  split in equal parts minus 20% mass
  351.                                             r(newRockN).x = r(r).x + irnd&(-30, 30) '       thrown from parent
  352.                                             r(newRockN).y = r(r).y + irnd&(-30, 30)
  353.                                             r(newRockN).c = r(r).c '                   same color as parent
  354.                                             r(newRockN).heading = rrnd(ship.angle - .75 * pi, ship.angle + .75 * pi)
  355.                                         NEXT
  356.                                     END IF ' big enough to split
  357.                                     b(i).live = 0 'kill bullet
  358.                                 END IF ' hit rock
  359.                             END IF 'rock is there
  360.                         NEXT ' rock
  361.                         IF b(i).live THEN fcirc b(i).x, b(i).y, 3, _RGB32(255, 255, 0) 'draws bullet
  362.                     ELSE
  363.                         b(i).live = 0 'out of bounds
  364.                     END IF ' bullet is in bounds
  365.                 END IF ' bullet live
  366.             NEXT ' bullet
  367.         END IF ' if ship still live
  368.         _DISPLAY
  369.         IF ship.live = 0 THEN
  370.             lives = lives - 1
  371.             IF lives MOD 4 = 0 THEN rocks = rocks + 1
  372.             IF lives MOD 4 = 2 THEN alienN = alienN + 1
  373.             s$ = "Lives:" + STR$(lives) + "  Hits:" + STR$(hits) + "  Bullets:" + STR$(bullets) + "  Shooting:" + STR$(INT(hits * 100 / bullets)) + "%"
  374.             _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2 - 80), s$
  375.             _FONT fnt2
  376.             s$ = STR$(points) + hs$
  377.             _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2), s$
  378.             _FONT fnt
  379.             s$ = "Press enter to enter next life."
  380.             _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2 + 120), s$
  381.             _DISPLAY
  382.             kh = 0
  383.             WHILE kh <> 13
  384.                 kh = _KEYHIT
  385.             WEND 'wait for enter key
  386.         ELSE
  387.             _LIMIT 60 ' if ship dies let's rest and regroup  before restart next life
  388.         END IF
  389.     WEND
  390.     _DISPLAY
  391. IF points > HS THEN
  392.     OPEN "Asteroids High Score.txt" FOR OUTPUT AS #1
  393.     PRINT #1, points
  394.     CLOSE #1
  395. ship.x = -200: ship.y = -200 'get it out of the way
  396. i = 0
  397.     drawStars 0
  398.     i = i + 1
  399.     IF i MOD 30 = 29 AND rocks < nRocks THEN rocks = rocks + 1: r(rocks).live = 1
  400.     FOR r = 1 TO nRocks
  401.         IF r(r).live THEN drawRock r
  402.     NEXT
  403.     s$ = "Lives:" + STR$(lives) + "  Hits:" + STR$(hits) + "  Bullets:" + STR$(bullets) + "  Shooting:" + STR$(INT(hits * 100 / bullets)) + "%"
  404.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2 - 80), s$
  405.     _FONT fnt2
  406.     s$ = STR$(points)
  407.     IF points > HS THEN s$ = s$ + " a New Record!" ELSE s$ = STR$(points) + hs$
  408.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2), s$
  409.     _FONT fnt
  410.     s$ = "Press q to quit, p or a to Play Again..."
  411.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(s$)) / 2, ymax / 2 + 120), s$
  412.     IF _KEYDOWN(ASC("a")) OR _KEYDOWN(ASC("p")) THEN GOTO restart
  413.     _DISPLAY
  414.     _LIMIT 60
  415.  
  416. SUB drawStars (moving)
  417.     TYPE starType
  418.         x AS SINGLE
  419.         y AS SINGLE
  420.         size AS SINGLE
  421.         c AS INTEGER
  422.     END TYPE
  423.     STATIC beenHere, stars(600) AS starType, cy AS LONG
  424.     DIM i AS LONG
  425.     IF beenHere = 0 THEN 'static part
  426.         FOR i = 0 TO 200
  427.             stars(i).x = RND * xmax: stars(i).y = RND * ymax: stars(i).size = 0
  428.             stars(i).c = irnd&(80, 140)
  429.         NEXT
  430.         FOR i = 0 TO 200
  431.             stars(i).x = RND * xmax: stars(i).y = RND * ymax: stars(i).size = .3
  432.             stars(i).c = irnd&(80, 140)
  433.         NEXT
  434.  
  435.         FOR i = 1 TO 140
  436.             stars(i + 400).x = RND * xmax: stars(i + 400).y = RND * ymax: stars(i + 100).size = .6
  437.             stars(i).c = irnd&(110, 170)
  438.         NEXT
  439.         FOR i = 1 TO 50
  440.             stars(i + 540).x = RND * xmax: stars(i + 540).y = RND * ymax: stars(i + 170).size = 1.2
  441.             stars(i).c = irnd&(140, 200)
  442.         NEXT
  443.         FOR i = 1 TO 10
  444.             stars(i + 590).x = RND * xmax: stars(i + 590).y = RND * ymax: stars(i + 195).size = 2.4
  445.             stars(i).c = irnd&(170, 235)
  446.         NEXT
  447.         cy = ymax / 2
  448.         beenHere = 1
  449.     END IF
  450.     FOR i = 0 TO cy
  451.         LINE (0, i)-(xmax, i), _RGB32(0, 0, .1 * i + 4)
  452.         LINE (0, ymax - i)-(xmax, ymax - i), _RGB(0, 0, .1 * i + 4)
  453.     NEXT
  454.     FOR i = 0 TO 200
  455.         IF moving THEN
  456.             stars(i).x = stars(i).x + .2 * stars(i).size ^ stars(i).size
  457.             IF stars(i).x > xmax THEN stars(i).x = -1 * RND * 20
  458.         END IF
  459.         fcirc stars(i).x, stars(i).y, stars(i).size, _RGB32(stars(i).c - 10, stars(i).c, stars(i).c + 10)
  460.     NEXT
  461.  
  462. SUB newAlien (i AS LONG)
  463.     DIM side AS LONG, heading
  464.     RANDOMIZE TIMER * RND 'to avoid making twins
  465.     side = irnd&(1, 4) 'bring rock in from one side, need to set heading according to side
  466.     IF RND < .6 THEN
  467.         aliens(i).fireX = ship.x: aliens(i).fireY = ship.y
  468.     ELSE
  469.         aliens(i).fireX = irnd(10, xmax - 10): aliens(i).fireY = irnd(10, ymax - 10)
  470.     END IF
  471.     aliens(i).attackFrame = irnd(50, 400) ' EDIT a tweak to survive a little long before getting murdered with low lives over and over...
  472.     SELECT CASE side
  473.         CASE 1
  474.             aliens(i).x = -10
  475.             aliens(i).y = rrnd(80, ymax - 80)
  476.         CASE 2
  477.             aliens(i).x = xmax + 10
  478.             aliens(i).y = rrnd(80, ymax - 80)
  479.         CASE 3
  480.             aliens(i).x = rrnd(80, xmax - 80)
  481.             aliens(i).y = -10
  482.         CASE 4
  483.             aliens(i).x = rrnd(80, xmax - 80)
  484.             aliens(i).y = ymax + 10
  485.     END SELECT
  486.     heading = _ATAN2(aliens(i).fireY - aliens(i).y, aliens(i).fireX - aliens(i).x)
  487.     aliens(i).dx = alienSpeed * COS(heading)
  488.     aliens(i).dy = alienSpeed * SIN(heading)
  489.     aliens(i).live = 0
  490.     aliens(i).transform = 0
  491.     aliens(i).c = _RGB32(irnd(128, 255), irnd(0, 255), irnd(0, 255))
  492.  
  493. FUNCTION plasma~& (new AS LONG)
  494.     STATIC r, g, b, cnt, beenHere
  495.     IF beenHere = 0 OR new THEN
  496.         r = RND: g = RND: b = RND: beenHere = 1: cnt = 0
  497.     END IF
  498.     cnt = cnt + .2
  499.     plasma~& = _RGB32(127 + 127 * SIN(r * cnt), 127 + 127 * SIN(g * cnt), 127 + 127 * SIN(b * cnt))
  500.  
  501. SUB drawAliens (i AS LONG) 'shipType
  502.     DIM light AS LONG, heading, r AS LONG, g AS LONG, b AS LONG
  503.     IF aliens(i).live THEN
  504.         SOUND 6000 + i * 200, .07
  505.         IF aliens(i).transform = 0 THEN
  506.             r = _RED32(aliens(i).c): g = _GREEN32(aliens(i).c): b = _BLUE32(aliens(i).c)
  507.             fellipse aliens(i).x, aliens(i).y, 6, 15, _RGB32(r, g - 120, b - 100)
  508.             fellipse aliens(i).x, aliens(i).y, 18, 11, _RGB32(r, g - 60, b - 50)
  509.             fellipse aliens(i).x, aliens(i).y, 30, 7, _RGB32(r, g, b)
  510.             FOR light = 0 TO 5
  511.                 fcirc aliens(i).x - 30 + 11 * light + aliens(i).ls, aliens(i).y, 1, _RGB32(aliens(i).ls * 50, aliens(i).ls * 50, aliens(i).ls * 50)
  512.             NEXT
  513.             aliens(i).ls = aliens(i).ls + 1
  514.             IF aliens(i).ls > 5 THEN aliens(i).ls = 0
  515.         ELSE
  516.             drawBall aliens(i).x, aliens(i).y, 30, aliens(i).c
  517.         END IF
  518.         'time to shoot?
  519.         aliens(i).x = aliens(i).x + aliens(i).dx
  520.         aliens(i).y = aliens(i).y + aliens(i).dy
  521.         IF SQR((aliens(i).fireX - aliens(i).x) ^ 2 + (aliens(i).fireY - aliens(i).y) ^ 2) < 5 THEN 'transform into the bolder of death
  522.             aliens(i).transform = 1
  523.             heading = _ATAN2(ship.y - aliens(i).y, ship.x - aliens(i).x)
  524.             aliens(i).dx = 2.5 * COS(heading)
  525.             aliens(i).dy = 2.5 * SIN(heading)
  526.         END IF
  527.         IF aliens(i).x < -10 OR aliens(i).x > xmax + 10 THEN
  528.             IF aliens(i).y < -10 OR aliens(i).y > ymax + 10 THEN '  out of bounds goodbye bolder of death!
  529.                 aliens(i).live = 0 'man we dodged a bullet here!!!!
  530.                 newAlien i 'reset the trap
  531.             END IF
  532.         END IF
  533.     ELSE
  534.         IF aliens(i).attackFrame THEN
  535.             aliens(i).attackFrame = aliens(i).attackFrame - 1
  536.             IF aliens(i).attackFrame = 0 THEN
  537.                 aliens(i).live = 1
  538.             END IF
  539.         END IF
  540.     END IF
  541.  
  542. FUNCTION freeRock&
  543.     DIM i AS LONG
  544.     FOR i = rocks + 1 TO nRocks ' look for inactive rock number
  545.         IF r(i).live = 0 AND r(i).explodeFrame = 0 THEN freeRock& = i: EXIT FUNCTION
  546.     NEXT
  547.  
  548. SUB explode (x AS LONG, y AS LONG, r AS LONG, frm AS LONG)
  549.     DIM maxParticles AS LONG, i AS LONG, rounds AS LONG, loopCount AS LONG
  550.     maxParticles = r * 4
  551.     FOR i = 1 TO r
  552.         NewDot i, x, y, r
  553.     NEXT
  554.     rounds = r
  555.     FOR loopCount = 0 TO frm
  556.         IF _KEYDOWN(27) THEN END
  557.         FOR i = 1 TO rounds
  558.             dots(i).x = dots(i).x + dots(i).dx
  559.             dots(i).y = dots(i).y + dots(i).dy
  560.             fcirc dots(i).x, dots(i).y, dots(i).size, dots(i).kolor
  561.         NEXT
  562.         IF rounds < maxParticles THEN
  563.             FOR i = 1 TO r
  564.                 NewDot (rounds + i), x, y, r
  565.             NEXT
  566.             rounds = rounds + r
  567.         END IF
  568.     NEXT
  569.  
  570. SUB NewDot (i AS LONG, x AS LONG, y AS LONG, r AS LONG)
  571.     DIM angle, rd
  572.     angle = pi * 2 * RND
  573.     rd = RND * 30
  574.     dots(i).x = x + rd * COS(angle)
  575.     dots(i).y = y + rd * SIN(angle)
  576.     dots(i).size = RND * r * .05
  577.     rd = RND 'STxAxTIC recommended for rounder spreads
  578.     dots(i).dx = rd * 10 * (10 - 2 * dots(i).size) * COS(angle)
  579.     dots(i).dy = rd * 10 * (10 - 2 * dots(i).size) * SIN(angle)
  580.     rd = 20 + RND * 70
  581.     dots(i).kolor = _RGBA32(rd, rd, rd, 80)
  582.  
  583. SUB drawship 'simple red iso triangle pointed towards radianAngle
  584.     DIM x1 AS LONG, y1 AS LONG, x2 AS LONG, y2 AS LONG, x3 AS LONG, y3 AS LONG
  585.     DIM x4 AS LONG, y4 AS LONG, x5 AS LONG, y5 AS LONG
  586.     IF ship.thrust > 0 THEN
  587.         'burn out flame as thruster dies out
  588.         x4 = ship.x + .5 * ship.thrust * COS(ship.angle - 17 / 18 * pi)
  589.         y4 = ship.y + .5 * ship.thrust * SIN(ship.angle - 17 / 18 * pi)
  590.         x5 = ship.x + .5 * ship.thrust * COS(ship.angle - 19 / 18 * pi)
  591.         y5 = ship.y + .5 * ship.thrust * SIN(ship.angle - 19 / 18 * pi)
  592.         ftri ship.x, ship.y, x4, y4, x5, y5, &H99FFFF88
  593.         ship.thrust = ship.thrust - 1
  594.     END IF
  595.     'draw ship dead or alive thrust or not, calculate 3 points of triangle ship
  596.     fcirc ship.x, ship.y, 30, &H05FFFFFF
  597.     x1 = ship.x + 30 * COS(ship.angle) ' front point
  598.     y1 = ship.y + 30 * SIN(ship.angle) '
  599.     x2 = ship.x + 30 * COS(ship.angle + .6666 * pi) ' wing
  600.     y2 = ship.y + 30 * SIN(ship.angle + .6666 * pi)
  601.     x3 = ship.x + 30 * COS(ship.angle - .6666 * pi) ' other wing
  602.     y3 = ship.y + 30 * SIN(ship.angle - .6666 * pi)
  603.     ftri ship.x, ship.y, x1, y1, x2, y2, _RGB32(80, 120, 80, 80)
  604.     ftri ship.x, ship.y, x1, y1, x3, y3, _RGB32(60, 100, 60, 80)
  605.     LINE (x1, y1)-(ship.x, ship.y), _RGB32(255, 255, 128)
  606.     LINE (x1, y1)-(x2, y2), _RGB32(255, 180, 40)
  607.     LINE (x1, y1)-(x3, y3), _RGB32(255, 180, 40)
  608.  
  609. SUB drawRock (iRock)
  610.     RANDOMIZE USING r(iRock).seed 'this prevents having to save a particular sequence of random number
  611.     DIM dx, dy, j AS LONG, rRad AS SINGLE, leg AS SINGLE, x0 AS LONG, y0 AS LONG, rc AS LONG, c~&, x1 AS LONG, y1 AS LONG, xoff, yoff, i AS LONG
  612.     DIM x2 AS LONG, y2 AS LONG
  613.     dx = r(iRock).speed * COS(r(iRock).heading)
  614.     dy = r(iRock).speed * SIN(r(iRock).heading) 'update location
  615.     r(iRock).ra = r(iRock).ra + r(iRock).spin
  616.     IF r(iRock).x + dx + r(iRock).r < 0 OR r(iRock).x + dx - r(iRock).r > xmax OR r(iRock).y + dy + r(iRock).r < 0 OR r(iRock).y + dy - r(iRock).r > ymax THEN
  617.         IF iRock <= rocks THEN newRock iRock ELSE r(iRock).live = 0
  618.         EXIT SUB ' reassigned get out of here
  619.     ELSE
  620.         r(iRock).x = r(iRock).x + dx
  621.         r(iRock).y = r(iRock).y + dy
  622.     END IF
  623.     FOR j = 10 TO 3 STEP -1 '                  rock drawing (see demo program where developed code)
  624.         rRad = .1 * j * r(iRock).r
  625.         leg = rRad * (RND * .7 + .3)
  626.         x0 = r(iRock).x + leg * COS(r(iRock).ra)
  627.         y0 = r(iRock).y + leg * SIN(r(iRock).ra)
  628.         rc = r(iRock).c + 30 * RND - 15
  629.         c~& = _RGB32(rc + 5, rc - 10, rc + 5)
  630.         x1 = x0
  631.         y1 = y0
  632.         xoff = RND * 20 - 10 + r(iRock).x
  633.         yoff = RND * 20 - 10 + r(iRock).y
  634.         FOR i = 1 TO 12
  635.             leg = rRad * (RND * .35 + .65)
  636.             IF i = 12 THEN
  637.                 x2 = x0: y2 = y0
  638.             ELSE
  639.                 x2 = xoff + leg * COS(i * polyAngle + r(iRock).ra)
  640.                 y2 = yoff + leg * SIN(i * polyAngle + r(iRock).ra)
  641.             END IF
  642.             ftri r(iRock).x, r(iRock).y, x1, y1, x2, y2, c~&
  643.             x1 = x2: y1 = y2
  644.         NEXT
  645.     NEXT
  646.  
  647. SUB newRock (iRock)
  648.     DIM side AS LONG
  649.     RANDOMIZE TIMER * RND 'to avoid making twins
  650.     side = irnd&(1, 4) 'bring rock in from one side, need to set heading according to side
  651.     SELECT CASE side
  652.         CASE 1
  653.             r(iRock).x = -100
  654.             r(iRock).y = rrnd(80, ymax - 80)
  655.             IF RND < .25 THEN r(iRock).heading = _ATAN2(ship.y - r(iRock).y, ship.x - r(iRock).x) ELSE r(iRock).heading = 3 * pi / 2 + RND * pi
  656.         CASE 2
  657.             r(iRock).x = xmax + 100
  658.             r(iRock).y = rrnd(80, ymax - 80)
  659.             IF RND < .25 THEN r(iRock).heading = _ATAN2(ship.y - r(iRock).y, ship.x - r(iRock).x) ELSE r(iRock).heading = pi / 2 + RND * pi
  660.         CASE 3
  661.             r(iRock).x = rrnd(80, xmax - 80)
  662.             r(iRock).y = -100
  663.             IF RND < .25 THEN r(iRock).heading = _ATAN2(ship.y - r(iRock).y, ship.x - r(iRock).x) ELSE r(iRock).heading = RND * pi
  664.         CASE 4
  665.             r(iRock).x = rrnd(80, xmax - 80)
  666.             r(iRock).y = ymax + 100
  667.             IF RND < .25 THEN r(iRock).heading = _ATAN2(ship.y - r(iRock).y, ship.x - r(iRock).x) ELSE r(iRock).heading = pi + RND * pi
  668.     END SELECT
  669.     r(iRock).speed = rrnd(minRockSpeed, maxRockSpeed) 'speed, rotation angle, radius, gray coloring, spin, seed, hit for explosion
  670.     r(iRock).ra = RND * 2 * pi
  671.     r(iRock).r = irnd&(minRockSize * 3, maxRockSize) 'every parent rock can be split up into at least 2 - 10 size rocks
  672.     r(iRock).c = irnd&(60, 110) ' Ken request increase in rock color
  673.     r(iRock).spin = rrnd(-pi / 20, pi / 20)
  674.     r(iRock).seed = INT(RND * 64000) - 32000
  675.     r(iRock).explodeFrame = 0
  676.     r(iRock).live = 1
  677.  
  678. FUNCTION irnd& (n1, n2) 'return an integer between 2 numbers
  679.     DIM l%, h%
  680.     IF n1 > n2 THEN l% = n2: h% = n1 ELSE l% = n1: h% = n2
  681.     irnd& = INT(RND * (h% - l% + 1)) + l%
  682.  
  683. FUNCTION rrnd (n1, n2) ' return number (expecting reals =_single, double, _float depending on default / define setup)
  684.     rrnd = (n2 - n1) * RND + n1
  685.  
  686. SUB drawBall (x, y, r, c AS _UNSIGNED LONG)
  687.     DIM red AS LONG, grn AS LONG, blu AS LONG, rr AS LONG, f
  688.     red = _RED32(c): grn = _GREEN32(c): blu = _BLUE32(c)
  689.     FOR rr = r TO 0 STEP -1
  690.         f = 1 - rr / r
  691.         fcirc x, y, rr, _RGB32(red * f, grn * f, blu * f)
  692.     NEXT
  693.  
  694. SUB fellipse (CX AS LONG, CY AS LONG, xr AS LONG, yr AS LONG, C AS _UNSIGNED LONG)
  695.     IF xr = 0 OR yr = 0 THEN EXIT SUB
  696.     DIM x AS LONG, y AS LONG
  697.     w2 = xr * xr: h2 = yr * yr: h2w2 = h2 * w2
  698.     LINE (CX - xr, CY)-(CX + xr, CY), C, BF
  699.     DO WHILE y < yr
  700.         y = y + 1
  701.         x = SQR((h2w2 - y * y * w2) \ h2)
  702.         LINE (CX - x, CY + y)-(CX + x, CY + y), C, BF
  703.         LINE (CX - x, CY - y)-(CX + x, CY - y), C, BF
  704.     LOOP
  705.  
  706. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  707.     DIM D AS LONG
  708.     STATIC a&
  709.     D = _DEST
  710.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  711.     _DEST a&
  712.     _DONTBLEND a& '  '<<<< new 2019-12-16 fix
  713.     PSET (0, 0), K
  714.     _BLEND a& '<<<< new 2019-12-16 fix
  715.     _DEST D
  716.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  717.  
  718. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG) 'vince version
  719.     DIM x0 AS LONG, y0 AS LONG, e AS LONG
  720.     x0 = R: y0 = 0: e = 0
  721.     DO WHILE y0 < x0
  722.         IF e <= 0 THEN
  723.             y0 = y0 + 1
  724.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  725.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  726.             e = e + 2 * y0
  727.         ELSE
  728.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  729.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  730.             x0 = x0 - 1: e = e - 2 * x0
  731.         END IF
  732.     LOOP
  733.     LINE (x - R, y)-(x + R, y), C, BF
  734.  
  735.  

« Last Edit: November 06, 2020, 05:12:41 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #89 on: November 06, 2020, 08:29:45 pm »
I love it B+! I had to dodge the rocks before I got to a 5,000 score this time and since so many more objects are coming out at once now the score goes up faster too! I can't think of anything better. :))) Congratulations!! I also deleted my High Score from the text file so I can start over. :)
« Last Edit: November 06, 2020, 08:31:58 pm by SierraKen »