Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pong Clone
#1
With the help of B+'s reflection math code, I decided to make a Pong Clone today. You play against the computer using your mouse. First to reach 10 points wins. B+, I added your name to the welcome screen. Tell me what you think. It was a bit tricky to make it not too easy but also not impossible, I believe I found the right middle ground. There's a photo of it below. Smile Thanks for the help B+, I've always wanted to make my own Pong. I know most of them have rectangle rackets but I found it's more enjoyable to aim the ball with a round racket instead. 

[Image: Pong-Clone-by-Sierra-Ken.jpg]

Code: (Select All)
'Pong Clone by SierraKen - May 25, 2022.
'Thank you to B+ for the deflection math code!

_Title "Pong Clone - by SierraKen"
Screen _NewImage(800, 600, 32)
Cls
Locate 4, 35: Print "P  O   N   G     C   L   O   N   E"
Locate 7, 44: Print "By SierraKen"
Locate 10, 44: Print "With help by B+"
Locate 15, 25: Print "Use your mouse to control the round paddle on the right side."
Locate 16, 25: Print "First one to reach 10 points wins."
Locate 20, 37: Print "Press Mouse Button To Begin."
Do
    While _MouseInput: Wend
    If _MouseButton(1) = -1 Then GoTo begin:
Loop

begin:
Randomize Timer

' these remain constant
px = 350: py = 250: pr = 5: pc = _RGB32(0, 255, 0) ' <<<< lets label everything of puck with p
speed = 7 ' really keeping puck at constant speed

cx = 100: cy = 300: cr = 25: cc = _RGB32(255, 0, 0) 'Computer Racket
mx = 700: mr = 25: mc = _RGB32(255, 0, 0) ' <<<< evrything mouse starts with m , use different radius for mouse - Your Racket

score = 0
cscore = 0

start:
px = 400: py = 300
Cls
angle:
pa = _Pi(2) * Rnd ' pa = puck angle this is rnd times all directions 0 to 360 in degrees 0 to 2*pi in radians
ang = _R2D(pa)

If ang > 85 And ang < 95 Then GoTo angle:
If ang > 265 And ang < 275 Then GoTo angle:
Do

    Cls ' Clear our work and recalulate and redraw everything
    Line (25, 25)-(775, 25), _RGB32(255, 255, 255)
    Line (25, 575)-(775, 575), _RGB32(255, 255, 255)
    For nety = 25 To 575 Step 20
        Line (400, nety)-(400, nety + 10), _RGB32(255, 255, 255)
    Next nety


    Locate 1, 10: Print " Computer: "; cscore
    Locate 1, 78: Print " You: "; score
    If cscore = 10 Then
        _AutoDisplay
        Cls
        Locate 5, 40
        Print "You Lose!"
        Locate 10, 40
        Print "Again (Y/N)?";
        again:
        ag$ = InKey$
        If ag$ = "y" Or ag$ = "Y" Then GoTo begin:
        If ag$ = "n" Or ag$ = "N" Or ag$ = Chr$(27) Then End
        GoTo again
    End If
    If score = 10 Then
        _AutoDisplay
        Cls
        Locate 5, 20
        Print "You Win!"
        Locate 10, 20
        Print "Again (Y/N)?";
        again2:
        ag2$ = InKey$
        If ag2$ = "y" Or ag2$ = "Y" Then GoTo begin:
        If ag2$ = "n" Or ag2$ = "N" Or ag2$ = Chr$(27) Then End
        GoTo again2
    End If

    a$ = InKey$
    If a$ = " " Then GoTo start:
    If a$ = Chr$(27) Then End

    While _MouseInput: Wend ' better way to poll mouse and label mouse x, y as mx, my like everyone else
    my = _MouseY
    fillCircle mx, my, mr, mc ' draw mouse paddle

    ' check for collision
    ' first part measure distance between mouse center and puck center, is it less than radius of mouse + puck?
    If Sqr((mx - px) ^ 2 + (my - py) ^ 2) < (pr + mr) Then ' (pr + pr2) to (r + rr)   collision!
        pa = _Atan2(py - my, px - mx) ' get the angle of the puck to the mouse

        px = px + speed * Cos(pa) ' move the puck out of the mouse paddle
        py = py + speed * Sin(pa) '

        ' show the collision and replacement of ball AFTER removed from inside the mouse
        Line (mx, my)-(px, py), &HFFFFFFFF
        _Display
        _Delay .1
    End If

    If py > cy Then
        cdist = py - cy
        cy = cy + cdist / 6.25
    End If
    If py < cy Then
        cdist = cy - py
        cy = cy - cdist / 6.25
    End If
    fillCircle cx, cy, cr, cc
    If Sqr((cx - px) ^ 2 + (cy - py) ^ 2) < (pr + cr) Then ' (pr + pr2) to (r + rr)   collision!
        pa = _Atan2(py - cy, px - cx) ' get the angle of the puck to the mouse

        px = px + speed * Cos(pa) ' move the puck out of the mouse paddle
        py = py + speed * Sin(pa) '

        ' show the collision and replacement of ball AFTER removed from inside the mouse
        Line (cx, cy)-(px, py), &HFFFFFFFF
        _Display
        _Delay .1
    End If


    'keep puck out of wall = wall boundary +- radius of puck
    If px > 775 Then cscore = cscore + 1: _Delay .25: GoTo start:
    If px < 25 Then score = score + 1: _Delay .25: GoTo start:
    If py > 575 - pr Then pa = -pa: py = 575 - pr ' move puck out of wall !!!
    If py < 25 + pr Then pa = -pa: py = 25 + pr ' move puck out of wall !!!

    ' nove the puck along and draw it
    px = px + speed * Cos(pa) ' now move the puck along  it's new direction pa = puck angle
    py = py + speed * Sin(pa) '
    fillCircle px, py, pr, pc ' draw puck

    _Display
    _Limit 60 ' hold screen for moment

Loop

'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
Reply
#2
I made a quick fix to make it easier after you win or lose and want to play again that you have enough time to look at the ball by going to the welcome screen instead.

Code: (Select All)
'Pong Clone by SierraKen - May 25, 2022.
'Thank you to B+ for the deflection math code!

_Title "Pong Clone - by SierraKen"
Screen _NewImage(800, 600, 32)
begin:
Cls
Locate 4, 35: Print "P  O   N   G     C   L   O   N   E"
Locate 7, 44: Print "By SierraKen"
Locate 10, 44: Print "With help by B+"
Locate 15, 25: Print "Use your mouse to control the round paddle on the right side."
Locate 16, 25: Print "First one to reach 10 points wins."
Locate 20, 37: Print "Press Mouse Button To Begin."
Do
    While _MouseInput: Wend
    If _MouseButton(1) = -1 Then GoTo begin2:
Loop

begin2:
Randomize Timer

' these remain constant
px = 350: py = 250: pr = 5: pc = _RGB32(0, 255, 0) ' <<<< lets label everything of puck with p
speed = 7 ' really keeping puck at constant speed

cx = 100: cy = 300: cr = 25: cc = _RGB32(255, 0, 0) 'Computer Racket
mx = 700: mr = 25: mc = _RGB32(255, 0, 0) ' <<<< evrything mouse starts with m , use different radius for mouse - Your Racket

score = 0
cscore = 0

start:
px = 400: py = 300
Cls
angle:
pa = _Pi(2) * Rnd ' pa = puck angle this is rnd times all directions 0 to 360 in degrees 0 to 2*pi in radians
ang = _R2D(pa)

If ang > 85 And ang < 95 Then GoTo angle:
If ang > 265 And ang < 275 Then GoTo angle:
Do

    Cls ' Clear our work and recalulate and redraw everything
    Line (25, 25)-(775, 25), _RGB32(255, 255, 255)
    Line (25, 575)-(775, 575), _RGB32(255, 255, 255)
    For nety = 25 To 575 Step 20
        Line (400, nety)-(400, nety + 10), _RGB32(255, 255, 255)
    Next nety


    Locate 1, 10: Print " Computer: "; cscore
    Locate 1, 78: Print " You: "; score
    If cscore = 10 Then
        _AutoDisplay
        Cls
        Locate 5, 40
        Print "You Lose!"
        Locate 10, 40
        Print "Again (Y/N)?";
        again:
        ag$ = InKey$
        If ag$ = "y" Or ag$ = "Y" Then GoTo begin:
        If ag$ = "n" Or ag$ = "N" Or ag$ = Chr$(27) Then End
        GoTo again
    End If
    If score = 10 Then
        _AutoDisplay
        Cls
        Locate 5, 20
        Print "You Win!"
        Locate 10, 20
        Print "Again (Y/N)?";
        again2:
        ag2$ = InKey$
        If ag2$ = "y" Or ag2$ = "Y" Then GoTo begin:
        If ag2$ = "n" Or ag2$ = "N" Or ag2$ = Chr$(27) Then End
        GoTo again2
    End If

    a$ = InKey$
    If a$ = " " Then GoTo start:
    If a$ = Chr$(27) Then End

    While _MouseInput: Wend ' better way to poll mouse and label mouse x, y as mx, my like everyone else
    my = _MouseY
    fillCircle mx, my, mr, mc ' draw mouse paddle

    ' check for collision
    ' first part measure distance between mouse center and puck center, is it less than radius of mouse + puck?
    If Sqr((mx - px) ^ 2 + (my - py) ^ 2) < (pr + mr) Then ' (pr + pr2) to (r + rr)   collision!
        pa = _Atan2(py - my, px - mx) ' get the angle of the puck to the mouse

        px = px + speed * Cos(pa) ' move the puck out of the mouse paddle
        py = py + speed * Sin(pa) '

        ' show the collision and replacement of ball AFTER removed from inside the mouse
        Line (mx, my)-(px, py), &HFFFFFFFF
        _Display
        _Delay .1
    End If

    If py > cy Then
        cdist = py - cy
        cy = cy + cdist / 6.25
    End If
    If py < cy Then
        cdist = cy - py
        cy = cy - cdist / 6.25
    End If
    fillCircle cx, cy, cr, cc
    If Sqr((cx - px) ^ 2 + (cy - py) ^ 2) < (pr + cr) Then ' (pr + pr2) to (r + rr)   collision!
        pa = _Atan2(py - cy, px - cx) ' get the angle of the puck to the mouse

        px = px + speed * Cos(pa) ' move the puck out of the mouse paddle
        py = py + speed * Sin(pa) '

        ' show the collision and replacement of ball AFTER removed from inside the mouse
        Line (cx, cy)-(px, py), &HFFFFFFFF
        _Display
        _Delay .1
    End If


    'keep puck out of wall = wall boundary +- radius of puck
    If px > 775 Then cscore = cscore + 1: _Delay .25: GoTo start:
    If px < 25 Then score = score + 1: _Delay .25: GoTo start:
    If py > 575 - pr Then pa = -pa: py = 575 - pr ' move puck out of wall !!!
    If py < 25 + pr Then pa = -pa: py = 25 + pr ' move puck out of wall !!!

    ' nove the puck along and draw it
    px = px + speed * Cos(pa) ' now move the puck along  it's new direction pa = puck angle
    py = py + speed * Sin(pa) '
    fillCircle px, py, pr, pc ' draw puck

    _Display
    _Limit 60 ' hold screen for moment

Loop

'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
Reply
#3
Hi Ken,

Looks pretty good. Don't need the delay or to show the white line of collision when a ball hits a paddle.

Do need a little delay before throwing out the next ball after someone wins a point and specially at start of game. Give human a chance to get his bearings.
Maybe a count down 3, 2, 1...?
b = b + ...
Reply
#4
Thanks B+, I took your recommendations and did all of them. Hopefully there's enough delay on it. 

Code: (Select All)
'Pong Clone by SierraKen - May 25, 2022.
'Thank you to B+ for the deflection math code!

_Title "Pong Clone - by SierraKen"
Screen _NewImage(800, 600, 32)
begin:
Cls
Locate 4, 35: Print "P  O   N   G     C   L   O   N   E"
Locate 7, 44: Print "By SierraKen"
Locate 10, 44: Print "With help by B+"
Locate 15, 25: Print "Use your mouse to control the round paddle on the right side."
Locate 16, 25: Print "First one to reach 10 points wins."
Locate 20, 37: Print "Press Mouse Button To Begin."
Do
    While _MouseInput: Wend
    If _MouseButton(1) = -1 Then GoTo begin2:
Loop

begin2:
Randomize Timer

' these remain constant
px = 350: py = 250: pr = 5: pc = _RGB32(0, 255, 0) ' <<<< lets label everything of puck with p
speed = 7 ' really keeping puck at constant speed

cx = 100: cy = 300: cr = 25: cc = _RGB32(255, 0, 0) 'Computer Racket
mx = 700: mr = 25: mc = _RGB32(255, 0, 0) ' <<<< evrything mouse starts with m , use different radius for mouse - Your Racket

score = 0
cscore = 0

start:
px = 400: py = 300
Cls
angle:
pa = _Pi(2) * Rnd ' pa = puck angle this is rnd times all directions 0 to 360 in degrees 0 to 2*pi in radians
ang = _R2D(pa)

If ang > 85 And ang < 95 Then GoTo angle:
If ang > 265 And ang < 275 Then GoTo angle:
_Delay .5
Do

    Cls ' Clear our work and recalulate and redraw everything
    Line (25, 25)-(775, 25), _RGB32(255, 255, 255)
    Line (25, 575)-(775, 575), _RGB32(255, 255, 255)
    For nety = 25 To 575 Step 20
        Line (400, nety)-(400, nety + 10), _RGB32(255, 255, 255)
    Next nety


    Locate 1, 10: Print " Computer: "; cscore
    Locate 1, 78: Print " You: "; score
    If cscore = 10 Then
        _AutoDisplay
        Cls
        Locate 5, 40
        Print "You Lose!"
        Locate 10, 40
        Print "Again (Y/N)?";
        again:
        ag$ = InKey$
        If ag$ = "y" Or ag$ = "Y" Then GoTo begin:
        If ag$ = "n" Or ag$ = "N" Or ag$ = Chr$(27) Then End
        GoTo again
    End If
    If score = 10 Then
        _AutoDisplay
        Cls
        Locate 5, 20
        Print "You Win!"
        Locate 10, 20
        Print "Again (Y/N)?";
        again2:
        ag2$ = InKey$
        If ag2$ = "y" Or ag2$ = "Y" Then GoTo begin:
        If ag2$ = "n" Or ag2$ = "N" Or ag2$ = Chr$(27) Then End
        GoTo again2
    End If

    a$ = InKey$
    If a$ = " " Then GoTo start:
    If a$ = Chr$(27) Then End

    While _MouseInput: Wend ' better way to poll mouse and label mouse x, y as mx, my like everyone else
    my = _MouseY
    fillCircle mx, my, mr, mc ' draw mouse paddle

    ' check for collision
    ' first part measure distance between mouse center and puck center, is it less than radius of mouse + puck?
    If Sqr((mx - px) ^ 2 + (my - py) ^ 2) < (pr + mr) Then ' (pr + pr2) to (r + rr)   collision!
        pa = _Atan2(py - my, px - mx) ' get the angle of the puck to the mouse

        px = px + speed * Cos(pa) ' move the puck out of the mouse paddle
        py = py + speed * Sin(pa) '

        _Display
    End If

    If py > cy Then
        cdist = py - cy
        cy = cy + cdist / 6.25
    End If
    If py < cy Then
        cdist = cy - py
        cy = cy - cdist / 6.25
    End If
    fillCircle cx, cy, cr, cc
    If Sqr((cx - px) ^ 2 + (cy - py) ^ 2) < (pr + cr) Then ' (pr + pr2) to (r + rr)   collision!
        pa = _Atan2(py - cy, px - cx) ' get the angle of the puck to the mouse

        px = px + speed * Cos(pa) ' move the puck out of the mouse paddle
        py = py + speed * Sin(pa) '

        _Display
    End If


    'keep puck out of wall = wall boundary +- radius of puck
    If px > 775 Then cscore = cscore + 1: _Delay .25: GoTo start:
    If px < 25 Then score = score + 1: _Delay .25: GoTo start:
    If py > 575 - pr Then pa = -pa: py = 575 - pr ' move puck out of wall !!!
    If py < 25 + pr Then pa = -pa: py = 25 + pr ' move puck out of wall !!!

    ' nove the puck along and draw it
    px = px + speed * Cos(pa) ' now move the puck along  it's new direction pa = puck angle
    py = py + speed * Sin(pa) '
    fillCircle px, py, pr, pc ' draw puck

    _Display
    _Limit 60 ' hold screen for moment

Loop

'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
Reply
#5
By the way, in case you were wondering, I didn't use your A.I. for the computer. I calculated the Y distance from his racket to the ball and the further the Y distance, the faster he goes. But I had to make somewhat of an offset to not make it impossible. lol
Reply
#6
Yeah that was good, I noticed it can't quite catch up on extreme angles.
b = b + ...
Reply
#7
Talking about angles. I made it so it doesn't start out at the most extreme angles, around 10 degrees before and after the tightest angles, so people wouldn't sit there waiting for it to bounce back and forth a million times. LOL
Sometimes it can catch up, but yeah sometimes it can't.
Reply
#8
nice. with sound, it would be better.
Reply
#9
You were right Coolman, sounds really livens it up, thanks for the recommendation. I also made the delay longer from 1/2 second to 1 second before each ball starts. 
B+, I didn't know that putting the Sound command in a Sub helps the flow of the program go on and not stop, that is so cool! I saw you did that on your Air Hockey game. I used a bit of a different sound than yours I think.
Here is the update: 

Code: (Select All)
'Pong Clone by SierraKen - May 25, 2022.
'Thank you to B+ for the deflection math code!
'Thanks also to Coolman for sounds recommendation.

_Title "Pong Clone - by SierraKen"
Screen _NewImage(800, 600, 32)
begin:
Cls
Locate 4, 35: Print "P  O   N   G     C   L   O   N   E"
Locate 7, 44: Print "By SierraKen"
Locate 10, 44: Print "With help by B+"
Locate 15, 25: Print "Use your mouse to control the round paddle on the right side."
Locate 16, 25: Print "First one to reach 10 points wins."
Locate 20, 37: Print "Press Mouse Button To Begin."
Do
    While _MouseInput: Wend
    If _MouseButton(1) = -1 Then GoTo begin2:
Loop

begin2:
Randomize Timer

' these remain constant
px = 350: py = 250: pr = 5: pc = _RGB32(0, 255, 0) ' <<<< lets label everything of puck with p
speed = 7 ' really keeping puck at constant speed

cx = 100: cy = 300: cr = 25: cc = _RGB32(255, 0, 0) 'Computer Racket
mx = 700: mr = 25: mc = _RGB32(255, 0, 0) ' <<<< evrything mouse starts with m , use different radius for mouse - Your Racket

score = 0
cscore = 0
freq = 600
timing = .5
start:
px = 400: py = 300
Cls
angle:
pa = _Pi(2) * Rnd ' pa = puck angle this is rnd times all directions 0 to 360 in degrees 0 to 2*pi in radians
ang = _R2D(pa)

If ang > 85 And ang < 95 Then GoTo angle:
If ang > 265 And ang < 275 Then GoTo angle:
_Delay 1
Do

    Cls ' Clear our work and recalulate and redraw everything
    Line (25, 25)-(775, 25), _RGB32(255, 255, 255)
    Line (25, 575)-(775, 575), _RGB32(255, 255, 255)
    For nety = 25 To 575 Step 20
        Line (400, nety)-(400, nety + 10), _RGB32(255, 255, 255)
    Next nety


    Locate 1, 10: Print " Computer: "; cscore
    Locate 1, 78: Print " You: "; score
    If cscore = 10 Then
        _AutoDisplay
        Cls
        Locate 5, 40
        Print "You Lose!"
        Locate 10, 40
        Print "Again (Y/N)?";
        again:
        ag$ = InKey$
        If ag$ = "y" Or ag$ = "Y" Then GoTo begin:
        If ag$ = "n" Or ag$ = "N" Or ag$ = Chr$(27) Then End
        GoTo again
    End If
    If score = 10 Then
        _AutoDisplay
        Cls
        Locate 5, 20
        Print "You Win!"
        Locate 10, 20
        Print "Again (Y/N)?";
        again2:
        ag2$ = InKey$
        If ag2$ = "y" Or ag2$ = "Y" Then GoTo begin:
        If ag2$ = "n" Or ag2$ = "N" Or ag2$ = Chr$(27) Then End
        GoTo again2
    End If

    a$ = InKey$
    If a$ = " " Then GoTo start:
    If a$ = Chr$(27) Then End

    While _MouseInput: Wend ' better way to poll mouse and label mouse x, y as mx, my like everyone else
    my = _MouseY
    fillCircle mx, my, mr, mc ' draw mouse paddle

    ' check for collision
    ' first part measure distance between mouse center and puck center, is it less than radius of mouse + puck?
    If Sqr((mx - px) ^ 2 + (my - py) ^ 2) < (pr + mr) Then ' (pr + pr2) to (r + rr)   collision!
        pa = _Atan2(py - my, px - mx) ' get the angle of the puck to the mouse

        px = px + speed * Cos(pa) ' move the puck out of the mouse paddle
        py = py + speed * Sin(pa) '
        sounds freq, timing
        _Display
    End If

    If py > cy Then
        cdist = py - cy
        cy = cy + cdist / 6.25
    End If
    If py < cy Then
        cdist = cy - py
        cy = cy - cdist / 6.25
    End If
    fillCircle cx, cy, cr, cc
    If Sqr((cx - px) ^ 2 + (cy - py) ^ 2) < (pr + cr) Then ' (pr + pr2) to (r + rr)   collision!
        pa = _Atan2(py - cy, px - cx) ' get the angle of the puck to the mouse

        px = px + speed * Cos(pa) ' move the puck out of the mouse paddle
        py = py + speed * Sin(pa) '
        sounds freq, timing
        _Display
    End If


    'keep puck out of wall = wall boundary +- radius of puck
    If px > 775 Then cscore = cscore + 1: _Delay .25: GoTo start:
    If px < 25 Then score = score + 1: _Delay .25: GoTo start:
    If py > 575 - pr Then sounds freq, timing: pa = -pa: py = 575 - pr ' move puck out of wall !!!
    If py < 25 + pr Then sounds freq, timing: pa = -pa: py = 25 + pr ' move puck out of wall !!!

    ' nove the puck along and draw it
    px = px + speed * Cos(pa) ' now move the puck along  it's new direction pa = puck angle
    py = py + speed * Sin(pa) '
    fillCircle px, py, pr, pc ' draw puck

    _Display
    _Limit 60 ' hold screen for moment

Loop

Sub sounds (freq, timing)
    Sound freq, timing
End Sub

'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
Reply
#10
Yeah sounds are great. Don't have to worry about speed after point score or end of game (Big Gong! would be great!).
b = b + ...
Reply




Users browsing this thread: 3 Guest(s)