Here's an even better one. The ball somewhat goes toward the direction of where the mouse pointer is now. It's still very random, but I think it would be a fun game.
Feel free to adjust the code of course. This was all done with experimentation.
Feel free to adjust the code of course. This was all done with experimentation.
Code: (Select All)
'Ken's Throw The Ball Demonstration
'I got the parabola equation and SGN command for random numbers from ChatGPT and I made the rest.
'Feel free to use this as you wish.
Screen _NewImage(800, 600, 32)
Cls
_Title "Click The Left Mouse Button To Throw"
' Define the coefficients for the parabola y = ax^2 + bx + c
Dim a As Double, b As Double, c As Double
centerX = 400
centerY = 300
c = 0
s = 100
ball = 8
Randomize Timer
Do
Do
Do While _MouseInput
If _MouseButton(1) Then
b = Int(Rnd * _Pi) + 6
a = Int(Rnd * 7) - 7
'randomx = (Rnd * 10) * Sgn(Rnd - 0.5)
If _MouseX < 400 Then randomx = _MouseX / 30 * -1
If _MouseX > 399 Then randomx = _MouseX / 50
randomy = _MouseY / 30
Cls
End If
Loop
Loop Until _MouseButton(1)
' Set up a loop to draw the parabola
For x = -20 To 30 + a Step .5
' Calculate y using the parabola equation
y = a * (x / 10) ^ 2 + b * (x / 10) + c
' Convert to screen coordinates
screenX = centerX + x * randomx
'screenY = centerY - y * 10
screeny = centerY - y * randomy
If ball > 1.5 Then ball = ball - .2
' Plot the point
Circle (screenX, screeny), ball, _RGB32(255, 255, 255)
_Delay .05
s = s + .1
Sound s, 1
_Display
Cls
Next x
s = 100
ball = 8
Loop Until InKey$ = Chr$(27)
End