Author Topic: MasterGy is looking for ideas to implement ("i suffer")  (Read 14595 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #60 on: March 29, 2021, 12:31:28 pm »
It would be a shame if this ended up containing several cool looking pieces of code-art but ended up buried under the cryptic title "i suffer".

Much like all your new "tools"

With no clear description of what the thread/post actually contains, content gets lost - not that that's not already a characteristic of forum boards, but we could at least make it more easily searchable.

I agree with Fellippe. This thread seems like it has taken a few different directions from when it was first created.


I am sure one or more of these ideas will "take" and end up in the programs section.

Meanwhile just enjoy the creative process and sharing of ideas. :)

Quote
end up buried under "another one for your toolbox".

Right here if anyone is interested, thanks for plug!
https://www.qb64.org/forum/index.php?topic=1511.msg107143#msg107143

There is a classic thread in FreeBASIC called Squares (if I recall correctly) that has gone on and on for years, it is the book of people having fun and sharing ideas even if it wanders all over the place.

PS for Pete's sake, I won't post a link ;-))
« Last Edit: March 29, 2021, 01:15:36 pm by bplus »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #61 on: March 29, 2021, 02:43:18 pm »
thank you! I didn’t put it in a separate topic because it just wanted to be a model. I want to make a 3D fighter game that moves around the planet (the starting point is a program where you can walk around the Earth) so you can feel gravity. The problem with the Earth program is that you can walk around, come, go, rotate, up, down, left, right in FPS mode. In fact, when we travel in space in a spaceship, we are not affected by a significant gravitational force from anywhere, we are weightless. There is no such thing as down, up, left, right. As soon as we reach the gravitational field of a planet, the up-and-down will have meaning. Since the spacecraft can be at any angle in space, FPS mode is not good. Because I get completely brainwashed from this problem to shoot the camera in 3d that we see from the spaceship. (BPLUS, that's why the arrow is glued to the middle of the screen, which is confusing to you because he's the reference point, everything moves relative to him) That's why I did it in 2D for the first time. I didn’t put it on a separate topic because it doesn’t matter that much. If anyone likes it, save it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #62 on: March 29, 2021, 02:57:08 pm »
@MasterGy

I did like it and I did save it, into a long overdue MasterGy folder on my hard disk.

I believe you have the better position, platform, base, orientation with the nose of rocket going up and always being in the center of Universe. That is Human perspective. It might even be excellent training for space navigators forced to fly by-the-seat-of-their-pants (no instrumentation to help orientate).

Forgive me if I like god's view more. ;-)) seeing the ship and everything around it in one perspective.

I have a problem with jerkiness in my mouse action shooter that I am curious as to how you might handle:
Code: QB64: [Select]
  1. _Title "Mouse Action Shooter #2 Targets fix" 'B+ 2021-03-19
  2. 'Mouse Action Shooter started from eRATication 5 by bplus 2018-08-06"
  3. ' upodate Mouse Action Shooter with MB triggers 2019-04-01
  4. ' 2019-04-03 add some targets for practice
  5.  
  6. ' SCORE System:
  7. ' Right click to fire a bullet, they cost 10 points each.
  8. ' Targets range from 30 for biggest targets to 100 points for smallest Targets
  9. ' Get hit by target loose 100 points and delay of game.
  10.  
  11. '2019-04-04 Keeping Ashish Target fix, wait until completely off screen.
  12. ' Now give the bullets a little long range before deactivating them.
  13. ' Fix shooter x, y by locating in center of shooter instead of nose. It's already OK!
  14.  
  15. ' 2021-03-19 using this code for oh program and want to fix point when target crashes into shooter/ship
  16. ' by reassignning target new coordinates by saying NewTarget index that should fix the continuous crashing right?
  17. ' Let's see, in oh it doesn't work, how about here?  Works just as expected. So what's up with oh?
  18. ' (Fixed it was an index goof for public variables used in GoSubs).
  19.  
  20.  
  21. 'screen dimensions
  22. Const xmax = 1200
  23. Const ymax = 700
  24. Const nBullets = 15
  25. Const bSpeed = 30
  26. Const nTargets = 3 'should probably depend on level of play
  27. Const tSpeed = 5 'should probably depend on level of play
  28. Const shooterRadius = 50
  29.  
  30. Type shooterType
  31.     x As Single
  32.     y As Single
  33.     a As Single
  34.  
  35. Type bulletType
  36.     x As Integer
  37.     y As Integer
  38.     dx As Integer
  39.     dy As Integer
  40.     live As Integer
  41.  
  42. Type targetType
  43.     x As Single
  44.     y As Single
  45.     a As Single
  46.     r As Integer
  47.  
  48. Screen _NewImage(xmax, ymax, 32)
  49. _ScreenMove 100, 20
  50.  
  51.  
  52. Dim Shared GameOn, mb1, last1, score
  53.  
  54. 'targets
  55. Dim Shared t(nTargets - 1) As targetType
  56. For i = 0 To nTargets - 1: newTarget i: Next
  57.  
  58. 'bullets
  59. Dim Shared b(nBullets - 1) As bulletType
  60.  
  61. 'shooter
  62. Dim Shared shooter As shooterType
  63. shooter.x = xmax / 2
  64. shooter.y = ymax / 2
  65. shooter.a = 0
  66. lastx = xmax / 2: lasty = ymax / 2
  67.  
  68. 'game
  69. GameOn = 1
  70. While GameOn
  71.     Cls
  72.     _Title "Target Practice   Score:" + Str$(score)
  73.     mb1 = 0: mb2 = 0
  74.     shooter.x = _MouseX: shooter.y = _MouseY
  75.     If Abs(lastx - shooter.x) > 3 Or Abs(lasty - shooter.y) > 3 Then
  76.         shooter.a = _Atan2(shooter.y - lasty, shooter.x - lastx)
  77.         lastx = shooter.x: lasty = shooter.y
  78.     End If
  79.     t = Timer(.001)
  80.     If _MouseButton(1) Then 'when ship is heading north the left button should be left
  81.         If t - last1 > .15 Then mb1 = 1: last1 = t
  82.     End If
  83.     handleTargets
  84.     drawshooter
  85.     handleBullets
  86.     _Display
  87.     _Limit 30
  88.  
  89. Sub handleTargets
  90.     For i = 0 To nTargets - 1
  91.         'update position
  92.         t(i).x = t(i).x + tSpeed * Cos(t(i).a)
  93.         t(i).y = t(i).y + tSpeed * Sin(t(i).a)
  94.         'inbounds?
  95.         If t(i).x < -shooterRadius Or t(i).x > xmax + shooterRadius Or t(i).y < -shooterRadius Or t(i).y > ymax + shooterradiu Then
  96.             newTarget i
  97.         Else
  98.             If hitShooter(i) Then 'now I discovered in oh program this continues to crash and deduct 100 until target moves through shooter
  99.                 'explosion
  100.                 Cls
  101.                 _PrintString (xmax / 2 - 40, ymax / 2 - 10), "Bang!... Ouch!"
  102.                 score = score - 100
  103.                 _Display
  104.                 _Delay .2
  105.                 ' fix target crashing into ship by removing target with reassigning
  106.                 newTarget i ' in oh this does not work
  107.             Else
  108.                 drawTarget i
  109.             End If
  110.         End If
  111.     Next
  112.  
  113. Sub newTarget (i)
  114.     'pick edge
  115.     edge = Int(Rnd * 4)
  116.     Select Case edge
  117.         Case 0: t(i).x = -shooterRadius: t(i).y = Rnd * (ymax - 300) + 150: t(i).a = Rnd * _Pi
  118.         Case 1: t(i).x = xmax + shooterRadius: t(i).y = Rnd * (ymax - 300) + 150: t(i).a = _Pi / 2 + Rnd * _Pi
  119.         Case 2: t(i).x = Rnd * xmax: t(i).y = -shooterRadius: t(i).a = Rnd * _Pi
  120.         Case 3: t(i).x = Rnd * xmax: t(i).y = ymax + shooterRadius: t(i).a = _Pi + Rnd * _Pi
  121.     End Select
  122.     t(i).r = (Int(Rnd * 8) + 3) * 10 '30 to 100 score 130 - radius 100 to 30
  123.  
  124. Sub drawTarget (i)
  125.     For r = t(i).r To 0 Step -t(i).r / 10
  126.         count = (count + 1) Mod 2
  127.         If count Then c~& = _RGB32(255, 0, 0) Else c~& = _RGB32(255, 255, 255)
  128.         fcirc t(i).x, t(i).y, r, c~&
  129.     Next
  130.  
  131. Sub handleBullets ()
  132.     For i = 0 To nBullets - 1
  133.         If b(i).live = 0 And mb1 = 1 Then 'have in active bullet index to use
  134.             b(i).x = shooter.x + .5 * shooterRadius * Cos(shooter.a)
  135.             b(i).y = shooter.y + .5 * shooterRadius * Sin(shooter.a)
  136.             b(i).dx = bSpeed * Cos(shooter.a)
  137.             b(i).dy = bSpeed * Sin(shooter.a)
  138.             b(i).live = 1
  139.             mb1 = 0
  140.             score = score - 10 'bullets cost 10 points
  141.  
  142.         ElseIf b(i).live = 1 Then 'new location
  143.             b(i).x = b(i).x + b(i).dx
  144.             b(i).y = b(i).y + b(i).dy
  145.             If b(i).x > -50 And b(i).x < xmax + 50 And b(i).y > -50 And b(i).y < ymax + 50 Then 'in bounds draw it
  146.                 'check for collision with ...
  147.                 t = hitTarget(i)
  148.                 If t > -1 Then
  149.                     score = score + 130 - t(t).r
  150.                     b(i).live = 0
  151.                     newTarget t
  152.                 Else
  153.                     'draw bullet
  154.                     ba = _Atan2(b(i).dy, b(i).dx): b = 15
  155.                     x1 = b(i).x + b * Cos(ba)
  156.                     y1 = b(i).y + b * Sin(ba)
  157.                     x2 = b(i).x + b * Cos(ba + _Pi(5 / 6))
  158.                     y2 = b(i).y + b * Sin(ba + _Pi(5 / 6))
  159.                     x3 = b(i).x + b * Cos(ba + _Pi(7 / 6))
  160.                     y3 = b(i).y + b * Sin(ba + _Pi(7 / 6))
  161.                     fTri x1, y1, x2, y2, x3, y3, _RGB32(10, 160, 160)
  162.                     'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
  163.                 End If
  164.             Else
  165.                 b(i).live = 0 'dectiveate
  166.             End If
  167.         End If
  168.     Next
  169.  
  170. Function hitTarget (bulletIndex)
  171.     hitTarget = -1
  172.     For i = 0 To nTargets - 1
  173.         If Sqr((t(i).x - b(bulletIndex).x) ^ 2 + (t(i).y - b(bulletIndex).y) ^ 2) <= t(i).r Then hitTarget = i: Exit Function
  174.     Next
  175.  
  176. Function hitShooter (TargetIndex)
  177.     If Sqr((shooter.x - t(TargetIndex).x) ^ 2 + (shooter.y - t(TargetIndex).y) ^ 2) <= t(i).r Then hitShooter = 1: Exit Function
  178.  
  179. Sub drawshooter ()
  180.     x1 = shooter.x + (shooterRadius - 30) * Cos(shooter.a)
  181.     y1 = shooter.y + (shooterRadius - 30) * Sin(shooter.a)
  182.     x2 = shooter.x + (shooterRadius + 20) * Cos(shooter.a + _Pi(11 / 16))
  183.     y2 = shooter.y + (shooterRadius + 20) * Sin(shooter.a + _Pi(11 / 16))
  184.     x3 = shooter.x + (shooterRadius + 20) * Cos(shooter.a - _Pi(11 / 16))
  185.     y3 = shooter.y + (shooterRadius + 20) * Sin(shooter.a - _Pi(11 / 16))
  186.     fTri x1, y1, x2, y2, x3, y3, _RGB32(85, 45, 0)
  187.     x1 = shooter.x + shooterRadius * Cos(shooter.a)
  188.     y1 = shooter.y + shooterRadius * Sin(shooter.a)
  189.     x2 = shooter.x + shooterRadius * Cos(shooter.a + _Pi(7 / 8))
  190.     y2 = shooter.y + shooterRadius * Sin(shooter.a + _Pi(7 / 8))
  191.     x3 = shooter.x + shooterRadius * Cos(shooter.a - _Pi(7 / 8))
  192.     y3 = shooter.y + shooterRadius * Sin(shooter.a - _Pi(7 / 8))
  193.     fTri x1, y1, x2, y2, x3, y3, _RGB32(0, 0, 200)
  194.     x2 = shooter.x + shooterRadius * Cos(shooter.a + _Pi(15 / 16))
  195.     y2 = shooter.y + shooterRadius * Sin(shooter.a + _Pi(15 / 16))
  196.     x3 = shooter.x + shooterRadius * Cos(shooter.a - _Pi(15 / 16))
  197.     y3 = shooter.y + shooterRadius * Sin(shooter.a - _Pi(15 / 16))
  198.     fTri x1, y1, x2, y2, x3, y3, _RGB32(255, 255, 255)
  199.  
  200.     'check shooter x, y  = fixed a long time ago!
  201.     'fcirc shooter.x, shooter.y, 4, _RGB32(140, 120, 140)
  202.  
  203. ' 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
  204. Sub fTri (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
  205.     a& = _NewImage(1, 1, 32)
  206.     _Dest a&
  207.     PSet (0, 0), K
  208.     _Dest 0
  209.     _MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
  210.     _FreeImage a& '<<< this is important!
  211.  
  212. Sub fcirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
  213.     Dim Radius As Integer, RadiusError As Integer
  214.     Dim X As Integer, Y As Integer
  215.  
  216.     Radius = Abs(R)
  217.     RadiusError = -Radius
  218.     X = Radius
  219.     Y = 0
  220.  
  221.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  222.  
  223.     ' Draw the middle span here so we don't draw it twice in the main loop,
  224.     ' which would be a problem with blending turned on.
  225.     Line (CX - X, CY)-(CX + X, CY), C, BF
  226.  
  227.     While X > Y
  228.         RadiusError = RadiusError + Y * 2 + 1
  229.         If RadiusError >= 0 Then
  230.             If X <> Y + 1 Then
  231.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  232.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  233.             End If
  234.             X = X - 1
  235.             RadiusError = RadiusError - X * 2
  236.         End If
  237.         Y = Y + 1
  238.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  239.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  240.     Wend
  241.  
  242.  

It flies nice but when it comes to precision shooting, specially if you stop to shoot, there is last moment jerk off target. @MasterGy I am wondering how you ( or anyone interested) might accomplish the flying and mouse-button shooting? (no keypresses except for escape of course)


« Last Edit: March 29, 2021, 03:04:02 pm by bplus »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #63 on: March 29, 2021, 03:56:10 pm »
thanks for the advice ! all ideas, suggestions, thoughts are very good! thanks !

I like imaginative shooting games! I like the way you solved the direction of the shot and the position of the plane. Ideal !! I don't understand exactly what your problem is with him. What's jerking? I don't see jerks. If the plane was "spinning up" due to a small mouse movement, I would only put one distance condition there, 2 lines, I attached. But maybe you are thinking of another problem? Because I think it's as good as you did.

Code: QB64: [Select]
  1. _TITLE "Mouse Action Shooter #2 Targets fix" 'B+ 2021-03-19
  2. 'Mouse Action Shooter started from eRATication 5 by bplus 2018-08-06"
  3. ' upodate Mouse Action Shooter with MB triggers 2019-04-01
  4. ' 2019-04-03 add some targets for practice
  5.  
  6. ' SCORE System:
  7. ' Right click to fire a bullet, they cost 10 points each.
  8. ' Targets range from 30 for biggest targets to 100 points for smallest Targets
  9. ' Get hit by target loose 100 points and delay of game.
  10.  
  11. '2019-04-04 Keeping Ashish Target fix, wait until completely off screen.
  12. ' Now give the bullets a little long range before deactivating them.
  13. ' Fix shooter x, y by locating in center of shooter instead of nose. It's already OK!
  14.  
  15. ' 2021-03-19 using this code for oh program and want to fix point when target crashes into shooter/ship
  16. ' by reassignning target new coordinates by saying NewTarget index that should fix the continuous crashing right?
  17. ' Let's see, in oh it doesn't work, how about here?  Works just as expected. So what's up with oh?
  18. ' (Fixed it was an index goof for public variables used in GoSubs).
  19.  
  20.  
  21. 'screen dimensions
  22. CONST xmax = 1200
  23. CONST ymax = 700
  24. CONST nBullets = 15
  25. CONST bSpeed = 30
  26. CONST nTargets = 3 'should probably depend on level of play
  27. CONST tSpeed = 5 'should probably depend on level of play
  28. CONST shooterRadius = 50
  29.  
  30. TYPE shooterType
  31.     x AS SINGLE
  32.     y AS SINGLE
  33.     a AS SINGLE
  34.  
  35. TYPE bulletType
  36.     x AS INTEGER
  37.     y AS INTEGER
  38.     dx AS INTEGER
  39.     dy AS INTEGER
  40.     live AS INTEGER
  41.  
  42. TYPE targetType
  43.     x AS SINGLE
  44.     y AS SINGLE
  45.     a AS SINGLE
  46.     r AS INTEGER
  47.  
  48. SCREEN _NEWIMAGE(xmax, ymax, 32)
  49. _SCREENMOVE 100, 20
  50.  
  51.  
  52. DIM SHARED GameOn, mb1, last1, score
  53.  
  54. 'targets
  55. DIM SHARED t(nTargets - 1) AS targetType
  56. FOR i = 0 TO nTargets - 1: newTarget i: NEXT
  57.  
  58. 'bullets
  59. DIM SHARED b(nBullets - 1) AS bulletType
  60.  
  61. 'shooter
  62. DIM SHARED shooter AS shooterType
  63. shooter.x = xmax / 2
  64. shooter.y = ymax / 2
  65. shooter.a = 0
  66. lastx = xmax / 2: lasty = ymax / 2
  67.  
  68. 'game
  69. GameOn = 1
  70. WHILE GameOn
  71.     CLS
  72.     _TITLE "Target Practice   Score:" + STR$(score)
  73.     mb1 = 0: mb2 = 0
  74.  
  75.     shooter.x = _MOUSEX: shooter.y = _MOUSEY
  76.  
  77.     IF SQR((shooter.y - lasty) ^ 2 + (shooter.x - lastx) ^ 2) > 10 THEN '-------------------------------------------------add 1. row
  78.  
  79.         IF ABS(lastx - shooter.x) > 3 OR ABS(lasty - shooter.y) > 3 THEN
  80.             shooter.a = _ATAN2(shooter.y - lasty, shooter.x - lastx)
  81.             lastx = shooter.x: lasty = shooter.y
  82.         END IF
  83.  
  84.     END IF '-------------------------------------------------------------------------------------------------------------- add 2.row
  85.  
  86.  
  87.     t = TIMER(.001)
  88.     IF _MOUSEBUTTON(1) THEN 'when ship is heading north the left button should be left
  89.         IF t - last1 > .15 THEN mb1 = 1: last1 = t
  90.     END IF
  91.     handleTargets
  92.     drawshooter
  93.     handleBullets
  94.     _DISPLAY
  95.     _LIMIT 30
  96.  
  97. SUB handleTargets
  98.     FOR i = 0 TO nTargets - 1
  99.         'update position
  100.         t(i).x = t(i).x + tSpeed * COS(t(i).a)
  101.         t(i).y = t(i).y + tSpeed * SIN(t(i).a)
  102.         'inbounds?
  103.         IF t(i).x < -shooterRadius OR t(i).x > xmax + shooterRadius OR t(i).y < -shooterRadius OR t(i).y > ymax + shooterradiu THEN
  104.             newTarget i
  105.         ELSE
  106.             IF hitShooter(i) THEN 'now I discovered in oh program this continues to crash and deduct 100 until target moves through shooter
  107.                 'explosion
  108.                 CLS
  109.                 _PRINTSTRING (xmax / 2 - 40, ymax / 2 - 10), "Bang!... Ouch!"
  110.                 score = score - 100
  111.                 _DISPLAY
  112.                 _DELAY .2
  113.                 ' fix target crashing into ship by removing target with reassigning
  114.                 newTarget i ' in oh this does not work
  115.             ELSE
  116.                 drawTarget i
  117.             END IF
  118.         END IF
  119.     NEXT
  120.  
  121. SUB newTarget (i)
  122.     'pick edge
  123.     edge = INT(RND * 4)
  124.     SELECT CASE edge
  125.         CASE 0: t(i).x = -shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = RND * _PI
  126.         CASE 1: t(i).x = xmax + shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = _PI / 2 + RND * _PI
  127.         CASE 2: t(i).x = RND * xmax: t(i).y = -shooterRadius: t(i).a = RND * _PI
  128.         CASE 3: t(i).x = RND * xmax: t(i).y = ymax + shooterRadius: t(i).a = _PI + RND * _PI
  129.     END SELECT
  130.     t(i).r = (INT(RND * 8) + 3) * 10 '30 to 100 score 130 - radius 100 to 30
  131.  
  132. SUB drawTarget (i)
  133.     FOR r = t(i).r TO 0 STEP -t(i).r / 10
  134.         count = (count + 1) MOD 2
  135.         IF count THEN c~& = _RGB32(255, 0, 0) ELSE c~& = _RGB32(255, 255, 255)
  136.         fcirc t(i).x, t(i).y, r, c~&
  137.     NEXT
  138.  
  139. SUB handleBullets ()
  140.     FOR i = 0 TO nBullets - 1
  141.         IF b(i).live = 0 AND mb1 = 1 THEN 'have in active bullet index to use
  142.             b(i).x = shooter.x + .5 * shooterRadius * COS(shooter.a)
  143.             b(i).y = shooter.y + .5 * shooterRadius * SIN(shooter.a)
  144.             b(i).dx = bSpeed * COS(shooter.a)
  145.             b(i).dy = bSpeed * SIN(shooter.a)
  146.             b(i).live = 1
  147.             mb1 = 0
  148.             score = score - 10 'bullets cost 10 points
  149.  
  150.         ELSEIF b(i).live = 1 THEN 'new location
  151.             b(i).x = b(i).x + b(i).dx
  152.             b(i).y = b(i).y + b(i).dy
  153.             IF b(i).x > -50 AND b(i).x < xmax + 50 AND b(i).y > -50 AND b(i).y < ymax + 50 THEN 'in bounds draw it
  154.                 'check for collision with ...
  155.                 t = hitTarget(i)
  156.                 IF t > -1 THEN
  157.                     score = score + 130 - t(t).r
  158.                     b(i).live = 0
  159.                     newTarget t
  160.                 ELSE
  161.                     'draw bullet
  162.                     ba = _ATAN2(b(i).dy, b(i).dx): b = 15
  163.                     x1 = b(i).x + b * COS(ba)
  164.                     y1 = b(i).y + b * SIN(ba)
  165.                     x2 = b(i).x + b * COS(ba + _PI(5 / 6))
  166.                     y2 = b(i).y + b * SIN(ba + _PI(5 / 6))
  167.                     x3 = b(i).x + b * COS(ba + _PI(7 / 6))
  168.                     y3 = b(i).y + b * SIN(ba + _PI(7 / 6))
  169.                     fTri x1, y1, x2, y2, x3, y3, _RGB32(10, 160, 160)
  170.                     'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
  171.                 END IF
  172.             ELSE
  173.                 b(i).live = 0 'dectiveate
  174.             END IF
  175.         END IF
  176.     NEXT
  177.  
  178. FUNCTION hitTarget (bulletIndex)
  179.     hitTarget = -1
  180.     FOR i = 0 TO nTargets - 1
  181.         IF SQR((t(i).x - b(bulletIndex).x) ^ 2 + (t(i).y - b(bulletIndex).y) ^ 2) <= t(i).r THEN hitTarget = i: EXIT FUNCTION
  182.     NEXT
  183.  
  184. FUNCTION hitShooter (TargetIndex)
  185.     IF SQR((shooter.x - t(TargetIndex).x) ^ 2 + (shooter.y - t(TargetIndex).y) ^ 2) <= t(i).r THEN hitShooter = 1: EXIT FUNCTION
  186.  
  187. SUB drawshooter ()
  188.     x1 = shooter.x + (shooterRadius - 30) * COS(shooter.a)
  189.     y1 = shooter.y + (shooterRadius - 30) * SIN(shooter.a)
  190.     x2 = shooter.x + (shooterRadius + 20) * COS(shooter.a + _PI(11 / 16))
  191.     y2 = shooter.y + (shooterRadius + 20) * SIN(shooter.a + _PI(11 / 16))
  192.     x3 = shooter.x + (shooterRadius + 20) * COS(shooter.a - _PI(11 / 16))
  193.     y3 = shooter.y + (shooterRadius + 20) * SIN(shooter.a - _PI(11 / 16))
  194.     fTri x1, y1, x2, y2, x3, y3, _RGB32(85, 45, 0)
  195.     x1 = shooter.x + shooterRadius * COS(shooter.a)
  196.     y1 = shooter.y + shooterRadius * SIN(shooter.a)
  197.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(7 / 8))
  198.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(7 / 8))
  199.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(7 / 8))
  200.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(7 / 8))
  201.     fTri x1, y1, x2, y2, x3, y3, _RGB32(0, 0, 200)
  202.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(15 / 16))
  203.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(15 / 16))
  204.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(15 / 16))
  205.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(15 / 16))
  206.     fTri x1, y1, x2, y2, x3, y3, _RGB32(255, 255, 255)
  207.  
  208.     'check shooter x, y  = fixed a long time ago!
  209.     'fcirc shooter.x, shooter.y, 4, _RGB32(140, 120, 140)
  210.  
  211. ' 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
  212. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  213.     a& = _NEWIMAGE(1, 1, 32)
  214.     _DEST a&
  215.     PSET (0, 0), K
  216.     _DEST 0
  217.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  218.     _FREEIMAGE a& '<<< this is important!
  219.  
  220. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  221.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  222.     DIM X AS INTEGER, Y AS INTEGER
  223.  
  224.     Radius = ABS(R)
  225.     RadiusError = -Radius
  226.     X = Radius
  227.     Y = 0
  228.  
  229.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  230.  
  231.     ' Draw the middle span here so we don't draw it twice in the main loop,
  232.     ' which would be a problem with blending turned on.
  233.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  234.  
  235.     WHILE X > Y
  236.         RadiusError = RadiusError + Y * 2 + 1
  237.         IF RadiusError >= 0 THEN
  238.             IF X <> Y + 1 THEN
  239.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  240.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  241.             END IF
  242.             X = X - 1
  243.             RadiusError = RadiusError - X * 2
  244.         END IF
  245.         Y = Y + 1
  246.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  247.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  248.     WEND
  249.  
  250.  
  251.  

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #64 on: March 29, 2021, 04:07:44 pm »
anyway thanks this time BPLUS! :) you see, people are always learning! So far, I have solved the angle measurement in "degrees".

Code: QB64: [Select]
  1. FUNCTION degree (a, b)
  2.     qarany = (a + .00001) / (b + .00001): degree = honnan + ATN(qarany) / pip180
  3.     IF 0 > b THEN degree = degree - 180
  4.     IF degree < 0 THEN degree = degree + 360


I didn't know "_ATAN2", it's the same, only in radians :) Man always
 study! :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #65 on: March 29, 2021, 05:18:12 pm »
Oh ha! Now I see it! LOL

Code: QB64: [Select]
  1. Function degree (a, b)
  2.     qarany = (a + .00001) / (b + .00001): degree = honnan + Atn(qarany) / pip180
  3.     If 0 > b Then degree = degree - 180
  4.     If degree < 0 Then degree = degree + 360
  5.  
  6.  

yeah, I know you had to be doing that somewhere! I forgot to search "atn" in your code. I searched, tan, atan, atan2 but forgot atn. :P

Adding .00001 interesting, is that to keep the divisor <> 0 ? Speaking of which, do I test for that? maybe that's the jerk ;-))

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #66 on: March 29, 2021, 05:33:03 pm »
check! :) know that for me pip180 is a constant always (= pi / 180) :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #67 on: March 29, 2021, 06:52:07 pm »
Well I just learned something new today!

Logically this is not a proper check for dividing by zero:
Code: QB64: [Select]
  1.     If Abs(lastx - shooter.x) > 3 Or Abs(lasty - shooter.y) > 3 Then
  2.         shooter.a = _Atan2(shooter.y - lasty, shooter.x - lastx)
  3.         lastx = shooter.x: lasty = shooter.y
  4.     End If
  5.  

update: well I fixed but now I am not sure if _ATAN2 ever has a problem with division by 0?

update 2: confirmed _ATAN2 has no division by 0 problems.

« Last Edit: March 29, 2021, 08:38:02 pm by bplus »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #68 on: March 30, 2021, 02:23:36 pm »
I came up with an even finer solution for shooting.

Code: QB64: [Select]
  1. _TITLE "Mouse Action Shooter #2 Targets fix" 'B+ 2021-03-19
  2. 'Mouse Action Shooter started from eRATication 5 by bplus 2018-08-06"
  3. ' upodate Mouse Action Shooter with MB triggers 2019-04-01
  4. ' 2019-04-03 add some targets for practice
  5.  
  6. ' SCORE System:
  7. ' Right click to fire a bullet, they cost 10 points each.
  8. ' Targets range from 30 for biggest targets to 100 points for smallest Targets
  9. ' Get hit by target loose 100 points and delay of game.
  10.  
  11. '2019-04-04 Keeping Ashish Target fix, wait until completely off screen.
  12. ' Now give the bullets a little long range before deactivating them.
  13. ' Fix shooter x, y by locating in center of shooter instead of nose. It's already OK!
  14.  
  15. ' 2021-03-19 using this code for oh program and want to fix point when target crashes into shooter/ship
  16. ' by reassignning target new coordinates by saying NewTarget index that should fix the continuous crashing right?
  17. ' Let's see, in oh it doesn't work, how about here?  Works just as expected. So what's up with oh?
  18. ' (Fixed it was an index goof for public variables used in GoSubs).
  19.  
  20.  
  21. 'screen dimensions
  22. CONST pip180 = 3.14159265 / 180
  23. CONST xmax = 1200
  24. CONST ymax = 700
  25. CONST nBullets = 15
  26. CONST bSpeed = 30
  27. CONST nTargets = 3 'should probably depend on level of play
  28. CONST tSpeed = 5 'should probably depend on level of play
  29. CONST shooterRadius = 50
  30.  
  31. TYPE shooterType
  32.     x AS SINGLE
  33.     y AS SINGLE
  34.     a AS SINGLE
  35.  
  36. TYPE bulletType
  37.     x AS INTEGER
  38.     y AS INTEGER
  39.     dx AS INTEGER
  40.     dy AS INTEGER
  41.     live AS INTEGER
  42.  
  43. TYPE targetType
  44.     x AS SINGLE
  45.     y AS SINGLE
  46.     a AS SINGLE
  47.     r AS INTEGER
  48.  
  49. SCREEN _NEWIMAGE(xmax, ymax, 32)
  50. _SCREENMOVE 100, 20
  51.  
  52.  
  53. DIM SHARED GameOn, mb1, last1, score
  54.  
  55. 'targets
  56. DIM SHARED t(nTargets - 1) AS targetType
  57. FOR i = 0 TO nTargets - 1: newTarget i: NEXT
  58.  
  59. 'bullets
  60. DIM SHARED b(nBullets - 1) AS bulletType
  61.  
  62. 'shooter
  63. DIM SHARED shooter AS shooterType
  64. shooter.x = xmax / 2
  65. shooter.y = ymax / 2
  66. shooter.a = 0
  67. lastx = xmax / 2: lasty = ymax / 2
  68.  
  69. 'game
  70. GameOn = 1
  71. WHILE GameOn
  72.     CLS
  73.     _TITLE "Target Practice   Score:" + STR$(score)
  74.     mb1 = 0: mb2 = 0
  75.  
  76.     shooter.x = _MOUSEX: shooter.y = _MOUSEY
  77.  
  78.  
  79.  
  80.  
  81.  
  82.     IF SQR((shooter.y - lasty) ^ 2 + (shooter.x - lastx) ^ 2) > 1 THEN
  83.         angle = degree(shooter.y - lasty, shooter.x - lastx) 'deg
  84.         dif_choice = 1000
  85.         FOR t = 0 TO 4
  86.             angle_dif = shooter_degree - (angle + 360 * (2 - t))
  87.             dif = ABS(angle_dif)
  88.             IF dif < dif_choice THEN angle_dif_choice = angle_dif: dif_choice = dif
  89.         NEXT t
  90.         shooter_degree = shooter_degree - angle_dif_choice * .25 'rotating speed (.25)
  91.         DO WHILE shooter_degree > 360: shooter_degree = shooter_degree - 360: LOOP
  92.         DO WHILE shooter_degree < 360: shooter_degree = shooter_degree + 360: LOOP
  93.         shooter.a = shooter_degree * pip180
  94.         lastx = shooter.x: lasty = shooter.y
  95.     END IF
  96.  
  97.  
  98.  
  99.  
  100.     t = TIMER(.001)
  101.     IF _MOUSEBUTTON(1) THEN 'when ship is heading north the left button should be left
  102.         IF t - last1 > .15 THEN mb1 = 1: last1 = t
  103.     END IF
  104.     handleTargets
  105.     drawshooter
  106.     handleBullets
  107.     _DISPLAY
  108.     _LIMIT 30
  109.  
  110. SUB handleTargets
  111.     FOR i = 0 TO nTargets - 1
  112.         'update position
  113.         t(i).x = t(i).x + tSpeed * COS(t(i).a)
  114.         t(i).y = t(i).y + tSpeed * SIN(t(i).a)
  115.         'inbounds?
  116.         IF t(i).x < -shooterRadius OR t(i).x > xmax + shooterRadius OR t(i).y < -shooterRadius OR t(i).y > ymax + shooterradiu THEN
  117.             newTarget i
  118.         ELSE
  119.             IF hitShooter(i) THEN 'now I discovered in oh program this continues to crash and deduct 100 until target moves through shooter
  120.                 'explosion
  121.                 CLS
  122.                 _PRINTSTRING (xmax / 2 - 40, ymax / 2 - 10), "Bang!... Ouch!"
  123.                 score = score - 100
  124.                 _DISPLAY
  125.                 _DELAY .2
  126.                 ' fix target crashing into ship by removing target with reassigning
  127.                 newTarget i ' in oh this does not work
  128.             ELSE
  129.                 drawTarget i
  130.             END IF
  131.         END IF
  132.     NEXT
  133.  
  134. SUB newTarget (i)
  135.     'pick edge
  136.     edge = INT(RND * 4)
  137.     SELECT CASE edge
  138.         CASE 0: t(i).x = -shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = RND * _PI
  139.         CASE 1: t(i).x = xmax + shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = _PI / 2 + RND * _PI
  140.         CASE 2: t(i).x = RND * xmax: t(i).y = -shooterRadius: t(i).a = RND * _PI
  141.         CASE 3: t(i).x = RND * xmax: t(i).y = ymax + shooterRadius: t(i).a = _PI + RND * _PI
  142.     END SELECT
  143.     t(i).r = (INT(RND * 8) + 3) * 10 '30 to 100 score 130 - radius 100 to 30
  144.  
  145. SUB drawTarget (i)
  146.     FOR r = t(i).r TO 0 STEP -t(i).r / 10
  147.         count = (count + 1) MOD 2
  148.         IF count THEN c~& = _RGB32(255, 0, 0) ELSE c~& = _RGB32(255, 255, 255)
  149.         fcirc t(i).x, t(i).y, r, c~&
  150.     NEXT
  151.  
  152. SUB handleBullets ()
  153.     FOR i = 0 TO nBullets - 1
  154.         IF b(i).live = 0 AND mb1 = 1 THEN 'have in active bullet index to use
  155.             b(i).x = shooter.x + .5 * shooterRadius * COS(shooter.a)
  156.             b(i).y = shooter.y + .5 * shooterRadius * SIN(shooter.a)
  157.             b(i).dx = bSpeed * COS(shooter.a)
  158.             b(i).dy = bSpeed * SIN(shooter.a)
  159.             b(i).live = 1
  160.             mb1 = 0
  161.             score = score - 10 'bullets cost 10 points
  162.  
  163.         ELSEIF b(i).live = 1 THEN 'new location
  164.             b(i).x = b(i).x + b(i).dx
  165.             b(i).y = b(i).y + b(i).dy
  166.             IF b(i).x > -50 AND b(i).x < xmax + 50 AND b(i).y > -50 AND b(i).y < ymax + 50 THEN 'in bounds draw it
  167.                 'check for collision with ...
  168.                 t = hitTarget(i)
  169.                 IF t > -1 THEN
  170.                     score = score + 130 - t(t).r
  171.                     b(i).live = 0
  172.                     newTarget t
  173.                 ELSE
  174.                     'draw bullet
  175.                     ba = _ATAN2(b(i).dy, b(i).dx): b = 15
  176.                     x1 = b(i).x + b * COS(ba)
  177.                     y1 = b(i).y + b * SIN(ba)
  178.                     x2 = b(i).x + b * COS(ba + _PI(5 / 6))
  179.                     y2 = b(i).y + b * SIN(ba + _PI(5 / 6))
  180.                     x3 = b(i).x + b * COS(ba + _PI(7 / 6))
  181.                     y3 = b(i).y + b * SIN(ba + _PI(7 / 6))
  182.                     fTri x1, y1, x2, y2, x3, y3, _RGB32(10, 160, 160)
  183.                     'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
  184.                 END IF
  185.             ELSE
  186.                 b(i).live = 0 'dectiveate
  187.             END IF
  188.         END IF
  189.     NEXT
  190.  
  191. FUNCTION hitTarget (bulletIndex)
  192.     hitTarget = -1
  193.     FOR i = 0 TO nTargets - 1
  194.         IF SQR((t(i).x - b(bulletIndex).x) ^ 2 + (t(i).y - b(bulletIndex).y) ^ 2) <= t(i).r THEN hitTarget = i: EXIT FUNCTION
  195.     NEXT
  196.  
  197. FUNCTION hitShooter (TargetIndex)
  198.     IF SQR((shooter.x - t(TargetIndex).x) ^ 2 + (shooter.y - t(TargetIndex).y) ^ 2) <= t(i).r THEN hitShooter = 1: EXIT FUNCTION
  199.  
  200. SUB drawshooter ()
  201.     x1 = shooter.x + (shooterRadius - 30) * COS(shooter.a)
  202.     y1 = shooter.y + (shooterRadius - 30) * SIN(shooter.a)
  203.     x2 = shooter.x + (shooterRadius + 20) * COS(shooter.a + _PI(11 / 16))
  204.     y2 = shooter.y + (shooterRadius + 20) * SIN(shooter.a + _PI(11 / 16))
  205.     x3 = shooter.x + (shooterRadius + 20) * COS(shooter.a - _PI(11 / 16))
  206.     y3 = shooter.y + (shooterRadius + 20) * SIN(shooter.a - _PI(11 / 16))
  207.     fTri x1, y1, x2, y2, x3, y3, _RGB32(85, 45, 0)
  208.     x1 = shooter.x + shooterRadius * COS(shooter.a)
  209.     y1 = shooter.y + shooterRadius * SIN(shooter.a)
  210.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(7 / 8))
  211.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(7 / 8))
  212.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(7 / 8))
  213.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(7 / 8))
  214.     fTri x1, y1, x2, y2, x3, y3, _RGB32(0, 0, 200)
  215.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(15 / 16))
  216.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(15 / 16))
  217.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(15 / 16))
  218.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(15 / 16))
  219.     fTri x1, y1, x2, y2, x3, y3, _RGB32(255, 255, 255)
  220.  
  221.     'check shooter x, y  = fixed a long time ago!
  222.     'fcirc shooter.x, shooter.y, 4, _RGB32(140, 120, 140)
  223.  
  224. ' 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
  225. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  226.     a& = _NEWIMAGE(1, 1, 32)
  227.     _DEST a&
  228.     PSET (0, 0), K
  229.     _DEST 0
  230.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  231.     _FREEIMAGE a& '<<< this is important!
  232.  
  233. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  234.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  235.     DIM X AS INTEGER, Y AS INTEGER
  236.  
  237.     Radius = ABS(R)
  238.     RadiusError = -Radius
  239.     X = Radius
  240.     Y = 0
  241.  
  242.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  243.  
  244.     ' Draw the middle span here so we don't draw it twice in the main loop,
  245.     ' which would be a problem with blending turned on.
  246.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  247.  
  248.     WHILE X > Y
  249.         RadiusError = RadiusError + Y * 2 + 1
  250.         IF RadiusError >= 0 THEN
  251.             IF X <> Y + 1 THEN
  252.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  253.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  254.             END IF
  255.             X = X - 1
  256.             RadiusError = RadiusError - X * 2
  257.         END IF
  258.         Y = Y + 1
  259.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  260.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  261.     WEND
  262.  
  263.  
  264. FUNCTION degree (a, b)
  265.     rd = (a + .00001) / (b + .0001): degree = ATN(rd) / pip180
  266.     IF 0 > b THEN degree = degree - 180
  267.     IF degree < 0 THEN degree = degree + 360
  268.  
  269.  
  270.  
« Last Edit: March 30, 2021, 02:33:11 pm by MasterGy »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #69 on: March 30, 2021, 05:17:02 pm »
I added explosion effects


Code: QB64: [Select]
  1. _TITLE "Mouse Action Shooter #2 Targets fix" 'B+ 2021-03-19
  2. 'Mouse Action Shooter started from eRATication 5 by bplus 2018-08-06"
  3. ' upodate Mouse Action Shooter with MB triggers 2019-04-01
  4. ' 2019-04-03 add some targets for practice
  5.  
  6. ' SCORE System:
  7. ' Right click to fire a bullet, they cost 10 points each.
  8. ' Targets range from 30 for biggest targets to 100 points for smallest Targets
  9. ' Get hit by target loose 100 points and delay of game.
  10.  
  11. '2019-04-04 Keeping Ashish Target fix, wait until completely off screen.
  12. ' Now give the bullets a little long range before deactivating them.
  13. ' Fix shooter x, y by locating in center of shooter instead of nose. It's already OK!
  14.  
  15. ' 2021-03-19 using this code for oh program and want to fix point when target crashes into shooter/ship
  16. ' by reassignning target new coordinates by saying NewTarget index that should fix the continuous crashing right?
  17. ' Let's see, in oh it doesn't work, how about here?  Works just as expected. So what's up with oh?
  18. ' (Fixed it was an index goof for public variables used in GoSubs).
  19.  
  20.  
  21. 'screen dimensions
  22. CONST pip180 = 3.14159265 / 180
  23. CONST xmax = 1200
  24. CONST ymax = 700
  25. CONST nBullets = 15
  26. CONST bSpeed = 30
  27. CONST nTargets = 3 'should probably depend on level of play
  28. CONST tSpeed = 5 'should probably depend on level of play
  29. CONST shooterRadius = 50
  30.  
  31. CONST explosions_buff = 2000: DIM SHARED explosions(explosions_buff - 1, 19) 'shards-dat array
  32. CONST explosions_s = 200 'number of shards 1 when exploding
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. TYPE shooterType
  43.     x AS SINGLE
  44.     y AS SINGLE
  45.     a AS SINGLE
  46.  
  47. TYPE bulletType
  48.     x AS INTEGER
  49.     y AS INTEGER
  50.     dx AS INTEGER
  51.     dy AS INTEGER
  52.     live AS INTEGER
  53.  
  54. TYPE targetType
  55.     x AS SINGLE
  56.     y AS SINGLE
  57.     a AS SINGLE
  58.     r AS INTEGER
  59.  
  60. SCREEN _NEWIMAGE(xmax, ymax, 32)
  61. _SCREENMOVE 100, 20
  62.  
  63.  
  64. DIM SHARED GameOn, mb1, last1, score
  65.  
  66. 'targets
  67. DIM SHARED t(nTargets - 1) AS targetType
  68. FOR i = 0 TO nTargets - 1: newTarget i: NEXT
  69.  
  70. 'bullets
  71. DIM SHARED b(nBullets - 1) AS bulletType
  72.  
  73. 'shooter
  74. DIM SHARED shooter AS shooterType
  75. shooter.x = xmax / 2
  76. shooter.y = ymax / 2
  77. shooter.a = 0
  78. lastx = xmax / 2: lasty = ymax / 2
  79.  
  80. 'game
  81. GameOn = 1
  82. WHILE GameOn
  83.     CLS
  84.     _TITLE "Target Practice   Score:" + STR$(score)
  85.     mb1 = 0: mb2 = 0
  86.  
  87.     shooter.x = _MOUSEX: shooter.y = _MOUSEY
  88.  
  89.  
  90.  
  91.  
  92.  
  93.     IF SQR((shooter.y - lasty) ^ 2 + (shooter.x - lastx) ^ 2) > 1 THEN
  94.         angle = degree(shooter.y - lasty, shooter.x - lastx) 'deg
  95.         dif_choice = 1000
  96.         FOR t = 0 TO 4
  97.             angle_dif = shooter_degree - (angle + 360 * (2 - t))
  98.             dif = ABS(angle_dif)
  99.             IF dif < dif_choice THEN angle_dif_choice = angle_dif: dif_choice = dif
  100.         NEXT t
  101.         shooter_degree = shooter_degree - angle_dif_choice * .25 'rotating speed (.25)
  102.         DO WHILE shooter_degree > 360: shooter_degree = shooter_degree - 360: LOOP
  103.         DO WHILE shooter_degree < 360: shooter_degree = shooter_degree + 360: LOOP
  104.         shooter.a = shooter_degree * pip180
  105.         lastx = shooter.x: lasty = shooter.y
  106.     END IF
  107.  
  108.  
  109.  
  110.  
  111.     t = TIMER(.001)
  112.     IF _MOUSEBUTTON(1) THEN 'when ship is heading north the left button should be left
  113.         IF t - last1 > .15 THEN mb1 = 1: last1 = t
  114.     END IF
  115.     handleTargets
  116.     drawshooter
  117.     handleBullets
  118.     explosions_control
  119.     explosions_draw
  120.     _DISPLAY
  121.     _LIMIT 30
  122.  
  123. SUB handleTargets
  124.     FOR i = 0 TO nTargets - 1
  125.         'update position
  126.         t(i).x = t(i).x + tSpeed * COS(t(i).a)
  127.         t(i).y = t(i).y + tSpeed * SIN(t(i).a)
  128.         'inbounds?
  129.         IF t(i).x < -shooterRadius OR t(i).x > xmax + shooterRadius OR t(i).y < -shooterRadius OR t(i).y > ymax + shooterradiu THEN
  130.  
  131.             newTarget i
  132.         ELSE
  133.             IF hitShooter(i) THEN 'now I discovered in oh program this continues to crash and deduct 100 until target moves through shooter
  134.                 'explosion
  135.                 CLS
  136.                 _PRINTSTRING (xmax / 2 - 40, ymax / 2 - 10), "Bang!... Ouch!"
  137.                 score = score - 100
  138.                 _DISPLAY
  139.                 _DELAY .2
  140.                 ' fix target crashing into ship by removing target with reassigning
  141.                 newTarget i ' in oh this does not work
  142.  
  143.             ELSE
  144.                 drawTarget i
  145.             END IF
  146.         END IF
  147.     NEXT
  148.  
  149. SUB newTarget (i)
  150.     'pick edge
  151.     edge = INT(RND * 4)
  152.     SELECT CASE edge
  153.         CASE 0: t(i).x = -shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = RND * _PI
  154.         CASE 1: t(i).x = xmax + shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = _PI / 2 + RND * _PI
  155.         CASE 2: t(i).x = RND * xmax: t(i).y = -shooterRadius: t(i).a = RND * _PI
  156.         CASE 3: t(i).x = RND * xmax: t(i).y = ymax + shooterRadius: t(i).a = _PI + RND * _PI
  157.     END SELECT
  158.     t(i).r = (INT(RND * 8) + 3) * 10 '30 to 100 score 130 - radius 100 to 30
  159.  
  160. SUB drawTarget (i)
  161.     FOR r = t(i).r TO 0 STEP -t(i).r / 10
  162.         count = (count + 1) MOD 2
  163.         IF count THEN c~& = _RGB32(255, 0, 0) ELSE c~& = _RGB32(255, 255, 255)
  164.         fcirc t(i).x, t(i).y, r, c~&
  165.     NEXT
  166.  
  167. SUB handleBullets ()
  168.     FOR i = 0 TO nBullets - 1
  169.         IF b(i).live = 0 AND mb1 = 1 THEN 'have in active bullet index to use
  170.             b(i).x = shooter.x + .5 * shooterRadius * COS(shooter.a)
  171.             b(i).y = shooter.y + .5 * shooterRadius * SIN(shooter.a)
  172.             b(i).dx = bSpeed * COS(shooter.a)
  173.             b(i).dy = bSpeed * SIN(shooter.a)
  174.             b(i).live = 1
  175.             mb1 = 0
  176.             score = score - 10 'bullets cost 10 points
  177.  
  178.         ELSEIF b(i).live = 1 THEN 'new location
  179.             b(i).x = b(i).x + b(i).dx
  180.             b(i).y = b(i).y + b(i).dy
  181.             IF b(i).x > -50 AND b(i).x < xmax + 50 AND b(i).y > -50 AND b(i).y < ymax + 50 THEN 'in bounds draw it
  182.                 'check for collision with ...
  183.                 t = hitTarget(i)
  184.                 IF t > -1 THEN
  185.                     score = score + 130 - t(t).r
  186.                     b(i).live = 0
  187.                     newTarget t
  188.  
  189.  
  190.                     explosions_add b(i).x, b(i).y, b(i).dx, b(i).dy
  191.                 ELSE
  192.                     'draw bullet
  193.                     ba = _ATAN2(b(i).dy, b(i).dx): b = 15
  194.                     x1 = b(i).x + b * COS(ba)
  195.                     y1 = b(i).y + b * SIN(ba)
  196.                     x2 = b(i).x + b * COS(ba + _PI(5 / 6))
  197.                     y2 = b(i).y + b * SIN(ba + _PI(5 / 6))
  198.                     x3 = b(i).x + b * COS(ba + _PI(7 / 6))
  199.                     y3 = b(i).y + b * SIN(ba + _PI(7 / 6))
  200.                     fTri x1, y1, x2, y2, x3, y3, _RGB32(10, 160, 160)
  201.                     'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
  202.                 END IF
  203.             ELSE
  204.                 b(i).live = 0 'dectiveate
  205.             END IF
  206.         END IF
  207.     NEXT
  208.  
  209. FUNCTION hitTarget (bulletIndex)
  210.     hitTarget = -1
  211.     FOR i = 0 TO nTargets - 1
  212.         IF SQR((t(i).x - b(bulletIndex).x) ^ 2 + (t(i).y - b(bulletIndex).y) ^ 2) <= t(i).r THEN hitTarget = i: EXIT FUNCTION
  213.     NEXT
  214.  
  215. FUNCTION hitShooter (TargetIndex)
  216.     IF SQR((shooter.x - t(TargetIndex).x) ^ 2 + (shooter.y - t(TargetIndex).y) ^ 2) <= t(i).r THEN hitShooter = 1: EXIT FUNCTION
  217.  
  218. SUB drawshooter ()
  219.     x1 = shooter.x + (shooterRadius - 30) * COS(shooter.a)
  220.     y1 = shooter.y + (shooterRadius - 30) * SIN(shooter.a)
  221.     x2 = shooter.x + (shooterRadius + 20) * COS(shooter.a + _PI(11 / 16))
  222.     y2 = shooter.y + (shooterRadius + 20) * SIN(shooter.a + _PI(11 / 16))
  223.     x3 = shooter.x + (shooterRadius + 20) * COS(shooter.a - _PI(11 / 16))
  224.     y3 = shooter.y + (shooterRadius + 20) * SIN(shooter.a - _PI(11 / 16))
  225.     fTri x1, y1, x2, y2, x3, y3, _RGB32(85, 45, 0)
  226.     x1 = shooter.x + shooterRadius * COS(shooter.a)
  227.     y1 = shooter.y + shooterRadius * SIN(shooter.a)
  228.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(7 / 8))
  229.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(7 / 8))
  230.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(7 / 8))
  231.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(7 / 8))
  232.     fTri x1, y1, x2, y2, x3, y3, _RGB32(0, 0, 200)
  233.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(15 / 16))
  234.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(15 / 16))
  235.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(15 / 16))
  236.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(15 / 16))
  237.     fTri x1, y1, x2, y2, x3, y3, _RGB32(255, 255, 255)
  238.  
  239.     'check shooter x, y  = fixed a long time ago!
  240.     'fcirc shooter.x, shooter.y, 4, _RGB32(140, 120, 140)
  241.  
  242. ' 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
  243. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  244.     a& = _NEWIMAGE(1, 1, 32)
  245.     _DEST a&
  246.     PSET (0, 0), K
  247.     _DEST 0
  248.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  249.     _FREEIMAGE a& '<<< this is important!
  250.  
  251. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  252.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  253.     DIM X AS INTEGER, Y AS INTEGER
  254.  
  255.     Radius = ABS(R)
  256.     RadiusError = -Radius
  257.     X = Radius
  258.     Y = 0
  259.  
  260.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  261.  
  262.     ' Draw the middle span here so we don't draw it twice in the main loop,
  263.     ' which would be a problem with blending turned on.
  264.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  265.  
  266.     WHILE X > Y
  267.         RadiusError = RadiusError + Y * 2 + 1
  268.         IF RadiusError >= 0 THEN
  269.             IF X <> Y + 1 THEN
  270.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  271.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  272.             END IF
  273.             X = X - 1
  274.             RadiusError = RadiusError - X * 2
  275.         END IF
  276.         Y = Y + 1
  277.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  278.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  279.     WEND
  280.  
  281.  
  282. FUNCTION degree (a, b)
  283.     rd = (a + .00001) / (b + .0001): degree = ATN(rd) / pip180
  284.     IF 0 > b THEN degree = degree - 180
  285.     IF degree < 0 THEN degree = degree + 360
  286.  
  287.  
  288. SUB explosions_add (x, y, xd, yd)
  289.     FOR t1 = 1 TO explosions_s
  290.         FOR t = 0 TO explosions_buff - 1
  291.             IF explosions(t, 0) THEN _CONTINUE
  292.             explosions(t, 0) = 1 'enable
  293.             explosions(t, 1) = x 'Xpos
  294.             explosions(t, 2) = y 'Ypos
  295.             explosions(t, 3) = 0 'xd / 2 'x direction
  296.             explosions(t, 4) = 0 'yd / 2 'y direction
  297.             angle = 360 * RND(1) 'random angle
  298.             speed = 50 * RND(1) 'shard speed
  299.             explosions(t, 5) = SIN(angle * pip180) * speed 'vector X
  300.             explosions(t, 6) = COS(angle * pip180) * speed 'vector Y
  301.             explosions(t, 7) = 100 * RND(1) 'boss cycle encounter
  302.             explosions(t, 8) = 360 * RND(1) ' random/actual angle in radian
  303.             explosions(t, 9) = (2 + 7 * RND(1)) * 4 'size
  304.             explosions(t, 10) = (2 + 8 * RND(1)) * 3 'stepping rotate in radian
  305.             explosions(t, 11) = 256 * RND(1) 'greyscale random color
  306.         NEXT t
  307.     NEXT t1
  308.  
  309. SUB explosions_control
  310.     FOR t = 0 TO explosions_buff - 1
  311.         IF explosions(t, 0) = 0 THEN _CONTINUE
  312.         explosions(t, 7) = explosions(t, 7) - 1 'cycle to dead
  313.         IF explosions(t, 7) <= 0 THEN explosions(t, 0) = 0: _CONTINUE 'if cycle 0, then inactive shard
  314.         explosions(t, 1) = explosions(t, 1) + explosions(t, 3) + explosions(t, 5) 'X pos add
  315.         explosions(t, 2) = explosions(t, 2) + explosions(t, 4) + explosions(t, 6) 'Y pos add
  316.         explosions(t, 8) = explosions(t, 8) + explosions(t, 10) 'actual degree in radian
  317.         explosions(t, 9) = explosions(t, 9) * .85 'size lower
  318.         explosions(t, 5) = explosions(t, 5) * .999 'vector X lower
  319.         explosions(t, 6) = explosions(t, 6) * .999 'vector Y lower
  320.     NEXT t
  321.  
  322. SUB explosions_draw
  323.     REDIM q(2, 1)
  324.     FOR t1 = 0 TO explosions_buff - 1
  325.         IF explosions(t1, 0) = 0 THEN _CONTINUE
  326.         FOR t = 0 TO 2
  327.             q(t, 0) = SIN((t * 120 + explosions(t1, 8)) * pip180) * explosions(t1, 9) + explosions(t1, 1)
  328.             q(t, 1) = COS((t * 120 + explosions(t1, 8)) * pip180) * explosions(t1, 9) + explosions(t1, 2)
  329.         NEXT t
  330.         fTri q(0, 0), q(0, 1), q(1, 0), q(1, 1), q(2, 0), q(2, 1), _RGB32(explosions(t1, 11), 0, 0)
  331.     NEXT t1
  332.    55:
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #70 on: March 30, 2021, 05:35:01 pm »
@MasterGy

Not seeing much difference in shooting but love the explosions!

Here are mine: https://www.qb64.org/forum/index.php?topic=3173.msg124984#msg124984

(In Hexagonal Minesweeper they leave craters!)
« Last Edit: March 30, 2021, 06:27:14 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #71 on: March 31, 2021, 11:24:00 am »
@MasterGy

I missed it on my first check but yes! You have fixed the jerkiness with the shooter with this:
Code: QB64: [Select]
  1.  
  2.  
  3.     IF SQR((shooter.y - lasty) ^ 2 + (shooter.x - lastx) ^ 2) > 1 THEN
  4.         angle = degree(shooter.y - lasty, shooter.x - lastx) 'deg
  5.         dif_choice = 1000
  6.         FOR t = 0 TO 4
  7.             angle_dif = shooter_degree - (angle + 360 * (2 - t))
  8.             dif = ABS(angle_dif)
  9.             IF dif < dif_choice THEN angle_dif_choice = angle_dif: dif_choice = dif
  10.         NEXT t
  11.         shooter_degree = shooter_degree - angle_dif_choice * .25 'rotating speed (.25)
  12.         DO WHILE shooter_degree > 360: shooter_degree = shooter_degree - 360: LOOP
  13.         DO WHILE shooter_degree < 360: shooter_degree = shooter_degree + 360: LOOP
  14.         shooter.a = shooter_degree * pip180
  15.         lastx = shooter.x: lasty = shooter.y
  16.     END IF
  17.  
  18.  

The test is to move and turn the shooter = ship in a tight circle, or spin even, and if the nose bounces between two angles with 5 -15 degrees difference it's "jerky".  MasterGy's version seems to have dampened down the the wild swings to a much smaller vibration 1-3 degrees.

Thank you! nice work. I will study and try to convert back to _ATAN2 if possible.
« Last Edit: March 31, 2021, 11:30:31 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MasterGy is looking for ideas to implement ("i suffer")
« Reply #72 on: April 01, 2021, 01:22:37 pm »
@MasterGy

Thanks for showing it possible to handle Mouse Action Shooting without the jerk problem caused by a method too sensitive to any movement like unintended movement when pressing left or right mouse button or just stopping mouse movement which often ends in a little unintended flick.

I managed to work out a system not requiring conversion to degrees or testing for minimum angles.
I posted it here:
https://www.qb64.org/forum/index.php?topic=3173.msg131314#msg131314

I am intending to install it in new update of Asteroids, b+ style :)