Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pinball
#1
I worked over 8 hours on this game so far, but I can't figure out how to make the oval flippers collide with the ball efficiently. So far, they work around 50% of the time. Much of this code is from when B+ helped me with hocky puck colliders awhile back and another big part of this code is math from ChatGPT, such as making the ovals turn on the axis at the end of the oval, for the flippers. 

You can still play this game if you keep pressing the 2 CTRL keys to move the flippers many times to hit the ball. But it would be nice if I could fix this, thanks. You can probably tell a lot of it has been made experimenting with numbers, etc. Smile I'm just zomped out. lol 

Code: (Select All)

'Pinball by SierraKen
'1-25-25

'Much of this code is from help by B+ with collisions awhile back.
'Thank you B+ and QB64pe Forum!
'Another large chunk of this math is from ChatGPT.

'The paddles only work about 50 percent of the time and I'm not sure how to fix that.
'OItherwise if you keep pressing the paddles they will work.

'The Left Paddle is the Left CTRL key and the Right Paddle is the Right CTRL key.

_Title "Pinball - by SierraKen - Press the Left and Right CTRL keys to move Paddles."


Randomize Timer
Screen _NewImage(800, 800, 32)

num = 12

ball = 10


Dim circx(num), circy(num), size(num), red(num), green(num), blue(num)

Dim X As Single, Y As Single
Dim Xc As Single, Yc As Single
Dim a As Single, b As Single
Dim theta As Single, t As Single
Dim thickness As Integer

Dim X2 As Single, Y2 As Single
Dim Xc2 As Single, Yc2 As Single
Dim a2 As Single, b2 As Single
Dim theta2 As Single, t2 As Single
Dim thickness2 As Integer

Xc = 500 ' Center of the screen
Yc = 700
a = 75 ' Semi-major axis
b = 25 ' Semi-minor axis
theta = 45 * _Pi / 180 ' Rotate 45 degrees in radians
thickness = 10 ' Thickness of the ellipse

Xc2 = 300 ' Center of the screen
Yc2 = 700
a2 = 75 ' Semi-major axis
b2 = 25 ' Semi-minor axis
theta2 = 45 * _Pi / -180 ' Rotate 45 degrees in radians
thickness2 = 10 ' Thickness of the ellipse

begin:

slotx = 280
sloty = 690
dir = 1

For cir = 1 To num
    If cir = 1 Then
        circx(cir) = 775
        circy(cir) = 25
        size(cir) = 50
    End If
    If cir = 2 Then
        circx(cir) = 25
        circy(cir) = 25
        size(cir) = 50
    End If
    If cir = 4 Then
        circx(cir) = 635
        circy(cir) = 200
        size(cir) = 40
    End If
    If cir = 5 Then
        circx(cir) = 175
        circy(cir) = 200
        size(cir) = 40
    End If
    If cir = 6 Then
        circx(cir) = 535
        circy(cir) = 350
        size(cir) = 30
    End If
    If cir = 7 Then
        circx(cir) = 275
        circy(cir) = 350
        size(cir) = 30
    End If
    If cir = 8 Then
        circx(cir) = 460
        circy(cir) = 500
        size(cir) = 20
    End If
    If cir = 9 Then
        circx(cir) = 355
        circy(cir) = 500
        size(cir) = 20
    End If
    If cir = 10 Then
        circx(cir) = 400
        circy(cir) = 550
        size(cir) = 15
    End If
    If cir = 11 Then
        circx(cir) = 800
        circy(cir) = 680
        size(cir) = 50
    End If
    If cir = 12 Then
        circx(cir) = 0
        circy(cir) = 680
        size(cir) = 165
    End If
    red(cir) = Rnd * 255
    green(cir) = Rnd * 255
    blue(cir) = Rnd * 255
Next cir


pr = 7 'Radius of ball
pc = _RGB32(0, 255, 0) 'Color of ball
'
speedx = 30 '
speedy = 30
gravity = 0.5 ' Gravitational acceleration (adjust this to simulate stronger/weaker gravity)
floorHeight = 680 ' Floor height, where the ball will stop when it hits


start:
px = (Rnd * 550) + 60: py = 60
_Delay 1
Cls

pa = _Pi(1) * Rnd


Play "MB"

Do

    _Limit 800
    Line (10, 10)-(790, 690), _RGB32(255, 255, 255), B

    For cir = 1 To num
        _Limit 800

        'Bumpers
        fillCircle circx(cir), circy(cir), size(cir), _RGB32(red(cir), green(cir), blue(cir))
        fillCircle circx(cir), circy(cir), size(cir) / 2, _RGB32(255, 255, 127)
        a$ = InKey$
        If a$ = " " Then GoTo start:
        If a$ = Chr$(27) Then End

        'Flippers
        If _KeyDown(100305) Then 'Right Side
            If theta > .85 Then GoTo skip1
            theta = theta + .05
        Else
            If theta < -.25 Then GoTo skip1
            theta = theta - .05
        End If
        skip1:
        If _KeyDown(100306) Then 'Left Side
            If theta2 < -.85 Then GoTo skip2
            theta2 = theta2 - .05
        Else
            If theta2 > .25 Then GoTo skip2
            theta2 = theta2 + .05
        End If
        skip2:
        For offset = 0 To thickness - 1 Step 0.5 ' Add layers for thickness
            For t2 = 0 To 2 * _Pi Step 0.01
                ' Calculate initial x and y for the oval before rotation
                X_initial = (a + offset) * Cos(t2)
                Y_initial = (b + offset) * Sin(t2)

                ' Translate so the end of the oval becomes the origin
                X_translated = X_initial - (a + offset)
                Y_translated = Y_initial

                ' Rotate around the new origin using theta
                X_rotated = X_translated * Cos(theta) - Y_translated * Sin(theta)
                Y_rotated = X_translated * Sin(theta) + Y_translated * Cos(theta)

                ' Translate back to the original position
                X2 = Xc + X_rotated + (a + offset)
                Y2 = Yc + Y_rotated

                ' Draw the point
                PSet (X2, Y2), _RGB32(255, 255, 255)
            Next
        Next

        For offset = 0 To thickness - 1 Step 0.5 ' Add layers for thickness
            For t = 0 To 2 * _Pi Step 0.01
                ' Calculate initial x and y for the second flipper
                X_initial = (a + offset) * Cos(t)
                Y_initial = (b + offset) * Sin(t)

                ' Translate so the opposite end of the oval becomes the origin
                X_translated = X_initial + (a + offset) ' Notice the + instead of -
                Y_translated = Y_initial

                ' Rotate around the new origin using theta for Flipper 2
                X_rotated = X_translated * Cos(theta2) - Y_translated * Sin(theta2)
                Y_rotated = X_translated * Sin(theta2) + Y_translated * Cos(theta2)

                ' Translate back to the original position for Flipper 2
                X = Xc2 + X_rotated - (a + offset) ' Translate back from the opposite end
                Y = Yc2 + Y_rotated

                ' Draw Flipper 2
                PSet (X, Y), _RGB32(255, 255, 255) ' Use a different color for Flipper 2
            Next
        Next

        'Check flippers
        For chk = -10 To 10 Step 1
            If Sqr((X + chk - px) ^ 2 + (Y + chk - py) ^ 2) < (pr + 35) Then
                pa = _Atan2(py - Y, px - X)
                collision px, py, pa, speedx, speedy
                px = px + speedx * Cos(pa)
                py = py + speedy * Sin(pa)
            End If
            If Sqr((X2 + chk - px) ^ 2 + (Y2 + chk - py) ^ 2) < (pr + 35) Then
                pa = _Atan2(py - Y2, px - Y2)
                collision px, py, pa, speedx, speedy
                px = px + speedx * Cos(pa)
                py = py + speedy * Sin(pa)
            End If
        Next chk

        'Check bumpers
        If Sqr((circx(cir) - px) ^ 2 + (circy(cir) - py) ^ 2) < (pr + size(cir)) Then
            pa = _Atan2(py - circy(cir), px - circx(cir))
            pa = pa + Rnd
            px = px + speedx * Cos(pa)
            py = py + speedy * Sin(pa)
            fillCircle circx(cir), circy(cir), size(cir), _RGB32(255, 0, 0)
            fillCircle circx(cir), circy(cir), size(cir) / 1.33, _RGB32(255, 255, 127)
            score = Int(score + 10000 / size(cir))
            Sound 350, .5, , , 2
            Sound 400, .5, , , 3
            Sound 350, .5, , , 4
            Sound 300, .5, , , 5
            _Title "Score: " + Str$(score) + "    Ball: " + Str$(ball) + "    Level: " + Str$(level)
            oldlevel = level
            level = Int(score \ 50000 + 1)
            If oldlevel <> level And level <> 1 Then GoTo begin:
        End If
        If speedx < 5 Then speedx = 5
        If speedy < 5 Then speedy = 5
        If speedx > 30 Then speedx = 30
        If speedy > 30 Then speedy = 30
    Next cir

    'Border reflection.
    If px > 790 - pr Then pa = _Pi - pa * Rnd + 1: px = 790 - pr
    If px < 10 + pr Then pa = _Pi - pa * Rnd + 1: px = 10 + pr
    If py > 790 - pr And floorHeight = 680 Then pa = -pa * Rnd + 1: py = 790 - pr
    If py < 10 + pr Then pa = -pa * Rnd + 1: py = 10 + pr

    If px > slotx + 30 And px < slotx + 170 And py > sloty - 70 Then
        floorHeight = floorHeight + 8
        If px > slotx + 60 And px < slotx + 200 And floorHeight > 760 Then
            ball = ball - 1
            _Title "Score: " + Str$(score) + "    Ball: " + Str$(ball) + "    Level: " + Str$(level)
            px = (Rnd * 550) + 60: py = 60
            down = 0
            floorHeight = 680
            _Delay 1
            If ball = 0 Then End
        End If
    Else
        floorHeight = 680
    End If

    ' Update velocities
    speedy = speedy + gravity ' Apply gravity to vertical speed

    ' Simulate ball bouncing off the floor
    If py + pr >= floorHeight And hit <> 1 Then
        py = floorHeight - pr ' Position ball on the floor
        speedy = -speedy * 0.9 ' Reverse direction and apply damping
    End If

    ' Simulate ball moving with some friction
    If Abs(speedx) > 0.1 Then
        speedx = speedx * 0.99 ' Friction effect on horizontal velocity
    Else
        speedx = 0 ' Stop ball when velocity is too low
    End If
    If speedx < 5 Then speedx = 5
    If speedy < 5 Then speedy = 5
    If speedx > 30 Then speedx = 30
    If speedy > 30 Then speedy = 30

    'Speed
    px = px + speedx * Cos(pa)
    py = py + speedy * Sin(pa)

    fillCircle px, py, pr, pc

    Line (slotx, sloty)-(slotx + 300, sloty), _RGB32(0, 0, 0)
    _Display
    Cls
Loop Until InKey$ = Chr$(27)

End

'from Steve Gold standard
Sub fillCircle (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, BF
    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    Wend
End Sub

Sub collision (px, py, pa, speedx, speedy)
    speedx = speedx + 5
    speedy = -speedy
    px = px + speedx * Cos(pa)
    py = py + speedy * Sin(pa)
End Sub
Reply
#2
What we need here is circle intersect ellipse routine. Anybody have one??

I am sure that AI would have something but can you get it to work?

Circle intersect circle, in my eyes, is so much easier that I used a whole string of circles to detect where the ball contacts the flipper. The ball going so fast one way and the flipper could be going the opposite the ball could jump right past the flipper without detection, ugly! Ha like the flipper was a hologram and not material.

I would focus on that one aspect, get that fixed and working like I did with flipper work here in WIP board. Literally forget the bells and whistles concentrate on flippers kicking the ball back correctly.

Good job getting the ellipsii to act as flipper, just need that collision detection!

Oh BTW you could probably Paint the interior of the flippers so they look solid.
b = b + ...
Reply
#3
@bplus I have improved the flippers a lot! They aren't 100% because they rarely can deflect from the bottom part down, so I might work on that soon. But so far so good! I also reshaped the flippers to a more realistic looking oval shape. Check it out. Smile If I can't fix the flipper deflection anymore than this, I will be satisfied. I used ChatGPT for some help again like you said. Smile I haven't tried PAINT yet on the flippers, but I might look into it. What do you think so far? 
Anyone, please copy any of this code if you wish to use some of it for your own projects, like usual. ChatGPT takes a lot of patience and a lot of testing. lol 

Code: (Select All)

'Pinball by SierraKen
'1-26-25

'Much of this code is from help by B+ with collisions awhile back.
'Thank you B+ and QB64pe Forum!
'Another large chunk of this math is from ChatGPT.

'The paddles only work about 50 percent of the time and I'm not sure how to fix that.
'OItherwise if you keep pressing the paddles they will work.

'The Left Paddle is the Left CTRL key and the Right Paddle is the Right CTRL key.

_Title "Pinball - by SierraKen - Press the Left and Right CTRL keys to move Paddles. Space Bar to reset ball."


Randomize Timer
Screen _NewImage(800, 800, 32)

num = 12

ball = 10


Dim circx(num), circy(num), size(num), red(num), green(num), blue(num)

Dim X As Single, Y As Single
Dim Xc As Single, Yc As Single
Dim a As Single, b As Single
Dim theta As Single, t As Single
Dim thickness As Integer

Dim X2 As Single, Y2 As Single
Dim Xc2 As Single, Yc2 As Single
Dim a2 As Single, b2 As Single
Dim theta2 As Single, t2 As Single
Dim thickness2 As Integer

Xc = 500 ' Center of the screen
Yc = 700
a = 75 ' Semi-major axis
b = 5 ' Semi-minor axis
theta = 45 * _Pi / 180 ' Rotate 45 degrees in radians
thickness = 10 ' Thickness of the ellipse

Xc2 = 300 ' Center of the screen
Yc2 = 700
a2 = 75 ' Semi-major axis
b2 = 10 ' Semi-minor axis
theta2 = 45 * _Pi / -180 ' Rotate 45 degrees in radians
thickness2 = 10 ' Thickness of the ellipse

begin:

slotx = 220
sloty = 690

For cir = 1 To num
    If cir = 1 Then
        circx(cir) = 775
        circy(cir) = 25
        size(cir) = 50
    End If
    If cir = 2 Then
        circx(cir) = 25
        circy(cir) = 25
        size(cir) = 50
    End If
    If cir = 4 Then
        circx(cir) = 635
        circy(cir) = 200
        size(cir) = 40
    End If
    If cir = 5 Then
        circx(cir) = 175
        circy(cir) = 200
        size(cir) = 40
    End If
    If cir = 6 Then
        circx(cir) = 535
        circy(cir) = 350
        size(cir) = 30
    End If
    If cir = 7 Then
        circx(cir) = 275
        circy(cir) = 350
        size(cir) = 30
    End If
    If cir = 8 Then
        circx(cir) = 460
        circy(cir) = 500
        size(cir) = 20
    End If
    If cir = 9 Then
        circx(cir) = 355
        circy(cir) = 500
        size(cir) = 20
    End If
    If cir = 10 Then
        circx(cir) = 400
        circy(cir) = 550
        size(cir) = 15
    End If
    If cir = 11 Then
        circx(cir) = 800
        circy(cir) = 680
        size(cir) = 50
    End If
    If cir = 12 Then
        circx(cir) = 0
        circy(cir) = 680
        size(cir) = 165
    End If
    red(cir) = Rnd * 255
    green(cir) = Rnd * 255
    blue(cir) = Rnd * 255
Next cir


pr = 12 'Radius of ball
pc = _RGB32(0, 255, 0) 'Color of ball

start: '
speedx = 30 '
speedy = 30
gravity = 0.5 ' Gravitational acceleration (adjust this to simulate stronger/weaker gravity)
floorHeight = 680 ' Floor height, where the ball will stop when it hits
px = (Rnd * 550) + 60: py = 60
_Delay 1
Cls

pa = _Pi(1) * Rnd

bounce = 0

Play "MB"

Do

    _Limit 1000

    Line (10, 10)-(790, 10), _RGB32(255, 255, 255)
    Line (790, 10)-(790, 690), _RGB32(255, 255, 255)
    Line (790, 690)-(slotx + 360, 690), _RGB32(255, 255, 255)
    Line (slotx, 690)-(10, 690), _RGB32(255, 255, 255)
    Line (10, 690)-(10, 10), _RGB32(255, 255, 255)

    For cir = 1 To num
        _Limit 1000

        'Bumpers
        fillCircle circx(cir), circy(cir), size(cir), _RGB32(red(cir), green(cir), blue(cir))
        fillCircle circx(cir), circy(cir), size(cir) / 2, _RGB32(255, 255, 127)
        a$ = InKey$
        If a$ = " " Then GoTo start
        If a$ = Chr$(27) Then End

        'Flippers
        If _KeyDown(100305) Then 'Right Side
            If theta > .85 Then GoTo skip1
            theta = theta + .05
        Else
            If theta < -.25 Then GoTo skip1
            theta = theta - .05
        End If
        skip1:
        If _KeyDown(100306) Then 'Left Side
            If theta2 < -.85 Then GoTo skip2
            theta2 = theta2 - .05
        Else
            If theta2 > .25 Then GoTo skip2
            theta2 = theta2 + .05
        End If
        skip2:
        'Right Fklipper
        For offset = 0 To thickness - 1 Step 0.5 ' Add layers for thickness
            For t2 = 0 To 2 * _Pi Step 0.01
                ' Calculate initial x and y for the oval before rotation
                X_initial = (a + offset) * Cos(t2)
                Y_initial = (b + offset) * Sin(t2)

                ' Translate so the end of the oval becomes the origin
                X_translated = X_initial - (a + offset)
                Y_translated = Y_initial

                ' Rotate around the new origin using theta
                X_rotated = X_translated * Cos(theta) - Y_translated * Sin(theta)
                Y_rotated = X_translated * Sin(theta) + Y_translated * Cos(theta)

                ' Translate back to the original position
                X2 = Xc + X_rotated + (a + offset)
                Y2 = Yc + Y_rotated

                ' Draw the point
                PSet (X2, Y2), _RGB32(255, 255, 255)
            Next
        Next

        'Left Flipper
        For offset = 0 To thickness - 1 Step 0.5 ' Add layers for thickness
            For t = 0 To 2 * _Pi Step 0.01
                ' Calculate initial x and y for the second flipper
                X_initial = (a + offset) * Cos(t)
                Y_initial = (b + offset) * Sin(t)

                ' Translate so the opposite end of the oval becomes the origin
                X_translated = X_initial + (a + offset) ' Notice the + instead of -
                Y_translated = Y_initial

                ' Rotate around the new origin using theta for Flipper 2
                X_rotated = X_translated * Cos(theta2) - Y_translated * Sin(theta2)
                Y_rotated = X_translated * Sin(theta2) + Y_translated * Cos(theta2)

                ' Translate back to the original position for Flipper 2
                X = Xc2 + X_rotated - (a + offset) ' Translate back from the opposite end
                Y = Yc2 + Y_rotated

                ' Draw Flipper 2
                PSet (X, Y), _RGB32(255, 255, 255) ' Use a different color for Flipper 2
            Next
        Next

        'Check flippers

        'Left flipper collision
        For chk = -5 To 30 Step .1
            If Sqr(((X - px + chk) / (a + thickness)) ^ 2 + ((Y - py + chk) / (b + thickness)) ^ 2) < 1 And bounce <> -1 Then
                ' Angle of impact considering flipper's rotation
                pa = _Atan2(py - Y, px - X)
                ' Adjust ball speed based on flipper angle
                speedx = speedx + 75 * Cos(theta2)
                speedy = speedy + 150 * Sin(theta2) ' Reverse Y velocity for upward motion
                speedy = -speedy
                px = px + speedx * Cos(pa)
                py = py + speedy * Sin(pa)
            End If
        Next chk
        For chk2 = 0 To -30 Step -.1

            'Right flipper collision
            If Sqr(((X2 - px + chk2) / (a + thickness)) ^ 2 + ((Y2 - py + chk2) / (b + thickness)) ^ 2) < 1 And bounce <> -1 Then
                ' Angle of impact considering flipper's rotation
                pa = _Atan2(py - Y2, px - X2)
                ' Adjust ball speed based on flipper angle
                speedx = speedx + 75 * Cos(theta)
                speedy = speedy + 150 * Sin(theta) ' Reverse Y velocity for upward motion
                speedy = -speedy
                px = px + speedx * Cos(pa)
                py = py + speedy * Sin(pa)
            End If
        Next chk2

        'Check bumpers
        If Sqr((circx(cir) - px) ^ 2 + (circy(cir) - py) ^ 2) < (pr + size(cir)) Then
            pa = _Atan2(py - circy(cir), px - circx(cir))
            pa = pa + Rnd
            px = px + speedx * Cos(pa)
            py = py + speedy * Sin(pa)
            fillCircle circx(cir), circy(cir), size(cir), _RGB32(255, 0, 0)
            fillCircle circx(cir), circy(cir), size(cir) / 1.33, _RGB32(255, 255, 127)
            score = Int(score + 10000 / size(cir))
            Sound 350, .5, , , 2
            Sound 400, .5, , , 3
            Sound 350, .5, , , 4
            Sound 300, .5, , , 5
            _Title "Score: " + Str$(score) + "    Ball: " + Str$(ball) + "    Level: " + Str$(level) + "    Space Bar To Reset Ball. CTRL keys for flippers."
            oldlevel = level
            level = Int(score \ 50000 + 1)
            If oldlevel <> level And level <> 1 Then GoTo begin:
        End If
        If speedx < -60 Then speedx = -60
        If speedy < -150 Then speedy = -150
        If speedx > 30 Then speedx = 30
        If speedy > 150 Then speedy = 150
    Next cir

    'Border reflection.
    If px > 790 - pr Then pa = _Pi - pa * Rnd + 1: px = 790 - pr
    If px < 10 + pr Then pa = _Pi - pa * Rnd + 1: px = 12 + pr
    If py > 790 - pr Then
        If px < slotx Or px > slotx + 360 Then
            pa = -pa * Rnd + 1: py = 790 - pr
        End If
    End If
    If py < 10 + pr Then pa = -pa * Rnd + 1: py = 10 + pr

    If px > slotx + 100 And px < slotx + 300 And py > 670 Then
        floorHeight = floorHeight + 6
        bounce = -1
        '_Title Str$(floorHeight)
        If px > slotx + 150 And px < slotx + 250 And py > 800 Then
            ball = ball - 1
            _Title "Score: " + Str$(score) + "    Ball: " + Str$(ball) + "    Level: " + Str$(level) + "    Space Bar To Reset Ball, CTRL keys for flippers."
            px = (Rnd * 550) + 60: py = 60
            down = 0
            floorHeight = 680
            _Delay 1
            If ball = 0 Then End
        End If
    Else
        bounce = 0
        floorHeight = 680
    End If


    ' Update velocities
    speedy = speedy + gravity ' Apply gravity to vertical speed

    ' Simulate ball bouncing off the floor
    If py + pr >= floorHeight And hit <> 1 Then
        py = floorHeight - pr ' Position ball on the floor
        speedy = -speedy * 0.9 ' Reverse direction and apply damping
    End If

    ' Simulate ball moving with some friction
    If Abs(speedx) > 0.1 Then
        speedx = speedx * 0.99 ' Friction effect on horizontal velocity
    Else
        speedx = 0 ' Stop ball when velocity is too low
    End If
    If speedx < 5 Then speedx = 5
    If speedy < 5 Then speedy = 5
    If speedx > 30 Then speedx = 30
    If speedy > 30 Then speedy = 30

    'Speed
    px = px + speedx * Cos(pa)
    py = py + speedy * Sin(pa)

    fillCircle px, py, pr, pc

    _Display
    Cls
Loop Until InKey$ = Chr$(27)

End

'from Steve Gold standard
Sub fillCircle (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, BF
    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    Wend
End Sub

Sub collision (px, py, pa, speedx, speedy)
    speedx = speedx + 5
    speedy = -speedy
    px = px + speedx * Cos(pa)
    py = py + speedy * Sin(pa)
End Sub
Reply
#4
It looks like the flippers aren't doing anything with ball collisions and the ball is taking really strange bounces off side walls like rolling upwards along the wall sometimes. The kicks off circles look OK.

If you Paint the flippers you can use Point to tell when the ball has collided with a flpper that makes collision detection easier.

BTW that screen height is more than my screen can handle, the title bar and below the flippers don't both fit. 720 is a comfortable maximum for my screen.
b = b + ...
Reply
#5
Thanks for your help B+, but I tried POINT and stuff keeps messing up. I will look at it again later.
Reply
#6
When you tried Point were the flippers one unique color? Right now it looks like the flippers AND the borders are white. And were the flippers Painted that one unique color?

And now for the hard part:
When you do catch the ball colliding with color flipper ie along the bottom semi circle edge of the ball (which is first to make contact with flipper) it will probably be over several points along the edge.
Math to gather those points on bottom edge of ball.

Which point to take, to shoot the ball back from? The Middle one would be a good guess.
And more Math!!!

Sorry but this More Math is nothing like the math for the collision of a circle and an ellipse, I think.
b = b + ...
Reply
#7
I have the same issue with screen height. If it were mouse driven, I'd be opening up all sorts of **** from my taskbar while playing.

Pete Big Grin
Reply




Users browsing this thread: 1 Guest(s)