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

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: b+ Asteroids makeover
« Reply #45 on: November 02, 2020, 07:49:53 pm »
Hey, this is getting better and better! 

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #46 on: November 02, 2020, 08:36:14 pm »
@SierraKen  that's a nice effect and in space you'd never slow down, you'd need reverse thrusters. Still working on my model, I needed a power nap :)

@Dav yeah I like how the aliens turned out, the ship colors, the explosions and of course the Boulders of Death.


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #47 on: November 02, 2020, 10:30:05 pm »
OK here is my model of flying with rocket thrusters:

up arrow is forward, down reverse thrusters notice wing tips
right arrow is right thrusters notice both tips
left arrow is left thrusters agian notice both wing tips

Code: QB64: [Select]
  1. _TITLE "Thruster Tests" 'b+ 2020-11-02
  2. CONST xmax = 1024, ymax = 700, pi = _PI
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 100, 10
  5.  
  6. TYPE shipType
  7.     x AS SINGLE
  8.     y AS SINGLE
  9.     live AS LONG
  10.     speed AS SINGLE
  11.     angle AS SINGLE '   rotated position usu gun left or right (mouse button), maybe up press w or down press z
  12.     thruster AS LONG ' 1 forward, 2 reverse, 3 left , 4 right 0 none for drawing
  13.  
  14. DIM SHARED ship AS shipType
  15. ship.x = xmax / 2: ship.y = ymax / 2: ship.angle = 0
  16. WHILE _KEYDOWN(27) = 0
  17.     CLS
  18.     ship.thruster = 0 'set to zero
  19.     k$ = INKEY$
  20.     IF LEN(k$) = 2 THEN
  21.         SELECT CASE ASC(RIGHT$(k$, 1))
  22.             CASE 72 'up = forward thruster increase speed
  23.                 ship.speed = ship.speed + .1: ship.thruster = 1
  24.             CASE 80 'down = reverse thruster decrease speed yeah will will probably go negative!
  25.                 ship.speed = ship.speed - .1: ship.thruster = 2
  26.             CASE 75 'left = left thruster turn clockwise
  27.                 ship.angle = ship.angle + pi / 6: ship.thruster = 3
  28.             CASE 77 'Right = right thruster turn counter clockwise
  29.                 ship.angle = ship.angle - pi / 6: ship.thruster = 4
  30.         END SELECT
  31.     END IF
  32.     drawship
  33.     _DISPLAY
  34.     _LIMIT 60
  35.  
  36. SUB drawship 'simple red iso triangle pointed towards radianAngle
  37.     DIM x1 AS LONG, y1 AS LONG, x2 AS LONG, y2 AS LONG, x3 AS LONG, y3 AS LONG
  38.     DIM x4 AS LONG, y4 AS LONG, x5 AS LONG, y5 AS LONG, x6 AS LONG, y6 AS LONG
  39.     DIM x7 AS LONG, y7 AS LONG
  40.  
  41.     'locate ship
  42.     ship.x = ship.x + ship.speed * COS(ship.angle)
  43.     ship.y = ship.y + ship.speed * SIN(ship.angle)
  44.     IF ship.x < 0 THEN ship.x = xmax - ABS(ship.x)
  45.     IF ship.x > xmax THEN ship.x = ship.x - xmax
  46.     IF ship.y < 0 THEN ship.y = ymax - ABS(ship.y)
  47.     IF ship.y > ymax THEN ship.y = ship.y - ymax
  48.  
  49.     'calculate 3 points of triangle ship
  50.     fcirc ship.x, ship.y, 30, &H05FFFFFF
  51.     x1 = ship.x + 30 * COS(ship.angle) ' front point
  52.     y1 = ship.y + 30 * SIN(ship.angle) '
  53.     x2 = ship.x + 30 * COS(ship.angle + .6666 * pi) ' wing
  54.     y2 = ship.y + 30 * SIN(ship.angle + .6666 * pi)
  55.     x3 = ship.x + 30 * COS(ship.angle - .6666 * pi) ' other wing
  56.     y3 = ship.y + 30 * SIN(ship.angle - .6666 * pi)
  57.     ftri ship.x, ship.y, x1, y1, x2, y2, _RGB32(80, 120, 80, 80)
  58.     ftri ship.x, ship.y, x1, y1, x3, y3, _RGB32(60, 100, 60, 80)
  59.     LINE (x1, y1)-(ship.x, ship.y), _RGB32(255, 255, 128)
  60.     LINE (x1, y1)-(x2, y2), _RGB32(180, 180, 120)
  61.     LINE (x1, y1)-(x3, y3), _RGB32(180, 180, 120)
  62.  
  63.     SELECT CASE ship.thruster
  64.         CASE 1 'forward apex = ship.x, ship,y  direction = ship.angle + pi
  65.             x4 = ship.x + 25 * COS(ship.angle - 17 / 18 * pi)
  66.             y4 = ship.y + 25 * SIN(ship.angle - 17 / 18 * pi)
  67.             x5 = ship.x + 25 * COS(ship.angle - 19 / 18 * pi)
  68.             y5 = ship.y + 25 * SIN(ship.angle - 19 / 18 * pi)
  69.             ftri ship.x, ship.y, x4, y4, x5, y5, &H99FFFF88
  70.         CASE 2 'reverse apex = x1, y1
  71.             x6 = x2 + 25 * COS(ship.angle + 1 / 18 * pi)
  72.             y6 = y2 + 25 * SIN(ship.angle + 1 / 18 * pi)
  73.             x7 = x2 + 25 * COS(ship.angle - 1 / 18 * pi)
  74.             y7 = y2 + 25 * SIN(ship.angle - 1 / 18 * pi)
  75.             ftri x2, y2, x6, y6, x7, y7, &H99FFFF88
  76.  
  77.             x6 = x3 + 25 * COS(ship.angle + 1 / 18 * pi)
  78.             y6 = y3 + 25 * SIN(ship.angle + 1 / 18 * pi)
  79.             x7 = x3 + 25 * COS(ship.angle - 1 / 18 * pi)
  80.             y7 = y3 + 25 * SIN(ship.angle - 1 / 18 * pi)
  81.             ftri x3, y3, x6, y6, x7, y7, &H99FFFF88
  82.         CASE 3 'left apex = x2, y2
  83.             x6 = x3 + 25 * COS(ship.angle - 17 / 18 * pi)
  84.             y6 = y3 + 25 * SIN(ship.angle - 17 / 18 * pi)
  85.             x7 = x3 + 25 * COS(ship.angle - 19 / 18 * pi)
  86.             y7 = y3 + 25 * SIN(ship.angle - 19 / 18 * pi)
  87.             ftri x3, y3, x6, y6, x7, y7, &H99FFFF88
  88.  
  89.             x6 = x2 + 25 * COS(ship.angle + 1 / 18 * pi)
  90.             y6 = y2 + 25 * SIN(ship.angle + 1 / 18 * pi)
  91.             x7 = x2 + 25 * COS(ship.angle - 1 / 18 * pi)
  92.             y7 = y2 + 25 * SIN(ship.angle - 1 / 18 * pi)
  93.             ftri x2, y2, x6, y6, x7, y7, &H99FFFF88
  94.         CASE 4 'right
  95.             x6 = x2 + 25 * COS(ship.angle - 17 / 18 * pi)
  96.             y6 = y2 + 25 * SIN(ship.angle - 17 / 18 * pi)
  97.             x7 = x2 + 25 * COS(ship.angle - 19 / 18 * pi)
  98.             y7 = y2 + 25 * SIN(ship.angle - 19 / 18 * pi)
  99.             ftri x2, y2, x6, y6, x7, y7, &H99FFFF88
  100.  
  101.             x6 = x3 + 25 * COS(ship.angle + 1 / 18 * pi)
  102.             y6 = y3 + 25 * SIN(ship.angle + 1 / 18 * pi)
  103.             x7 = x3 + 25 * COS(ship.angle - 1 / 18 * pi)
  104.             y7 = y3 + 25 * SIN(ship.angle - 1 / 18 * pi)
  105.             ftri x3, y3, x6, y6, x7, y7, &H99FFFF88
  106.     END SELECT
  107.  
  108. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  109.     DIM D AS LONG
  110.     STATIC a&
  111.     D = _DEST
  112.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  113.     _DEST a&
  114.     _DONTBLEND a& '  '<<<< new 2019-12-16 fix
  115.     PSET (0, 0), K
  116.     _BLEND a& '<<<< new 2019-12-16 fix
  117.     _DEST D
  118.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  119.  
  120. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG) 'vince version
  121.     DIM x0 AS LONG, y0 AS LONG, e AS LONG
  122.     x0 = R: y0 = 0: e = 0
  123.     DO WHILE y0 < x0
  124.         IF e <= 0 THEN
  125.             y0 = y0 + 1
  126.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  127.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  128.             e = e + 2 * y0
  129.         ELSE
  130.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  131.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  132.             x0 = x0 - 1: e = e - 2 * x0
  133.         END IF
  134.     LOOP
  135.     LINE (x - R, y)-(x + R, y), C, BF
  136.  

Here is our rocket fuel formula: &H99FFFF88  ;-))


UPDATE: THIS IS WRONG!    Press left arrow, turn left not left thruster, right thruster!
« Last Edit: November 03, 2020, 10:41:49 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #48 on: November 02, 2020, 11:35:32 pm »
That is perfect B+! I can't wait to see it in your game!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #49 on: November 02, 2020, 11:37:52 pm »
You might need to slow down your asteroids though since your spacecraft moves slower now.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #50 on: November 02, 2020, 11:53:58 pm »
You might need to slow down your asteroids though since your spacecraft moves slower now.

You ain't kidding!!!!  Man I suck at flying rockets!  Spacebar to start next life because you will be pressing arrows when your ship dies. 

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

I swear this is turning just the wrong way press left arrow...

When I am a bird dipping my wing down left I turn counter clockwise and vice versa.

What do you bird brains think?
« Last Edit: November 03, 2020, 12:09:48 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #51 on: November 03, 2020, 12:31:40 am »
This is getting to be more real than the arcade version! I like it! You might want to speed up the moving thruster to get out of the way of asteroids quicker, but just a little bit. The turning does take a little bit getting used to since it's opposite when the ship is facing downward than it was facing upward. But to me that's just the fun of the game. And once someone adds sounds to it, it will even be more fun. I'm not sure of a different way you can make it turn, but you can experiment of course.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #52 on: November 03, 2020, 12:54:09 am »
OK try this way of turning, to me it seems better, more natural for flying (plus less rocks now and forward reverse thrusters  increased):

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

What I am saying is if I press down on left it seems natural to pivot on left and my right wing swings way around on outside circle, this is counter clockwise so the thrust really needs to be on right wing to move more. I thought right arrow = right thruster side but no, push down on left and thrust on right to swing around.

« Last Edit: November 03, 2020, 01:03:45 am by bplus »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: b+ Asteroids makeover
« Reply #53 on: November 03, 2020, 08:26:12 am »
Nice!  I like this one better using arrows to control.  Feels more like asteroids to me now. 

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #54 on: November 03, 2020, 10:22:22 am »
Nice!  I like this one better using arrows to control.  Feels more like asteroids to me now. 

- Dav

It's certainly more challenging! 

I am pretty sure I am correct, hit left button to turn left, just like with car or even airplane I imagine.
So to turn left, the right thruster must fire.

So it's not Right Arrow = Right Thruster, right?  ;-) of course not! I wonder if I was doing that with old Lander games?

Also I noticed INKEY$ getting stuck and I am not exactly able to turn on a dime so _KEYDOWN(Arrows)

So life lesson to go forward thrust from behind, to go right thrust from left. Pete might like that :-)
« Last Edit: November 03, 2020, 10:27:53 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #55 on: November 03, 2020, 02:04:35 pm »
I was going to do more with this but have my mind stuck with menu / array displays :)
Checking out new engine and instrument panel response, recalibrating numbers for _Keydown arrow detection as opposed to INKEY$ which seemed to lock up. I noticed I had to pound the right arrow key to get it to turn with the INKEY$ detection method.

Lesson #1 knowing when to stop:

Code: QB64: [Select]
  1. _TITLE "Thruster Tests #2 Flying Lessons" 'b+ 2020-11-03
  2. CONST xmax = 1024, ymax = 700, pi = _PI
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 100, 10
  5.  
  6.  
  7. TYPE shipType
  8.     x AS SINGLE
  9.     y AS SINGLE
  10.     live AS LONG
  11.     speed AS SINGLE
  12.     angle AS SINGLE '   rotated position usu gun left or right (mouse button), maybe up press w or down press z
  13.     thruster AS LONG ' 1 forward, 2 reverse, 3 left , 4 right 0 none for drawing
  14.  
  15. DIM SHARED ship AS shipType
  16. ship.x = xmax / 2: ship.y = ymax / 2: ship.angle = 0
  17. WHILE _KEYDOWN(27) = 0
  18.     CLS
  19.     PRINT "The first lesson is seeing how fast you can go without getting close to borders."
  20.     PRINT "In b+ Asteroids borders are where new Asteroids arrive that you can't see coming."
  21.     PRINT "I learn we need a button for full stop! use spacebar?"
  22.     ' Instruments Panel
  23.     ship.thruster = 0 'set to zero   thruster signals drawShip to show exhaust at certain points
  24.  
  25.     ' Imagine ship pointed up for following code
  26.  
  27.     'Up arrow = forward so back thruster
  28.     IF _KEYDOWN(18432) THEN ship.speed = ship.speed + .1: ship.thruster = 1
  29.  
  30.     'Down arrow = reverse thruster decrease speed yeah will will probably go negative!
  31.     IF _KEYDOWN(20480) THEN ship.speed = ship.speed - .1: ship.thruster = 2
  32.  
  33.     'Left Arrow = right thruster turn clockwise  or pivot on left wing tip
  34.     IF _KEYDOWN(19200) THEN ship.angle = ship.angle - pi / 48: ship.thruster = 4
  35.  
  36.     'Right arrow = left thruster turn counter clockwise   or pivot of right wing tip
  37.     IF _KEYDOWN(19712) THEN ship.angle = ship.angle + pi / 48: ship.thruster = 3
  38.  
  39.     IF _KEYDOWN(32) THEN ship.speed = 0
  40.  
  41.     drawship
  42.     _DISPLAY
  43.     _LIMIT 60 ' same as Asteroids Game
  44.  
  45. SUB drawship 'simple red iso triangle pointed towards radianAngle
  46.     DIM x1 AS LONG, y1 AS LONG, x2 AS LONG, y2 AS LONG, x3 AS LONG, y3 AS LONG
  47.     DIM x4 AS LONG, y4 AS LONG, x5 AS LONG, y5 AS LONG, x6 AS LONG, y6 AS LONG
  48.     DIM x7 AS LONG, y7 AS LONG
  49.  
  50.     'locate ship
  51.     ship.x = ship.x + ship.speed * COS(ship.angle)
  52.     ship.y = ship.y + ship.speed * SIN(ship.angle)
  53.     IF ship.x < 0 THEN ship.x = xmax - ABS(ship.x)
  54.     IF ship.x > xmax THEN ship.x = ship.x - xmax
  55.     IF ship.y < 0 THEN ship.y = ymax - ABS(ship.y)
  56.     IF ship.y > ymax THEN ship.y = ship.y - ymax
  57.  
  58.     'calculate 3 points of triangle ship
  59.     fcirc ship.x, ship.y, 30, &H05FFFFFF
  60.     x1 = ship.x + 30 * COS(ship.angle) ' front point
  61.     y1 = ship.y + 30 * SIN(ship.angle) '
  62.     x2 = ship.x + 30 * COS(ship.angle + .6666 * pi) ' wing
  63.     y2 = ship.y + 30 * SIN(ship.angle + .6666 * pi)
  64.     x3 = ship.x + 30 * COS(ship.angle - .6666 * pi) ' other wing
  65.     y3 = ship.y + 30 * SIN(ship.angle - .6666 * pi)
  66.     ftri ship.x, ship.y, x1, y1, x2, y2, _RGB32(80, 120, 80, 80)
  67.     ftri ship.x, ship.y, x1, y1, x3, y3, _RGB32(60, 100, 60, 80)
  68.     LINE (x1, y1)-(ship.x, ship.y), _RGB32(255, 255, 128)
  69.     LINE (x1, y1)-(x2, y2), _RGB32(180, 180, 120)
  70.     LINE (x1, y1)-(x3, y3), _RGB32(180, 180, 120)
  71.  
  72.     SELECT CASE ship.thruster
  73.         CASE 1 'forward apex = ship.x, ship,y  direction = ship.angle + pi
  74.             x4 = ship.x + 25 * COS(ship.angle - 17 / 18 * pi)
  75.             y4 = ship.y + 25 * SIN(ship.angle - 17 / 18 * pi)
  76.             x5 = ship.x + 25 * COS(ship.angle - 19 / 18 * pi)
  77.             y5 = ship.y + 25 * SIN(ship.angle - 19 / 18 * pi)
  78.             ftri ship.x, ship.y, x4, y4, x5, y5, &H99FFFF88
  79.         CASE 2 'reverse apex = x1, y1
  80.             x6 = x2 + 25 * COS(ship.angle + 1 / 18 * pi)
  81.             y6 = y2 + 25 * SIN(ship.angle + 1 / 18 * pi)
  82.             x7 = x2 + 25 * COS(ship.angle - 1 / 18 * pi)
  83.             y7 = y2 + 25 * SIN(ship.angle - 1 / 18 * pi)
  84.             ftri x2, y2, x6, y6, x7, y7, &H99FFFF88
  85.  
  86.             x6 = x3 + 25 * COS(ship.angle + 1 / 18 * pi)
  87.             y6 = y3 + 25 * SIN(ship.angle + 1 / 18 * pi)
  88.             x7 = x3 + 25 * COS(ship.angle - 1 / 18 * pi)
  89.             y7 = y3 + 25 * SIN(ship.angle - 1 / 18 * pi)
  90.             ftri x3, y3, x6, y6, x7, y7, &H99FFFF88
  91.         CASE 3 'left apex = x2, y2
  92.             x6 = x3 + 25 * COS(ship.angle - 17 / 18 * pi)
  93.             y6 = y3 + 25 * SIN(ship.angle - 17 / 18 * pi)
  94.             x7 = x3 + 25 * COS(ship.angle - 19 / 18 * pi)
  95.             y7 = y3 + 25 * SIN(ship.angle - 19 / 18 * pi)
  96.             ftri x3, y3, x6, y6, x7, y7, &H99FFFF88
  97.  
  98.         CASE 4 'right
  99.             x6 = x2 + 25 * COS(ship.angle - 17 / 18 * pi)
  100.             y6 = y2 + 25 * SIN(ship.angle - 17 / 18 * pi)
  101.             x7 = x2 + 25 * COS(ship.angle - 19 / 18 * pi)
  102.             y7 = y2 + 25 * SIN(ship.angle - 19 / 18 * pi)
  103.             ftri x2, y2, x6, y6, x7, y7, &H99FFFF88
  104.     END SELECT
  105.  
  106. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  107.     DIM D AS LONG
  108.     STATIC a&
  109.     D = _DEST
  110.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  111.     _DEST a&
  112.     _DONTBLEND a& '  '<<<< new 2019-12-16 fix
  113.     PSET (0, 0), K
  114.     _BLEND a& '<<<< new 2019-12-16 fix
  115.     _DEST D
  116.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  117.  
  118. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG) 'vince version
  119.     DIM x0 AS LONG, y0 AS LONG, e AS LONG
  120.     x0 = R: y0 = 0: e = 0
  121.     DO WHILE y0 < x0
  122.         IF e <= 0 THEN
  123.             y0 = y0 + 1
  124.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  125.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  126.             e = e + 2 * y0
  127.         ELSE
  128.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  129.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  130.             x0 = x0 - 1: e = e - 2 * x0
  131.         END IF
  132.     LOOP
  133.     LINE (x - R, y)-(x + R, y), C, BF
  134.  
  135.  
« Last Edit: November 03, 2020, 02:43:33 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: b+ Asteroids makeover
« Reply #56 on: November 03, 2020, 04:10:07 pm »
I love the new turning on this. Yes, Space Bar would be a nice automatic stop. I was also thinking, this full version above would be a good Beginner or Easy difficulty because I could play this almost for hours on the same game. In the beginning you could have Easy, Medium, or Hard and have this one for Easy and then increase the amount of asteroids for Medium and Hard. I noticed that the hardest part is trying to see the darkest asteroids. I would make the darkest asteroids a little lighter color, but that's just me. Anyway, I don't mean to be so critical on this game though, just some ideas. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #57 on: November 03, 2020, 05:28:10 pm »
Roger that, next version I will lighten the rocks (I noticed same).

Thanks @SierraKen  comments, ideas, experiences always welcome! :) I specially appreciate experiences from arcades.

 

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: b+ Asteroids makeover
« Reply #58 on: November 03, 2020, 06:30:31 pm »
I like the new turning too.  Really smooth now.  Nice to have a stop button.  If I remember the old arcade version right (I should, I spent a lot of money playing it), the only way to stop moving forward and slow down was to turn the ship around and thrust the other way. 

Funny, what I remember most about the original was the repeating sound that got faster and faster as the level advanced and the enemy ufo attacked, which sometimes made me nervous and mess up .  I'd guess the programmer got that idea from the "jaws" movie which had that chromatic suspense music when the shark attacked. Very effective.

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: b+ Asteroids makeover
« Reply #59 on: November 03, 2020, 07:23:22 pm »
Oh yeah Jaws! that would be great!

But there was no reverse thrusters in Asteroids?  I am going to watch more videos of this game.

You know allot of times at startup of a new life I wished it was already going forward and I didn't have to worry so much about forward speeds so I could concentrate of steering.

They say sharks have to be constantly moving to breath and birds have to be constantly moving to fly, maybe instead of full stop just a return to a slow constant forward speed?