Author Topic: Return of the Cheese Chewers  (Read 5960 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Return of the Cheese Chewers
« on: August 06, 2018, 12:24:27 am »
Couldn't let all that cheese go to waste...

Code: QB64: [Select]
  1. _TITLE "Return of the Cheese Chewer(s) by bplus 2018-08-06"
  2. ' QB64 X 64 version 1.2 20180228/86  from git b301f92
  3.  
  4. ' 2018-07-13 eRATication - 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. ' 2018-07-15 some minor changes since post of e #2
  9. ' 2018-07-20 eRATication 3
  10. ' Shooter: location controlled by mouse
  11. '          mouse left and right button works like left and right arrow keys.
  12. ' Code: use type for objects, simplify math where possible
  13. '       complete makeover of code.
  14. '       Fixed problem of running into burning rat.
  15. ' Display: Life # and Points on screen as Fellippe suggested.
  16. ' Points: should be directly proportional to rat's speed and indirectly
  17. '          proportional to size, so speed\size!
  18. '          but compare that to number of shots taken!
  19.  
  20. '2018-08-06 Return of the Cheese Chewer(s)
  21. ' All that cheese going to waste?
  22. ' nope! redesigned shooter to chucky cheese rat eater
  23.  
  24.  
  25. '================================ Instructions ==========================
  26. '
  27. '                     Move cheese, eat rats, get a-round(er)
  28. '
  29. '                               Eat or be eaten!
  30. '
  31. '========================================================================
  32.  
  33. 'screen dimensions
  34. CONST ww = 1280
  35. CONST wh = 740
  36. CONST cx0 = 400
  37. CONST cy0 = 300
  38. CONST ratPack = 5
  39. CONST maxLife = 3
  40.  
  41. TYPE cheeseType
  42.     x AS INTEGER
  43.     y AS INTEGER
  44.     r AS INTEGER
  45.     a AS DOUBLE 'curr angle
  46.     ma AS DOUBLE 'mouth angle
  47.     dma AS INTEGER 'mouth angle growing 1 or shrinking -1
  48.  
  49. TYPE rat
  50.     x AS INTEGER
  51.     y AS INTEGER
  52.     r AS INTEGER
  53.     dx AS INTEGER
  54.     dy AS INTEGER
  55.     c AS _UNSIGNED LONG
  56.     dead AS INTEGER
  57.  
  58. SCREEN _NEWIMAGE(ww, wh, 32)
  59.  
  60. DIM SHARED life, nRats, points, GameOn, newRound, cheese&
  61. DIM SHARED r(maxLife * ratPack + maxLife) AS rat
  62. DIM SHARED chucky AS cheeseType
  63.  
  64. restart:
  65.  
  66. chucky.x = ww / 2
  67. chucky.y = wh / 2
  68. chucky.r = 50
  69. chucky.a = 0 'mouth direction
  70. chucky.ma = _PI(1 / 3) 'mouth angle
  71. chucky.dma = 1 'mouth angle direction up or down
  72. lastx = ww / 2: lasty = wh / 2
  73. life = 1
  74. nRats = life * ratPack
  75. points = 0
  76. GameOn = 1
  77. newRound = 0
  78. FOR i = 0 TO nRats
  79.     newRat i
  80. growCheese
  81.  
  82. WHILE GameOn
  83.     CLS
  84.     newRound = 0
  85.  
  86.     'KISS control!!!
  87.     chucky.x = _MOUSEX: chucky.y = _MOUSEY
  88.     IF chucky.x <> lastx OR chucky.y <> lasty THEN
  89.         chucky.a = _ATAN2(chucky.y - lasty, chucky.x - lastx)
  90.         lastx = chucky.x: lasty = chucky.y
  91.     END IF
  92.     IF _MOUSEBUTTON(1) THEN chucky.a = chucky.a - _PI(10 / 360)
  93.     IF _MOUSEBUTTON(2) THEN chucky.a = chucky.a + _PI(10 / 360)
  94.     WHILE chucky.a < 0
  95.         chucky.a = chucky.a + _PI(2)
  96.     WEND
  97.     WHILE chucky.a >= _PI(2)
  98.         chucky.a = chuck.a - _PI(2)
  99.     WEND
  100.     drawChucky
  101.     stats
  102.     handleRats
  103.     IF newRound THEN
  104.         'signal new round but finsih drawing rats
  105.         'chucky  goes, round over
  106.         FOR ra = 0 TO _PI(2) STEP _PI(1 / 24)
  107.             xx = chucky.x + (chucky.r + 20) * COS(ra)
  108.             yy = chucky.y + (chucky.r + 20) * SIN(ra)
  109.             xx2 = chucky.x + 5 * chucky.r * COS(ra)
  110.             yy2 = chucky.y + 5 * chucky.r * SIN(ra)
  111.             ln xx, yy, xx2, yy2, _RGB32(200, 0, 0)
  112.         NEXT
  113.         _DISPLAY
  114.         _DELAY 1.5
  115.         IF life + 1 <= maxLife THEN
  116.             life = life + 1
  117.             nRats = life * ratPack
  118.             'new set o rats
  119.             FOR i = 0 TO nRats
  120.                 newRat i
  121.             NEXT
  122.         ELSE
  123.             GameOn = 0
  124.         END IF
  125.     ELSE
  126.         chucky.r = 50 + INT(points / 5)
  127.         IF chucky.r > 150 THEN chucky.r = 150
  128.         _DISPLAY
  129.         _LIMIT 30
  130.     END IF
  131. _DELAY 4 'so don't start printing spaces in the editor
  132. GOTO restart
  133.  
  134. SUB newRat (iRat)
  135.     side = rand(1, 4)
  136.     SELECT CASE life
  137.         CASE IS = 1: m = 1
  138.         CASE IS = 2: m = 1.125
  139.         CASE IS = 3: m = 1.5
  140.     END SELECT
  141.     SELECT CASE side
  142.         CASE 1
  143.             r(iRat).x = 0: r(iRat).y = rand(0, wh)
  144.             r(iRat).dx = rand(1, 6) * m: r(iRat).dy = rand(-4, 4) * m
  145.         CASE 2
  146.             r(iRat).x = ww: r(iRat).y = rand(0, wh)
  147.             r(iRat).dx = rand(-6, -1) * m: r(iRat).dy = rand(-4, 4) * m
  148.         CASE 3
  149.             r(iRat).x = rand(0, ww): r(iRat).y = 0
  150.             r(iRat).dx = rand(-6, 6) * m: r(iRat).dy = rand(1, 4) * m
  151.         CASE 4
  152.             r(iRat).x = rand(0, ww): r(iRat).y = wh:
  153.             r(iRat).dx = rand(-6, 6) * m: r(iRat).dy = rand(-4, -1) * m
  154.     END SELECT
  155.     r(iRat).r = rand(10, 60 / m)
  156.     r(iRat).dead = 0
  157.     r = rand(60, 255): g = r \ 2 + rand(0, 10): b = g \ 2
  158.     r(iRat).c = _RGB32(r, g, b)
  159.  
  160. SUB handleRats ()
  161.     FOR i = 0 TO nRats
  162.         IF r(i).dead = 0 THEN 'if rat not dead move it
  163.             r(i).x = r(i).x + r(i).dx
  164.             r(i).y = r(i).y + r(i).dy
  165.         END IF
  166.  
  167.         ' rat collides with chucky:
  168.         IF ((r(i).x - chucky.x) ^ 2 + (r(i).y - chucky.y) ^ 2) ^ .5 < .85 * chucky.r AND r(i).dead = 0 THEN
  169.             'Who gets who ??
  170.             'if rat (abdomen) in chucky's mouth chucky lives, rat dies... otherwise vice versa
  171.             'we can determine this from the angle between two centers and the direction = direction of chucky's mouth
  172.             mx = chucky.x + .5 * chucky.r * COS(chucky.a)
  173.             my = chucky.y + .5 * chucky.r * SIN(chucky.a)
  174.             IF ((r(i).x - mx) ^ 2 + (r(i).y - my) ^ 2) ^ .5 < .65 * chucky.r THEN 'very near center of mouth
  175.                 'rat dies
  176.                 IF r(i).dead = 0 THEN
  177.                     r(i).dead = 1
  178.                     points = points + life
  179.                 END IF
  180.             ELSE
  181.                 newRound = 1 'draw rest of rats to show collisions
  182.             END IF
  183.         END IF
  184.         'is the rat on screen
  185.         IF r(i).x > 0 AND r(i).x < ww AND r(i).y > 0 AND r(i).y < wh THEN 'inbounds
  186.             IF r(i).dead THEN 'show the burn out until reaches rat radius
  187.                 r(i).dead = r(i).dead + 2
  188.                 IF r(i).dead < r(i).r THEN
  189.                     FOR d = 1 TO 2 * r(i).r
  190.                         r1 = rand(-r(i).r, r(i).r): ra1 = RND * _PI(2): r2 = RND
  191.                         dx1 = chucky.x + .5 * chucky.r * COS(chucky.a) + r2 * r1 * COS(ra1)
  192.                         dy1 = chucky.y + .5 * chucky.r * SIN(chucky.a) + r2 * r1 * SIN(ra1)
  193.                         fcirc dx1, dy1, 2, _RGB32(255 - r(i).dead, 128 - r(i).dead, 0)
  194.                     NEXT
  195.                 ELSE
  196.                     newRat i
  197.                 END IF
  198.             ELSE
  199.                 'draw it
  200.                 DIM heading AS SINGLE
  201.                 heading = _ATAN2(r(i).dy, r(i).dx)
  202.                 noseX = r(i).x + 2 * r(i).r * COS(heading)
  203.                 noseY = r(i).y + 2 * r(i).r * SIN(heading)
  204.                 neckX = r(i).x + .75 * r(i).r * COS(heading)
  205.                 neckY = r(i).y + .75 * r(i).r * SIN(heading)
  206.                 tailX = r(i).x + 2 * r(i).r * COS(heading + _PI)
  207.                 tailY = r(i).y + 2 * r(i).r * SIN(heading + _PI)
  208.                 earLX = r(i).x + r(i).r * COS(heading - _PI(1 / 12))
  209.                 earLY = r(i).y + r(i).r * SIN(heading - _PI(1 / 12))
  210.                 earRX = r(i).x + r(i).r * COS(heading + _PI(1 / 12))
  211.                 earRY = r(i).y + r(i).r * SIN(heading + _PI(1 / 12))
  212.                 fcirc r(i).x, r(i).y, .65 * r(i).r, r(i).c
  213.                 fcirc neckX, neckY, r(i).r * .3, r(i).c
  214.                 fTri noseX, noseY, earLX, earLY, earRX, earRY, r(i).c
  215.                 fcirc earLX, earLY, r(i).r * .3, r(i).c
  216.                 fcirc earRX, earRY, r(i).r * .3, r(i).c
  217.                 wX = .5 * r(i).r * COS(heading - _PI(11 / 18))
  218.                 wY = .5 * r(i).r * SIN(heading - _PI(11 / 18))
  219.                 ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, r(i).c
  220.                 wX = .5 * r(i).r * COS(heading - _PI(7 / 18))
  221.                 wY = .5 * r(i).r * SIN(heading - _PI(7 / 18))
  222.                 ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, r(i).c
  223.                 ln r(i).x, r(i).y, tailX, tailY, r(i).c
  224.             END IF
  225.         ELSE 'out of bounds
  226.             newRat i
  227.         END IF
  228.     NEXT
  229.  
  230. SUB drawChucky ()
  231.     'first makeCheese and use cheese& image to build chucky image
  232.     'dim shared chucky as cheeseType
  233.  
  234.     'first chucky's mouth angle
  235.     chucky.ma = chucky.ma + _PI(1 / 5) * chucky.dma
  236.     IF chucky.ma > _PI(5 / 6) THEN chucky.ma = _PI(5 / 6): chucky.dma = -1 * chucky.dma
  237.     IF chucky.ma < _PI(1 / 12) THEN chucky.ma = _PI(1 / 12): chucky.dma = -1 * chucky.dma
  238.     ma2 = .5 * chucky.ma
  239.  
  240.     'next first leg of chucky
  241.     x1 = chucky.x + chucky.r * COS(chucky.a + ma2)
  242.     y1 = chucky.y + chucky.r * SIN(chucky.a + ma2)
  243.     'first leg of cheese
  244.     cx1 = cx0 + chucky.r * COS(ma2)
  245.     cy1 = cy0 + chucky.r * SIN(ma2)
  246.  
  247.     'take small traingles off cheese& image  and map them onto main screen at chucky's and mouth angle position
  248.     stepper = _PI(1 / 20)
  249.     starter = ma2 + stepper
  250.     stopper = _PI(2) - ma2
  251.     FOR a = starter TO stopper STEP stepper
  252.         'one to one ratio of mapping
  253.         x2 = chucky.x + chucky.r * COS(chucky.a + a)
  254.         y2 = chucky.y + chucky.r * SIN(chucky.a + a)
  255.         cx2 = cx0 + chucky.r * COS(a)
  256.         cy2 = cy0 + chucky.r * SIN(a)
  257.         _MAPTRIANGLE (cx0, cy0)-(cx1, cy1)-(cx2, cy2), cheese& TO(chucky.x, chucky.y)-(x1, y1)-(x2, y2), 0
  258.         x1 = x2: y1 = y2: cx1 = cx2: cy1 = cy2
  259.     NEXT
  260.  
  261.  
  262. SUB growCheese () 'make this more self contained than first version, all hole stuff just in here
  263.     curr& = _DEST
  264.     IF cheese& THEN _FREEIMAGE cheese&
  265.     cheese& = _NEWIMAGE(ww, wh, 32)
  266.     _DEST cheese&
  267.     nHoles = 300: maxHoleLife = 20: maxHoleRadius = 7: tfStart = 1
  268.     DIM hx(nHoles), hy(nHoles), hLife(nHoles)
  269.     FOR i = 1 TO nHoles
  270.         GOSUB newHole
  271.     NEXT
  272.     tfStart = 0
  273.     FOR layr = 1 TO 30
  274.         LINE (0, 0)-(ww, wh), _RGBA32(255, 255, 0, 50), BF 'layer of cheese
  275.         FOR i = 1 TO nHoles 'holes in layer
  276.             IF hLife(i) + 1 > maxHoleLife THEN GOSUB newHole ELSE hLife(i) = hLife(i) + 1
  277.             hx(i) = hx(i) + RND * 2 - 1
  278.             hy(i) = hy(i) + RND * 2 - 1
  279.             IF hLife(i) < maxHoleRadius THEN
  280.                 radius = hLife(i)
  281.             ELSEIF maxHoleLife - hLife(i) < maxHoleRadius THEN
  282.                 radius = maxHoleLife - hLife(i)
  283.             ELSE
  284.                 radius = maxHoleRadius
  285.             END IF
  286.             fcirc hx(i), hy(i), radius, _RGBA32(0, 0, 0, 50)
  287.         NEXT
  288.     NEXT
  289.     _DEST curr&
  290.     EXIT SUB
  291.  
  292.     newHole:
  293.     hx(i) = ww * RND
  294.     hy(i) = wh * RND
  295.     IF tfStart THEN hLife(i) = INT(RND * maxHoleLife) ELSE hLife(i) = 1
  296.     RETURN
  297.  
  298.  
  299. SUB stats ()
  300.     COLOR _RGB(200, 225, 255)
  301.     _PRINTSTRING (5, 5), "Life #" + LTRIM$(STR$(life)) + "  Points:" + STR$(points)
  302.  
  303. FUNCTION rand% (lo%, hi%)
  304.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  305.  
  306. ' 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
  307. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  308.     a& = _NEWIMAGE(1, 1, 32)
  309.     _DEST a&
  310.     PSET (0, 0), K
  311.     _DEST 0
  312.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  313.     _FREEIMAGE a& '<<< this is important!
  314.  
  315. SUB ln (x1, y1, x2, y2, K AS _UNSIGNED LONG)
  316.     LINE (x1, y1)-(x2, y2), K
  317.  
  318. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  319. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG, c AS _UNSIGNED LONG)
  320.     DIM subRadius AS LONG, RadiusError AS LONG
  321.     DIM X AS LONG, Y AS LONG
  322.  
  323.     subRadius = ABS(R)
  324.     RadiusError = -subRadius
  325.     X = subRadius
  326.     Y = 0
  327.  
  328.     IF subRadius = 0 THEN PSET (CX, CY), c: EXIT SUB
  329.  
  330.     ' Draw the middle span here so we don't draw it twice in the main loop,
  331.     ' which would be a problem with blending turned on.
  332.     LINE (CX - X, CY)-(CX + X, CY), c, BF
  333.  
  334.     WHILE X > Y
  335.         RadiusError = RadiusError + Y * 2 + 1
  336.         IF RadiusError >= 0 THEN
  337.             IF X <> Y + 1 THEN
  338.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), c, BF
  339.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), c, BF
  340.             END IF
  341.             X = X - 1
  342.             RadiusError = RadiusError - X * 2
  343.         END IF
  344.         Y = Y + 1
  345.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), c, BF
  346.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), c, BF
  347.     WEND
  348.  
  349.  

Sorry, some of the comments aren't updated and are from old code or tests.
« Last Edit: August 06, 2018, 12:36:58 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Return of the Cheese Chewers
« Reply #1 on: August 30, 2018, 08:04:59 pm »
Watch out rats the cheese is sharp!  ;-)) 
Code: QB64: [Select]
  1. _TITLE "eRATication 5 by bplus 2018-08-06"
  2. ' QB64 X 64 version 1.2 20180228/86  from git b301f92
  3.  
  4. ' 2018-07-13 eRATication - 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. ' 2018-07-15 some minor changes since post of e #2
  9. ' 2018-07-20 eRATication 3
  10. ' Shooter: location controlled by mouse
  11. '          mouse left and right button works like left and right arrow keys.
  12. ' Code: use type for objects, simplify math where possible
  13. '       complete makeover of code.
  14. '       Fixed problem of running into burning rat.
  15. ' Display: Life # and Points on screen as Fellippe suggested.
  16. ' Points: should be directly proportional to rat's speed and indirectly
  17. '          proportional to size, so speed\size!
  18. '          but compare that to number of shots taken!
  19.  
  20. '2018-08-06 Return of the Cheese Chewer(s)
  21. ' All that cheese going to waste?
  22. ' nope! redesigned shooter to chucky cheese rat eater
  23.  
  24. '2018-08-07 eRATication 5:
  25. ' The setting is on a cheese floor!
  26. ' Back to bullets with cheese wedge shooter BUT!
  27. ' they are blue triangle shapes and fire less often,
  28. ' not like firing from a water hose BUT
  29. ' you can also stab the rats in the abdomen to eRATicate!
  30. ' More dramatic bloody mouse explosions from bullet hits.
  31. ' Points system: back to 1 rat = current life value.
  32. ' I have cut back on rat speeds and shrinking of rats
  33. ' as life value increases but now the wedge grows in size adding
  34. ' another level of difficulty as life goes on.
  35.  
  36. '============================== Instructions ==========================
  37. '
  38. ' Move cheese wedge (with mouse), stab or aim bullets for rat abdomen
  39. '
  40. '                               or be eaten!
  41. '
  42. '======================================================================
  43.  
  44. 'screen dimensions
  45. CONST ww = 1280
  46. CONST wh = 740
  47. CONST cx0 = 640
  48. CONST cy0 = 370
  49. CONST ratPack = 5
  50. CONST maxLife = 3
  51. CONST pi56## = 2.617993877991494
  52. CONST nBullets = 1000
  53. CONST bSpeed = 40
  54. CONST air_resistance = .85
  55.  
  56. TYPE particle
  57.     x AS SINGLE
  58.     y AS SINGLE
  59.     dx AS SINGLE
  60.     dy AS SINGLE
  61.     size AS SINGLE
  62.     kolor AS LONG
  63.  
  64. TYPE bullet
  65.     x AS INTEGER
  66.     y AS INTEGER
  67.     dx AS INTEGER
  68.     dy AS INTEGER
  69.     live AS INTEGER
  70.  
  71. TYPE cheeseType
  72.     x AS INTEGER
  73.     y AS INTEGER
  74.     r AS INTEGER
  75.     a AS _FLOAT 'what will stop the wobble!  NOT Integer, single or double
  76.  
  77. TYPE rat
  78.     x AS INTEGER
  79.     y AS INTEGER
  80.     r AS INTEGER
  81.     dx AS INTEGER
  82.     dy AS INTEGER
  83.     c AS _UNSIGNED LONG
  84.     dead AS INTEGER
  85.  
  86. SCREEN _NEWIMAGE(ww, wh, 32)
  87.  
  88. h1& = _LOADFONT("C:\Windows\Fonts\Arial.ttf", 48)
  89. _FONT h1&
  90.  
  91. DIM SHARED life, nRats, points, GameOn, newRound, cheese&, fire
  92. DIM SHARED r(maxLife * ratPack + maxLife) AS rat
  93. DIM SHARED b(nBullets) AS bullet, chucky AS cheeseType
  94. DIM SHARED dots(2000) AS particle
  95.  
  96.  
  97. restart:
  98.  
  99. chucky.x = ww / 2
  100. chucky.y = wh / 2
  101. chucky.r = 50
  102. chucky.a = 0
  103. lastx = ww / 2: lasty = wh / 2
  104. life = 1
  105. nRats = life * ratPack
  106. points = 0
  107. GameOn = 1
  108. newRound = 0
  109. FOR i = 0 TO nRats
  110.     newRat i
  111. growCheese
  112. _PUTIMAGE , cheese&
  113. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 0, 0)
  114. _PRINTSTRING (80, 350), "Where there is cheese, there is... (press any key)"
  115. WHILE GameOn
  116.     _PUTIMAGE , cheese&
  117.     newRound = 0
  118.  
  119.     'KISS control!!!
  120.     chucky.x = _MOUSEX: chucky.y = _MOUSEY
  121.     'why the heck is this so wobbly???????? I tried everything (exept the right thing) to stop the shaking
  122.     IF lastx <> chucky.x OR lasty <> chucky.y THEN
  123.         chucky.a = _R2D(_ATAN2(chucky.y - lasty, chucky.x - lastx))
  124.         lastx = chucky.x: lasty = chucky.y
  125.     ELSE 'let no gun idly shoot in same direction
  126.         chucky.a = chucky.a + 2
  127.     END IF
  128.     IF _MOUSEBUTTON(1) THEN chucky.a = (chucky.a - 4)
  129.     IF _MOUSEBUTTON(2) THEN chucky.a = (chucky.a + 4)
  130.     WHILE chucky.a < 0
  131.         chucky.a = chucky.a + 360
  132.     WEND
  133.     WHILE chucky.a >= 360
  134.         chucky.a = chucky.a - 360
  135.     WEND
  136.  
  137.     lc = (lc + 1) MOD 4
  138.     IF lc = 0 THEN fire = 1 ELSE fire = 0
  139.     drawChucky
  140.     stats
  141.     handleRats
  142.     IF newRound THEN
  143.         'chucky  goes, round over show last frame to see rat overlap
  144.         FOR ra = 0 TO _PI(2) STEP _PI(1 / 24)
  145.             xx = chucky.x + (chucky.r + 20) * COS(ra)
  146.             yy = chucky.y + (chucky.r + 20) * SIN(ra)
  147.             xx2 = chucky.x + 5 * chucky.r * COS(ra)
  148.             yy2 = chucky.y + 5 * chucky.r * SIN(ra)
  149.             ln xx, yy, xx2, yy2, _RGB32(200, 0, 0)
  150.         NEXT
  151.         _DISPLAY
  152.         _DELAY 1.5
  153.         IF life + 1 <= maxLife THEN
  154.             life = life + 1
  155.             nRats = life * ratPack
  156.             'new set o rats
  157.             FOR i = 0 TO nRats
  158.                 newRat i
  159.             NEXT
  160.         ELSE
  161.             GameOn = 0
  162.         END IF
  163.     ELSE
  164.         handleBullets
  165.         chucky.r = 50 + INT(points / 5)
  166.         IF chucky.r > 150 THEN chucky.r = 150
  167.         _DISPLAY
  168.         _LIMIT 35
  169.     END IF
  170. _DELAY 4 ' pause to examine score,
  171. ' no play again prompt necessary, of course you want to play again!
  172. GOTO restart
  173.  
  174. SUB handleBullets ()
  175.     rA = _D2R(chucky.a)
  176.     FOR i = 0 TO nBullets
  177.         IF b(i).live = 0 AND fire = 1 THEN 'have in active bullet index to use
  178.             b(i).x = chucky.x + (chucky.r + 5) * COS(rA)
  179.             b(i).y = chucky.y + (chucky.r + 5) * SIN(rA)
  180.             b(i).dx = bSpeed * COS(rA)
  181.             b(i).dy = bSpeed * SIN(rA)
  182.             b(i).live = 1
  183.             fire = 0
  184.         END IF
  185.         IF b(i).live = 1 THEN 'new location
  186.             b(i).x = b(i).x + b(i).dx
  187.             b(i).y = b(i).y + b(i).dy
  188.             IF b(i).x > 0 AND b(i).x < ww AND b(i).y > 0 AND b(i).y < wh THEN 'in bounds draw it
  189.                 'check for collision with rat
  190.                 FOR r = 0 TO nRats
  191.                     IF ((r(r).x - b(i).x) ^ 2 + (r(r).y - b(i).y) ^ 2) ^ .5 < r(r).r THEN
  192.                         IF r(r).dead = 0 THEN
  193.                             r(r).dead = 1
  194.                             points = points + life
  195.                             b(i).live = 0
  196.                         END IF
  197.                     ELSE
  198.                         ba = _ATAN2(b(i).dy, b(i).dx): b = 15
  199.                         x1 = b(i).x + b * COS(ba)
  200.                         y1 = b(i).y + b * SIN(ba)
  201.                         x2 = b(i).x + b * COS(ba + _PI(5 / 6))
  202.                         y2 = b(i).y + b * SIN(ba + _PI(5 / 6))
  203.                         x3 = b(i).x + b * COS(ba + _PI(7 / 6))
  204.                         y3 = b(i).y + b * SIN(ba + _PI(7 / 6))
  205.                         fTri x1, y1, x2, y2, x3, y3, _RGB32(0, 0, 160)
  206.                         'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
  207.                     END IF
  208.                 NEXT
  209.             ELSE
  210.                 b(i).live = 0
  211.             END IF
  212.         END IF
  213.     NEXT
  214.  
  215. SUB newRat (iRat)
  216.     side = rand(1, 4)
  217.     SELECT CASE life
  218.         CASE IS = 1: m = 1
  219.         CASE IS = 2: m = 1.25
  220.         CASE IS = 3: m = 1.5
  221.     END SELECT
  222.     SELECT CASE side
  223.         CASE 1
  224.             r(iRat).x = 0: r(iRat).y = rand(0, wh)
  225.             r(iRat).dx = rand(1, 6) * m: r(iRat).dy = rand(-4, 4) * m
  226.         CASE 2
  227.             r(iRat).x = ww: r(iRat).y = rand(0, wh)
  228.             r(iRat).dx = rand(-6, -1) * m: r(iRat).dy = rand(-4, 4) * m
  229.         CASE 3
  230.             r(iRat).x = rand(0, ww): r(iRat).y = 0
  231.             r(iRat).dx = rand(-6, 6) * m: r(iRat).dy = rand(1, 4) * m
  232.         CASE 4
  233.             r(iRat).x = rand(0, ww): r(iRat).y = wh:
  234.             r(iRat).dx = rand(-6, 6) * m: r(iRat).dy = rand(-4, -1) * m
  235.     END SELECT
  236.     r(iRat).r = rand(10, 60 / m)
  237.     r(iRat).dead = 0
  238.     r = rand(30, 150): g = r \ 2 + rand(0, 20): b = g \ 2 + rand(-2, 15)
  239.     r(iRat).c = _RGB32(r, g, b)
  240.  
  241. SUB handleRats ()
  242.     cra = _D2R(chucky.a)
  243.     FOR i = 0 TO nRats
  244.         IF r(i).dead = 0 THEN 'if rat not dead move it
  245.             r(i).x = r(i).x + r(i).dx
  246.             r(i).y = r(i).y + r(i).dy
  247.         END IF
  248.  
  249.         ' rat collides with chucky:
  250.         IF ((r(i).x - chucky.x) ^ 2 + (r(i).y - chucky.y) ^ 2) ^ .5 < .85 * chucky.r AND r(i).dead = 0 THEN
  251.             'Who gets who ??
  252.             'if rat (abdomen) in chucky's mouth chucky lives, rat dies... otherwise vice versa
  253.             'we can determine this from the angle between two centers and the direction = direction of chucky's mouth
  254.             mx = chucky.x + .5 * chucky.r * COS(cra)
  255.             my = chucky.y + .5 * chucky.r * SIN(cra)
  256.             IF ((r(i).x - mx) ^ 2 + (r(i).y - my) ^ 2) ^ .5 < .65 * chucky.r THEN 'very near center of mouth
  257.                 'rat dies
  258.                 IF r(i).dead = 0 THEN
  259.                     r(i).dead = -1
  260.                     points = points + life
  261.                 END IF
  262.             ELSE
  263.                 newRound = 1 'draw rest of rats to show collisions
  264.             END IF
  265.         END IF
  266.         'is the rat on screen
  267.         IF r(i).x > 0 AND r(i).x < ww AND r(i).y > 0 AND r(i).y < wh THEN 'inbounds
  268.             IF r(i).dead THEN 'show the burn out until reaches rat radius
  269.                 IF ABS(r(i).dead) < r(i).r THEN
  270.                     IF r(i).dead < 0 THEN 'death by stabbing
  271.                         r(i).dead = r(i).dead - 6
  272.                         fcirc r(i).x, r(i).y, r(i).r + r(i).dead, _RGB32(255 + r(i).dead, 128 + r(i).dead, 0)
  273.                         explode r(i).x, r(i).y, r(i).r, r(i).r + r(i).dead
  274.                     ELSEIF r(i).dead > 0 THEN 'death by bullet
  275.                         r(i).dead = r(i).dead + 6
  276.                         fcirc r(i).x, r(i).y, r(i).r - r(i).dead, _RGB32(255 - r(i).dead, 128 - r(i).dead, 0)
  277.                         explode r(i).x, r(i).y, r(i).r, r(i).r - r(i).dead
  278.                     END IF
  279.                 ELSE
  280.                     newRat i
  281.                 END IF
  282.             ELSE
  283.                 'draw it
  284.                 DIM heading AS SINGLE
  285.                 heading = _ATAN2(r(i).dy, r(i).dx)
  286.                 noseX = r(i).x + 2 * r(i).r * COS(heading)
  287.                 noseY = r(i).y + 2 * r(i).r * SIN(heading)
  288.                 neckX = r(i).x + .75 * r(i).r * COS(heading)
  289.                 neckY = r(i).y + .75 * r(i).r * SIN(heading)
  290.                 tailX = r(i).x + 2 * r(i).r * COS(heading + _PI)
  291.                 tailY = r(i).y + 2 * r(i).r * SIN(heading + _PI)
  292.                 earLX = r(i).x + r(i).r * COS(heading - _PI(1 / 12))
  293.                 earLY = r(i).y + r(i).r * SIN(heading - _PI(1 / 12))
  294.                 earRX = r(i).x + r(i).r * COS(heading + _PI(1 / 12))
  295.                 earRY = r(i).y + r(i).r * SIN(heading + _PI(1 / 12))
  296.                 fcirc r(i).x, r(i).y, .65 * r(i).r, r(i).c
  297.                 fcirc neckX, neckY, r(i).r * .3, r(i).c
  298.                 fTri noseX, noseY, earLX, earLY, earRX, earRY, r(i).c
  299.                 fcirc earLX, earLY, r(i).r * .3, r(i).c
  300.                 fcirc earRX, earRY, r(i).r * .3, r(i).c
  301.                 wX = .5 * r(i).r * COS(heading - _PI(11 / 18))
  302.                 wY = .5 * r(i).r * SIN(heading - _PI(11 / 18))
  303.                 ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, r(i).c
  304.                 wX = .5 * r(i).r * COS(heading - _PI(7 / 18))
  305.                 wY = .5 * r(i).r * SIN(heading - _PI(7 / 18))
  306.                 ln noseX + wX, noseY + wY, noseX - wX, noseY - wY, r(i).c
  307.                 ln r(i).x, r(i).y, tailX, tailY, r(i).c
  308.             END IF
  309.         ELSE 'out of bounds
  310.             newRat i
  311.         END IF
  312.     NEXT
  313.  
  314. SUB drawChucky ()
  315.     'first makeCheese and use cheese& image to build chucky image
  316.     'dim shared chucky as cheeseType
  317.     cra = _D2R(chucky.a)
  318.  
  319.     'next first leg of chucky
  320.     x1 = chucky.x + chucky.r * COS(cra)
  321.     y1 = chucky.y + chucky.r * SIN(cra)
  322.     x2 = chucky.x + chucky.r * COS(cra + pi56##)
  323.     y2 = chucky.y + chucky.r * SIN(cra + pi56##)
  324.  
  325.     'first leg of cheese
  326.     cx1 = cx0 + chucky.r * COS(0)
  327.     cy1 = cy0 + chucky.r * SIN(0)
  328.     cx2 = cx0 + chucky.r * COS(pi56##)
  329.     cy2 = cy0 + chucky.r * SIN(pi56##)
  330.  
  331.  
  332.     'take small traingles off cheese& image  and map them onto main screen at chucky's and mouth angle position
  333.     stepper = _PI(1 / 20)
  334.     starter = pi56## + stepper
  335.     stopper = _PI(7 / 6)
  336.     FOR a = starter TO stopper STEP stepper
  337.         'one to one ratio of mapping
  338.         x3 = chucky.x + chucky.r * COS(cra + a)
  339.         y3 = chucky.y + chucky.r * SIN(cra + a)
  340.         cx3 = cx0 + chucky.r * COS(a)
  341.         cy3 = cy0 + chucky.r * SIN(a)
  342.         _MAPTRIANGLE (cx1, cy1)-(cx2, cy2)-(cx3, cy3), cheese& TO(x1, y1)-(x2, y2)-(x3, y3), 0
  343.         x2 = x3: y2 = y3: cx2 = cx3: cy2 = cy3
  344.     NEXT
  345.     pieSlice x1, y1, 2 * chucky.r, cra + _PI(11 / 12), cra + _PI(13 / 12), _RGB32(0, 0, 0)
  346.  
  347.  
  348. SUB growCheese () 'make this more self contained than first version, all hole stuff just in here
  349.     curr& = _DEST
  350.     IF cheese& THEN _FREEIMAGE cheese&
  351.     cheese& = _NEWIMAGE(ww, wh, 32)
  352.     _DEST cheese&
  353.     nHoles = ww * wh / 1000: maxHoleLife = 20: maxHoleRadius = 7: tfStart = 1
  354.     DIM hx(nHoles), hy(nHoles), hLife(nHoles)
  355.     FOR i = 1 TO nHoles
  356.         GOSUB newHole
  357.     NEXT
  358.     tfStart = 0
  359.     FOR layr = 1 TO 30
  360.         LINE (0, 0)-(ww, wh), _RGBA32(255, 255, 0, 50), BF 'layer of cheese
  361.         FOR i = 1 TO nHoles 'holes in layer
  362.             IF hLife(i) + 1 > maxHoleLife THEN GOSUB newHole ELSE hLife(i) = hLife(i) + 1
  363.             hx(i) = hx(i) + RND * 2 - 1
  364.             hy(i) = hy(i) + RND * 2 - 1
  365.             IF hLife(i) < maxHoleRadius THEN
  366.                 radius = hLife(i)
  367.             ELSEIF maxHoleLife - hLife(i) < maxHoleRadius THEN
  368.                 radius = maxHoleLife - hLife(i)
  369.             ELSE
  370.                 radius = maxHoleRadius
  371.             END IF
  372.             fcirc hx(i), hy(i), radius, _RGBA32(0, 0, 0, 50)
  373.         NEXT
  374.     NEXT
  375.     _DEST curr&
  376.     EXIT SUB
  377.  
  378.     newHole:
  379.     hx(i) = ww * RND
  380.     hy(i) = wh * RND
  381.     IF tfStart THEN hLife(i) = INT(RND * maxHoleLife) ELSE hLife(i) = 1
  382.     RETURN
  383.  
  384.  
  385. SUB explode (x, y, r, frm)
  386.     maxParticles = r * 10
  387.     FOR i = 1 TO r
  388.         NewDot i, x, y, r
  389.     NEXT
  390.     rounds = r
  391.     FOR loopCount = 0 TO frm
  392.         IF _KEYDOWN(27) THEN END
  393.         FOR i = 1 TO rounds
  394.             dots(i).x = dots(i).x + dots(i).dx
  395.             dots(i).y = dots(i).y + dots(i).dy
  396.             dots(i).dx = dots(i).dx * air_resistance
  397.             dots(i).dy = air_resistance * dots(i).dy
  398.             fcirc dots(i).x, dots(i).y, dots(i).size / 2, dots(i).kolor
  399.         NEXT
  400.         IF rounds < maxParticles THEN
  401.             FOR i = 1 TO r
  402.                 NewDot (rounds + i), x, y, r
  403.             NEXT
  404.             rounds = rounds + r
  405.         END IF
  406.     NEXT
  407.  
  408. SUB NewDot (i, x, y, r)
  409.     angle = _PI(2 * RND)
  410.     rd = RND * 30
  411.     dots(i).x = x + rd * COS(angle)
  412.     dots(i).y = y + rd * SIN(angle)
  413.     dots(i).size = RND * r * .1
  414.     rd = RND 'STxAxTIC recommended for rounder spreads
  415.     dots(i).dx = rd * 7 * (7 - dots(i).size) * COS(angle)
  416.     dots(i).dy = rd * 7 * (7 - dots(i).size) * SIN(angle)
  417.     dots(i).kolor = _RGB32(140 + rd * 80, rd * 40, 0)
  418.  
  419.  
  420. SUB stats ()
  421.     COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 0, 0)
  422.     _PRINTSTRING (5, 5), "Life #" + LTRIM$(STR$(life)) + "  Points:" + STR$(points)
  423.  
  424. FUNCTION rand% (lo%, hi%)
  425.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  426.  
  427. ' 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
  428. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  429.     a& = _NEWIMAGE(1, 1, 32)
  430.     _DEST a&
  431.     PSET (0, 0), K
  432.     _DEST 0
  433.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  434.     _FREEIMAGE a& '<<< this is important!
  435.  
  436. SUB ln (x1, y1, x2, y2, K AS _UNSIGNED LONG)
  437.     LINE (x1, y1)-(x2, y2), K
  438.  
  439. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  440. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG, c AS _UNSIGNED LONG)
  441.     DIM subRadius AS LONG, RadiusError AS LONG
  442.     DIM X AS LONG, Y AS LONG
  443.  
  444.     subRadius = ABS(R)
  445.     RadiusError = -subRadius
  446.     X = subRadius
  447.     Y = 0
  448.  
  449.     IF subRadius = 0 THEN PSET (CX, CY), c: EXIT SUB
  450.  
  451.     ' Draw the middle span here so we don't draw it twice in the main loop,
  452.     ' which would be a problem with blending turned on.
  453.     LINE (CX - X, CY)-(CX + X, CY), c, BF
  454.  
  455.     WHILE X > Y
  456.         RadiusError = RadiusError + Y * 2 + 1
  457.         IF RadiusError >= 0 THEN
  458.             IF X <> Y + 1 THEN
  459.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), c, BF
  460.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), c, BF
  461.             END IF
  462.             X = X - 1
  463.             RadiusError = RadiusError - X * 2
  464.         END IF
  465.         Y = Y + 1
  466.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), c, BF
  467.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), c, BF
  468.     WEND
  469.  
  470. 'use radians
  471. SUB arc (x, y, r, raStart, raStop, c AS _UNSIGNED LONG)
  472.     'x, y origin, r = radius, c = color
  473.  
  474.     'raStart is first angle clockwise from due East = 0 degrees
  475.     ' arc will start drawing there and clockwise until raStop angle reached
  476.  
  477.     IF raStop < raStart THEN
  478.         arc x, y, r, raStart, _PI(2), c
  479.         arc x, y, r, 0, raStop, c
  480.     ELSE
  481.         ' modified to easier way suggested by Steve
  482.         'Why was the line method not good? I forgot.
  483.         al = _PI * r * r * (raStop - raStart) / _PI(2)
  484.         FOR a = raStart TO raStop STEP 1 / al
  485.             PSET (x + r * COS(a), y + r * SIN(a)), c
  486.         NEXT
  487.     END IF
  488.  
  489. 'draw lines from origin to arc on sides
  490. SUB pieSlice (x, y, r, raStart, raStop, c AS _UNSIGNED LONG)
  491.     arc x, y, r, raStart, raStop, c
  492.     px = x + r * COS(raStart): py = y + r * SIN(raStart)
  493.     LINE (x, y)-(px, py), c
  494.     px = x + r * COS(raStop): py = y + r * SIN(raStop)
  495.     LINE (x, y)-(px, py), c
  496.  
« Last Edit: August 30, 2018, 08:07:35 pm by bplus »

Offline ExilePrisoner

  • Newbie
  • Posts: 6
    • View Profile
Re: Return of the Cheese Chewers
« Reply #2 on: September 05, 2018, 10:31:02 pm »
Incorrect number of arguements passed to function on line 120

Code: QB64: [Select]
  1. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 0, 0)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Return of the Cheese Chewers
« Reply #3 on: September 05, 2018, 10:34:13 pm »
Incorrect number of arguements passed to function on line 120

Code: QB64: [Select]
  1. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 0, 0)

Change the second part to _RGBA(255,255,0,0), or else download the latest QB64 development build instead of the stable build.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Return of the Cheese Chewers
« Reply #4 on: October 28, 2018, 04:19:25 pm »
Given that my house is presently overrun by rats, there is a strange satisfaction in playing this game. ;)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Return of the Cheese Chewers
« Reply #5 on: October 28, 2018, 05:15:20 pm »
Yeah, I know, I call it the "bubble-wrap popping syndrome". :-))

Oh, that would make a great sound for this!

update: video KILLed
That's not it, that sounds like a haircut for hedges! (12 hours??? I thought I was crazy!)

Haven't found THE sound yet, so far it's just Rice Krispies! These people need to get industrial sized bubbled wrap.
« Last Edit: May 12, 2020, 04:02:08 pm by bplus »