Results 1 to 7 of 7

Thread: Pong

  1. #1

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372

    Pong

    Yes, it's yet another Pong Game.

    I'm writing a pong program for a VB course I'm doing. I've got the two paddles moving up and down in a picture box but how do I keep them from disappearing off the screen?

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Are you moving the ball using vectors,
    Code:
    X=X+A
    Y=Y+B
    Or using angles?
    Code:
    X=X+(Sin(Angle)*Speed)
    Y=Y+(Cos(Angle)*Speed)
    The first is easier (for starting anyway), you'd do something like this (example is for the top paddle (has the lowest y value as the origin is at the top left):
    X, Y is the position of the picbox (it's origin is also top left), and a and b are the speed vectors to add to them to create movement.
    VB Code:
    1. If Ball.Y < paddle.Y + paddle.Height And Ball.X + Ball.Width > paddle.X And Ball.X < paddle.X + paddle.Width Then
    2.     'Ball hit the paddle, so change it's y direction (a way from the paddle)
    3.     Ball.B = -Abs(Ball.B)
    4.     'Could manipulate the Ball.A value here according to where the ball hit the pad.
    5. End If

    Here is the code if you're using the angle & speed method:

    VB Code:
    1. If Ball.Y < paddle.Y + paddle.Height And Ball.X + Ball.Width > paddle.X And Ball.X < paddle.X + paddle.Width Then
    2.     Ball.Angle = 90-(Ball.Angle-270)
    3.     'Note: This will be different for all other collisions
    4. End If
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    For a lot more info, and stuff that will get you the best grade check out this thread:

    http://www.vbforums.com/showthread.p...hreadid=163044
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  4. #4

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    Thanks, I'll go check it out.

  5. #5

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    I have another little prob not covered by the other thread. I want to play a sound everytime the ball hits the walls. I've used this code:

    If BallX < 0 Then
    BallX = 0
    BallXDir = 1
    RtnValue = sndPlaySound(Bounce, SND_ASYNC Or SND_MEMORY)

    The sound has been stored here:

    Dim Buffer As String
    Dim F As Integer
    Dim SoundBuffer As String
    On Error GoTo NoiseGet_Error
    Buffer = Space(1024)
    SoundBuffer = ""
    F = FreeFile
    Open FileName For Binary As F
    Do While Not EOF(F)
    Get #F, , Buffer
    SoundBuffer = SoundBuffer & Buffer
    Loop
    Close F
    StoreSound = Trim(SoundBuffer)
    Exit Function
    NoiseGet_Error:
    SoundBuffer = ""
    Exit Function

    And in the form load:
    Bounce = StoreSound(App.Path + "Bounce.wav")

    I think I've declared everything I should:

    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Private Const SND_ASYNC = &H1
    Private Const SND_SYNC = &H0
    Private Const SND_MEMORY = &H4


    But the sound won't play. Can you see where I might have gone wrong? Maybe I left something out.

  6. #6
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    If the ball is changing direction correctly, then the problem is with your sound code, as i havn't used sound before i can't help you
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    OK, Thanks anyway

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width