QB64.org Forum

Active Forums => Programs => Topic started by: bplus on July 13, 2018, 11:18:30 pm

Title: eRATication
Post by: bplus on July 13, 2018, 11:18:30 pm
Astroids inspired, though I did similar in SmallBASIC with plasma ray shooter.

Code: QB64: [Select]
  1. _TITLE "eRATication by bplus 2018-07-13"
  2. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  3.  
  4. ' 2018-07-13 modified from Asteroids game
  5.  
  6. 'screen dimensions
  7. CONST xmax = 1200
  8. CONST ymax = 700
  9.  
  10. pi = _PI
  11.  
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. _SCREENMOVE 100, 20
  14.  
  15. CONST nRats = 100
  16. CONST nBullets = 1000
  17. CONST bSpeed = 20
  18.  
  19. 'r for rat prefix have x, y location, r for radius, h for heading, s for speed, k for kolor
  20. DIM SHARED rx(nRats), ry(nRats), rr(nRats), rh(nRats), rs(nRats), rk(nRats) AS _UNSIGNED LONG
  21. DIM SHARED shooterAngle, shooterX, shooterY, life, points
  22. 'b prefix for bullet, x, y, dx, dy, a for active
  23. DIM SHARED bx(nBullets), by(nBullets), bdx(nBullets), bdy(nBullets), ba(nBullets)
  24. points = 0
  25. FOR i = 1 TO 100
  26.     newRat i
  27. life = 1
  28. shooterX = xmax / 2: shooterY = ymax / 2
  29. rats = 5
  30. shooterAngle = 0
  31. WHILE life <= 3
  32.     CLS
  33.     FOR i = 1 TO life * rats 'the rats
  34.         drawRat i
  35.     NEXT
  36.  
  37.     '    _KEYDOWN WORKS NICE!!!!
  38.     'use arrow keys to swing shooter, spacebar to fire
  39.     IF _KEYDOWN(19200) THEN shooterAngle = shooterAngle - _PI(1 / 60)
  40.     IF _KEYDOWN(19712) THEN shooterAngle = shooterAngle + _PI(1 / 60)
  41.     IF _KEYDOWN(18432) OR _KEYDOWN(20480) THEN shooterAngle = shooterAngle + _PI(1 / 30)
  42.     IF _KEYDOWN(32) THEN fire = 1 ELSE fire = 0
  43.     drawshooter xmax / 2, ymax / 2, shooterAngle
  44.  
  45.     'handle bullets
  46.     FOR i = 0 TO nBullets
  47.         IF ba(i) = 0 AND fire = 1 THEN 'have in active bullet index to use
  48.             bx(i) = shooterX + 3 * bSpeed * COS(shooterAngle)
  49.             by(i) = shooterY + 3 * bSpeed * SIN(shooterAngle)
  50.             bdx(i) = bSpeed * COS(shooterAngle)
  51.             bdy(i) = bSpeed * SIN(shooterAngle)
  52.             ba(i) = 1
  53.             fire = 0
  54.         END IF
  55.         IF ba(i) = 1 THEN 'new location
  56.             bx(i) = bx(i) + bdx(i)
  57.             by(i) = by(i) + bdy(i)
  58.             IF bx(i) > 0 AND bx(i) < xmax AND by(i) > 0 AND by(i) < ymax THEN 'in bounds draw it
  59.                 'check for collision with rock
  60.                 FOR r = 1 TO rats * life
  61.                     IF ((rx(r) - bx(i)) ^ 2 + (ry(r) - by(i)) ^ 2) ^ .5 < .75 * rr(r) THEN
  62.                         FOR rad = 1 TO rr(r)
  63.                             fcirc rx(r), ry(r), rad, _RGB32(255 - rad, 128 - rad, 0)
  64.                             _DISPLAY
  65.                         NEXT
  66.                         points = points + life ^ life
  67.                         _TITLE "Rats Hit:" + STR$(points) + "   Life #" + STR$(life)
  68.                         _DISPLAY
  69.                         newRat r
  70.                         ba(i) = 0
  71.                     ELSE
  72.                         fcirc bx(i), by(i), 2, _RGB32(255, 255, 0)
  73.                     END IF
  74.                 NEXT
  75.             ELSE
  76.                 ba(i) = 0
  77.             END IF
  78.         END IF
  79.     NEXT
  80.     _DISPLAY
  81.     _LIMIT 30
  82.  
  83. SUB drawshooter (x, y, radianAngle) 'simple red iso triangle pointed towards radianAngle
  84.     'calculate 3 points of triangle shooter
  85.     x1 = x + 60 * COS(radianAngle) 'main point of shooter according to heading
  86.     y1 = y + 60 * SIN(radianAngle)
  87.     x2 = x + 30 * COS(radianAngle + _PI(2 / 3)) 'next two points are 120 degrees off main point in direction
  88.     y2 = y + 30 * SIN(radianAngle + _PI(2 / 3))
  89.     x3 = x + 30 * COS(radianAngle - _PI(2 / 3))
  90.     y3 = y + 30 * SIN(radianAngle - _PI(2 / 3))
  91.     fTri x, y, x1, y1, x2, y2, _RGB(255, 0, 0)
  92.     fTri x, y, x1, y1, x3, y3, _RGB(255, 0, 0)
  93.     ln x1, y1, x2, y2, _RGB32(255, 255, 128)
  94.     ln x1, y1, x3, y3, _RGB32(255, 255, 128)
  95.     ln x1, y1, x, y, _RGB32(255, 255, 128)
  96.  
  97. SUB drawRat (i)
  98.     rx(i) = rx(i) + rs(i) * COS(rh(i) + RND * _PI(rand(-5, 5) / 10))
  99.     ry(i) = ry(i) + rs(i) * SIN(rh(i) + RND * _PI(rand(-5, 5) / 10))
  100.     'rat collides with shooter?
  101.     IF ((rx(i) - shooterX) ^ 2 + (ry(i) - shooterY) ^ 2) ^ .5 < rr(i) + 20 THEN
  102.         FOR rad = 1 TO 200
  103.             fcirc shooterX, shooterY, rad, _RGB32(255 - rad, 255 - 2 * rad, 0)
  104.             _DISPLAY
  105.             _LIMIT 300
  106.         NEXT
  107.         life = life + 1
  108.         IF life <= 3 THEN
  109.             _TITLE "Rats Hit:" + STR$(points) + "   Life #" + STR$(life)
  110.         ELSE
  111.             _TITLE "Rats Hit:" + STR$(points) + " THE END"
  112.         END IF
  113.         _DISPLAY
  114.         newRat i
  115.         EXIT SUB
  116.     END IF
  117.     IF rx(i) > 0 AND rx(i) < xmax AND ry(i) > 0 AND ry(i) < ymax THEN
  118.         noseX = rx(i) + 2 * rr(i) * COS(rh(i))
  119.         noseY = ry(i) + 2 * rr(i) * SIN(rh(i))
  120.         neckX = rx(i) + .75 * rr(i) * COS(rh(i))
  121.         neckY = ry(i) + .75 * rr(i) * SIN(rh(i))
  122.         tailX = rx(i) + 2 * rr(i) * COS(rh(i) + _PI)
  123.         tailY = ry(i) + 2 * rr(i) * SIN(rh(i) + _PI)
  124.         earLX = rx(i) + rr(i) * COS(rh(i) - _PI(1 / 12))
  125.         earLY = ry(i) + rr(i) * SIN(rh(i) - _PI(1 / 12))
  126.         earRX = rx(i) + rr(i) * COS(rh(i) + _PI(1 / 12))
  127.         earRY = ry(i) + rr(i) * SIN(rh(i) + _PI(1 / 12))
  128.         fcirc rx(i), ry(i), .65 * rr(i), rk(i)
  129.         fcirc neckX, neckY, rr(i) * .3, rk(i)
  130.         fTri noseX, noseY, earLX, earLY, earRX, earRY, rk(i)
  131.         fcirc earLX, earLY, rr(i) * .3, rk(i)
  132.         fcirc earRX, earRY, rr(i) * .3, rk(i)
  133.         wX = .5 * rr(i) * COS(rh(i) - _PI(11 / 18))
  134.         wY = .5 * rr(i) * SIN(rh(i) - _PI(11 / 18))
  135.         ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, rk(i)
  136.         wX = .5 * rr(i) * COS(rh(i) - _PI(7 / 18))
  137.         wY = .5 * rr(i) * SIN(rh(i) - _PI(7 / 18))
  138.         ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, rk(i)
  139.         ln rx(i), ry(i), tailX, tailY, rk(i)
  140.     ELSE
  141.         newRat i
  142.     END IF
  143.  
  144. SUB newRat (iRat)
  145.     'bring rock in from one side, need to set heading according to side
  146.     'RANDOMIZE TIMER + RND
  147.     side = rand(1, 4)
  148.     SELECT CASE side
  149.         CASE 1: rx(iRat) = 0: ry(iRat) = RND * ymax: rh(iRat) = 3 * pi / 2 + RND * pi
  150.         CASE 2: rx(iRat) = xmax: ry(iRat) = RND * ymax: rh(iRat) = pi / 2 + RND * pi
  151.         CASE 3: rx(iRat) = RND * xmax: ry(iRat) = 0: rh(iRat) = RND * pi
  152.         CASE 4: rx(iRat) = RND * xmax: ry(iRat) = ymax: rh(iRat) = pi + RND * pi
  153.     END SELECT
  154.     'speed, angle, radius, gray coloring, spin, seed
  155.     rs(iRat) = RND * 5 * life + 1
  156.     rr(iRat) = RND * 55 + 15
  157.     r = rand(60, 255)
  158.     rk(iRat) = _RGB32(r, .9 * r, .8 * r)
  159.  
  160. FUNCTION rand% (lo%, hi%)
  161.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  162.  
  163. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  164. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  165.     a& = _NEWIMAGE(1, 1, 32)
  166.     _DEST a&
  167.     PSET (0, 0), K
  168.     _DEST 0
  169.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  170.     _FREEIMAGE a& '<<< this is important!
  171.  
  172. SUB ln (x1, y1, x2, y2, K AS _UNSIGNED LONG) 'box frame
  173.     LINE (x1, y1)-(x2, y2), K
  174.  
  175. 'vince version
  176. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  177.     x0 = R
  178.     y0 = 0
  179.     e = 0
  180.     DO WHILE y0 < x0
  181.         IF e <= 0 THEN
  182.             y0 = y0 + 1
  183.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  184.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  185.             e = e + 2 * y0
  186.         ELSE
  187.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  188.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  189.             x0 = x0 - 1
  190.             e = e - 2 * x0
  191.         END IF
  192.     LOOP
  193.     LINE (x - R, y)-(x + R, y), C, BF
  194.  
  195.  
Title: Re: eRATication
Post by: bplus on July 14, 2018, 07:23:21 am
Code: QB64: [Select]
  1. I ran your program (called it ratgame.bas) and defeated it by holding down UpArrow and Space and
  2. let it run indefinitely and killed 100s of rats..
  3.  
  4. Erik.
  5.  

Yeah, not exactly meant to be a game of skill... ;)

Life #1 easy peasy, 1 point per rat
Life #2 might work up a sweat, 4 points per rat
Life #3 Ha! 27 points per rat
Title: Re: eRATication
Post by: bplus on July 14, 2018, 07:33:17 am
Yeah, so you CAN play this like a game of skill and try to kill one rat with one shot (or burst) PLUS you can just hose the rats off screen, very satisfying like popping bubble wrap. I won't judge which way you try. ;)
Title: Re: eRATication
Post by: Petr on July 14, 2018, 02:18:17 pm
Nice work! :-D
Title: Re: eRATication
Post by: bplus on July 15, 2018, 09:01:48 am
Thanks Petr, thanks to Erik's feedback, I hope to add a rat palette and track life/death of each rat so as to not delay action when one is hit. Perhaps if I just leave out poisoned cheese, no shooting would be necessary. ;D
Title: Re: eRATication
Post by: Petr on July 15, 2018, 09:06:20 am
Bplus, I'll come to see TJP behind you and Erik. 
Title: Re: eRATication
Post by: bplus on July 15, 2018, 02:37:56 pm
Hi Petr,

I can keep you updated here.

Here is improvements suggested by Erik PLUS I made life #3 even harder to survive. ;D

Code: QB64: [Select]
  1. _TITLE "eRATication no 2 by bplus 2018-07-15"
  2. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  3.  
  4. ' 2018-07-13 modified from Asteroids game
  5. ' 2018-07-15 eRATication 2
  6. ' color rats, eliminate jerks when kill rat,
  7. ' decrease rat size as life progresses
  8.  
  9. 'screen dimensions
  10. CONST xmax = 1200
  11. CONST ymax = 700
  12.  
  13. pi = _PI
  14.  
  15. SCREEN _NEWIMAGE(xmax, ymax, 32)
  16. _SCREENMOVE 100, 20
  17.  
  18. CONST nRats = 100
  19. CONST nBullets = 1000
  20. CONST bSpeed = 20
  21.  
  22. 'r for rat prefix have x, y location, r for radius, h for heading, s for speed, k for kolor
  23. DIM SHARED rx(nRats), ry(nRats), rr(nRats), rh(nRats), rs(nRats), rdead(nRats), rk(nRats) AS _UNSIGNED LONG
  24. DIM SHARED shooterAngle, shooterX, shooterY, life, points, walk
  25. 'b prefix for bullet, x, y, dx, dy, a for active
  26. DIM SHARED bx(nBullets), by(nBullets), bdx(nBullets), bdy(nBullets), ba(nBullets)
  27.  
  28. life = 1
  29. rats = 5
  30. points = 0
  31. shooterAngle = 0
  32. shooterX = xmax / 2
  33. shooterY = ymax / 2
  34. FOR i = 0 TO nRats - 1
  35.     newRat i
  36. WHILE life <= 3
  37.     CLS , _RGB32(188, 178, 168)
  38.     walk = (walk + 1) MOD 2
  39.     FOR i = 1 TO life * rats 'the rats
  40.         drawRat i
  41.     NEXT
  42.  
  43.     '    _KEYDOWN WORKS NICE!!!!
  44.     'use arrow keys to swing shooter, spacebar to fire
  45.     IF _KEYDOWN(19200) THEN shooterAngle = shooterAngle - _PI(1 / 60)
  46.     IF _KEYDOWN(19712) THEN shooterAngle = shooterAngle + _PI(1 / 60)
  47.     IF _KEYDOWN(18432) OR _KEYDOWN(20480) THEN shooterAngle = shooterAngle + _PI(1 / 30)
  48.     IF _KEYDOWN(32) THEN fire = 1 ELSE fire = 0
  49.     drawshooter xmax / 2, ymax / 2, shooterAngle
  50.  
  51.     'handle bullets
  52.     FOR i = 0 TO nBullets
  53.         IF ba(i) = 0 AND fire = 1 THEN 'have in active bullet index to use
  54.             bx(i) = shooterX + 3 * bSpeed * COS(shooterAngle)
  55.             by(i) = shooterY + 3 * bSpeed * SIN(shooterAngle)
  56.             bdx(i) = bSpeed * COS(shooterAngle)
  57.             bdy(i) = bSpeed * SIN(shooterAngle)
  58.             ba(i) = 1
  59.             fire = 0
  60.         END IF
  61.         IF ba(i) = 1 THEN 'new location
  62.             bx(i) = bx(i) + bdx(i)
  63.             by(i) = by(i) + bdy(i)
  64.             IF bx(i) > 0 AND bx(i) < xmax AND by(i) > 0 AND by(i) < ymax THEN 'in bounds draw it
  65.                 'check for collision with rock
  66.                 FOR r = 0 TO rats * life
  67.                     IF ((rx(r) - bx(i)) ^ 2 + (ry(r) - by(i)) ^ 2) ^ .5 < .75 * rr(r) THEN
  68.                         IF rdead(r) = 0 THEN
  69.                             rdead(r) = 1
  70.                             points = points + life ^ life
  71.                             _TITLE "Rats Hit:" + STR$(points) + "   Life #" + STR$(life)
  72.                             ba(i) = 0
  73.                         END IF
  74.                     ELSE
  75.                         fcirc bx(i), by(i), 2, _RGB32(30, 60, 80)
  76.                     END IF
  77.                 NEXT
  78.             ELSE
  79.                 ba(i) = 0
  80.             END IF
  81.         END IF
  82.     NEXT
  83.     _DISPLAY
  84.     _LIMIT 30
  85. _DELAY 5 'so don't start printing spaces in the editor
  86.  
  87. SUB drawshooter (x, y, radianAngle) 'simple red iso triangle pointed towards radianAngle
  88.     'calculate 3 points of triangle shooter
  89.     x1 = x + 60 * COS(radianAngle) 'main point of shooter according to heading
  90.     y1 = y + 60 * SIN(radianAngle)
  91.     x2 = x + 30 * COS(radianAngle + _PI(2 / 3)) 'next two points are 120 degrees off main point in direction
  92.     y2 = y + 30 * SIN(radianAngle + _PI(2 / 3))
  93.     x3 = x + 30 * COS(radianAngle - _PI(2 / 3))
  94.     y3 = y + 30 * SIN(radianAngle - _PI(2 / 3))
  95.     fTri x, y, x1, y1, x2, y2, _RGB(255, 0, 0)
  96.     fTri x, y, x1, y1, x3, y3, _RGB(255, 0, 0)
  97.     ln x1, y1, x2, y2, _RGB32(255, 255, 128)
  98.     ln x1, y1, x3, y3, _RGB32(255, 255, 128)
  99.     ln x1, y1, x, y, _RGB32(255, 255, 128)
  100.  
  101. SUB drawRat (i)
  102.     IF rdead(i) = 0 THEN 'if rat not dead move it
  103.         rx(i) = rx(i) + rs(i) * COS(rh(i)) + rand(-.1 * rr(i), .1 * rr(i))
  104.         ry(i) = ry(i) + rs(i) * SIN(rh(i)) + rand(-.1 * rr(i), .1 * rr(i))
  105.     END IF
  106.  
  107.     'rat collides with shooter?
  108.     IF ((rx(i) - shooterX) ^ 2 + (ry(i) - shooterY) ^ 2) ^ .5 < rr(i) + 20 THEN
  109.         FOR rad = 1 TO 350
  110.             fcirc shooterX, shooterY, rad, _RGB32(255 - .25 * rad, 128 - .125 * rad, 0)
  111.             _DISPLAY
  112.             _LIMIT 300
  113.         NEXT
  114.         life = life + 1
  115.         'new set o rats
  116.         FOR i = 0 TO nRats - 1
  117.             newRat i
  118.         NEXT
  119.         IF life <= 3 THEN
  120.             _TITLE "Rats Hit:" + STR$(points) + "   Life #" + STR$(life)
  121.         ELSE
  122.             _TITLE "Rats Hit:" + STR$(points) + " THE END"
  123.             _DELAY 5 'so don't start printing spaces in the editor
  124.             END
  125.         END IF
  126.         _DISPLAY
  127.         EXIT SUB
  128.     END IF
  129.  
  130.     IF rx(i) > 0 AND rx(i) < xmax AND ry(i) > 0 AND ry(i) < ymax THEN 'inbounds
  131.         IF rdead(i) THEN 'show the burn out until reaches rat radius
  132.             rdead(i) = rdead(i) + 2
  133.             IF rdead(i) < rr(i) THEN
  134.                 fcirc rx(i), ry(i), rr(i) - rdead(i), _RGB32(255 - rdead(i), 128 - rdead(i), 0)
  135.                 _DISPLAY
  136.             ELSE
  137.                 newRat i
  138.             END IF
  139.         ELSE
  140.             noseX = rx(i) + 2 * rr(i) * COS(rh(i))
  141.             noseY = ry(i) + 2 * rr(i) * SIN(rh(i))
  142.             neckX = rx(i) + .75 * rr(i) * COS(rh(i))
  143.             neckY = ry(i) + .75 * rr(i) * SIN(rh(i))
  144.             tailX = rx(i) + 2 * rr(i) * COS(rh(i) + _PI)
  145.             tailY = ry(i) + 2 * rr(i) * SIN(rh(i) + _PI)
  146.             earLX = rx(i) + rr(i) * COS(rh(i) - _PI(1 / 12))
  147.             earLY = ry(i) + rr(i) * SIN(rh(i) - _PI(1 / 12))
  148.             earRX = rx(i) + rr(i) * COS(rh(i) + _PI(1 / 12))
  149.             earRY = ry(i) + rr(i) * SIN(rh(i) + _PI(1 / 12))
  150.             fcirc rx(i), ry(i), .65 * rr(i), rk(i)
  151.             fcirc neckX, neckY, rr(i) * .3, rk(i)
  152.             fTri noseX, noseY, earLX, earLY, earRX, earRY, rk(i)
  153.             fcirc earLX, earLY, rr(i) * .3, rk(i)
  154.             fcirc earRX, earRY, rr(i) * .3, rk(i)
  155.             wX = .5 * rr(i) * COS(rh(i) - _PI(11 / 18))
  156.             wY = .5 * rr(i) * SIN(rh(i) - _PI(11 / 18))
  157.             ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, rk(i)
  158.             wX = .5 * rr(i) * COS(rh(i) - _PI(7 / 18))
  159.             wY = .5 * rr(i) * SIN(rh(i) - _PI(7 / 18))
  160.             ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, rk(i)
  161.             ln rx(i), ry(i), tailX, tailY, rk(i)
  162.         END IF
  163.     ELSE 'out of bounds
  164.         newRat i
  165.     END IF
  166.  
  167. SUB newRat (iRat)
  168.     'bring rock in from one side, need to set heading according to side
  169.     'RANDOMIZE TIMER + RND
  170.     side = rand(1, 4)
  171.     SELECT CASE side
  172.         CASE 1: rx(iRat) = 0: ry(iRat) = RND * ymax: rh(iRat) = 3 * pi / 2 + RND * pi
  173.         CASE 2: rx(iRat) = xmax: ry(iRat) = RND * ymax: rh(iRat) = pi / 2 + RND * pi
  174.         CASE 3: rx(iRat) = RND * xmax: ry(iRat) = 0: rh(iRat) = RND * pi
  175.         CASE 4: rx(iRat) = RND * xmax: ry(iRat) = ymax: rh(iRat) = pi + RND * pi
  176.     END SELECT
  177.     'speed, angle, radius, gray coloring, spin, seed
  178.     rs(iRat) = RND * 5 * life + 1
  179.     rr(iRat) = RND * 60 / life + 10
  180.     rdead(iRat) = 0
  181.     rk(iRat) = ratKolor~&
  182.  
  183. FUNCTION ratKolor~& ()
  184.     r% = INT(RND * 140)
  185.     g% = rand(INT(.5 * r%), INT(.8 * r%))
  186.     b% = rand(INT(.5 * g%), INT(.8 * g%))
  187.     ratKolor~& = _RGB32(r%, g%, b%)
  188.  
  189. FUNCTION rand% (lo%, hi%)
  190.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  191.  
  192. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  193. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  194.     a& = _NEWIMAGE(1, 1, 32)
  195.     _DEST a&
  196.     PSET (0, 0), K
  197.     _DEST 0
  198.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  199.     _FREEIMAGE a& '<<< this is important!
  200.  
  201. SUB ln (x1, y1, x2, y2, K AS _UNSIGNED LONG) 'box frame
  202.     LINE (x1, y1)-(x2, y2), K
  203.  
  204. 'vince version
  205. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  206.     x0 = R
  207.     y0 = 0
  208.     e = 0
  209.     DO WHILE y0 < x0
  210.         IF e <= 0 THEN
  211.             y0 = y0 + 1
  212.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  213.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  214.             e = e + 2 * y0
  215.         ELSE
  216.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  217.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  218.             x0 = x0 - 1
  219.             e = e - 2 * x0
  220.         END IF
  221.     LOOP
  222.     LINE (x - R, y)-(x + R, y), C, BF
  223.  
  224.  
Title: Re: eRATication
Post by: bplus on July 15, 2018, 02:53:05 pm
better gun action with arrows keys:
Code: QB64: [Select]
  1.     '    _KEYDOWN WORKS NICE!!!!
  2.     'use arrow keys to swing shooter, spacebar to fire
  3.     IF _KEYDOWN(19200) THEN shooterAngle = shooterAngle - _PI(1 / 60)
  4.     IF _KEYDOWN(19712) THEN shooterAngle = shooterAngle + _PI(1 / 60)
  5.     IF _KEYDOWN(18432) THEN shooterAngle = shooterAngle - _PI(1 / 20)
  6.     IF _KEYDOWN(20480) THEN shooterAngle = shooterAngle + _PI(1 / 20)
  7.     IF _KEYDOWN(32) THEN fire = 1 ELSE fire = 0
  8.     drawshooter xmax / 2, ymax / 2, shooterAngle
  9.  

fast and slow swing both ways.
Title: Re: eRATication
Post by: Petr on July 15, 2018, 05:36:58 pm
Nice! Strategy if i spin to right, is reliable, but small mice i have to shoot straight, they are monsters :-D
Title: Re: eRATication
Post by: johnno56 on July 15, 2018, 05:46:25 pm
Oh. You noticed THAT too? Those sneaky little mongrels! You shoot at them with a hail of bullets, but NO, they're small enough to avoid getting hit and then "stab you in the back" when you least expect it!

B+. You have a mean streak within you. Clever but mean! lol

J
Title: Re: eRATication
Post by: Ashish on July 16, 2018, 03:55:18 am
Nice game, bplus! Here's my highscore in the attachment.
Title: Re: eRATication
Post by: bplus on July 16, 2018, 09:04:53 am
Thanks guys! your comments have me smiling and laughing.

Erik has done some interesting mods at TJP, slowing the bullet speed but doubling the bullets. He also has overridden the max life # of 3 to 10 input at the beginning of the game. He also is tracking high score adding a comma delimited score. Is he optimistic or what? ;)   PLUS he is storing high scores to file using _STARTDIR$ keyword for current directory.

So up to 10 lives! ? He allows.

Let's take a closer look at how a new rat is started, Johnno you might get some ideas about taking the edge off my cruel streak. ;)
Code: QB64: [Select]
  1. SUB newRat (iRat)
  2.     'bring rock in from one side, need to set heading according to side
  3.     'RANDOMIZE TIMER + RND
  4.     side = rand(1, 4)
  5.     SELECT CASE side
  6.         CASE 1: rx(iRat) = 0: ry(iRat) = RND * ymax: rh(iRat) = 3 * pi / 2 + RND * pi
  7.         CASE 2: rx(iRat) = xmax: ry(iRat) = RND * ymax: rh(iRat) = pi / 2 + RND * pi
  8.         CASE 3: rx(iRat) = RND * xmax: ry(iRat) = 0: rh(iRat) = RND * pi
  9.         CASE 4: rx(iRat) = RND * xmax: ry(iRat) = ymax: rh(iRat) = pi + RND * pi
  10.     END SELECT
  11.     'speed, angle, radius, gray coloring, spin, seed
  12.     rs(iRat) = RND * 5 * life + 1    '<<<<<<<<<<<<<<<<<<<<<< rat speed is set here and adjusted according to life #
  13.     rr(iRat) = RND * 60 / life + 10 ' <<<<<<<<<<<<<<<<<<<<<< rat radius or size of rat is set here and also adjusted according to life #
  14.     rdead(iRat) = 0
  15.     rk(iRat) = ratKolor~&
  16.  

With a range of life from 1 to 10 as Erik has it, rat speeds will vary from 1 to 6 in life #1 and 1 to 51 in life #10.   51!!!! Yikes!
With a range of life from 1 to 10 as Erik has it, rat radii will vary from 10 to 70 in life #1 and 10 to 16 in life #10

And the number of rats is 5 * life so start with 5 in life #1 and could go as high as 50 in life # 10.

I think if you really want to get into point systems if you are taking trouble to store High scores:
1. You should make a table for High Scores depending on the life # you choose to play.
2. You might start getting deductions for wasteful use of bullets ie skill starts to be factored into score.

Oh BTW if you are in life #10 and kill a rat that is worth 10 ^ 10 points! No wonder Erik starts to need a comma delimited score!
Title: Re: eRATication
Post by: FellippeHeitor on July 16, 2018, 11:03:21 am
Very fun to play, bplus!

You may consider using the main canvas to show score/lives as the title bar doesn't update as reliably on Linux/macOS (if you intend to support those platforms as well).
Title: Re: eRATication
Post by: bplus on July 16, 2018, 11:58:40 pm
Hi Fellippe, Thanks for feedback with Linux.
Title: Re: eRATication
Post by: Cobalt on July 17, 2018, 10:19:57 am
very interesting game Bplus. I give it a B+!

One thing I noticed(least in the first version at top of the thread) is that you only hit the rats in the arse area, and the shot continues on after the hit.

A slight improvement to would be to have the explosions happen as part of the main loop so there is not that slight pause every time you make a kill, that may just be my old laptop causing it though.  basically you have a explosion routine that is called each loop that makes the explosion grow a step. That way the explosions happen but the game doesn't pause, and it could even have multiple kills happening at once. kind of how my first (and only 100% completed) BASIC game , Space Dodger and the Giant Killer Space Hamsters, ran. a game lost to Geocities I'm afraid. 
Title: Re: eRATication
Post by: bplus on July 17, 2018, 10:35:47 am
Hi Cobalt,

I think we have the gun action fixed in eRATication #2, Erik was complaining of jerkiness and that was caused by the delay to display a rat burn but now that is done in the main looping display.

Bullets have been made inactive with rat hit, ba(i) = 0

See reply #6 for eRATication #2 code, and then new gun action in next reply.

Ha, you did Hamsters! Great minds think alike.

Thanks for your grade, B is for Best! :D
Title: Re: eRATication
Post by: _vince on July 17, 2018, 10:37:41 am
in the fcirc sub
Code: QB64: [Select]
  1. e = 0
should be
Code: QB64: [Select]
  1. e = -R

A mistake I made that got spread about. Otherwise, anyone's welcome to use the fcirc, simplest implementation of midpoint circle fill algo, no credit necessary.
Title: Re: eRATication
Post by: bplus on July 17, 2018, 10:44:03 am
Hi v,

Thanks for correction. I did notice when playing with gradient code (see recent dithering thread) that Steve's fcirc did seem less bumpy around the edges. Maybe just my imagination, would the -R make a difference for that?
Title: Re: eRATication
Post by: _vince on July 17, 2018, 11:04:21 am
would the -R make a difference for that?

Yes it will make it just like Steve's
Title: Re: eRATication
Post by: Cobalt on July 17, 2018, 10:51:13 pm
If you want to have some good laughs change the following line in the NEWRAT routine,

rr(iRat) = RND * 60 / life + 10

to

rr(iRat) = RND * 60 / life + 1

and try shooting that little turd!

a possible scoring mod would be having a base score say 71 per rat and subtract the size of the rat from that
so a full size rat (60+10) would only give you 1 point(71-70) but a micro rat (0+1) would give 70, if you could hit the thing that is! you could multiply it by the rats speed too.
 
 
Title: Re: eRATication
Post by: Cobalt on July 18, 2018, 12:40:59 am
hope you dont mind Bplus but I've made some slight mods to your game, and now the player can move the shooter around the screen!
Code: QB64: [Select]
  1.  'use arrow keys to swing shooter, spacebar to fire
  2.  'left shift to speed up rotation, this frees up the UP arrow to allow for movement
  3.  'of the players craft.
  4.  IF _KEYDOWN(100304) THEN speed%% = 20 ELSE speed%% = 60
  5.  IF _KEYDOWN(19200) THEN P.Rot = P.Rot - _PI(1 / speed%%)
  6.  IF _KEYDOWN(19712) THEN P.Rot = P.Rot + _PI(1 / speed%%)
  7.  
  8.  IF _KEYDOWN(18432) THEN 'up arrow provides thrust!
  9.   P.Momentum = P.Momentum + .056
  10.   IF P.Momentum > 1.86 THEN P.Momentum = 1.86
  11.  ELSEIF P.Momentum THEN 'player is no longer thrusting and still has momentum
  12.   P.Momentum = P.Momentum - Drag
  13.   IF P.Momentum < 0 THEN P.Momentum = 0
  14.  
  15.  ' IF _KEYDOWN(20480) THEN P.Rot = P.Rot + _PI(1 / 30)
  16.  IF _KEYDOWN(32) THEN fire = 1 ELSE fire = 0
  17.  
  18.  'move player around if they have momentum
  19.  P.Xloc = P.Xloc + P.Momentum * COS(P.Rot)
  20.  P.Yloc = P.Yloc + P.Momentum * SIN(P.Rot)
  21.  'stop the player if they encroach upon the screen bounds
  22.  IF P.Xloc < 30 OR P.Yloc < 30 OR P.Xloc > ScrnX - 30 OR P.Yloc > ScrnY - 30 THEN P.Momentum = 0
  23.  'now that does allow player to move extreamly slow, like they are stuck in tar! but they
  24.  'can still leave screen, in that case they lose a life.
  25.  
  26.  IF P.Xloc <= 0 OR P.Xloc >= ScrnX OR P.Yloc <= 0 OR P.Yloc >= ScrnY THEN
  27.   P.Life = P.Life + 1 'player left screen by force! KILL EM'
  28.   P.Xloc = ScrnX \ 2: P.Yloc = ScrnY \ 2
  29.  drawshooter P.Xloc, P.Yloc, P.Rot
  30.  

'drag' is a CONST set to .01 and slows the player rather quickly not that 1.86 moves the player that fast anyway.
I've taken the liberty and setup my own variables as TYPEs just cause that is easier for me to work with.
it still needs some work cause I'd like the craft to keep moving in the direction the player was traveling when they
let go of the UP key regaurdless of whether they rotate. but not quite sure how to do that one. maybe a variable
for thrust Rotation (p.Thrstrot) that stores the rotation of the craft at the time the key was held. and just use that
variable instead of p.rot in the movement lines.
Title: Re: eRATication
Post by: Cobalt on July 18, 2018, 01:29:24 am
not sure what i did but every so often one of my rats has lost his arse! this shot shows one of the smaller rats but they do get even smaller than that when you change that +10 to a +1!
Title: Re: eRATication
Post by: bplus on July 18, 2018, 08:57:19 am
Hi Cobalt,

Mod all you want, that is the beauty of sharing code. It's fun to see what other people are doing with it. I myself was inspired by SirCrow's efforts. Besides, it's not like this idea is original. :)

I have thought about moving the shooter like Asteroids but there seem to be too many buttons needed for one comfortable control. So it becomes a 2 handed job, but my left hand is not very smart when my right hand is busy. ha! just got an idea, use mouse to move shooter and left and right mouse buttons to spin the shooter. That leaves the simple task of pounding the spacebar to the left hand (or vice versa for Lefties).

Speaking of spacebars, do you think they serve coffee there?



Title: Re: eRATication
Post by: Cobalt on July 19, 2018, 01:36:44 pm
so here is a preview release of the MODed version of Bplus's eRATication game.
Still some work to do but, it gives you an idea of the feel I'm going for.
probably start new thread when Its completed.

Code: QB64: [Select]
  1. 'eRATication by Bplus 2018-07-15
  2. 'Ultra Mod version by Cobalt 2018-07-19 13:25 Build 0001 Ver 1.0beta
  3.  
  4. 'known things to fix/complete:
  5. '   re-add rat collision with player
  6. '    À-Currently in GOD mode. :)
  7. '   add Title screen and Title Bar text
  8. '   fix bullet collision with rat so Mini rats are hit correctly
  9. '    À-add more points of detection shots tend to pass right by :(
  10. '   add highscore list
  11. '   re-add hit explosions
  12. '    À-rats simply vanish at the moment :(
  13.  
  14. TYPE RatData
  15.  Xloc AS SINGLE 'X location
  16.  Yloc AS SINGLE 'Y location
  17.  Siz AS INTEGER 'Size(radius)
  18.  Rot AS SINGLE 'Rotation(heading)
  19.  Spd AS SINGLE 'Speed
  20.  Colr AS _UNSIGNED LONG 'color of rat
  21.  Val AS _UNSIGNED _BYTE 'score value of rat
  22.  
  23. TYPE Bulletdata
  24.  Xloc AS SINGLE 'locations
  25.  Yloc AS SINGLE
  26.  DXval AS SINGLE 'movement values
  27.  DYval AS SINGLE
  28.  RemFlag AS _BYTE 'if the shot has hit a rat or gone offscreen flag for removal
  29.  
  30. TYPE PlayerData
  31.  Rot AS SINGLE
  32.  Xloc AS SINGLE
  33.  Yloc AS SINGLE
  34.  Life AS _BYTE
  35.  Points AS _UNSIGNED LONG
  36.  walk AS SINGLE '???
  37.  Momentum AS SINGLE 'players movement speed
  38.  ThrstRot AS SINGLE 'the rotation of players craft when thrust was stopped
  39.  
  40. 'constants
  41. CONST ScrnX = 800
  42. CONST ScrnY = 600
  43.  
  44. CONST MaxRats = 100
  45. CONST MaxBullets = 25
  46. CONST MaxShots = 3 'only 3 shots at a time on screen
  47. CONST BulletSpeed = 20
  48. CONST RatScore = 71 'how much the base score of each rat is
  49. CONST Drag = .015 'how much the players movement slows over time
  50. CONST Rate = .25 'delay between shots fired
  51. CONST RatCount = 5 'base rat count
  52. CONST TRUE = -1, FALSE = NOT TRUE
  53.  
  54. 'Make screen and set timer
  55. SCREEN _NEWIMAGE(ScrnX, ScrnY, 32)
  56.  
  57. 'set up arrays
  58. DIM SHARED P AS PlayerData
  59. DIM SHARED Rats(MaxRats) AS RatData
  60. DIM SHARED Shot(MaxBullets) AS Bulletdata
  61.  
  62. 'set up layers, an idea for haveing everything on its own layer then
  63. 'combining them on to the display
  64. 'DIM SHARED shiplayer&, ratlayer&
  65. 'shiplayer& = _NEWIMAGE(ScrnX, ScrnY, 32)
  66. 'ratlayer& = _NEWIMAGE(ScrnX, ScrnY, 32)
  67.  
  68. 'initilize starting Values
  69. ShotsFired%% = 0 'number of shots fired
  70. P.Life = 1 'player on life #1
  71. P.Points = 0
  72. P.Rot = 0
  73. P.Xloc = ScrnX \ 2
  74. P.Yloc = ScrnY \ 2
  75.  
  76. 'make some Rats
  77. FOR i%% = 0 TO RatCount - 1
  78.  newRat i%%
  79. 'OPEN "debug.txt" FOR OUTPUT AS #1
  80.  CLS
  81.  walk = (walk + 1) MOD 2
  82.  FOR i = 1 TO P.Life * RatCount 'the rats
  83.   drawRat i
  84.  
  85.  'use arrow keys to swing shooter, spacebar to fire
  86.  'left shift to speed up rotation, this frees up the UP arrow to allow for movement
  87.  'of the players craft.
  88.  IF _KEYDOWN(100304) THEN speed%% = 20 ELSE speed%% = 60
  89.  IF _KEYDOWN(19200) THEN P.Rot = P.Rot - _PI(1 / speed%%)
  90.  IF _KEYDOWN(19712) THEN P.Rot = P.Rot + _PI(1 / speed%%)
  91.  
  92.  IF _KEYDOWN(18432) THEN 'up arrow provides thrust!
  93.   P.Momentum = P.Momentum + .056
  94.   IF P.Momentum > 2.86 THEN P.Momentum = 2.86
  95.   P.ThrstRot = P.Rot 'get current rotation
  96.  ELSEIF P.Momentum THEN 'player is no longer thrusting and still has momentum
  97.   P.Momentum = P.Momentum - Drag
  98.   IF P.Momentum < 0 THEN P.Momentum = 0
  99.  
  100.  ' IF _KEYDOWN(20480) THEN P.Rot = P.Rot + _PI(1 / 30)
  101.  'added cooldown to shooting so you can't auto gun 'normally' maybe add specails
  102.  'or bonuses to allow that later
  103.  IF _KEYDOWN(32) AND ShotsFired%% < MaxShots AND cooldown! + Rate < TIMER THEN
  104.   ShotsFired%% = NewShot(ShotsFired%%): cooldown! = TIMER
  105.  
  106.  IF ShotsFired%% THEN ShotsFired%% = shotprocess(ShotsFired%%)
  107.  PlayerMovement
  108.  drawshooter P.Xloc, P.Yloc, P.Rot
  109.  
  110.  IF P.Life > 3 THEN ExitFlag%% = TRUE
  111.  IF INKEY$ = CHR$(27) THEN ExitFlag%% = TRUE
  112.  
  113.  LOCATE 1, 1: PRINT "Life:"; P.Life; TAB(10); "Points:";
  114.  PRINT USING "#,###,###"; P.Points
  115.  
  116.  _DELAY .05
  117. LOOP UNTIL ExitFlag%%
  118.  
  119.  
  120. SUB newRat (iRat)
  121.  'bring rock in from one side, need to set heading according to side
  122.  'RANDOMIZE TIMER + RND
  123.  side%% = INT(RND * 4) + 1
  124.  SELECT CASE side%%
  125.   CASE 1: Rats(iRat).Xloc = 0: Rats(iRat).Yloc = RND * ScrnY: Rats(iRat).Rot = 3 * _PI / 2 + RND * _PI
  126.   CASE 2: Rats(iRat).Xloc = ScrnX: Rats(iRat).Yloc = RND * ScrnY: Rats(iRat).Rot = _PI / 2 + RND * _PI
  127.   CASE 3: Rats(iRat).Xloc = RND * ScrnX: Rats(iRat).Yloc = 0: Rats(iRat).Rot = RND * _PI
  128.   CASE 4: Rats(iRat).Xloc = RND * ScrnX: Rats(iRat).Yloc = ScrnY: Rats(iRat).Rot = _PI + RND * _PI
  129.  
  130.  'speed, angle, radius, gray coloring, spin, seed
  131.  Rats(iRat).Spd = RND * 5 * P.Life + 1
  132.  Rats(iRat).Siz = RND * 60 / P.Life + 3
  133.  Rats(iRat).Colr = ratKolor~&
  134.  
  135. SUB drawRat (i)
  136.  'move the rat
  137.  Rats(i).Xloc = Rats(i).Xloc + Rats(i).Spd * COS(Rats(i).Rot) + rand(-.1 * Rats(i).Siz, .1 * Rats(i).Siz)
  138.  Rats(i).Yloc = Rats(i).Yloc + Rats(i).Spd * SIN(Rats(i).Rot) + rand(-.1 * Rats(i).Siz, .1 * Rats(i).Siz)
  139.  
  140.  IF Rats(i).Xloc > 0 AND Rats(i).Xloc < ScrnX AND Rats(i).Yloc > 0 AND Rats(i).Yloc < ScrnY THEN 'inbounds
  141.   noseX = Rats(i).Xloc + 2 * Rats(i).Siz * COS(Rats(i).Rot)
  142.   noseY = Rats(i).Yloc + 2 * Rats(i).Siz * SIN(Rats(i).Rot)
  143.   neckX = Rats(i).Xloc + .75 * Rats(i).Siz * COS(Rats(i).Rot)
  144.   neckY = Rats(i).Yloc + .75 * Rats(i).Siz * SIN(Rats(i).Rot)
  145.   tailX = Rats(i).Xloc + 2 * Rats(i).Siz * COS(Rats(i).Rot + _PI)
  146.   tailY = Rats(i).Yloc + 2 * Rats(i).Siz * SIN(Rats(i).Rot + _PI)
  147.   earLX = Rats(i).Xloc + Rats(i).Siz * COS(Rats(i).Rot - _PI(1 / 12))
  148.   earLY = Rats(i).Yloc + Rats(i).Siz * SIN(Rats(i).Rot - _PI(1 / 12))
  149.   earats.sizats.xloc = Rats(i).Xloc + Rats(i).Siz * COS(Rats(i).Rot + _PI(1 / 12))
  150.   earats.sizats.yloc = Rats(i).Yloc + Rats(i).Siz * SIN(Rats(i).Rot + _PI(1 / 12))
  151.   fcirc Rats(i).Xloc, Rats(i).Yloc, .65 * Rats(i).Siz, Rats(i).Colr
  152.   fcirc neckX, neckY, Rats(i).Siz * .3, Rats(i).Colr
  153.   fTri noseX, noseY, earLX, earLY, earats.sizats.xloc, earats.sizats.yloc, Rats(i).Colr
  154.   fcirc earLX, earLY, Rats(i).Siz * .3, Rats(i).Colr
  155.   fcirc earats.sizats.xloc, earats.sizats.yloc, Rats(i).Siz * .3, Rats(i).Colr
  156.   wX = .5 * Rats(i).Siz * COS(Rats(i).Rot - _PI(11 / 18))
  157.   wY = .5 * Rats(i).Siz * SIN(Rats(i).Rot - _PI(11 / 18))
  158.   LINE (noseX + wX, noseY + wY)-(noseX - wX, noseY - wY), Rats(i).Colr
  159.   wX = .5 * Rats(i).Siz * COS(Rats(i).Rot - _PI(7 / 18))
  160.   wY = .5 * Rats(i).Siz * SIN(Rats(i).Rot - _PI(7 / 18))
  161.   LINE (noseX + wX, noseY + wY)-(noseX - wX, noseY - wY), Rats(i).Colr
  162.   LINE (Rats(i).Xloc, Rats(i).Yloc)-(tailX, tailY), Rats(i).Colr
  163.  ELSE 'out of bounds
  164.   newRat i
  165.  
  166. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  167.  a& = _NEWIMAGE(1, 1, 32)
  168.  _DEST a&
  169.  PSET (0, 0), K
  170.  _DEST 0
  171.  _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  172.  _FREEIMAGE a& '<<< this is important!
  173.  
  174. 'vince version
  175. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  176.  x0 = R
  177.  y0 = 0
  178.  e = 0
  179.  DO WHILE y0 < x0
  180.   IF e <= 0 THEN
  181.    y0 = y0 + 1
  182.    LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  183.    LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  184.    e = e + 2 * y0
  185.   ELSE
  186.    LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  187.    LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  188.    x0 = x0 - 1
  189.    e = e - 2 * x0
  190.   END IF
  191.  LINE (x - R, y)-(x + R, y), C, BF
  192.  
  193. FUNCTION ratKolor~& ()
  194.  r% = INT(RND * 70) + 70
  195.  g% = INT(RND * (.5 * r%)) + .2 * r%
  196.  b% = INT(RND * (.4 * g%)) + .1 * g%
  197.  ' r% = 165: g% = 95: b% = 25
  198.  ratKolor~& = _RGB32(r%, g%, b%)
  199.  
  200. FUNCTION rand% (lo%, hi%)
  201.  rand% = INT(RND * (hi% - lo% + 1)) + lo%
  202.  
  203. SUB drawshooter (x, y, radianAngle) 'simple red iso triangle pointed towards radianAngle
  204.  'calculate 3 points of triangle shooter
  205.  x1 = x + 60 * COS(radianAngle) 'main point of shooter according to heading
  206.  y1 = y + 60 * SIN(radianAngle)
  207.  x2 = x + 30 * COS(radianAngle + _PI(2 / 3)) 'next two points are 120 degrees off main point in direction
  208.  y2 = y + 30 * SIN(radianAngle + _PI(2 / 3))
  209.  x3 = x + 30 * COS(radianAngle - _PI(2 / 3))
  210.  y3 = y + 30 * SIN(radianAngle - _PI(2 / 3))
  211.  fTri x, y, x1, y1, x2, y2, _RGB(255, 0, 0)
  212.  fTri x, y, x1, y1, x3, y3, _RGB(255, 0, 0)
  213.  LINE (x1, y1)-(x2, y2), _RGB32(255, 255, 128)
  214.  LINE (x1, y1)-(x3, y3), _RGB32(255, 255, 128)
  215.  LINE (x1, y1)-(x, y), _RGB32(255, 255, 128)
  216.  
  217. FUNCTION shotprocess (Count%%)
  218.  IF Count%% THEN 'are there active shots to move
  219.   FOR i%% = 0 TO Count%% - 1
  220.    Shot(i%%).Xloc = Shot(i%%).Xloc + Shot(i%%).DXval
  221.    Shot(i%%).Yloc = Shot(i%%).Yloc + Shot(i%%).DYval
  222.  
  223.    'check for shot hitting rat
  224.    IF RatCollision(i%%) THEN behappy = yes
  225.  
  226.    IF Shot(i%%).Xloc > 0 AND Shot(i%%).Xloc < ScrnX AND Shot(i%%).Yloc > 0 AND Shot(i%%).Yloc < ScrnY THEN 'in bounds draw it
  227.     fcirc Shot(i%%).Xloc, Shot(i%%).Yloc, 2, _RGB32(170, 130, 10)
  228.    ELSE 'shot is off screen
  229.     Shot(i%%).RemFlag = TRUE
  230.    END IF
  231.   NEXT i%%
  232.   'check for offscreen shots
  233.   FOR j%% = 0 TO Count%%
  234.    IF Shot(j%%).RemFlag THEN 'shot is flaged for removal from rathit or offscreen
  235.     FOR i%% = j%% TO Count%% + 1
  236.      Shot(i%%).Xloc = Shot(i%% + 1).Xloc
  237.      Shot(i%%).Yloc = Shot(i%% + 1).Yloc
  238.      Shot(i%%).DXval = Shot(i%% + 1).DXval
  239.      Shot(i%%).DYval = Shot(i%% + 1).DYval
  240.      Shot(i%%).RemFlag = Shot(i%% + 1).RemFlag
  241.     NEXT i%%
  242.     Count%% = Count%% - 1
  243.    END IF
  244.   NEXT j%%
  245.  shotprocess = Count%%
  246.  
  247. FUNCTION NewShot (id%%)
  248.  'fire a bullet
  249.  Shot(id%%).Xloc = P.Xloc + 3 * BulletSpeed * COS(P.Rot)
  250.  Shot(id%%).Yloc = P.Yloc + 3 * BulletSpeed * SIN(P.Rot)
  251.  Shot(id%%).DXval = BulletSpeed * COS(P.Rot)
  252.  Shot(id%%).DYval = BulletSpeed * SIN(P.Rot)
  253.  Shot(id%%).RemFlag = FALSE
  254.  id%% = id%% + 1
  255.  NewShot = id%%
  256.  
  257. SUB PlayerMovement
  258.  'move player around if they have momentum
  259.  P.Xloc = P.Xloc + P.Momentum * COS(P.ThrstRot)
  260.  P.Yloc = P.Yloc + P.Momentum * SIN(P.ThrstRot)
  261.  'stop the player if they encroach upon the screen bounds
  262.  IF P.Xloc < 30 OR P.Yloc < 30 OR P.Xloc > ScrnX - 30 OR P.Yloc > ScrnY - 30 THEN P.Momentum = 0
  263.  'now that does allow player to move extreamly slow, like they are stuck in tar! but they
  264.  'can still leave screen, in that case they lose a life.
  265.  
  266.  IF P.Xloc <= 0 OR P.Xloc >= ScrnX OR P.Yloc <= 0 OR P.Yloc >= ScrnY THEN
  267.   P.Life = P.Life + 1 'player left screen by force! KILL EM'
  268.   P.Xloc = ScrnX \ 2: P.Yloc = ScrnY \ 2
  269.  
  270. FUNCTION RatCollision (id%%)
  271.  FOR j%% = 0 TO RatCount * P.Life
  272.   check~& = POINT(Shot(id%%).Xloc, Shot(id%%).Yloc)
  273.   IF check~& <> 0 THEN 'if bullet finds a nother color
  274.    FOR i%% = 0 TO RatCount * P.Life 'which rat was hit.
  275.     IF Rats(i%%).Colr = check~& THEN 'found dead rat
  276.      'give player points
  277.      P.Points = P.Points + (RatScore - Rats(i%%).Siz)
  278.      'kill that rat
  279.      newRat i%%
  280.      'kill the shot
  281.      Shot(id%%).RemFlag = TRUE
  282.      'exit the for next loop
  283.      i%% = RatCount * P.Life + 2
  284.     END IF
  285.    NEXT i%%
  286.    results%% = TRUE
  287.   ELSE
  288.    results%% = FALSE
  289.   END IF
  290.  NEXT j%%
  291.  RatCollision = results%%
  292.  
Title: Re: eRATication
Post by: bplus on July 20, 2018, 12:25:26 pm
Hi Cobalt,

To me, it seems like you are a little stingy with the bullets. ;-))

But it appears you are moving the shooter like I did with Lander, which is cool, specially now that I have practiced. :)

Oh I also meant to report I have tried the idea I mentioned above and love the control!!
Title: Re: eRATication
Post by: Cobalt on July 20, 2018, 05:09:18 pm
To me, it seems like you are a little stingy with the bullets. ;-))
It does add a bit of difficulty doesn't it! It may become part of the difficulty setting if I go that far with this.

But it appears you are moving the shooter like I did with Lander, which is cool, specially now that I have practiced. :)

not totally happy with it, as if your drifting and thrust again you instantly start moving in the new direction instead of slowing down\stopping first, but fixing that is beyond my skill.

but I have the Title screen done and have added sounds with background music! Check it out!
Haven't converted the wav to mp3 yet cause I'm still tweaking them, rest assured when I decide I'm happy with them they will be compressed down to mp3 files. The BGM came that way thats why it already is. The sounds are from 'FreeSound.org' and the BGM is from 'dig.ccmixter.org' , a credits screen is in the works but not there yet.
Title: Re: eRATication
Post by: bplus on July 20, 2018, 07:18:13 pm
Quote

' 2018-07-20 eRATication 3
' Shooter: location controlled by mouse
'          mouse left and right button works like left and right arrow keys.
' Code: use type for objects, simplify math where possible
'       complete makeover of code.
'       Fixed problem of running into burning rat.
' Display: Life # and Points on screen as Fellippe suggested.
' Points: should be directly proportional to rat's speed and indirectly
'          proportional to size, so speed\size!
'          but compare that to number of shots taken!


'================================ Instructions ==========================
' Up and down arrows for fast rotation of shooter.
' Left and right arrows for more fine tuned rotation of shooter.
' Shooter is connected to mouse, moving mouse moves shooter.
' Left mouse button down for counter-clock wise rotation and
' Right mouse button down for clock- wise rotation.
' Spacebar fires bullets.
'========================================================================

DEFINT A-Z