Author Topic: eRATication  (Read 10798 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
eRATication
« 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.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: eRATication
« Reply #1 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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: eRATication
« Reply #2 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. ;)

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: eRATication
« Reply #3 on: July 14, 2018, 02:18:17 pm »
Nice work! :-D

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: eRATication
« Reply #4 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

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: eRATication
« Reply #5 on: July 15, 2018, 09:06:20 am »
Bplus, I'll come to see TJP behind you and Erik. 

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: eRATication
« Reply #6 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.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: eRATication
« Reply #7 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.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: eRATication
« Reply #8 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

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: eRATication
« Reply #9 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
Logic is the beginning of wisdom.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: eRATication
« Reply #10 on: July 16, 2018, 03:55:18 am »
Nice game, bplus! Here's my highscore in the attachment.
Screenshot_1.png
* Screenshot_1.png (Filesize: 13.05 KB, Dimensions: 1204x730, Views: 265)
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: eRATication
« Reply #11 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!

FellippeHeitor

  • Guest
Re: eRATication
« Reply #12 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).

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: eRATication
« Reply #13 on: July 16, 2018, 11:58:40 pm »
Hi Fellippe, Thanks for feedback with Linux.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: eRATication
« Reply #14 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. 
Granted after becoming radioactive I only have a half-life!